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

Hi higer,

If you use JFace, there is a GridDataFactory class that makes it
really easy to set this information.  It provides you will utility
methods to create and set all of the fields on GridData that you can
chain together and apply to a control i.e.

Button btn1 = new Button(shell, SWT.PUSH);
GridDataFactory.swtDefaults().grab(true,true).applyTo(btn1);

This sounds similar to what you are looking for.  There is still some
duplication, but it is shorter and easier to setup the layout data
than setting the fields directly.

Shawn

On Thu, Mar 4, 2010 at 7:22 PM, zhong nanhai <higerinbeijing@xxxxxxxxx> wrote:
> 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
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>



-- 
Shawn Minto
shawn.minto@xxxxxxxxxxx
Tasktop Technologies, Inc.
http://www.tasktop.com