Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] trivial work about setting layout data -- need improvements

Hi, guys:

As is known to everyone, we often use layout and layout data to show
our controls in a composite panel when using SWT, but don't you find
it's very trivial and boring to set the layout data?

Everytime we layout a control we have to create a new ***Data(e.g.
GridData) and set its prapameters in a proper way, and when we create
another control which have the same layout requirements, we then
always create a complete new ***Data and set it step by step, it's
boring and it sucks! The following is a simple example:

.................
Button btn1 = new Button(shell, SWT.PUSH);
GridData data = new GridData();
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
data.***=**
data.***=**
btn1.setLayoutData(data);
Button btn2 = new Button(shell, SWT.PUSH);
/* Then all the following steps are complete the same*/
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
data.***=**
data.***=**
btn2.setLayoutData(data);
................


So, I think SWT should provide a new way to do this work, for example,
SWT can provide a clone method to a layout data object , and when we
set another control, we just need to clone an old layout data object
and set some parameters if necessary, then this work could become
every easy. The above code may look like this:

...............
Button btn1 = new Button(shell, SWT.PUSH);
GridData data = new GridData();
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
data.***=**
data.***=**
btn1.setLayoutData(data);
Button btn2 = new Button(shell, SWT.PUSH);
/* more simple way to create a layout data*/
data = data.clone();
data.grabExcessHorizontalSpace = false; // just need to modify the
necessary parameters
btn2.setLayoutData(data);

.................

So, what a wonderful job!

I do not know why such a method doesn't exist in SWT and I want to do
some improvements , then I need you guys' good advices and directions
about this idea.

Many thanks!


Best wishes to everyone,
higer


Back to the top