List of usage examples for org.eclipse.swt.widgets Composite Composite
public Composite(Composite parent, int style)
From source file:PaintExample.java
/** * Handles a mouseDown event./* w ww. jav a 2 s .c o m*/ * * @param event the mouse event detail information */ public void mouseDown(MouseEvent event) { if (event.button == 1) { // draw with left mouse button getPaintSurface().commitRubberbandSelection(); } else { // set text with right mouse button getPaintSurface().clearRubberbandSelection(); Shell shell = getPaintSurface().getShell(); final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setText(PaintExample.getResourceString("tool.Text.dialog.title")); dialog.setLayout(new GridLayout()); Label label = new Label(dialog, SWT.NONE); label.setText(PaintExample.getResourceString("tool.Text.dialog.message")); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); final Text field = new Text(dialog, SWT.SINGLE | SWT.BORDER); field.setText(drawText); field.selectAll(); field.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Composite buttons = new Composite(dialog, SWT.NONE); GridLayout layout = new GridLayout(2, true); layout.marginWidth = 0; buttons.setLayout(layout); buttons.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); Button ok = new Button(buttons, SWT.PUSH); ok.setText(PaintExample.getResourceString("OK")); ok.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); ok.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { drawText = field.getText(); dialog.dispose(); } }); Button cancel = new Button(buttons, SWT.PUSH); cancel.setText(PaintExample.getResourceString("Cancel")); cancel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { dialog.dispose(); } }); dialog.setDefaultButton(ok); dialog.pack(); dialog.open(); Display display = dialog.getDisplay(); while (!shell.isDisposed() && !dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }
From source file:org.eclipse.swt.examples.fileviewer.FileViewer.java
/** * Creates the file details table.// w w w . j a v a 2s. c o m * * @param parent the parent control */ private void createTableView(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 1; gridLayout.marginHeight = gridLayout.marginWidth = 2; gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0; composite.setLayout(gridLayout); tableContentsOfLabel = new Label(composite, SWT.BORDER); tableContentsOfLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); table = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); for (int i = 0; i < tableTitles.length; ++i) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(tableTitles[i]); column.setWidth(tableWidths[i]); } table.setHeaderVisible(true); table.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { notifySelectedFiles(getSelectedFiles()); } @Override public void widgetDefaultSelected(SelectionEvent event) { doDefaultFileAction(getSelectedFiles()); } private File[] getSelectedFiles() { final TableItem[] items = table.getSelection(); final File[] files = new File[items.length]; for (int i = 0; i < items.length; ++i) { files[i] = (File) items[i].getData(TABLEITEMDATA_FILE); } return files; } }); createTableDragSource(table); createTableDropTarget(table); }
From source file:SWTFileViewerDemo.java
/** * Creates the file details table./* w ww . j a v a 2 s . c om*/ * * @param parent * the parent control */ private void createTableView(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 1; gridLayout.marginHeight = gridLayout.marginWidth = 2; gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0; composite.setLayout(gridLayout); tableContentsOfLabel = new Label(composite, SWT.BORDER); tableContentsOfLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); table = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); for (int i = 0; i < tableTitles.length; ++i) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(tableTitles[i]); column.setWidth(tableWidths[i]); } table.setHeaderVisible(true); table.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { notifySelectedFiles(getSelectedFiles()); } public void widgetDefaultSelected(SelectionEvent event) { doDefaultFileAction(getSelectedFiles()); } private File[] getSelectedFiles() { final TableItem[] items = table.getSelection(); final File[] files = new File[items.length]; for (int i = 0; i < items.length; ++i) { files[i] = (File) items[i].getData(TABLEITEMDATA_FILE); } return files; } }); createTableDragSource(table); createTableDropTarget(table); }
From source file:SWTAddressBook.java
/** * Class constructor that sets the parent shell and the table widget that * the dialog will search./*from ww w . ja v a2s .co m*/ * * @param parent * Shell The shell that is the parent of the dialog. */ public SearchDialog(Shell parent) { shell = new Shell(parent, SWT.CLOSE | SWT.BORDER | SWT.TITLE); GridLayout layout = new GridLayout(); layout.numColumns = 2; shell.setLayout(layout); shell.setText("Search"); shell.addShellListener(new ShellAdapter() { public void shellClosed(ShellEvent e) { // don't dispose of the shell, just hide it for later use e.doit = false; shell.setVisible(false); } }); Label label = new Label(shell, SWT.LEFT); label.setText("Dialog_find_what"); searchText = new Text(shell, SWT.BORDER); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.widthHint = 200; searchText.setLayoutData(gridData); searchText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { boolean enableFind = (searchText.getCharCount() != 0); findButton.setEnabled(enableFind); } }); searchAreaLabel = new Label(shell, SWT.LEFT); searchArea = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.widthHint = 200; searchArea.setLayoutData(gridData); matchCase = new Button(shell, SWT.CHECK); matchCase.setText("Dialog_match_case"); gridData = new GridData(); gridData.horizontalSpan = 2; matchCase.setLayoutData(gridData); matchWord = new Button(shell, SWT.CHECK); matchWord.setText("Dialog_match_word"); gridData = new GridData(); gridData.horizontalSpan = 2; matchWord.setLayoutData(gridData); Group direction = new Group(shell, SWT.NONE); gridData = new GridData(); gridData.horizontalSpan = 2; direction.setLayoutData(gridData); direction.setLayout(new FillLayout()); direction.setText("Dialog_direction"); Button up = new Button(direction, SWT.RADIO); up.setText("Dialog_dir_up"); up.setSelection(false); down = new Button(direction, SWT.RADIO); down.setText("Dialog_dir_down"); down.setSelection(true); Composite composite = new Composite(shell, SWT.NONE); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 2; composite.setLayoutData(gridData); layout = new GridLayout(); layout.numColumns = 2; layout.makeColumnsEqualWidth = true; composite.setLayout(layout); findButton = new Button(composite, SWT.PUSH); findButton.setText("Dialog_find"); findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); findButton.setEnabled(false); findButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (!findHandler.find()) { MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL); box.setText(shell.getText()); box.setMessage("Cannot_find" + "\"" + searchText.getText() + "\""); box.open(); } } }); Button cancelButton = new Button(composite, SWT.PUSH); cancelButton.setText("Cancel"); cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.setVisible(false); } }); shell.pack(); }
From source file:org.eclipse.swt.examples.texteditor.TextEditor.java
void createToolBar() { coolBar = new CoolBar(shell, SWT.FLAT); ToolBar styleToolBar = new ToolBar(coolBar, SWT.FLAT); boldControl = new ToolItem(styleToolBar, SWT.CHECK); boldControl.setImage(iBold);//w w w . j a v a 2 s . c om boldControl.setToolTipText(getResourceString("Bold")); //$NON-NLS-1$ boldControl.addSelectionListener(widgetSelectedAdapter(event -> setStyle(BOLD))); italicControl = new ToolItem(styleToolBar, SWT.CHECK); italicControl.setImage(iItalic); italicControl.setToolTipText(getResourceString("Italic")); //$NON-NLS-1$ italicControl.addSelectionListener(widgetSelectedAdapter(event -> setStyle(ITALIC))); final Menu underlineMenu = new Menu(shell, SWT.POP_UP); underlineSingleItem = new MenuItem(underlineMenu, SWT.RADIO); underlineSingleItem.setText(getResourceString("Single_menuitem")); //$NON-NLS-1$ underlineSingleItem.addSelectionListener(widgetSelectedAdapter(event -> { if (underlineSingleItem.getSelection()) { setStyle(UNDERLINE_SINGLE); } })); underlineSingleItem.setSelection(true); underlineDoubleItem = new MenuItem(underlineMenu, SWT.RADIO); underlineDoubleItem.setText(getResourceString("Double_menuitem")); //$NON-NLS-1$ underlineDoubleItem.addSelectionListener(widgetSelectedAdapter(event -> { if (underlineDoubleItem.getSelection()) { setStyle(UNDERLINE_DOUBLE); } })); underlineSquiggleItem = new MenuItem(underlineMenu, SWT.RADIO); underlineSquiggleItem.setText(getResourceString("Squiggle_menuitem")); //$NON-NLS-1$ underlineSquiggleItem.addSelectionListener(widgetSelectedAdapter(event -> { if (underlineSquiggleItem.getSelection()) { setStyle(UNDERLINE_SQUIGGLE); } })); underlineErrorItem = new MenuItem(underlineMenu, SWT.RADIO); underlineErrorItem.setText(getResourceString("Error_menuitem")); //$NON-NLS-1$ underlineErrorItem.addSelectionListener(widgetSelectedAdapter(event -> { if (underlineErrorItem.getSelection()) { setStyle(UNDERLINE_ERROR); } })); MenuItem underlineColorItem = new MenuItem(underlineMenu, SWT.PUSH); underlineColorItem.setText(getResourceString("Color_menuitem")); //$NON-NLS-1$ underlineColorItem.addSelectionListener(widgetSelectedAdapter(event -> { ColorDialog dialog = new ColorDialog(shell); RGB rgb = underlineColor != null ? underlineColor.getRGB() : null; dialog.setRGB(rgb); RGB newRgb = dialog.open(); if (newRgb != null) { if (!newRgb.equals(rgb)) { disposeResource(underlineColor); underlineColor = new Color(display, newRgb); } if (underlineSingleItem.getSelection()) setStyle(UNDERLINE_SINGLE); else if (underlineDoubleItem.getSelection()) setStyle(UNDERLINE_DOUBLE); else if (underlineErrorItem.getSelection()) setStyle(UNDERLINE_ERROR); else if (underlineSquiggleItem.getSelection()) setStyle(UNDERLINE_SQUIGGLE); } })); final ToolItem underlineControl = new ToolItem(styleToolBar, SWT.DROP_DOWN); underlineControl.setImage(iUnderline); underlineControl.setToolTipText(getResourceString("Underline")); //$NON-NLS-1$ underlineControl.addSelectionListener(widgetSelectedAdapter(event -> { if (event.detail == SWT.ARROW) { Rectangle rect = underlineControl.getBounds(); Point pt = new Point(rect.x, rect.y + rect.height); underlineMenu.setLocation(display.map(underlineControl.getParent(), null, pt)); underlineMenu.setVisible(true); } else { if (underlineSingleItem.getSelection()) setStyle(UNDERLINE_SINGLE); else if (underlineDoubleItem.getSelection()) setStyle(UNDERLINE_DOUBLE); else if (underlineErrorItem.getSelection()) setStyle(UNDERLINE_ERROR); else if (underlineSquiggleItem.getSelection()) setStyle(UNDERLINE_SQUIGGLE); } })); ToolItem strikeoutControl = new ToolItem(styleToolBar, SWT.DROP_DOWN); strikeoutControl.setImage(iStrikeout); strikeoutControl.setToolTipText(getResourceString("Strikeout")); //$NON-NLS-1$ strikeoutControl.addSelectionListener(widgetSelectedAdapter(event -> { if (event.detail == SWT.ARROW) { ColorDialog dialog = new ColorDialog(shell); RGB rgb = strikeoutColor != null ? strikeoutColor.getRGB() : null; dialog.setRGB(rgb); RGB newRgb = dialog.open(); if (newRgb == null) return; if (!newRgb.equals(rgb)) { disposeResource(strikeoutColor); strikeoutColor = new Color(display, newRgb); } } setStyle(STRIKEOUT); })); final Menu borderMenu = new Menu(shell, SWT.POP_UP); borderSolidItem = new MenuItem(borderMenu, SWT.RADIO); borderSolidItem.setText(getResourceString("Solid")); //$NON-NLS-1$ borderSolidItem.addSelectionListener(widgetSelectedAdapter(event -> { if (borderSolidItem.getSelection()) { setStyle(BORDER_SOLID); } })); borderSolidItem.setSelection(true); borderDashItem = new MenuItem(borderMenu, SWT.RADIO); borderDashItem.setText(getResourceString("Dash")); //$NON-NLS-1$ borderDashItem.addSelectionListener(widgetSelectedAdapter(event -> { if (borderDashItem.getSelection()) { setStyle(BORDER_DASH); } })); borderDotItem = new MenuItem(borderMenu, SWT.RADIO); borderDotItem.setText(getResourceString("Dot")); //$NON-NLS-1$ borderDotItem.addSelectionListener(widgetSelectedAdapter(event -> { if (borderDotItem.getSelection()) { setStyle(BORDER_DOT); } })); MenuItem borderColorItem = new MenuItem(borderMenu, SWT.PUSH); borderColorItem.setText(getResourceString("Color_menuitem")); //$NON-NLS-1$ borderColorItem.addSelectionListener(widgetSelectedAdapter(event -> { ColorDialog dialog = new ColorDialog(shell); RGB rgb = borderColor != null ? borderColor.getRGB() : null; dialog.setRGB(rgb); RGB newRgb = dialog.open(); if (newRgb != null) { if (!newRgb.equals(rgb)) { disposeResource(borderColor); borderColor = new Color(display, newRgb); } if (borderDashItem.getSelection()) setStyle(BORDER_DASH); else if (borderDotItem.getSelection()) setStyle(BORDER_DOT); else if (borderSolidItem.getSelection()) setStyle(BORDER_SOLID); } })); final ToolItem borderControl = new ToolItem(styleToolBar, SWT.DROP_DOWN); borderControl.setImage(iBorderStyle); borderControl.setToolTipText(getResourceString("Box")); //$NON-NLS-1$ borderControl.addSelectionListener(widgetSelectedAdapter(event -> { if (event.detail == SWT.ARROW) { Rectangle rect = borderControl.getBounds(); Point pt = new Point(rect.x, rect.y + rect.height); borderMenu.setLocation(display.map(borderControl.getParent(), null, pt)); borderMenu.setVisible(true); } else { if (borderDashItem.getSelection()) setStyle(BORDER_DASH); else if (borderDotItem.getSelection()) setStyle(BORDER_DOT); else if (borderSolidItem.getSelection()) setStyle(BORDER_SOLID); } })); ToolItem foregroundItem = new ToolItem(styleToolBar, SWT.DROP_DOWN); foregroundItem.setImage(iTextForeground); foregroundItem.setToolTipText(getResourceString("TextForeground")); //$NON-NLS-1$ foregroundItem.addSelectionListener(widgetSelectedAdapter(event -> { if (event.detail == SWT.ARROW || textForeground == null) { ColorDialog dialog = new ColorDialog(shell); RGB rgb = textForeground != null ? textForeground.getRGB() : null; dialog.setRGB(rgb); RGB newRgb = dialog.open(); if (newRgb == null) return; if (!newRgb.equals(rgb)) { disposeResource(textForeground); textForeground = new Color(display, newRgb); } } setStyle(FOREGROUND); })); ToolItem backgroundItem = new ToolItem(styleToolBar, SWT.DROP_DOWN); backgroundItem.setImage(iTextBackground); backgroundItem.setToolTipText(getResourceString("TextBackground")); //$NON-NLS-1$ backgroundItem.addSelectionListener(widgetSelectedAdapter(event -> { if (event.detail == SWT.ARROW || textBackground == null) { ColorDialog dialog = new ColorDialog(shell); RGB rgb = textBackground != null ? textBackground.getRGB() : null; dialog.setRGB(rgb); RGB newRgb = dialog.open(); if (newRgb == null) return; if (!newRgb.equals(rgb)) { disposeResource(textBackground); textBackground = new Color(display, newRgb); } } setStyle(BACKGROUND); })); ToolItem baselineUpItem = new ToolItem(styleToolBar, SWT.PUSH); baselineUpItem.setImage(iBaselineUp); String tooltip = "IncreaseFont"; //$NON-NLS-1$ if (USE_BASELINE) tooltip = "IncreaseBaseline"; //$NON-NLS-1$ baselineUpItem.setToolTipText(getResourceString(tooltip)); baselineUpItem.addSelectionListener(widgetSelectedAdapter(event -> { if (USE_BASELINE) { setStyle(BASELINE_UP); } else { adjustFontSize(1); } })); ToolItem baselineDownItem = new ToolItem(styleToolBar, SWT.PUSH); baselineDownItem.setImage(iBaselineDown); tooltip = "DecreaseFont"; //$NON-NLS-1$ if (USE_BASELINE) tooltip = "DecreaseBaseline"; //$NON-NLS-1$ baselineDownItem.setToolTipText(getResourceString(tooltip)); baselineDownItem.addSelectionListener(widgetSelectedAdapter(event -> { if (USE_BASELINE) { setStyle(BASELINE_DOWN); } else { adjustFontSize(-1); } })); ToolItem linkItem = new ToolItem(styleToolBar, SWT.PUSH); linkItem.setImage(iLink); linkItem.setToolTipText(getResourceString("Link")); //$NON-NLS-1$ linkItem.addSelectionListener(widgetSelectedAdapter(event -> setLink())); CoolItem coolItem = new CoolItem(coolBar, SWT.NONE); coolItem.setControl(styleToolBar); Composite composite = new Composite(coolBar, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 1; composite.setLayout(layout); fontNameControl = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); fontNameControl.setItems(getFontNames()); fontNameControl.setVisibleItemCount(12); fontSizeControl = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); fontSizeControl.setItems(FONT_SIZES); fontSizeControl.setVisibleItemCount(8); SelectionListener adapter = widgetSelectedAdapter(event -> { String name = fontNameControl.getText(); int size = Integer.parseInt(fontSizeControl.getText()); disposeResource(textFont); textFont = new Font(display, name, size, SWT.NORMAL); setStyle(FONT); }); fontSizeControl.addSelectionListener(adapter); fontNameControl.addSelectionListener(adapter); coolItem = new CoolItem(coolBar, SWT.NONE); coolItem.setControl(composite); ToolBar alignmentToolBar = new ToolBar(coolBar, SWT.FLAT); blockSelectionItem = new ToolItem(alignmentToolBar, SWT.CHECK); blockSelectionItem.setImage(iBlockSelection); blockSelectionItem.setToolTipText(getResourceString("BlockSelection")); //$NON-NLS-1$ blockSelectionItem.addSelectionListener( widgetSelectedAdapter(event -> styledText.invokeAction(ST.TOGGLE_BLOCKSELECTION))); leftAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO); leftAlignmentItem.setImage(iLeftAlignment); leftAlignmentItem.setToolTipText(getResourceString("AlignLeft")); //$NON-NLS-1$ leftAlignmentItem.setSelection(true); leftAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> { Point selection = styledText.getSelection(); int lineStart = styledText.getLineAtOffset(selection.x); int lineEnd = styledText.getLineAtOffset(selection.y); styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.LEFT); })); leftAlignmentItem.setEnabled(false); centerAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO); centerAlignmentItem.setImage(iCenterAlignment); centerAlignmentItem.setToolTipText(getResourceString("Center_menuitem")); //$NON-NLS-1$ centerAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> { Point selection = styledText.getSelection(); int lineStart = styledText.getLineAtOffset(selection.x); int lineEnd = styledText.getLineAtOffset(selection.y); styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.CENTER); })); centerAlignmentItem.setEnabled(false); rightAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO); rightAlignmentItem.setImage(iRightAlignment); rightAlignmentItem.setToolTipText(getResourceString("AlignRight")); //$NON-NLS-1$ rightAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> { Point selection = styledText.getSelection(); int lineStart = styledText.getLineAtOffset(selection.x); int lineEnd = styledText.getLineAtOffset(selection.y); styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.RIGHT); })); rightAlignmentItem.setEnabled(false); justifyAlignmentItem = new ToolItem(alignmentToolBar, SWT.CHECK); justifyAlignmentItem.setImage(iJustifyAlignment); justifyAlignmentItem.setToolTipText(getResourceString("Justify")); //$NON-NLS-1$ justifyAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> { Point selection = styledText.getSelection(); int lineStart = styledText.getLineAtOffset(selection.x); int lineEnd = styledText.getLineAtOffset(selection.y); styledText.setLineJustify(lineStart, lineEnd - lineStart + 1, justifyAlignmentItem.getSelection()); })); justifyAlignmentItem.setEnabled(false); ToolItem bulletListItem = new ToolItem(alignmentToolBar, SWT.PUSH); bulletListItem.setImage(iBulletList); bulletListItem.setToolTipText(getResourceString("BulletList")); //$NON-NLS-1$ bulletListItem.addSelectionListener(widgetSelectedAdapter(event -> setBullet(ST.BULLET_DOT))); ToolItem numberedListItem = new ToolItem(alignmentToolBar, SWT.PUSH); numberedListItem.setImage(iNumberedList); numberedListItem.setToolTipText(getResourceString("NumberedList")); //$NON-NLS-1$ numberedListItem .addSelectionListener(widgetSelectedAdapter(event -> setBullet(ST.BULLET_NUMBER | ST.BULLET_TEXT))); coolItem = new CoolItem(coolBar, SWT.NONE); coolItem.setControl(alignmentToolBar); composite = new Composite(coolBar, SWT.NONE); layout = new GridLayout(4, false); layout.marginHeight = 1; composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setText(getResourceString("Indent")); //$NON-NLS-1$ Spinner indent = new Spinner(composite, SWT.BORDER); indent.addSelectionListener(widgetSelectedAdapter(event -> { Spinner spinner = (Spinner) event.widget; styledText.setIndent(spinner.getSelection()); })); label = new Label(composite, SWT.NONE); label.setText(getResourceString("Spacing")); //$NON-NLS-1$ Spinner spacing = new Spinner(composite, SWT.BORDER); spacing.addSelectionListener(widgetSelectedAdapter(event -> { Spinner spinner = (Spinner) event.widget; styledText.setLineSpacing(spinner.getSelection()); })); coolItem = new CoolItem(coolBar, SWT.NONE); coolItem.setControl(composite); // Button to toggle Mouse Navigator in StyledText composite = new Composite(coolBar, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button mouseNavigator = new Button(composite, SWT.CHECK); mouseNavigator.setText(getResourceString("MouseNav")); mouseNavigator.addSelectionListener( widgetSelectedAdapter(event -> styledText.setMouseNavigatorEnabled(mouseNavigator.getSelection()))); coolItem = new CoolItem(coolBar, SWT.NONE); coolItem.setControl(composite); // Compute Size for various CoolItems CoolItem[] coolItems = coolBar.getItems(); for (CoolItem item : coolItems) { Control control = item.getControl(); Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT); item.setMinimumSize(size); size = item.computeSize(size.x, size.y); item.setPreferredSize(size); item.setSize(size); } coolBar.addControlListener(ControlListener.controlResizedAdapter(event -> handleResize(event))); }
From source file:SWTAddressBook.java
private void createControlButtons() { Composite composite = new Composite(shell, SWT.NULL); composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); GridLayout layout = new GridLayout(); layout.numColumns = 2;/* w w w . ja v a 2 s .c om*/ composite.setLayout(layout); Button okButton = new Button(composite, SWT.PUSH); okButton.setText("OK"); okButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.close(); } }); Button cancelButton = new Button(composite, SWT.PUSH); cancelButton.setText("Cancel"); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { values = null; shell.close(); } }); shell.setDefaultButton(okButton); }
From source file:SWTAddressBook.java
private void createTextWidgets() { if (labels == null) return;/* www . j a v a 2 s . c o m*/ Composite composite = new Composite(shell, SWT.NULL); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = new GridLayout(); layout.numColumns = 2; composite.setLayout(layout); if (values == null) values = new String[labels.length]; for (int i = 0; i < labels.length; i++) { Label label = new Label(composite, SWT.RIGHT); label.setText(labels[i]); Text text = new Text(composite, SWT.BORDER); GridData gridData = new GridData(); gridData.widthHint = 400; text.setLayoutData(gridData); if (values[i] != null) { text.setText(values[i]); } text.setData("index", new Integer(i)); addTextListener(text); } }
From source file:DNDExample.java
public void open(Display display) { Shell shell = new Shell(display); shell.setText("Drag and Drop Example"); shell.setLayout(new FillLayout()); ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); Composite parent = new Composite(sc, SWT.NONE); sc.setContent(parent);//from w w w . ja v a 2s .co m parent.setLayout(new FormLayout()); Label dragLabel = new Label(parent, SWT.LEFT); dragLabel.setText("Drag Source:"); Group dragWidgetGroup = new Group(parent, SWT.NONE); dragWidgetGroup.setText("Widget"); createDragWidget(dragWidgetGroup); Composite cLeft = new Composite(parent, SWT.NONE); cLeft.setLayout(new GridLayout(2, false)); Group dragOperationsGroup = new Group(cLeft, SWT.NONE); dragOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1)); dragOperationsGroup.setText("Allowed Operation(s):"); createDragOperations(dragOperationsGroup); Group dragTypesGroup = new Group(cLeft, SWT.NONE); dragTypesGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); dragTypesGroup.setText("Transfer Type(s):"); createDragTypes(dragTypesGroup); dragConsole = new Text(cLeft, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI); dragConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); Menu menu = new Menu(shell, SWT.POP_UP); MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText("Clear"); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { dragConsole.setText(""); } }); item = new MenuItem(menu, SWT.CHECK); item.setText("Show Event detail"); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { MenuItem item = (MenuItem) e.widget; dragEventDetail = item.getSelection(); } }); dragConsole.setMenu(menu); Label dropLabel = new Label(parent, SWT.LEFT); dropLabel.setText("Drop Target:"); Group dropWidgetGroup = new Group(parent, SWT.NONE); dropWidgetGroup.setText("Widget"); createDropWidget(dropWidgetGroup); Composite cRight = new Composite(parent, SWT.NONE); cRight.setLayout(new GridLayout(2, false)); Group dropOperationsGroup = new Group(cRight, SWT.NONE); dropOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 2)); dropOperationsGroup.setText("Allowed Operation(s):"); createDropOperations(dropOperationsGroup); Group dropTypesGroup = new Group(cRight, SWT.NONE); dropTypesGroup.setText("Transfer Type(s):"); createDropTypes(dropTypesGroup); Group feedbackTypesGroup = new Group(cRight, SWT.NONE); feedbackTypesGroup.setText("Feedback Type(s):"); createFeedbackTypes(feedbackTypesGroup); dropConsole = new Text(cRight, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI); dropConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); menu = new Menu(shell, SWT.POP_UP); item = new MenuItem(menu, SWT.PUSH); item.setText("Clear"); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { dropConsole.setText(""); } }); item = new MenuItem(menu, SWT.CHECK); item.setText("Show Event detail"); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { MenuItem item = (MenuItem) e.widget; dropEventDetail = item.getSelection(); } }); dropConsole.setMenu(menu); int height = 200; FormData data = new FormData(); data.top = new FormAttachment(0, 10); data.left = new FormAttachment(0, 10); dragLabel.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(dragLabel, 10); data.left = new FormAttachment(0, 10); data.right = new FormAttachment(50, -10); data.height = height; dragWidgetGroup.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(dragWidgetGroup, 10); data.left = new FormAttachment(0, 10); data.right = new FormAttachment(50, -10); data.bottom = new FormAttachment(100, -10); cLeft.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(0, 10); data.left = new FormAttachment(cLeft, 10); dropLabel.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(dropLabel, 10); data.left = new FormAttachment(cLeft, 10); data.right = new FormAttachment(100, -10); data.height = height; dropWidgetGroup.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(dropWidgetGroup, 10); data.left = new FormAttachment(cLeft, 10); data.right = new FormAttachment(100, -10); data.bottom = new FormAttachment(100, -10); cRight.setLayoutData(data); sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); sc.setExpandHorizontal(true); sc.setExpandVertical(true); Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle monitorArea = shell.getMonitor().getClientArea(); shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
From source file:com.bdaum.zoom.report.internal.wizards.ReportComponent.java
public ReportComponent(Composite parent, int style, int preview) { super(parent, style); this.preview = preview; setLayout(new FillLayout()); stack = new Composite(this, SWT.NONE); stackLayout = new StackLayout(); stack.setLayout(stackLayout);/* ww w. j av a 2 s . com*/ chartComposite = new ChartComposite(stack, SWT.NONE, null, preview == Integer.MAX_VALUE, preview == Integer.MAX_VALUE, preview == Integer.MAX_VALUE, preview == Integer.MAX_VALUE, preview == Integer.MAX_VALUE); chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); pendingComp = new Composite(stack, SWT.NONE); pendingComp.setLayout(new GridLayout(1, false)); Label label = new Label(pendingComp, SWT.NONE); label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true)); label.setText(Messages.ReportPage_pending); if (preview == Integer.MAX_VALUE) { progressBar = new ProgressIndicator(pendingComp, SWT.BORDER); GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); data.heightHint = PROGRESS_THICKNESS; progressBar.setLayoutData(data); } stackLayout.topControl = pendingComp; }
From source file:org.eclipse.swt.examples.dnd.DNDExample.java
public void open(Display display) { Shell shell = new Shell(display); shell.setText("Drag and Drop Example"); shell.setLayout(new FillLayout()); itemImage = new Image(display, DNDExample.class.getResourceAsStream("openFolder.gif")); ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); Composite parent = new Composite(sc, SWT.NONE); sc.setContent(parent);// ww w . ja va 2 s . c om parent.setLayout(new FormLayout()); Label dragLabel = new Label(parent, SWT.LEFT); dragLabel.setText("Drag Source:"); Group dragWidgetGroup = new Group(parent, SWT.NONE); dragWidgetGroup.setText("Widget"); createDragWidget(dragWidgetGroup); Composite cLeft = new Composite(parent, SWT.NONE); cLeft.setLayout(new GridLayout(2, false)); Group dragOperationsGroup = new Group(cLeft, SWT.NONE); dragOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1)); dragOperationsGroup.setText("Allowed Operation(s):"); createDragOperations(dragOperationsGroup); Group dragTypesGroup = new Group(cLeft, SWT.NONE); dragTypesGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); dragTypesGroup.setText("Transfer Type(s):"); createDragTypes(dragTypesGroup); dragConsole = new Text(cLeft, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI); dragConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); Menu menu = new Menu(shell, SWT.POP_UP); MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText("Clear"); item.addSelectionListener(widgetSelectedAdapter(e -> dragConsole.setText(""))); item = new MenuItem(menu, SWT.CHECK); item.setText("Show Event detail"); item.addSelectionListener(widgetSelectedAdapter(e -> { MenuItem eItem = (MenuItem) e.widget; dragEventDetail = eItem.getSelection(); })); dragConsole.setMenu(menu); Label dropLabel = new Label(parent, SWT.LEFT); dropLabel.setText("Drop Target:"); Group dropWidgetGroup = new Group(parent, SWT.NONE); dropWidgetGroup.setText("Widget"); createDropWidget(dropWidgetGroup); Composite cRight = new Composite(parent, SWT.NONE); cRight.setLayout(new GridLayout(2, false)); Group dropOperationsGroup = new Group(cRight, SWT.NONE); dropOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 2)); dropOperationsGroup.setText("Allowed Operation(s):"); createDropOperations(dropOperationsGroup); Group dropTypesGroup = new Group(cRight, SWT.NONE); dropTypesGroup.setText("Transfer Type(s):"); createDropTypes(dropTypesGroup); Group feedbackTypesGroup = new Group(cRight, SWT.NONE); feedbackTypesGroup.setText("Feedback Type(s):"); createFeedbackTypes(feedbackTypesGroup); dropConsole = new Text(cRight, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI); dropConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); menu = new Menu(shell, SWT.POP_UP); item = new MenuItem(menu, SWT.PUSH); item.setText("Clear"); item.addSelectionListener(widgetSelectedAdapter(e -> dropConsole.setText(""))); item = new MenuItem(menu, SWT.CHECK); item.setText("Show Event detail"); item.addSelectionListener(widgetSelectedAdapter(e -> { MenuItem eItem = (MenuItem) e.widget; dropEventDetail = eItem.getSelection(); })); dropConsole.setMenu(menu); if (dragEnabled) createDragSource(); if (dropEnabled) createDropTarget(); int height = 200; FormData data = new FormData(); data.top = new FormAttachment(0, 10); data.left = new FormAttachment(0, 10); dragLabel.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(dragLabel, 10); data.left = new FormAttachment(0, 10); data.right = new FormAttachment(50, -10); data.height = height; dragWidgetGroup.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(dragWidgetGroup, 10); data.left = new FormAttachment(0, 10); data.right = new FormAttachment(50, -10); data.bottom = new FormAttachment(100, -10); cLeft.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(0, 10); data.left = new FormAttachment(cLeft, 10); dropLabel.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(dropLabel, 10); data.left = new FormAttachment(cLeft, 10); data.right = new FormAttachment(100, -10); data.height = height; dropWidgetGroup.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(dropWidgetGroup, 10); data.left = new FormAttachment(cLeft, 10); data.right = new FormAttachment(100, -10); data.bottom = new FormAttachment(100, -10); cRight.setLayoutData(data); sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); sc.setExpandHorizontal(true); sc.setExpandVertical(true); Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle monitorArea = shell.getMonitor().getClientArea(); shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } itemImage.dispose(); }