SWT GUI Builder User Guide

 

Installation

 

System requirements: eclipse 2.1 or newer, JDK 1.4 or newer.

Unzip plugin zip file into eclipse/plugins folder. Restart eclipse.

 

 

Create new SWT GUI

 

Select New, Other

 

 

Select SGB File Wizards, Shell with Menues.

 

Type fully qualified class name and press finish.

 

SWT GUI Builder should open up.

 

 

 

Note: before running/debugging generated source file in eclipse, make sure swt.jar is on the classpath, and required shared library is passed in. Figures below show typical setup on Windows:

 

 

 

 

 

 

Open existing SWT GUI

 

Open context menu for java file and select Open SWT GUI Builder

 

 

 

 

Common Tasks How-to

 

Add components to a GUI:

1.      Activate Multi View window

2.      Select Component Group (Control, Composites, Complex, etc)

3.      Click on interested Control to select it

4.      Click on a composite in a tree view that will be a parent of new control

5.      Using context menu (mouse right click) or Component menu select Insert Selected or press Alt-Insert on a keyboard

Add components to a GUI (2):

1.      Activate Multi View window

2.      Click on composite in a tree view that will be a parent of new control

3.      Using context menu or Component menu select Insert Other

4.      Select component from the submenu to be added

Remove component:

1.      Activate Multi View window

2.      Select component to be removed by clicking on it in a tree view

3.      Using Component menu or context menu select Delete, or press Alt-Delete on a keyboard

Change component property:

1.      Activate Multi View window

2.      Click on Properties tab

3.      Select component in a tree view

4.      Change property in a properties view

Change component style:

1.      Activate Multi View window

2.      Click on Style tab

3.      Select component in a tree view

4.      Select/deselect style

Add/remove event:

1.      Activate Multi View window

2.      Click on Events tab

3.      Select component in a tree view

4.      Select/deselect event type

Rename component:

1.      Activate Multi View window

2.      Select component in a tree view

3.      Using Component menu or context menu select Rename, or press Alt-Enter on a keyboard

Rename component (2):

1.      Activate Multi View window

2.      Double click on a component in a tree view

Change ordering of components:

1.      Activate Multi View window

2.      Select component in a tree view

3.      Using Component menu or context menu select Move Up (Down), or press Alt-Up (Down) on a keyboard

Show component bounds:

1.      Activate Multi View window

2.      Select component in a tree view

3.      Using Component menu or context menu select Show

Show Dialog (Color, File, Print, etc.):

1.      Activate Multi View window

2.      Select dialog in a tree view

3.      Using Component menu or context menu select Show

Create a sibling of a component:

1.      Activate Multi View window

2.      Select component in a tree view

3.      Using Component menu or context menu select Duplicate, or press Alt-d on a keyboard

Change text property:

1.      Activate Multi View window

2.      Click on Properties tab

3.      Select component in a tree view

4.      Type in text then press Enter

Note: to insert tabs and new line character type \n or \t

Example: ‘first line\nsecond line\n\tthird line with tab’

Move/resize control:

1.      Select control in a tree view

2.      Type in new values into Bounds property or press ‘…’ to change bounds using mouse. To move component drag it. To resize component move cursor to the right bottom corner of the component (cursor should change from hand to resize) and then drag it.

Note: if parent of the control has layout, bounds property will be disabled

Set/modify layout:

1.      Select composite in a tree view

2.      Change layout property by selecting appropriate layout from the drop down

3.      Click on … to open Layout Editor.

 

 

Backparsing Overview

 

