...
Here is an extract from a basic TextEditor that shows how to use the JFace builder:
| No Format |
|---|
mainapp = jface.applicationWindow( title:"Groovy Text Editor", location:[100,100], size:[500, 300] ) { gridLayout gridLayout(numColumns:1) menuManager menuManager( text:"File" ) { action action ( text:"Exit", closure:{ mainapp.close() } ) } menuManager menuManager( text:"Edit" ) { action action ( text:"Cut", accelerator: SWT.MOD1 + (int) 'X', closure:{ handleCutCopy(); text.cut() } ) action action ( text:"Copy", accelerator: SWT.MOD1 + (int) 'C',closure:{ handleCutCopy(); text.copy() } ) action action ( text:"Paste", accelerator: SWT.MOD1 + (int) 'P',closure:{ text.paste() } ) separator separator() action action ( text:"Set Font", closure:{ setFont() } ) } toolBar toolBar( style:"none" ) { boldButton boldButton = toolItem(style:"check", toolTipText:"Bold") { image image( src:"src/examples/groovy/swt/examples/TextEditor/bold.png" ) onEvent onEvent(type:"Selection", closure:{setStyle(it.widget)}) } italicButton italicButton = toolItem(style:"check", toolTipText:"Italic") { image image( src:"src/examples/groovy/swt/examples/TextEditor/italic.png" ) onEvent onEvent(type:"Selection", closure:{setStyle(it.widget)}) } underlineButton underlineButton = toolItem(style:"check", toolTipText:"Underline") { image image( src:"src/examples/groovy/swt/examples/TextEditor/underline.png" ) onEvent onEvent(type:"Selection", closure:{setStyle(it.widget)}) } strikeoutButton strikeoutButton = toolItem(style:"check", toolTipText:"Strikeout") { image image( src:"src/examples/groovy/swt/examples/TextEditor/strikeout.png" ) onEvent onEvent(type:"Selection", closure:{setStyle(it.widget)}) } toolItem toolItem(style:"separator") toolItem toolItem(style:"push", toolTipText:"Red text") { image image( src:"src/examples/groovy/swt/examples/TextEditor/red.png" ) onEvent onEvent(type:"Selection", closure:{fgColor(RED)}) } toolItem toolItem(style:"push", toolTipText:"Blue text") { image image( src:"src/examples/groovy/swt/examples/TextEditor/blue.png" ) onEvent onEvent(type:"Selection", closure:{fgColor(BLUE)}) } toolItem toolItem(style:"push", toolTipText:"Green text") { image image( src:"src/examples/groovy/swt/examples/TextEditor/green.png" ) onEvent onEvent(type:"Selection", closure:{fgColor(GREEN)}) } toolItem toolItem(style:"separator") toolItem toolItem(style:"push", toolTipText:"Clear formatting") { image image( src:"src/examples/groovy/swt/examples/TextEditor/erase.png" ) onEvent onEvent(type:"Selection", closure:{clear()}) } } text } text = styledText ( style: "Border, Multi, V_Scroll, H_Scroll") { gridData gridData(horizontalAlignment: GridData.FILL, verticalAlignment: GridData.FILL, grabExcessHorizontalSpace: true, grabExcessVerticalSpace: true ) } text text.addExtendedModifyListener(this) } |
Simple isn't it? ![]()
For the complete code see subversion or the attached snapshot.