List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:com.android.ddmuilib.HeapPanel.java
private void createLegend(Composite parent) { mLegend = new Group(parent, SWT.NONE); mLegend.setText(getLegendText(0));//from w ww . j av a2s . c o m mLegend.setLayout(new GridLayout(2, false)); RGB[] colors = mMapPalette.colors; for (int i = 0; i < NUM_PALETTE_ENTRIES; i++) { Image tmpImage = createColorRect(parent.getDisplay(), colors[i]); Label l = new Label(mLegend, SWT.NONE); l.setImage(tmpImage); l = new Label(mLegend, SWT.NONE); l.setText(mMapLegend[i]); } }
From source file:CustomControlExample.java
/** * Creates the "Colors" group. This is typically a child of the "Control" * group. Subclasses override this method to customize and set system * colors./* www .ja v a2s . c o m*/ */ void createColorGroup() { /* Create the group */ colorGroup = new Group(controlGroup, SWT.NONE); colorGroup.setLayout(new GridLayout(2, false)); colorGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); colorGroup.setText(ControlExample.getResourceString("Colors")); new Label(colorGroup, SWT.NONE).setText(ControlExample.getResourceString("Foreground_Color")); foregroundButton = new Button(colorGroup, SWT.PUSH); new Label(colorGroup, SWT.NONE).setText(ControlExample.getResourceString("Background_Color")); backgroundButton = new Button(colorGroup, SWT.PUSH); fontButton = new Button(colorGroup, SWT.PUSH); fontButton.setText(ControlExample.getResourceString("Font")); fontButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); Button defaultsButton = new Button(colorGroup, SWT.PUSH); defaultsButton.setText(ControlExample.getResourceString("Defaults")); Shell shell = controlGroup.getShell(); final ColorDialog foregroundDialog = new ColorDialog(shell); final ColorDialog backgroundDialog = new ColorDialog(shell); final FontDialog fontDialog = new FontDialog(shell); /* Create images to display current colors */ int imageSize = 12; Display display = shell.getDisplay(); foregroundImage = new Image(display, imageSize, imageSize); backgroundImage = new Image(display, imageSize, imageSize); /* Add listeners to set the colors and font */ foregroundButton.setImage(foregroundImage); // sets the size of the // button foregroundButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Color oldColor = foregroundColor; if (oldColor == null) { Control[] controls = getExampleWidgets(); if (controls.length > 0) oldColor = controls[0].getForeground(); } if (oldColor != null) foregroundDialog.setRGB(oldColor.getRGB()); // seed dialog // with current // color RGB rgb = foregroundDialog.open(); if (rgb == null) return; oldColor = foregroundColor; // save old foreground color to // dispose when done foregroundColor = new Color(event.display, rgb); setExampleWidgetForeground(); if (oldColor != null) oldColor.dispose(); } }); backgroundButton.setImage(backgroundImage); // sets the size of the // button backgroundButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Color oldColor = backgroundColor; if (oldColor == null) { Control[] controls = getExampleWidgets(); if (controls.length > 0) oldColor = controls[0].getBackground(); // seed dialog // with current // color } if (oldColor != null) backgroundDialog.setRGB(oldColor.getRGB()); RGB rgb = backgroundDialog.open(); if (rgb == null) return; oldColor = backgroundColor; // save old background color to // dispose when done backgroundColor = new Color(event.display, rgb); setExampleWidgetBackground(); if (oldColor != null) oldColor.dispose(); } }); fontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Font oldFont = font; if (oldFont == null) { Control[] controls = getExampleWidgets(); if (controls.length > 0) oldFont = controls[0].getFont(); } if (oldFont != null) fontDialog.setFontList(oldFont.getFontData()); // seed // dialog // with // current // font FontData fontData = fontDialog.open(); if (fontData == null) return; oldFont = font; // dispose old font when done font = new Font(event.display, fontData); setExampleWidgetFont(); setExampleWidgetSize(); if (oldFont != null) oldFont.dispose(); } }); defaultsButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { resetColorsAndFonts(); } }); shell.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent event) { if (foregroundImage != null) foregroundImage.dispose(); if (backgroundImage != null) backgroundImage.dispose(); if (foregroundColor != null) foregroundColor.dispose(); if (backgroundColor != null) backgroundColor.dispose(); if (font != null) font.dispose(); foregroundColor = null; backgroundColor = null; font = null; } }); }
From source file:LayoutExample.java
/** * Creates the control widgets./*w ww. j av a 2s. com*/ */ void createControlWidgets() { /* Controls the type of RowLayout */ Group typeGroup = new Group(controlGroup, SWT.NONE); typeGroup.setText(LayoutExample.getResourceString("Type")); typeGroup.setLayout(new GridLayout()); GridData data = new GridData(GridData.FILL_HORIZONTAL); typeGroup.setLayoutData(data); horizontal = new Button(typeGroup, SWT.RADIO); horizontal.setText("SWT.HORIZONTAL"); horizontal.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); horizontal.setSelection(true); horizontal.addSelectionListener(selectionListener); vertical = new Button(typeGroup, SWT.RADIO); vertical.setText("SWT.VERTICAL"); vertical.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); vertical.addSelectionListener(selectionListener); /* Controls the margins and spacing of the RowLayout */ String[] marginValues = new String[] { "0", "3", "5", "10" }; Group marginGroup = new Group(controlGroup, SWT.NONE); marginGroup.setText(LayoutExample.getResourceString("Margins_Spacing")); data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); data.verticalSpan = 2; marginGroup.setLayoutData(data); GridLayout layout = new GridLayout(); layout.numColumns = 2; marginGroup.setLayout(layout); new Label(marginGroup, SWT.NONE).setText("marginRight"); marginRight = new Combo(marginGroup, SWT.NONE); marginRight.setItems(marginValues); marginRight.select(1); marginRight.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); marginRight.addSelectionListener(selectionListener); marginRight.addTraverseListener(traverseListener); new Label(marginGroup, SWT.NONE).setText("marginLeft"); marginLeft = new Combo(marginGroup, SWT.NONE); marginLeft.setItems(marginValues); marginLeft.select(1); marginLeft.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); marginLeft.addSelectionListener(selectionListener); marginLeft.addTraverseListener(traverseListener); new Label(marginGroup, SWT.NONE).setText("marginTop"); marginTop = new Combo(marginGroup, SWT.NONE); marginTop.setItems(marginValues); marginTop.select(1); marginTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); marginTop.addSelectionListener(selectionListener); marginTop.addTraverseListener(traverseListener); new Label(marginGroup, SWT.NONE).setText("marginBottom"); marginBottom = new Combo(marginGroup, SWT.NONE); marginBottom.setItems(marginValues); marginBottom.select(1); marginBottom.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); marginBottom.addSelectionListener(selectionListener); marginBottom.addTraverseListener(traverseListener); new Label(marginGroup, SWT.NONE).setText("spacing"); spacing = new Combo(marginGroup, SWT.NONE); spacing.setItems(marginValues); spacing.select(1); spacing.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); spacing.addSelectionListener(selectionListener); spacing.addTraverseListener(traverseListener); /* Controls other parameters of the RowLayout */ Group specGroup = new Group(controlGroup, SWT.NONE); specGroup.setText(LayoutExample.getResourceString("Properties")); specGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); specGroup.setLayout(new GridLayout()); wrap = new Button(specGroup, SWT.CHECK); wrap.setText("wrap"); wrap.setSelection(true); wrap.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); wrap.addSelectionListener(selectionListener); pack = new Button(specGroup, SWT.CHECK); pack.setText("pack"); pack.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); pack.setSelection(true); pack.addSelectionListener(selectionListener); justify = new Button(specGroup, SWT.CHECK); justify.setText("justify"); justify.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); justify.addSelectionListener(selectionListener); /* Add common controls */ super.createControlWidgets(); /* Position the sash */ sash.setWeights(new int[] { 6, 5 }); }
From source file:org.eclipse.swt.examples.controlexample.Tab.java
/** * Creates and opens the "Listener selection" dialog. *///from ww w . j a v a 2 s. c o m void createListenerSelectionDialog() { final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL); dialog.setText(ControlExample.getResourceString("Select_Listeners")); dialog.setLayout(new GridLayout(2, false)); final Table table = new Table(dialog, SWT.BORDER | SWT.V_SCROLL | SWT.CHECK); GridData data = new GridData(GridData.FILL_BOTH); data.verticalSpan = 3; table.setLayoutData(data); for (int i = 0; i < EVENT_INFO.length; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(EVENT_INFO[i].name); item.setChecked(eventsFilter[i]); } final String[] customNames = getCustomEventNames(); for (int i = 0; i < customNames.length; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(customNames[i]); item.setChecked(eventsFilter[EVENT_INFO.length + i]); } Button selectAll = new Button(dialog, SWT.PUSH); selectAll.setText(ControlExample.getResourceString("Select_All")); selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); selectAll.addSelectionListener(widgetSelectedAdapter(e -> { TableItem[] items = table.getItems(); for (int i = 0; i < EVENT_INFO.length; i++) { items[i].setChecked(true); } for (int i = 0; i < customNames.length; i++) { items[EVENT_INFO.length + i].setChecked(true); } })); Button deselectAll = new Button(dialog, SWT.PUSH); deselectAll.setText(ControlExample.getResourceString("Deselect_All")); deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); deselectAll.addSelectionListener(widgetSelectedAdapter(e -> { TableItem[] items = table.getItems(); for (int i = 0; i < EVENT_INFO.length; i++) { items[i].setChecked(false); } for (int i = 0; i < customNames.length; i++) { items[EVENT_INFO.length + i].setChecked(false); } })); final Button editEvent = new Button(dialog, SWT.PUSH); editEvent.setText(ControlExample.getResourceString("Edit_Event")); editEvent.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING)); editEvent.addSelectionListener(widgetSelectedAdapter(e -> { Point pt = editEvent.getLocation(); pt = e.display.map(editEvent, null, pt); int index = table.getSelectionIndex(); if (getExampleWidgets().length > 0 && index != -1) { createEditEventDialog(dialog, pt.x, pt.y, index); } })); editEvent.setEnabled(false); table.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { int fields = 0; int index = table.getSelectionIndex(); if (index != -1 && index < EVENT_INFO.length) { // TODO: Allow custom widgets to specify event info fields = (EVENT_INFO[index].settableFields); } editEvent.setEnabled(fields != 0); } @Override public void widgetDefaultSelected(SelectionEvent e) { if (editEvent.getEnabled()) { Point pt = editEvent.getLocation(); pt = e.display.map(editEvent, null, pt); int index = table.getSelectionIndex(); if (getExampleWidgets().length > 0 && index != -1 && index < EVENT_INFO.length) { createEditEventDialog(dialog, pt.x, pt.y, index); } } } }); new Label(dialog, SWT.NONE); /* Filler */ Button ok = new Button(dialog, SWT.PUSH); ok.setText(ControlExample.getResourceString("OK")); dialog.setDefaultButton(ok); ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); ok.addSelectionListener(widgetSelectedAdapter(e -> { TableItem[] items = table.getItems(); for (int i = 0; i < EVENT_INFO.length; i++) { eventsFilter[i] = items[i].getChecked(); } for (int i = 0; i < customNames.length; i++) { eventsFilter[EVENT_INFO.length + i] = items[EVENT_INFO.length + i].getChecked(); } dialog.dispose(); })); dialog.pack(); /* * If the preferred size of the dialog is too tall for the display, * then reduce the height, so that the vertical scrollbar will appear. */ Rectangle bounds = dialog.getBounds(); Rectangle trim = dialog.computeTrim(0, 0, 0, 0); Rectangle clientArea = display.getClientArea(); if (bounds.height > clientArea.height) { dialog.setSize(bounds.width, clientArea.height - trim.height); } dialog.setLocation(bounds.x, clientArea.y); dialog.open(); while (!dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
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);/*from w w w . j a v a 2 s. c o m*/ 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 createTextWidgets() { if (labels == null) return;//from w w w . 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
private Control createWidget(int type, Composite parent, String prefix) { switch (type) { case BUTTON_CHECK: { Button button = new Button(parent, SWT.CHECK); button.setText(prefix + " Check box"); return button; }// www . j a va 2 s .com case BUTTON_TOGGLE: { Button button = new Button(parent, SWT.TOGGLE); button.setText(prefix + " Toggle button"); return button; } case BUTTON_RADIO: { Button button = new Button(parent, SWT.RADIO); button.setText(prefix + " Radio button"); return button; } case TABLE: { Table table = new Table(parent, SWT.BORDER | SWT.MULTI); TableColumn column1 = new TableColumn(table, SWT.NONE); TableColumn column2 = new TableColumn(table, SWT.NONE); for (int i = 0; i < 10; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(0, prefix + " name " + i); item.setText(1, prefix + " value " + i); } column1.pack(); column2.pack(); return table; } case TEXT: { Text text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); text.setText(prefix + " Text"); return text; } case TREE: { Tree tree = new Tree(parent, SWT.BORDER); for (int i = 0; i < 3; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText(prefix + " item " + i); for (int j = 0; j < 3; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText(prefix + " item " + j); for (int k = 0; k < 3; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); subsubItem.setText(prefix + " item " + k); } } } return tree; } case CANVAS: { Canvas canvas = new Canvas(parent, SWT.BORDER); canvas.setData("STRINGS", new String[] { prefix + " Canvas widget" }); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Canvas c = (Canvas) e.widget; Image image = (Image) c.getData("IMAGE"); if (image != null) { e.gc.drawImage(image, 5, 5); } else { String[] strings = (String[]) c.getData("STRINGS"); if (strings != null) { FontMetrics metrics = e.gc.getFontMetrics(); int height = metrics.getHeight(); int y = 5; for (int i = 0; i < strings.length; i++) { e.gc.drawString(strings[i], 5, y); y += height + 5; } } } } }); return canvas; } case LABEL: { Label label = new Label(parent, SWT.BORDER); label.setText(prefix + " Label"); return label; } case LIST: { List list = new List(parent, SWT.BORDER); list.setItems(new String[] { prefix + " Item a", prefix + " Item b", prefix + " Item c", prefix + " Item d" }); return list; } default: throw new SWTError(SWT.ERROR_NOT_IMPLEMENTED); } }
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 . j a va 2s . 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(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:org.eclipse.swt.examples.controlexample.Tab.java
Shell createSetGetDialog(String[] methodNames) { final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MODELESS); dialog.setLayout(new GridLayout(2, false)); dialog.setText(getTabText() + " " + ControlExample.getResourceString("Set_Get")); nameCombo = new Combo(dialog, SWT.READ_ONLY); nameCombo.setItems(methodNames);//from w ww . ja va 2 s . com nameCombo.setText(methodNames[0]); nameCombo.setVisibleItemCount(methodNames.length); nameCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); nameCombo.addSelectionListener(widgetSelectedAdapter(e -> resetLabels())); returnTypeLabel = new Label(dialog, SWT.NONE); returnTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); setButton = new Button(dialog, SWT.PUSH); setButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); setButton.addSelectionListener(widgetSelectedAdapter(e -> { setValue(); setText.selectAll(); setText.setFocus(); })); setText = new Text(dialog, SWT.SINGLE | SWT.BORDER); setText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); getButton = new Button(dialog, SWT.PUSH); getButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); getButton.addSelectionListener(widgetSelectedAdapter(e -> getValue())); getText = new Text(dialog, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.widthHint = 240; data.heightHint = 200; getText.setLayoutData(data); resetLabels(); dialog.setDefaultButton(setButton); dialog.pack(); dialog.addDisposeListener(e -> setGetDialog = null); return dialog; }
From source file:org.eclipse.swt.examples.dnd.DNDExample.java
private Control createWidget(int type, Composite parent, String prefix) { switch (type) { case BUTTON_CHECK: { Button button = new Button(parent, SWT.CHECK); button.setText(prefix + " Check box"); return button; }/* w ww . j a v a 2 s. co m*/ case BUTTON_TOGGLE: { Button button = new Button(parent, SWT.TOGGLE); button.setText(prefix + " Toggle button"); return button; } case BUTTON_RADIO: { Button button = new Button(parent, SWT.RADIO); button.setText(prefix + " Radio button"); return button; } case STYLED_TEXT: { StyledText text = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); text.setText(prefix + " Styled Text"); return text; } case TABLE: { Table table = new Table(parent, SWT.BORDER | SWT.MULTI); table.setHeaderVisible(true); TableColumn column0 = new TableColumn(table, SWT.LEFT); column0.setText("Name"); TableColumn column1 = new TableColumn(table, SWT.RIGHT); column1.setText("Value"); TableColumn column2 = new TableColumn(table, SWT.CENTER); column2.setText("Description"); for (int i = 0; i < 10; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(0, prefix + " name " + i); item.setText(1, prefix + " value " + i); item.setText(2, prefix + " description " + i); item.setImage(itemImage); } column0.pack(); column1.pack(); column2.pack(); return table; } case TEXT: { Text text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); text.setText(prefix + " Text"); return text; } case TREE: { Tree tree = new Tree(parent, SWT.BORDER | SWT.MULTI); tree.setHeaderVisible(true); TreeColumn column0 = new TreeColumn(tree, SWT.LEFT); column0.setText("Name"); TreeColumn column1 = new TreeColumn(tree, SWT.RIGHT); column1.setText("Value"); TreeColumn column2 = new TreeColumn(tree, SWT.CENTER); column2.setText("Description"); for (int i = 0; i < 3; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText(0, prefix + " name " + i); item.setText(1, prefix + " value " + i); item.setText(2, prefix + " description " + i); item.setImage(itemImage); for (int j = 0; j < 3; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText(0, prefix + " name " + i + " " + j); subItem.setText(1, prefix + " value " + i + " " + j); subItem.setText(2, prefix + " description " + i + " " + j); subItem.setImage(itemImage); for (int k = 0; k < 3; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); subsubItem.setText(0, prefix + " name " + i + " " + j + " " + k); subsubItem.setText(1, prefix + " value " + i + " " + j + " " + k); subsubItem.setText(2, prefix + " description " + i + " " + j + " " + k); subsubItem.setImage(itemImage); } } } column0.pack(); column1.pack(); column2.pack(); return tree; } case CANVAS: { Canvas canvas = new Canvas(parent, SWT.BORDER); canvas.setData("STRINGS", new String[] { prefix + " Canvas widget" }); canvas.addPaintListener(e -> { Canvas c = (Canvas) e.widget; Image image = (Image) c.getData("IMAGE"); if (image != null) { e.gc.drawImage(image, 5, 5); } else { String[] strings = (String[]) c.getData("STRINGS"); if (strings != null) { FontMetrics metrics = e.gc.getFontMetrics(); int height = metrics.getHeight(); int y = 5; for (String string : strings) { e.gc.drawString(string, 5, y); y += height + 5; } } } }); return canvas; } case LABEL: { Label label = new Label(parent, SWT.BORDER); label.setText(prefix + " Label"); return label; } case LIST: { List list = new List(parent, SWT.BORDER | SWT.MULTI); list.setItems(prefix + " Item a", prefix + " Item b", prefix + " Item c", prefix + " Item d"); return list; } case COMBO: { Combo combo = new Combo(parent, SWT.BORDER); combo.setItems("Item a", "Item b", "Item c", "Item d"); return combo; } default: throw new SWTError(SWT.ERROR_NOT_IMPLEMENTED); } }