List of usage examples for org.eclipse.swt.widgets Label setText
public void setText(String text)
From source file:org.pentaho.di.ui.spoon.trans.TransPerfDelegate.java
/** * Tell the user that the transformation is not running or that there is no monitoring configured. *///from w ww . j a v a 2 s . co m private void showEmptyGraph() { if (perfComposite.isDisposed()) { return; } emptyGraph = true; Label label = new Label(perfComposite, SWT.CENTER); label.setText(BaseMessages.getString(PKG, "TransLog.Dialog.PerformanceMonitoringNotEnabled.Message")); label.setBackground(perfComposite.getBackground()); label.setFont(GUIResource.getInstance().getFontMedium()); FormData fdLabel = new FormData(); fdLabel.left = new FormAttachment(5, 0); fdLabel.right = new FormAttachment(95, 0); fdLabel.top = new FormAttachment(5, 0); label.setLayoutData(fdLabel); Button button = new Button(perfComposite, SWT.CENTER); button.setText(BaseMessages.getString(PKG, "TransLog.Dialog.PerformanceMonitoring.Button")); button.setBackground(perfComposite.getBackground()); button.setFont(GUIResource.getInstance().getFontMedium()); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { TransGraph.editProperties(spoon.getActiveTransformation(), spoon, spoon.rep, true, TransDialog.Tabs.MONITOR_TAB); } }); FormData fdButton = new FormData(); fdButton.left = new FormAttachment(40, 0); fdButton.right = new FormAttachment(60, 0); fdButton.top = new FormAttachment(label, 5); button.setLayoutData(fdButton); perfComposite.layout(true, true); }
From source file:AddressBookDemo.java
public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout);//from w w w . ja v a 2 s.c o m layout.numColumns = 2; layout.verticalSpacing = 9; Label label = new Label(container, SWT.NULL); label.setText("&Given Name:"); givenNameText = new Text(container, SWT.BORDER | SWT.SINGLE); GridData gd = new GridData(GridData.FILL_HORIZONTAL); givenNameText.setLayoutData(gd); givenNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); label = new Label(container, SWT.NULL); label.setText("&Family Name:"); familyNameText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); familyNameText.setLayoutData(gd); familyNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); label = new Label(container, SWT.NULL); label.setText("&Nickname:"); nickNameText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); nickNameText.setLayoutData(gd); createLine(container, layout.numColumns); label = new Label(container, SWT.NULL); label.setText("&Business Phone:"); businessPhoneText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); businessPhoneText.setLayoutData(gd); label = new Label(container, SWT.NULL); label.setText("&Home Phone:"); homePhoneText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); homePhoneText.setLayoutData(gd); createLine(container, layout.numColumns); label = new Label(container, SWT.NULL); label.setText("&E-Mail Address:"); emailText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); emailText.setLayoutData(gd); emailText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); // dialogChanged(); setControl(container); }
From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java
void createControlTransfer(Composite parent) { // TODO: CCombo and Spinner also have cut(), copy() and paste() API Label l = new Label(parent, SWT.NONE); l.setText("Text:"); Button b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(widgetSelectedAdapter(e -> text.cut())); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> text.copy())); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(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.widthHint = HSIZE;/* w w w . ja v a2 s . c o m*/ data.heightHint = VSIZE; text.setLayoutData(data); l = new Label(parent, SWT.NONE); l.setText("Combo:"); b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(widgetSelectedAdapter(e -> combo.cut())); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> combo.copy())); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> combo.paste())); combo = new Combo(parent, SWT.NONE); combo.setItems("Item 1", "Item 2", "Item 3", "A longer Item"); combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); l = new Label(parent, SWT.NONE); l.setText("StyledText:"); b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(widgetSelectedAdapter(e -> styledText.cut())); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> styledText.copy())); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> styledText.paste())); styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = HSIZE; data.heightHint = VSIZE; styledText.setLayoutData(data); }
From source file:SendMessage.java
/** * Creates the main window's contents// w w w . j a v a 2s . c om * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(5, true)); // Create a big text box for the message text final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 5; text.setLayoutData(data); // Create the Confirm button Button confirm = new Button(composite, SWT.PUSH); confirm.setText("Confirm"); confirm.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Error button Button error = new Button(composite, SWT.PUSH); error.setText("Error"); error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Information button Button information = new Button(composite, SWT.PUSH); information.setText("Information"); information.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Question button Button question = new Button(composite, SWT.PUSH); question.setText("Question"); question.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Warning button Button warning = new Button(composite, SWT.PUSH); warning.setText("Warning"); warning.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the label to display the return value final Label label = new Label(composite, SWT.NONE); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 5; label.setLayoutData(data); // Save ourselves some typing final Shell shell = parent.getShell(); // Display a Confirmation dialog confirm.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { boolean b = MessageDialog.openConfirm(shell, "Confirm", text.getText()); label.setText("Returned " + Boolean.toString(b)); } }); // Display an Error dialog error.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { MessageDialog.openError(shell, "Error", text.getText()); label.setText("Returned void"); } }); // Display an Information dialog information.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { MessageDialog.openInformation(shell, "Information", text.getText()); label.setText("Returned void"); } }); // Display a Question dialog question.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { boolean b = MessageDialog.openQuestion(shell, "Question", text.getText()); label.setText("Returned " + Boolean.toString(b)); } }); // Display a Warning dialog warning.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { MessageDialog.openWarning(shell, "Warning", text.getText()); label.setText("Returned void"); } }); return composite; }
From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java
void createRTFTransfer(Composite copyParent, Composite pasteParent) { // RTF Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("RTFTransfer:"); //$NON-NLS-1$ final Text 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_BOTH); data.widthHint = HSIZE;//from ww w .jav a 2 s.c o m data.heightHint = VSIZE; copyRtfText.setLayoutData(data); Button b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> { String textData = copyRtfText.getText(); if (textData.length() > 0) { status.setText(""); StringBuilder buffer = new StringBuilder(); buffer.append("{\\rtf1\\ansi\\uc1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i "); for (int i = 0; i < textData.length(); i++) { char ch = textData.charAt(i); if (ch > 0xFF) { buffer.append("\\u"); buffer.append(Integer.toString((short) ch)); buffer.append('?'); } else { if (ch == '}' || ch == '{' || ch == '\\') { buffer.append('\\'); } buffer.append(ch); if (ch == '\n') buffer.append("\\par "); if (ch == '\r' && (i - 1 == textData.length() || textData.charAt(i + 1) != '\n')) { buffer.append("\\par "); } } } buffer.append("}"); clipboard.setContents(new Object[] { buffer.toString() }, new Transfer[] { RTFTransfer.getInstance() }); } else { status.setText("No RTF to copy"); } })); l = new Label(pasteParent, SWT.NONE); l.setText("RTFTransfer:"); //$NON-NLS-1$ final Text pasteRtfText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.widthHint = HSIZE; data.heightHint = VSIZE; pasteRtfText.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> { String textData = (String) clipboard.getContents(RTFTransfer.getInstance()); if (textData != null && textData.length() > 0) { status.setText(""); pasteRtfText.setText("start paste>" + textData + "<end paste"); } else { status.setText("No RTF to paste"); } })); }
From source file:at.ac.tuwien.inso.subcat.ui.widgets.DistributionView.java
private void addOptionConfiguration(DistributionChartOptionConfigData config) { assert (config != null); assert (config.getAttributes() != null); if (config.getAttributes().getData().size() == 0) { return;//from w ww .j ava2s .co m } if (optionCount > 0) { Helper.separator(optionComposite, 3); } ChartIdentifier identifier = new ChartIdentifier(config.getConfig(), optionCount); identifiers.add(identifier); Label lblTitle = new Label(optionComposite, SWT.NONE); lblTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Helper.setLabelStyle(lblTitle, SWT.BOLD); lblTitle.setText(config.getName()); Iterator<DropDownData> filterIter = config.getFilter().iterator(); if (filterIter.hasNext()) { Combo filterCombo = new Combo(optionComposite, SWT.DROP_DOWN | SWT.READ_ONLY); filterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); fillCombo(filterCombo, filterIter.next(), identifier); identifier.filter.add(filterCombo); } else { new Label(optionComposite, SWT.NONE); } Combo attCombo = new Combo(optionComposite, SWT.DROP_DOWN | SWT.READ_ONLY); fillAttributeCombo(attCombo, config.getAttributes(), identifier); attCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); identifier.attributes = attCombo; while (filterIter.hasNext()) { new Label(optionComposite, SWT.NONE); Combo filterCombo = new Combo(optionComposite, SWT.DROP_DOWN | SWT.READ_ONLY); filterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); new Label(optionComposite, SWT.NONE); fillCombo(filterCombo, filterIter.next(), identifier); identifier.filter.add(filterCombo); } identifier.paint = drawingSupplier.getNextPaint(); optionCount++; }
From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java
void createFileTransfer(Composite copyParent, Composite pasteParent) { //File Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("FileTransfer:"); //$NON-NLS-1$ GridData data = new GridData(); data.verticalSpan = 3;/*ww w.j a va 2 s . c o m*/ l.setLayoutData(data); final Table copyFileTable = new Table(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.widthHint = HSIZE; data.heightHint = VSIZE; data.verticalSpan = 3; copyFileTable.setLayoutData(data); Button b = new Button(copyParent, SWT.PUSH); b.setText("Select file(s)"); b.addSelectionListener(widgetSelectedAdapter(e -> { FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); String result = dialog.open(); if (result != null && result.length() > 0) { String path = dialog.getFilterPath(); String[] names = dialog.getFileNames(); for (String name : names) { TableItem item = new TableItem(copyFileTable, SWT.NONE); item.setText(path + File.separator + name); } } })); b = new Button(copyParent, SWT.PUSH); b.setText("Select directory"); b.addSelectionListener(widgetSelectedAdapter(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(widgetSelectedAdapter(e -> { TableItem[] items = copyFileTable.getItems(); if (items.length > 0) { status.setText(""); String[] itemsData = new String[items.length]; for (int i = 0; i < itemsData.length; i++) { itemsData[i] = items[i].getText(); } clipboard.setContents(new Object[] { itemsData }, new Transfer[] { FileTransfer.getInstance() }); } else { status.setText("No file to copy"); } })); l = new Label(pasteParent, SWT.NONE); l.setText("FileTransfer:"); //$NON-NLS-1$ final Table pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.widthHint = HSIZE; data.heightHint = VSIZE; pasteFileTable.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> { String[] textData = (String[]) clipboard.getContents(FileTransfer.getInstance()); if (textData != null && textData.length > 0) { status.setText(""); pasteFileTable.removeAll(); for (String element : textData) { TableItem item = new TableItem(pasteFileTable, SWT.NONE); item.setText(element); } } else { status.setText("No file to paste"); } })); }
From source file:ShowMessageBox.java
/** * Creates the main window's contents/*from w ww.j a v a2 s . com*/ * * @param shell the parent shell */ private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, false)); // Create the dropdown to allow icon selection new Label(shell, SWT.NONE).setText("Icon:"); final Combo icons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); for (int i = 0, n = ICONS.length; i < n; i++) icons.add(ICONS[i]); icons.select(0); // Create the dropdown to allow button selection new Label(shell, SWT.NONE).setText("Buttons:"); final Combo buttons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); for (int i = 0, n = BUTTONS.length; i < n; i++) buttons.add(BUTTONS[i]); buttons.select(0); // Create the entry field for the message new Label(shell, SWT.NONE).setText("Message:"); final Text message = new Text(shell, SWT.BORDER); message.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the label to show the return from the open call new Label(shell, SWT.NONE).setText("Return:"); final Label returnVal = new Label(shell, SWT.NONE); returnVal.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the button and event handler // to display the message box Button button = new Button(shell, SWT.PUSH); button.setText("Show Message"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Clear any previously returned value returnVal.setText(""); // This will hold the style to pass to the MessageBox constructor int style = 0; // Determine which icon was selected and // add it to the style switch (icons.getSelectionIndex()) { case 0: style |= SWT.ICON_ERROR; break; case 1: style |= SWT.ICON_INFORMATION; break; case 2: style |= SWT.ICON_QUESTION; break; case 3: style |= SWT.ICON_WARNING; break; case 4: style |= SWT.ICON_WORKING; break; } // Determine which set of buttons was selected // and add it to the style switch (buttons.getSelectionIndex()) { case 0: style |= SWT.OK; break; case 1: style |= SWT.OK | SWT.CANCEL; break; case 2: style |= SWT.YES | SWT.NO; break; case 3: style |= SWT.YES | SWT.NO | SWT.CANCEL; break; case 4: style |= SWT.RETRY | SWT.CANCEL; break; case 5: style |= SWT.ABORT | SWT.RETRY | SWT.IGNORE; break; } // Display the message box MessageBox mb = new MessageBox(shell, style); mb.setText("Message from SWT"); mb.setMessage(message.getText()); int val = mb.open(); String valString = ""; switch (val) // val contains the constant of the selected button { case SWT.OK: valString = "SWT.OK"; break; case SWT.CANCEL: valString = "SWT.CANCEL"; break; case SWT.YES: valString = "SWT.YES"; break; case SWT.NO: valString = "SWT.NO"; break; case SWT.RETRY: valString = "SWT.RETRY"; break; case SWT.ABORT: valString = "SWT.ABORT"; break; case SWT.IGNORE: valString = "SWT.IGNORE"; break; } returnVal.setText(valString); } }); }
From source file:at.ac.tuwien.inso.subcat.ui.widgets.DistributionChart.java
private void addOptionConfiguration(DistributionChartOptionConfigData config, List<String> flags) { assert (config != null); assert (config.getAttributes() != null); if (config.getAttributes().getData().size() == 0) { return;/*from www . j a v a 2 s .c o m*/ } if (optionCount > 0) { Helper.separator(optionComposite, 3); } ChartIdentifier identifier = new ChartIdentifier(config.getConfig(), optionCount); identifiers.add(identifier); Label lblTitle = new Label(optionComposite, SWT.NONE); lblTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Helper.setLabelStyle(lblTitle, SWT.BOLD); lblTitle.setText(config.getName()); DropDownData firstDropdownData = null; Iterator<DropDownData> filterIter = config.getFilter().iterator(); while (filterIter.hasNext()) { DropDownData data = filterIter.next(); if (data.getConfig().show(flags)) { firstDropdownData = data; break; } } if (firstDropdownData != null) { Combo filterCombo = new Combo(optionComposite, SWT.DROP_DOWN | SWT.READ_ONLY); filterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); fillCombo(filterCombo, firstDropdownData, identifier); identifier.filter.add(filterCombo); } else { new Label(optionComposite, SWT.NONE); } Combo attCombo = new Combo(optionComposite, SWT.DROP_DOWN | SWT.READ_ONLY); fillAttributeCombo(attCombo, config.getAttributes(), flags, identifier); attCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); identifier.attributes = attCombo; while (filterIter.hasNext()) { DropDownData iterValue = filterIter.next(); if (iterValue.getConfig().show(flags)) { new Label(optionComposite, SWT.NONE); Combo filterCombo = new Combo(optionComposite, SWT.DROP_DOWN | SWT.READ_ONLY); filterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); new Label(optionComposite, SWT.NONE); fillCombo(filterCombo, iterValue, identifier); identifier.filter.add(filterCombo); } } identifier.paint = drawingSupplier.getNextPaint(); optionCount++; }
From source file:org.eclipse.swt.examples.paint.PaintExample.java
/** * Creates the GUI.// w w w . j a va 2s. c o m */ public void createGUI(Composite parent) { GridLayout gridLayout; GridData gridData; /*** Create principal GUI layout elements ***/ Composite displayArea = new Composite(parent, SWT.NONE); gridLayout = new GridLayout(); gridLayout.numColumns = 1; displayArea.setLayout(gridLayout); // Creating these elements here avoids the need to instantiate the GUI elements // in strict layout order. The natural layout ordering is an artifact of using // SWT layouts, but unfortunately it is not the same order as that required to // instantiate all of the non-GUI application elements to satisfy referential // dependencies. It is possible to reorder the initialization to some extent, but // this can be very tedious. // paint canvas final Canvas paintCanvas = new Canvas(displayArea, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); paintCanvas.setLayoutData(gridData); paintCanvas.setBackground(paintColorWhite); // color selector frame final Composite colorFrame = new Composite(displayArea, SWT.NONE); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); colorFrame.setLayoutData(gridData); // tool settings frame final Composite toolSettingsFrame = new Composite(displayArea, SWT.NONE); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); toolSettingsFrame.setLayoutData(gridData); // status text final Text statusText = new Text(displayArea, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); statusText.setLayoutData(gridData); /*** Create the remaining application elements inside the principal GUI layout elements ***/ // paintSurface paintSurface = new PaintSurface(paintCanvas, statusText, paintColorWhite); // finish initializing the tool data tools[Pencil_tool].data = new PencilTool(toolSettings, paintSurface); tools[Airbrush_tool].data = new AirbrushTool(toolSettings, paintSurface); tools[Line_tool].data = new LineTool(toolSettings, paintSurface); tools[PolyLine_tool].data = new PolyLineTool(toolSettings, paintSurface); tools[Rectangle_tool].data = new RectangleTool(toolSettings, paintSurface); tools[RoundedRectangle_tool].data = new RoundedRectangleTool(toolSettings, paintSurface); tools[Ellipse_tool].data = new EllipseTool(toolSettings, paintSurface); tools[Text_tool].data = new TextTool(toolSettings, paintSurface); // colorFrame gridLayout = new GridLayout(); gridLayout.numColumns = 3; gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; colorFrame.setLayout(gridLayout); // activeForegroundColorCanvas, activeBackgroundColorCanvas activeForegroundColorCanvas = new Canvas(colorFrame, SWT.BORDER); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.heightHint = 24; gridData.widthHint = 24; activeForegroundColorCanvas.setLayoutData(gridData); activeBackgroundColorCanvas = new Canvas(colorFrame, SWT.BORDER); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.heightHint = 24; gridData.widthHint = 24; activeBackgroundColorCanvas.setLayoutData(gridData); // paletteCanvas final Canvas paletteCanvas = new Canvas(colorFrame, SWT.BORDER | SWT.NO_BACKGROUND); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.heightHint = 24; paletteCanvas.setLayoutData(gridData); paletteCanvas.addListener(SWT.MouseDown, new Listener() { @Override public void handleEvent(Event e) { Rectangle bounds = paletteCanvas.getClientArea(); Color color = getColorAt(bounds, e.x, e.y); if (e.button == 1) setForegroundColor(color); else setBackgroundColor(color); } private Color getColorAt(Rectangle bounds, int x, int y) { if (bounds.height <= 1 && bounds.width <= 1) return paintColorWhite; final int row = (y - bounds.y) * numPaletteRows / bounds.height; final int col = (x - bounds.x) * numPaletteCols / bounds.width; return paintColors[Math.min(Math.max(row * numPaletteCols + col, 0), paintColors.length - 1)]; } }); Listener refreshListener = e -> { if (e.gc == null) return; Rectangle bounds = paletteCanvas.getClientArea(); for (int row = 0; row < numPaletteRows; ++row) { for (int col = 0; col < numPaletteCols; ++col) { final int x = bounds.width * col / numPaletteCols; final int y = bounds.height * row / numPaletteRows; final int width = Math.max(bounds.width * (col + 1) / numPaletteCols - x, 1); final int height = Math.max(bounds.height * (row + 1) / numPaletteRows - y, 1); e.gc.setBackground(paintColors[row * numPaletteCols + col]); e.gc.fillRectangle(bounds.x + x, bounds.y + y, width, height); } } }; paletteCanvas.addListener(SWT.Resize, refreshListener); paletteCanvas.addListener(SWT.Paint, refreshListener); //paletteCanvas.redraw(); // toolSettingsFrame gridLayout = new GridLayout(); gridLayout.numColumns = 4; gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; toolSettingsFrame.setLayout(gridLayout); Label label = new Label(toolSettingsFrame, SWT.NONE); label.setText(getResourceString("settings.AirbrushRadius.text")); final Scale airbrushRadiusScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL); airbrushRadiusScale.setMinimum(5); airbrushRadiusScale.setMaximum(50); airbrushRadiusScale.setSelection(toolSettings.airbrushRadius); airbrushRadiusScale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); airbrushRadiusScale.addSelectionListener(widgetSelectedAdapter(e -> { toolSettings.airbrushRadius = airbrushRadiusScale.getSelection(); updateToolSettings(); })); label = new Label(toolSettingsFrame, SWT.NONE); label.setText(getResourceString("settings.AirbrushIntensity.text")); final Scale airbrushIntensityScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL); airbrushIntensityScale.setMinimum(1); airbrushIntensityScale.setMaximum(100); airbrushIntensityScale.setSelection(toolSettings.airbrushIntensity); airbrushIntensityScale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); airbrushIntensityScale.addSelectionListener(widgetSelectedAdapter(e -> { toolSettings.airbrushIntensity = airbrushIntensityScale.getSelection(); updateToolSettings(); })); }