List of usage examples for org.eclipse.swt.widgets Composite setLayoutData
public void setLayoutData(Object layoutData)
From source file:at.ac.tuwien.inso.subcat.ui.widgets.TrendChart.java
public void addConfiguration(TrendChartConfigData config, List<String> flags) { assert (config != null); ArrayList<Combo> combos = new ArrayList<Combo>(); // Title Row: Label lblGrpTitle = new Label(optionComposite, SWT.NONE); lblGrpTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); Helper.setLabelStyle(lblGrpTitle, SWT.BOLD); lblGrpTitle.setText(config.getName()); Composite topOptions = new Composite(optionComposite, SWT.NONE); topOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); topOptions.setLayout(new GridLayout(config.getDropDowns().size(), true)); for (DropDownData dropData : config.getDropDowns()) { if (dropData.getConfig().show(flags)) { Combo comboDropDown = new Combo(topOptions, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY); comboDropDown.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); comboDropDown.setData(dropData); combos.add(comboDropDown);// w w w. ja va2 s. c o m for (DropDownData.Pair data : dropData.getData()) { comboDropDown.add(data.name); } comboDropDown.select(0); comboDropDown.addSelectionListener(this.comboListener); } } // Separator: Helper.separator(optionComposite, 3); // Left Option Labels: new Label(optionComposite, SWT.NONE); Composite leftOptions = new Composite(optionComposite, SWT.NONE); leftOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); leftOptions.setLayout(new GridLayout(1, true)); for (OptionListConfigData.Pair pair : config.getOptionList().getData()) { Label lblOpt = new Label(leftOptions, SWT.NONE); lblOpt.setText(pair.name); } // Check Boxes: Composite selectionComposite = new Composite(optionComposite, SWT.NONE); selectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); selectionComposite.setLayout(new GridLayout(combos.size(), true)); OptionListConfig leftConfig = config.getOptionList().getConfig(); for (OptionListConfigData.Pair pair : config.getOptionList().getData()) { int x = 0; for (Combo combo : combos) { TrendChartPlotConfig topConfig = (TrendChartPlotConfig) config.getDropDowns().get(x).getConfig(); Button button = new Button(selectionComposite, SWT.CHECK); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); button.setData(new ChartIdentifier(topConfig, combo, leftConfig, pair.id, boxWeight++)); button.addSelectionListener(boxListener); x++; } } // Scrolling area size update: scrolledComposite.setMinSize(optionComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); }
From source file:org.eclipse.swt.examples.ole.win32.OleBrowserView.java
/** * Creates the Web browser toolbar.//from ww w .ja v a2s . co m */ private void createToolbar() { // Add a toolbar ToolBar bar = new ToolBar(displayArea, SWT.NONE); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 3; bar.setLayoutData(gridData); // Add a button to navigate backwards through previously visited web sites webCommandBackward = new ToolItem(bar, SWT.NONE); webCommandBackward.setToolTipText(OlePlugin.getResourceString("browser.Back.tooltip")); webCommandBackward.setText(OlePlugin.getResourceString("browser.Back.text")); webCommandBackward.setImage(OlePlugin.images[OlePlugin.biBack]); webCommandBackward.setEnabled(false); webCommandBackward.addListener(SWT.Selection, e -> { if (webBrowser == null) return; webBrowser.GoBack(); }); // Add a button to navigate forward through previously visited web sites webCommandForward = new ToolItem(bar, SWT.NONE); webCommandForward.setToolTipText(OlePlugin.getResourceString("browser.Forward.tooltip")); webCommandForward.setText(OlePlugin.getResourceString("browser.Forward.text")); webCommandForward.setImage(OlePlugin.images[OlePlugin.biForward]); webCommandForward.setEnabled(false); webCommandForward.addListener(SWT.Selection, e -> { if (webBrowser == null) return; webBrowser.GoForward(); }); // Add a separator new ToolItem(bar, SWT.SEPARATOR); // Add a button to navigate to the Home page webCommandHome = new ToolItem(bar, SWT.NONE); webCommandHome.setToolTipText(OlePlugin.getResourceString("browser.Home.tooltip")); webCommandHome.setText(OlePlugin.getResourceString("browser.Home.text")); webCommandHome.setImage(OlePlugin.images[OlePlugin.biHome]); webCommandHome.setEnabled(false); webCommandHome.addListener(SWT.Selection, e -> { if (webBrowser == null) return; webBrowser.GoHome(); }); // Add a button to abort web page loading webCommandStop = new ToolItem(bar, SWT.NONE); webCommandStop.setToolTipText(OlePlugin.getResourceString("browser.Stop.tooltip")); webCommandStop.setText(OlePlugin.getResourceString("browser.Stop.text")); webCommandStop.setImage(OlePlugin.images[OlePlugin.biStop]); webCommandStop.setEnabled(false); webCommandStop.addListener(SWT.Selection, e -> { if (webBrowser == null) return; webBrowser.Stop(); }); // Add a button to refresh the current web page webCommandRefresh = new ToolItem(bar, SWT.NONE); webCommandRefresh.setToolTipText(OlePlugin.getResourceString("browser.Refresh.tooltip")); webCommandRefresh.setText(OlePlugin.getResourceString("browser.Refresh.text")); webCommandRefresh.setImage(OlePlugin.images[OlePlugin.biRefresh]); webCommandRefresh.setEnabled(false); webCommandRefresh.addListener(SWT.Selection, e -> { if (webBrowser == null) return; webBrowser.Refresh(); }); // Add a separator new ToolItem(bar, SWT.SEPARATOR); // Add a button to search the web webCommandSearch = new ToolItem(bar, SWT.NONE); webCommandSearch.setToolTipText(OlePlugin.getResourceString("browser.Search.tooltip")); webCommandSearch.setText(OlePlugin.getResourceString("browser.Search.text")); webCommandSearch.setImage(OlePlugin.images[OlePlugin.biSearch]); webCommandSearch.setEnabled(false); webCommandSearch.addListener(SWT.Selection, e -> { if (webBrowser == null) return; webBrowser.GoSearch(); }); // Add a text area for Users to enter a url Composite addressBar = new Composite(displayArea, SWT.NONE); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); gridData.horizontalSpan = 3; addressBar.setLayoutData(gridData); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; addressBar.setLayout(gridLayout); Label addressLabel = new Label(addressBar, SWT.NONE); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); addressLabel.setLayoutData(gridData); addressLabel.setText(OlePlugin.getResourceString("browser.Address.label")); addressLabel.setFont(OlePlugin.browserFont); webUrl = new Text(addressBar, SWT.SINGLE | SWT.BORDER); webUrl.setFont(OlePlugin.browserFont); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); webUrl.setLayoutData(gridData); webUrl.addFocusListener(FocusListener .focusGainedAdapter(e -> webNavigateButton.getShell().setDefaultButton(webNavigateButton))); // Add a button to navigate to the web site specified in the Text area defined above webNavigateButton = new Button(addressBar, SWT.PUSH); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); webNavigateButton.setLayoutData(gridData); webNavigateButton.setText(OlePlugin.getResourceString("browser.Go.text")); webNavigateButton.setFont(OlePlugin.browserFont); webNavigateButton.addListener(SWT.Selection, event -> { if (webBrowser == null) return; webBrowser.Navigate(webUrl.getText()); }); }
From source file:org.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java
private void createInputTab(final CTabFolder parentTabFolder) { inputTab = new CTabItem(parentTabFolder, SWT.NONE); inputTab.setText(Messages.ProcessExecutionDialog_tabparameters); ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL); scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite container = new Composite(scroller, SWT.NONE); container.setLayout(new GridLayout(1, false)); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // local moran's i Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$ uiBuilder.createLabel(container, Messages.ScatterPlotDialog_InputLayer, EMPTY, image, 1); cboLayer = uiBuilder.createCombo(container, 1, true); fillLayers(map, cboLayer, VectorLayerType.ALL); uiBuilder.createLabel(container, Messages.ScatterPlotDialog_IndependentField, EMPTY, image, 1); cboXField = uiBuilder.createCombo(container, 1, true); uiBuilder.createLabel(container, Messages.ScatterPlotDialog_DependentField, EMPTY, image, 1); cboYField = uiBuilder.createCombo(container, 1, true); uiBuilder.createLabel(container, null, null, 1); chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 1); chkPearson = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_Pearson, null, 1); // register events cboLayer.addModifyListener(new ModifyListener() { @Override/* www .j a v a 2 s .c o m*/ public void modifyText(ModifyEvent e) { inputLayer = MapUtils.getLayer(map, cboLayer.getText()); if (inputLayer != null) { fillFields(cboXField, inputLayer.getSchema(), FieldType.Number); fillFields(cboYField, inputLayer.getSchema(), FieldType.Number); } } }); // finally scroller.setContent(container); inputTab.setControl(scroller); scroller.setMinSize(450, container.getSize().y - 2); scroller.setExpandVertical(true); scroller.setExpandHorizontal(true); scroller.pack(); container.pack(); }
From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java
private void createInputTab(final CTabFolder parentTabFolder) { inputTab = new CTabItem(parentTabFolder, SWT.NONE); inputTab.setText(Messages.ProcessExecutionDialog_tabparameters); ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL); scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite container = new Composite(scroller, SWT.NONE); container.setLayout(new GridLayout(2, false)); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // local moran's i Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$ uiBuilder.createLabel(container, Messages.HistogramDialog_InputLayer, EMPTY, image, 2); cboLayer = uiBuilder.createCombo(container, 2, true); fillLayers(map, cboLayer, VectorLayerType.ALL); uiBuilder.createLabel(container, Messages.HistogramDialog_InputField, EMPTY, image, 2); cboField = uiBuilder.createCombo(container, 2, true); uiBuilder.createLabel(container, Messages.HistogramDialog_BinCount, EMPTY, image, 2); spinner = uiBuilder.createSpinner(container, 10, 1, 50, 0, 1, 5, 2); // yXais Type uiBuilder.createLabel(container, Messages.HistogramDialog_YAxisType, EMPTY, image, 1); GridLayout layout = new GridLayout(2, false); layout.marginWidth = 0;/*from w ww . j av a2 s.c o m*/ Composite subCon = new Composite(container, SWT.NONE); subCon.setLayout(layout); subCon.setLayoutData(new GridData(SWT.LEFT_TO_RIGHT, SWT.CENTER, false, false, 1, 1)); final Button chkRatio = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Ratio, null, 1); final Button chkFrequency = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Frequency, null, 1); chkFrequency.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { if (chkFrequency.getSelection()) { histogramType = HistogramType.FREQUENCY; } } }); chkRatio.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { if (chkRatio.getSelection()) { histogramType = HistogramType.RELATIVE_FREQUENCY; } } }); chkRatio.setSelection(true); uiBuilder.createLabel(container, null, null, 2); chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 2); // register events cboLayer.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { inputLayer = MapUtils.getLayer(map, cboLayer.getText()); if (inputLayer != null) { fillFields(cboField, inputLayer.getSchema(), FieldType.Number); } } }); // finally scroller.setContent(container); inputTab.setControl(scroller); scroller.setMinSize(450, container.getSize().y - 2); scroller.setExpandVertical(true); scroller.setExpandHorizontal(true); scroller.pack(); container.pack(); }
From source file:org.eclipse.swt.examples.graphics.GradientDialog.java
/** * Creates the controls of the dialog.//from ww w . j a v a2 s . com * */ public void createDialogControls(final Shell parent) { final Display display = parent.getDisplay(); // message Label message = new Label(parent, SWT.NONE); message.setText(GraphicsExample.getResourceString("GradientDlgMsg")); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 2; message.setLayoutData(gridData); // default colors are white and black if (rgb1 == null || rgb2 == null) { rgb1 = display.getSystemColor(SWT.COLOR_WHITE).getRGB(); rgb2 = display.getSystemColor(SWT.COLOR_BLACK).getRGB(); } // canvas canvas = new Canvas(parent, SWT.NONE); gridData = new GridData(GridData.FILL_BOTH); gridData.widthHint = 200; gridData.heightHint = 100; canvas.setLayoutData(gridData); canvas.addListener(SWT.Paint, e -> { Image preview = null; Point size = canvas.getSize(); Color color1 = new Color(display, rgb1); Color color2 = new Color(display, rgb2); preview = GraphicsExample.createImage(display, color1, color2, size.x, size.y); if (preview != null) { e.gc.drawImage(preview, 0, 0); } preview.dispose(); color1.dispose(); color2.dispose(); }); // composite used for both color buttons Composite colorButtonComp = new Composite(parent, SWT.NONE); // layout buttons RowLayout layout = new RowLayout(); layout.type = SWT.VERTICAL; layout.pack = false; colorButtonComp.setLayout(layout); // position composite gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); colorButtonComp.setLayoutData(gridData); ColorMenu colorMenu = new ColorMenu(); // color controls: first color colorButton1 = new Button(colorButtonComp, SWT.PUSH); colorButton1.setText(GraphicsExample.getResourceString("GradientDlgButton1")); Color color1 = new Color(display, rgb1); Image img1 = GraphicsExample.createImage(display, color1); color1.dispose(); colorButton1.setImage(img1); resources.add(img1); menu1 = colorMenu.createMenu(parent.getParent(), gb -> { rgb1 = gb.getBgColor1().getRGB(); colorButton1.setImage(gb.getThumbNail()); if (canvas != null) canvas.redraw(); }); colorButton1.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu1.setLocation(point.x, point.y + bounds.height); menu1.setVisible(true); }); // color controls: second color colorButton2 = new Button(colorButtonComp, SWT.PUSH); colorButton2.setText(GraphicsExample.getResourceString("GradientDlgButton2")); Color color2 = new Color(display, rgb2); Image img2 = GraphicsExample.createImage(display, color2); color2.dispose(); colorButton2.setImage(img2); resources.add(img2); menu2 = colorMenu.createMenu(parent.getParent(), gb -> { rgb2 = gb.getBgColor1().getRGB(); colorButton2.setImage(gb.getThumbNail()); if (canvas != null) canvas.redraw(); }); colorButton2.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu2.setLocation(point.x, point.y + bounds.height); menu2.setVisible(true); }); // composite used for ok and cancel buttons Composite okCancelComp = new Composite(parent, SWT.NONE); // layout buttons RowLayout rowLayout = new RowLayout(); rowLayout.pack = false; rowLayout.marginTop = 5; okCancelComp.setLayout(rowLayout); // position composite gridData = new GridData(GridData.HORIZONTAL_ALIGN_END); gridData.horizontalSpan = 2; okCancelComp.setLayoutData(gridData); // OK button okButton = new Button(okCancelComp, SWT.PUSH); okButton.setText("&OK"); okButton.addListener(SWT.Selection, event -> { returnVal = SWT.OK; parent.close(); }); // cancel button cancelButton = new Button(okCancelComp, SWT.PUSH); cancelButton.setText("&Cancel"); cancelButton.addListener(SWT.Selection, event -> parent.close()); }
From source file:ClipboardExample.java
void createFileTransfer(Composite copyParent, Composite pasteParent) { // File Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("FileTransfer:"); //$NON-NLS-1$ Composite c = new Composite(copyParent, SWT.NONE); c.setLayout(new GridLayout(2, false)); GridData data = new GridData(GridData.FILL_HORIZONTAL); c.setLayoutData(data); copyFileTable = new Table(c, SWT.MULTI | SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; data.horizontalSpan = 2;/* www .j a v a 2 s . c om*/ copyFileTable.setLayoutData(data); Button b = new Button(c, SWT.PUSH); b.setText("Select file(s)"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); String result = dialog.open(); if (result != null && result.length() > 0) { // copyFileTable.removeAll(); String separator = System.getProperty("file.separator"); String path = dialog.getFilterPath(); String[] names = dialog.getFileNames(); for (int i = 0; i < names.length; i++) { TableItem item = new TableItem(copyFileTable, SWT.NONE); item.setText(path + separator + names[i]); } } } }); b = new Button(c, SWT.PUSH); b.setText("Select directory"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN); String result = dialog.open(); if (result != null && result.length() > 0) { // copyFileTable.removeAll(); TableItem item = new TableItem(copyFileTable, SWT.NONE); item.setText(result); } } }); b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] items = copyFileTable.getItems(); if (items.length > 0) { status.setText(""); String[] data = new String[items.length]; for (int i = 0; i < data.length; i++) { data[i] = items[i].getText(); } clipboard.setContents(new Object[] { data }, new Transfer[] { FileTransfer.getInstance() }); } else { status.setText("nothing to copy"); } } }); l = new Label(pasteParent, SWT.NONE); l.setText("FileTransfer:"); //$NON-NLS-1$ pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; pasteFileTable.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String[] data = (String[]) clipboard.getContents(FileTransfer.getInstance()); if (data != null && data.length > 0) { status.setText(""); pasteFileTable.removeAll(); for (int i = 0; i < data.length; i++) { TableItem item = new TableItem(pasteFileTable, SWT.NONE); item.setText(data[i]); } } else { status.setText("nothing to paste"); } } }); }
From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java
private void createInputTab(final CTabFolder parentTabFolder) { inputTab = new CTabItem(parentTabFolder, SWT.NONE); inputTab.setText(Messages.ProcessExecutionDialog_tabparameters); ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL); scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite container = new Composite(scroller, SWT.NONE); container.setLayout(new GridLayout(1, false)); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // local moran's i Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$ uiBuilder.createLabel(container, Messages.ScatterPlotDialog_InputLayer, EMPTY, image, 1); cboLayer = uiBuilder.createCombo(container, 1, true); fillLayers(map, cboLayer, VectorLayerType.ALL); uiBuilder.createLabel(container, Messages.BubbleChartDialog_XField, EMPTY, image, 1); cboXField = uiBuilder.createCombo(container, 1, true); uiBuilder.createLabel(container, Messages.BubbleChartDialog_YField, EMPTY, image, 1); cboYField = uiBuilder.createCombo(container, 1, true); uiBuilder.createLabel(container, Messages.BubbleChartDialog_SizeField, EMPTY, image, 1); cboSize = uiBuilder.createCombo(container, 1, true); uiBuilder.createLabel(container, null, null, 1); chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 1); // register events cboLayer.addModifyListener(new ModifyListener() { @Override/*from w w w.j a v a 2 s . c o m*/ public void modifyText(ModifyEvent e) { inputLayer = MapUtils.getLayer(map, cboLayer.getText()); if (inputLayer != null) { fillFields(cboXField, inputLayer.getSchema(), FieldType.Number); fillFields(cboYField, inputLayer.getSchema(), FieldType.Number); fillFields(cboSize, inputLayer.getSchema(), FieldType.Number); } } }); // finally scroller.setContent(container); inputTab.setControl(scroller); scroller.setMinSize(450, container.getSize().y - 2); scroller.setExpandVertical(true); scroller.setExpandHorizontal(true); scroller.pack(); container.pack(); }
From source file:org.eclipse.swt.examples.paint.PaintExample.java
/** * Creates the GUI.// www .j a va 2 s . 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(); })); }
From source file:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java
/** * Creates a page to allow users to create a traceability link. */// ww w. j av a2 s . c o m void createTraceabilityLinkPage() { final Composite composite = new Composite(getContainer(), SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 5)); composite.setLayout(new GridLayout()); Label concernLabel = new Label(composite, SWT.BORDER); concernLabel.setText("Crosscuttings Concerns(CCC)"); concernLabel.setToolTipText("This are the Crosscuttings Concerns detected on the requierement document"); GridData gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); concernLabel.setLayoutData(gridData); topNewLink = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); createColumns(composite, topNewLink); final Table table = topNewLink.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); topNewLink.setContentProvider(new ArrayContentProvider()); getSite().setSelectionProvider(topNewLink); // define layout for the viewer gridData = new GridData(SWT.FILL, SWT.FILL, true, true); topNewLink.getControl().setLayoutData(gridData); Button button = new Button(composite, SWT.PUSH); button.setText("Link"); button.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent event) { } public void widgetSelected(SelectionEvent event) { IStructuredSelection topSelection = (IStructuredSelection) topNewLink.getSelection(); IStructuredSelection bottomSelection = (IStructuredSelection) bottomNewLink.getSelection(); String[] crosscuttingConcern = (String[]) topSelection.getFirstElement(); String[] designDecision = (String[]) bottomSelection.getFirstElement(); if ((crosscuttingConcern != null) && (designDecision != null)) { // create dialog with ok and cancel button and info icon MessageBox dialog = new MessageBox(composite.getShell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); dialog.setText("Link confirmation"); dialog.setMessage("Do you want to link the selected items?"); // open dialog and await user selection int response = dialog.open(); if (response == SWT.OK) { PluginUtil.createNewLink(crosscuttingConcern, designDecision, cp); dirty = true; firePropertyChange(IEditorPart.PROP_DIRTY); } } else { MessageDialog.openError(composite.getShell(), "Error", "Please select item(s) to link"); } } }); gridData = new GridData(SWT.CENTER, SWT.TOP, false, false, 2, 1); button.setLayoutData(gridData); Label ddsLabel = new Label(composite, SWT.BORDER); ddsLabel.setText("Architectural design decisions"); ddsLabel.setToolTipText("This are the design decisions detected in the architectural document"); gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); ddsLabel.setLayoutData(gridData); bottomNewLink = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); createColumns(composite, bottomNewLink); Table table2 = bottomNewLink.getTable(); table2.setHeaderVisible(true); table2.setLinesVisible(true); bottomNewLink.setContentProvider(new ArrayContentProvider()); getSite().setSelectionProvider(bottomNewLink); gridData = new GridData(SWT.FILL, SWT.FILL, true, true); bottomNewLink.getControl().setLayoutData(gridData); int index = addPage(composite); setPageText(index, "New Link"); }
From source file:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java
private void createInputTab(final CTabFolder parentTabFolder) { inputTab = new CTabItem(parentTabFolder, SWT.NONE); inputTab.setText(Messages.ProcessExecutionDialog_tabparameters); ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL); scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite container = new Composite(scroller, SWT.NONE); container.setLayout(new GridLayout(1, false)); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // local moran's i Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$ uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_InputLayer, EMPTY, image, 1); cboLayer = uiBuilder.createCombo(container, 1, true); fillLayers(map, cboLayer, VectorLayerType.ALL); uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_InputField, EMPTY, image, 1); cboField = uiBuilder.createCombo(container, 1, true); uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_Conceptualization, EMPTY, 1); cboConcept = uiBuilder.createCombo(container, 1, true); cboConcept.addModifyListener(new ModifyListener() { @Override/*from w w w. j av a 2 s .co m*/ public void modifyText(ModifyEvent e) { for (Object enumVal : SpatialConcept.class.getEnumConstants()) { if (enumVal.toString().equalsIgnoreCase(cboConcept.getText())) { params.put(GlobalMoransIProcessFactory.spatialConcept.key, enumVal); break; } } } }); fillEnum(cboConcept, SpatialConcept.class); uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_DistanceMethod, EMPTY, 1); cboDistance = uiBuilder.createCombo(container, 1, true); cboDistance.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { for (Object enumVal : DistanceMethod.class.getEnumConstants()) { if (enumVal.toString().equalsIgnoreCase(cboDistance.getText())) { params.put(GlobalMoransIProcessFactory.distanceMethod.key, enumVal); break; } } } }); fillEnum(cboDistance, DistanceMethod.class); uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_Standardization, EMPTY, 1); cboStandard = uiBuilder.createCombo(container, 1, true); cboStandard.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { for (Object enumVal : StandardizationMethod.class.getEnumConstants()) { if (enumVal.toString().equalsIgnoreCase(cboStandard.getText())) { params.put(GlobalMoransIProcessFactory.standardization.key, enumVal); break; } } } }); fillEnum(cboStandard, StandardizationMethod.class); uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_DistanceBand, EMPTY, 1); final Text txtDistance = uiBuilder.createText(container, EMPTY, 1, true); txtDistance.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { Object obj = Converters.convert(txtDistance.getText(), Double.class); if (obj == null) { params.put(GlobalMoransIProcessFactory.searchDistance.key, Double.valueOf(0d)); } else { params.put(GlobalMoransIProcessFactory.searchDistance.key, obj); } } }); // register events cboLayer.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { inputLayer = MapUtils.getLayer(map, cboLayer.getText()); if (inputLayer == null) { return; } SimpleFeatureCollection features = MapUtils.getFeatures(inputLayer); params.put(GlobalMoransIProcessFactory.inputFeatures.key, features); fillFields(cboField, inputLayer.getSchema(), FieldType.Number); } }); cboField.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { params.put(GlobalMoransIProcessFactory.inputField.key, cboField.getText()); } }); // finally scroller.setContent(container); inputTab.setControl(scroller); scroller.setMinSize(450, container.getSize().y - 2); scroller.setExpandVertical(true); scroller.setExpandHorizontal(true); scroller.pack(); container.pack(); }