The SWT GUI Builder comes with recursive descent (top-down) parser. To make parser more efficient and to eliminate undesirable code changes, every file to be parsed must include special tags. The parser will only parse and modify content within those tags. Here is an example:

 

            // beginning of source code

            …

            …

 

            // START VISUALS_DECLARATION

            private Shell Shell_1 = null;

            private Display Display_1 = null;

            // END VISUALS_DECLARATION

 

            …

 

            private void createControls()

            {

                        …

 

                        // START VISUALS_INITIALIZATION

                        // init visuals

                        Display_1 = Display.getDefault();

                        Shell_1 = new Shell(Display_1, SWT.SHELL_TRIM);

                       

                        // set properties

                        Shell_1.setText("ABC");

                        Shell_1.setBounds(new Rectangle(424, 246, 217, 164));

                        Shell_1.setVisible(true);

                        // END VISUALS_INITIALIZATION

 

                        … 

 

                        // START EVENT_INITIALIZATION                       

                        Shell_1.addShellListener(new org.eclipse.swt.events.ShellAdapter()

                        {

                                    public void shellClosed(org.eclipse.swt.events.ShellEvent e)

                                    {

                                                Shell_1_shellClosed(e);

                                    }

                        });                   

                        // END EVENT_INITIALIZATION

           

                        …

}

           

            // START EVENT_HANDLING

            public void Shell_1_shellClosed(org.eclipse.swt.events.ShellEvent e)

            {

                        System.out.println("Shell_1_shellClosed: " + e );

            }

            // END EVENT_HANDLING

 

            …

…

// end of source code

 

Everything within 

// START VISUALS_DECLARATION

// END VISUALS_DECLARATION

and

// START VISUALS_INITIALIZATION

// END VISUALS_INITIALIZATION

and

// START EVENT_INITIALIZATION                       

// END EVENT_INITIALIZATION

will be modified by SGB (red background on diagram). It is not recommended to put user code within those tags. Generated code within

// START EVENT_HANDLING

// END EVENT_HANDLING

will never be modified (green background on diagram). It is save to put user event handling there. Those functions will never be removed even if event handler itself is removed.

 

Accepted source file grammar:

 

[ <PackageDeclaration> ]                                   

( <ImportDeclaration> )*

...

"class " <ID>

...

// START VISUALS_DECLARATION

(<Declaration>)*

// END VISUALS_DECLARATION

...

// START VISUALS_INITIALIZATION

(<Statement>)*

// END VISUALS_INITIALIZATION

...

// START EVENT_INITIALIZATION             

( <EventInit> )*

// END EVENT_INITIALIZATION

...

// START EVENT_HANDLING

...

// END EVENT_HANDLING

...

EOF

 

 

DECLARATION_BLOCK := ( <Declaration> )*

INITIALIZATION_BLOCK               := ( <Statement> )*

EVENT_INIT_BLOCK        := ( <EventInit> )*

 

Declaration := [ "public" | "private" | "protected" ] <TYPE> <ID> [ "=" "null" ] ";"

 

Statement :=          <AnonymousInit> |

                                [<TYPE>] <ID> "=" <Assignment> |

                                <SetMethod> |

                                <FieldSet> ";"

 

Assignment          := null | <AnonymousInit>

 

AnonymousInit    := "new" <TYPE> "(" <PARAMS> ")"

 

SetMethod            := <ID> ".set" <FUNC_NAME> "(" <PARAM> ")"

 

FieldSet := <ID> "." <FIELD_NAME> "=" <PARAM>

 

MethodCall           := <ID> "." <FUNC_NAME> "(" ")"

 

PARAM :=            INTEGER |

                                FLOAT |

                                BOOLEAN |

                                STRING                 |

                                CHARACTER       |

                                <ArrayInit>           |

                                <Assignment>      |

                                <MethodCall>      |

                                <OrParams>         

 

Params := [ <Param> ( "," <Param> )* ]

 

OrParams := ( <STATIC_FIELD> ("+" | "|") <CHARACTER> )+

 

TYPE := <ID> ( "." <ID>)*

 

STATIC_FIELD := <TYPE> "." <FIELD_NAME>

                               

EventInit :=           <ID> ".add" <FUNC_NAME> "(" "new" <TYPE> "(" ")"

                                "{"

                                                (

                                                "public" "void" <FUNC_NAME> "(" <PARAMS> ")"

                                                "{"

                                                                <FUNC_NAME> "(" <PARAMS> ")" ";"

                                                "}"

                                                )+

                               

                                "}" ")" ";"

 

ArrayInit := "new" <TYPE> "[" "]" "{" <Params> "}"

 

FUNC_NAME := <ID>