List of usage examples for org.eclipse.swt.widgets Label setLayoutData
public void setLayoutData(Object layoutData)
From source file:PrintKTableExample.java
public MsgBox(Display d, String title, String message, String buttons) { this.d = d;/* ww w . j a v a 2s .com*/ this.s = new Shell(d, SWT.TITLE | SWT.APPLICATION_MODAL); this.s.setText(title); additionalControl = null; ende = false; FormLayout fl = new FormLayout(); this.s.setLayout(fl); bild = new Label(this.s, SWT.LEFT); bild.setImage(IconSource.getImage("MsgBox")); bild.setBackground(d.getSystemColor(SWT.COLOR_WHITE)); FormData f = new FormData(); f.top = new FormAttachment(0, 0); f.left = new FormAttachment(0, 0); f.bottom = new FormAttachment(100, 0); bild.setLayoutData(f); Label separator = new Label(this.s, SWT.SEPARATOR); f = new FormData(); f.top = new FormAttachment(0, 0); f.left = new FormAttachment(bild, 0); f.bottom = new FormAttachment(100, 0); separator.setLayoutData(f); meldung = new Label(s, SWT.LEFT | SWT.WRAP); meldung.setText(message); f = new FormData(); f.top = new FormAttachment(0, 25); f.left = new FormAttachment(bild, 25); f.right = new FormAttachment(100, -25); f.bottom = new FormAttachment(100, -55); meldung.setLayoutData(f); ButtonBar butBar = new ButtonBar(s, 80); StringTokenizer t = new StringTokenizer(buttons, ","); boolean first = true; while (t.hasMoreTokens()) { Button but = butBar.addButton(t.nextToken(), "", new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { pressedButton = ((Button) e.getSource()).getText(); ende = true; } }); if (first) { first = false; s.setDefaultButton(but); } } f = new FormData(); f.bottom = new FormAttachment(100, -4); f.left = new FormAttachment(bild, 15); f.right = new FormAttachment(100, -15); butBar.setLayoutData(f); }
From source file:PrintKTableExample.java
/** * Adds a ToolItem to the dialog's toolbar. Creates the toolbar if not * already done.// w w w . j a va 2 s . c om * * @param name * The name if the ToolItem. Although this name is never * displayed to the user you can use it in onToolItem to identify * the activated ToolItem. * @param tooltip * The item's tooltip * @param icon * The icon to show. * @return ToolItem The ToolItem created by this method. */ public ToolItem addToolItem(String name, String tooltip, Image icon) { if (guiToolBar == null) { FormLayout layout = new FormLayout(); guiToolBarArea.setLayout(layout); // layout.horizontalSpacing = 0; // layout.verticalSpacing = 0; layout.marginHeight = 0; layout.marginWidth = 0; guiToolBar = new ToolBar(guiToolBarArea, SWT.FLAT); FormData fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(0, 0); guiToolBar.setLayoutData(fd); Label line = new Label(guiToolBarArea, SWT.SEPARATOR | SWT.HORIZONTAL); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(guiToolBar, 1); fd.right = new FormAttachment(100, 0); line.setLayoutData(fd); guiLastToolControl = guiToolBar; } ToolItem ti = new ToolItem(guiToolBar, SWT.PUSH); ti.setImage(icon); ti.setToolTipText(tooltip); ti.setEnabled(true); ti.setData(name); ti.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { onToolItem((ToolItem) e.widget, (String) e.widget.getData()); } }); guiToolBarGridData.heightHint = guiToolBarArea.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; return ti; }
From source file:CustomControlExample.java
/** * Creates the "StyledText Style" group. *///w ww . ja v a 2 s . c om void createStyledTextStyleGroup() { final Display display = controlGroup.getDisplay(); styledTextStyleGroup = new Group(controlGroup, SWT.NONE); styledTextStyleGroup.setText(ControlExample.getResourceString("StyledText_Styles")); styledTextStyleGroup.setLayout(new GridLayout(7, false)); GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); data.horizontalSpan = 2; styledTextStyleGroup.setLayoutData(data); /* Get images */ boldImage = createBitmapImage(display, "bold"); italicImage = createBitmapImage(display, "italic"); redImage = createBitmapImage(display, "red"); yellowImage = createBitmapImage(display, "yellow"); underlineImage = createBitmapImage(display, "underline"); strikeoutImage = createBitmapImage(display, "strikeout"); /* Create controls to modify the StyledText */ Label label = new Label(styledTextStyleGroup, SWT.NONE); label.setText(ControlExample.getResourceString("StyledText_Style_Instructions")); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 7; label.setLayoutData(data); new Label(styledTextStyleGroup, SWT.NONE).setText(ControlExample.getResourceString("Bold")); boldButton = new Button(styledTextStyleGroup, SWT.PUSH); boldButton.setImage(boldImage); new Label(styledTextStyleGroup, SWT.NONE).setText(ControlExample.getResourceString("Underline")); underlineButton = new Button(styledTextStyleGroup, SWT.PUSH); underlineButton.setImage(underlineImage); new Label(styledTextStyleGroup, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(styledTextStyleGroup, SWT.NONE).setText(ControlExample.getResourceString("Foreground_Style")); redButton = new Button(styledTextStyleGroup, SWT.PUSH); redButton.setImage(redImage); new Label(styledTextStyleGroup, SWT.NONE).setText(ControlExample.getResourceString("Italic")); italicButton = new Button(styledTextStyleGroup, SWT.PUSH); italicButton.setImage(italicImage); new Label(styledTextStyleGroup, SWT.NONE).setText(ControlExample.getResourceString("Strikeout")); strikeoutButton = new Button(styledTextStyleGroup, SWT.PUSH); strikeoutButton.setImage(strikeoutImage); new Label(styledTextStyleGroup, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(styledTextStyleGroup, SWT.NONE).setText(ControlExample.getResourceString("Background_Style")); yellowButton = new Button(styledTextStyleGroup, SWT.PUSH); yellowButton.setImage(yellowImage); SelectionListener styleListener = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Point sel = styledText.getSelectionRange(); if ((sel == null) || (sel.y == 0)) return; StyleRange style; for (int i = sel.x; i < sel.x + sel.y; i++) { StyleRange range = styledText.getStyleRangeAtOffset(i); if (range != null) { style = (StyleRange) range.clone(); style.start = i; style.length = 1; } else { style = new StyleRange(i, 1, null, null, SWT.NORMAL); } if (e.widget == boldButton) { style.fontStyle ^= SWT.BOLD; } else if (e.widget == italicButton) { style.fontStyle ^= SWT.ITALIC; } else if (e.widget == underlineButton) { style.underline = !style.underline; } else if (e.widget == strikeoutButton) { style.strikeout = !style.strikeout; } styledText.setStyleRange(style); } styledText.setSelectionRange(sel.x + sel.y, 0); } }; SelectionListener colorListener = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Point sel = styledText.getSelectionRange(); if ((sel == null) || (sel.y == 0)) return; Color fg = null, bg = null; if (e.widget == redButton) { fg = display.getSystemColor(SWT.COLOR_RED); } else if (e.widget == yellowButton) { bg = display.getSystemColor(SWT.COLOR_YELLOW); } StyleRange style; for (int i = sel.x; i < sel.x + sel.y; i++) { StyleRange range = styledText.getStyleRangeAtOffset(i); if (range != null) { style = (StyleRange) range.clone(); style.start = i; style.length = 1; style.foreground = style.foreground != null ? null : fg; style.background = style.background != null ? null : bg; } else { style = new StyleRange(i, 1, fg, bg, SWT.NORMAL); } styledText.setStyleRange(style); } styledText.setSelectionRange(sel.x + sel.y, 0); } }; boldButton.addSelectionListener(styleListener); italicButton.addSelectionListener(styleListener); underlineButton.addSelectionListener(styleListener); strikeoutButton.addSelectionListener(styleListener); redButton.addSelectionListener(colorListener); yellowButton.addSelectionListener(colorListener); yellowButton.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { boldImage.dispose(); italicImage.dispose(); redImage.dispose(); yellowImage.dispose(); underlineImage.dispose(); strikeoutImage.dispose(); } }); }