public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); Composite c = new Composite(sc, SWT.NONE); c.setLayout(new GridLayout(10, true)); for (int i = 0; i < 300; i++) { Button b = new Button(c, SWT.PUSH); b.setText("Button " + i); } sc.setContent(c); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT)); sc.setShowFocusedControl(true); shell.setSize(300, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
/** Experimental. Switching themes at runtime does not yet work properly. */ protected void createThemeSwitcher(final Composite parent) { final Button button = new Button(parent, SWT.PUSH); button.setText("Theme Switcher"); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { Shell shell = new Shell(parent.getShell(), SWT.DIALOG_TRIM); shell.setText("Theme Switcher"); shell.setLayout(new GridLayout()); Button themeButton = new Button(shell, SWT.PUSH); themeButton.setText("Switch Theme"); themeButton.addSelectionListener( new SelectionAdapter() { String[] availableThemeIds = ThemeUtil.getAvailableThemeIds(); public void widgetSelected(final SelectionEvent e) { int index = 0; String currThemeId = ThemeUtil.getCurrentThemeId(); for (int i = 0; i < availableThemeIds.length; i++) { if (currThemeId.equals(availableThemeIds[i])) { index = (i + 1) % availableThemeIds.length; } } String newThemeId = availableThemeIds[index]; ThemeUtil.setCurrentThemeId(newThemeId); } }); shell.pack(); shell.open(); } }); }
/** * Creates a checkbox that controls whether a background image is set on the registered controls. * * @return the created checkbox */ protected Button createBgImageButton() { final Button button = new Button(styleComp, SWT.CHECK); button.setText("Background Image"); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { showBgImage = button.getSelection(); updateBgImage(); } }); return button; }
/** * Creates a button to change the background color of all registered controls. * * @return the created button */ protected Button createBgColorButton() { bgColorChooser = new ColorChooser(); final Button button = new Button(styleComp, SWT.PUSH); button.setText("Background"); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { bgIndex = (bgIndex + 1) % fgColors.length; updateBgColor(); } }); return button; }
/** * Creates a checkbutton to enable / disabled the registered controls. * * @return the created checkbutton. */ protected Button createEnablementButton() { final Button button = new Button(styleComp, SWT.CHECK); button.setText("Enabled"); button.setSelection(enabled); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { enabled = button.getSelection(); updateEnabled(); } }); return button; }
/** * Creates a checkbutton to show / hide the registered controls. * * @return the created checkbutton */ protected Button createVisibilityButton() { final Button button = new Button(styleComp, SWT.CHECK); button.setText("Visible"); button.setSelection(visible); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { visible = button.getSelection(); updateVisible(); } }); return button; }
protected Button createStyleButton(final String name, final int style, final boolean checked) { Button button = new Button(styleComp, SWT.CHECK); button.setText(name); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { createNew(); } }); button.setData("style", new Integer(style)); button.setSelection(checked); return button; }
void createRTFTransfer(Composite copyParent, Composite pasteParent) { // RTF Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("RTFTransfer:"); // $NON-NLS-1$ copyRtfText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); copyRtfText.setText("some\nrtf\ntext"); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; copyRtfText.setLayoutData(data); Button b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String data = copyRtfText.getText(); if (data.length() > 0) { status.setText(""); data = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i " + data + "}"; clipboard.setContents( new Object[] {data}, new Transfer[] {RTFTransfer.getInstance()}); } else { status.setText("nothing to copy"); } } }); l = new Label(pasteParent, SWT.NONE); l.setText("RTFTransfer:"); // $NON-NLS-1$ pasteRtfText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; pasteRtfText.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String data = (String) clipboard.getContents(RTFTransfer.getInstance()); if (data != null && data.length() > 0) { status.setText(""); pasteRtfText.setText("start paste>" + data + "<end paste"); } else { status.setText("nothing to paste"); } } }); }
void createHTMLTransfer(Composite copyParent, Composite pasteParent) { // HTML Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("HTMLTransfer:"); // $NON-NLS-1$ copyHtmlText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); copyHtmlText.setText("<b>Hello World</b>"); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; copyHtmlText.setLayoutData(data); Button b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String data = copyHtmlText.getText(); if (data.length() > 0) { status.setText(""); clipboard.setContents( new Object[] {data}, new Transfer[] {HTMLTransfer.getInstance()}); } else { status.setText("nothing to copy"); } } }); l = new Label(pasteParent, SWT.NONE); l.setText("HTMLTransfer:"); // $NON-NLS-1$ pasteHtmlText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; pasteHtmlText.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String data = (String) clipboard.getContents(HTMLTransfer.getInstance()); if (data != null && data.length() > 0) { status.setText(""); pasteHtmlText.setText("start paste>" + data + "<end paste"); } else { status.setText("nothing to paste"); } } }); }
void createAvailableTypes(Composite parent) { final List list = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_BOTH); data.heightHint = 100; list.setLayoutData(data); Button b = new Button(parent, SWT.PUSH); b.setText("Get Available Types"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { list.removeAll(); String[] names = clipboard.getAvailableTypeNames(); for (int i = 0; i < names.length; i++) { list.add(names[i]); } } }); }
protected Button createPropertyCheckbox( final String text, final String prop, final boolean checked) { final Button button = new Button(styleComp, SWT.CHECK); button.setText(text); button.setSelection(checked); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { if (button.getSelection()) { properties.add(prop); } else { properties.remove(prop); } createNew(); } }); return button; }
protected Button createFontChooser() { final Button button = new Button(styleComp, SWT.PUSH); button.setText("Font"); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { fontChooser = new SimpleFontDialog(getShell()); Control control = (Control) controls.get(0); fontChooser.setFont(control.getFont()); fontChooser.open( new Runnable() { public void run() { font = fontChooser.getFont(); updateFont(); } }); } }); return button; }
protected int getStyle() { int result = SWT.NONE; Control[] ctrls = styleComp.getChildren(); if (ctrls.length == 0) { result = defaultStyle; } else { for (int i = 0; i < ctrls.length; i++) { if (ctrls[i] instanceof Button) { Button button = (Button) ctrls[i]; if (button.getSelection()) { Object data = button.getData("style"); if (data instanceof Integer) { int style = ((Integer) data).intValue(); result |= style; } } } } } return result; }
/** Creates a text that controls whether a border radius is set on the registered controls. */ protected void cteateRoundedBorderGroup() { Group group = new Group(styleComp, SWT.NONE); group.setText("Rounded Border"); group.setLayout(new GridLayout(2, false)); new Label(group, SWT.NONE).setText("Width"); final Text textWidth = new Text(group, SWT.SINGLE | SWT.BORDER); textWidth.setLayoutData(new GridData(20, SWT.DEFAULT)); new Label(group, SWT.NONE).setText("Color"); final Button buttonColor = new Button(group, SWT.PUSH); buttonColor.setLayoutData(new GridData(20, 20)); buttonColor.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { rbIndex = (rbIndex + 1) % bgColors.length; if (bgColors[rbIndex] == null) { buttonColor.setText(""); } else { buttonColor.setText("\u2588"); } buttonColor.setForeground(bgColors[rbIndex]); } }); new Label(group, SWT.NONE).setText("Radius "); Composite radiusGroup = new Composite(group, SWT.NONE); radiusGroup.setLayout(new GridLayout(4, false)); new Label(radiusGroup, SWT.NONE).setText("T-L"); final Text textTopLeft = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER); textTopLeft.setLayoutData(new GridData(20, SWT.DEFAULT)); new Label(radiusGroup, SWT.NONE).setText("T-R"); final Text textTopRight = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER); textTopRight.setLayoutData(new GridData(20, SWT.DEFAULT)); new Label(radiusGroup, SWT.NONE).setText("B-L"); final Text textBottomLeft = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER); textBottomLeft.setLayoutData(new GridData(20, SWT.DEFAULT)); new Label(radiusGroup, SWT.NONE).setText("B-R"); final Text textBottomRight = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER); textBottomRight.setLayoutData(new GridData(20, SWT.DEFAULT)); Button button = new Button(group, SWT.PUSH); button.setText("Set"); button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { int width = parseInt(textWidth.getText()); Color color = buttonColor.getBackground(); int topLeft = parseInt(textTopLeft.getText()); int topRight = parseInt(textTopRight.getText()); int bottomRight = parseInt(textBottomRight.getText()); int bottomLeft = parseInt(textBottomLeft.getText()); updateRoundedBorder(width, color, topLeft, topRight, bottomRight, bottomLeft); } }); }
void createControlTransfer(Composite parent) { Label l = new Label(parent, SWT.NONE); l.setText("Text:"); Button b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.cut(); } }); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.copy(); } }); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.paste(); } }); text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; text.setLayoutData(data); l = new Label(parent, SWT.NONE); l.setText("Combo:"); b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { combo.cut(); } }); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { combo.copy(); } }); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { combo.paste(); } }); combo = new Combo(parent, SWT.NONE); combo.setItems(new String[] {"Item 1", "Item 2", "Item 3", "A longer Item"}); l = new Label(parent, SWT.NONE); l.setText("StyledText:"); l = new Label(parent, SWT.NONE); l.setVisible(false); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { styledText.copy(); } }); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { styledText.paste(); } }); styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; styledText.setLayoutData(data); }
void createFileTransfer(Composite copyParent, Composite pasteParent) { // File Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("FileTransfer:"); // $NON-NLS-1$ Composite c = new Composite(copyParent, SWT.NONE); c.setLayout(new GridLayout(2, false)); GridData data = new GridData(GridData.FILL_HORIZONTAL); c.setLayoutData(data); copyFileTable = new Table(c, SWT.MULTI | SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; data.horizontalSpan = 2; copyFileTable.setLayoutData(data); Button b = new Button(c, SWT.PUSH); b.setText("Select file(s)"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); String result = dialog.open(); if (result != null && result.length() > 0) { // copyFileTable.removeAll(); String separator = System.getProperty("file.separator"); String path = dialog.getFilterPath(); String[] names = dialog.getFileNames(); for (int i = 0; i < names.length; i++) { TableItem item = new TableItem(copyFileTable, SWT.NONE); item.setText(path + separator + names[i]); } } } }); b = new Button(c, SWT.PUSH); b.setText("Select directory"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN); String result = dialog.open(); if (result != null && result.length() > 0) { // copyFileTable.removeAll(); TableItem item = new TableItem(copyFileTable, SWT.NONE); item.setText(result); } } }); b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] items = copyFileTable.getItems(); if (items.length > 0) { status.setText(""); String[] data = new String[items.length]; for (int i = 0; i < data.length; i++) { data[i] = items[i].getText(); } clipboard.setContents( new Object[] {data}, new Transfer[] {FileTransfer.getInstance()}); } else { status.setText("nothing to copy"); } } }); l = new Label(pasteParent, SWT.NONE); l.setText("FileTransfer:"); // $NON-NLS-1$ pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; pasteFileTable.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String[] data = (String[]) clipboard.getContents(FileTransfer.getInstance()); if (data != null && data.length > 0) { status.setText(""); pasteFileTable.removeAll(); for (int i = 0; i < data.length; i++) { TableItem item = new TableItem(pasteFileTable, SWT.NONE); item.setText(data[i]); } } else { status.setText("nothing to paste"); } } }); }
protected Button createPropertyButton(final String text, final int style) { Button button = new Button(styleComp, style); button.setText(text); return button; }