public ToolTipHandler(org.eclipse.swt.widgets.Shell parent) { final org.eclipse.swt.widgets.Display display = parent.getDisplay(); this.parentShell = parent; tipShell = new org.eclipse.swt.widgets.Shell(parent, SWT.ON_TOP | SWT.TOOL); org.eclipse.swt.layout.GridLayout gridLayout = new org.eclipse.swt.layout.GridLayout(); gridLayout.numColumns = 2; gridLayout.marginWidth = 2; gridLayout.marginHeight = 2; tipShell.setLayout(gridLayout); tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); tipLabelImage = new org.eclipse.swt.widgets.Label(tipShell, SWT.NONE); tipLabelImage.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); tipLabelImage.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); tipLabelImage.setLayoutData( new org.eclipse.swt.layout.GridData( GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER)); tipLabelText = new org.eclipse.swt.widgets.Label(tipShell, SWT.NONE); tipLabelText.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); tipLabelText.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); tipLabelText.setLayoutData( new org.eclipse.swt.layout.GridData( (-(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER)))); }
public void createGUI(org.eclipse.swt.widgets.Composite parent) { org.eclipse.swt.layout.GridLayout gridLayout; org.eclipse.swt.layout.GridData gridData; org.eclipse.swt.widgets.Composite displayArea = new org.eclipse.swt.widgets.Composite(parent, SWT.NONE); gridLayout = new org.eclipse.swt.layout.GridLayout(); gridLayout.numColumns = 1; displayArea.setLayout(gridLayout); final org.eclipse.swt.widgets.Canvas paintCanvas = new org.eclipse.swt.widgets.Canvas( displayArea, (-(SWT.BORDER | SWT.V_SCROLL)) | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND); gridData = new org.eclipse.swt.layout.GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); paintCanvas.setLayoutData(gridData); paintCanvas.setBackground(paintColorWhite); final org.eclipse.swt.widgets.Composite colorFrame = new org.eclipse.swt.widgets.Composite(displayArea, SWT.NONE); gridData = new org.eclipse.swt.layout.GridData( GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); colorFrame.setLayoutData(gridData); final org.eclipse.swt.widgets.Composite toolSettingsFrame = new org.eclipse.swt.widgets.Composite(displayArea, SWT.NONE); gridData = new org.eclipse.swt.layout.GridData( GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); toolSettingsFrame.setLayoutData(gridData); final org.eclipse.swt.widgets.Text statusText = new org.eclipse.swt.widgets.Text(displayArea, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); gridData = new org.eclipse.swt.layout.GridData( GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); statusText.setLayoutData(gridData); paintSurface = new org.eclipse.swt.examples.paint.PaintSurface(paintCanvas, statusText, paintColorWhite); tools[Pencil_tool].data = new org.eclipse.swt.examples.paint.PencilTool(toolSettings, paintSurface); tools[Airbrush_tool].data = new org.eclipse.swt.examples.paint.AirbrushTool(toolSettings, paintSurface); tools[Line_tool].data = new org.eclipse.swt.examples.paint.LineTool(toolSettings, paintSurface); tools[PolyLine_tool].data = new org.eclipse.swt.examples.paint.PolyLineTool(toolSettings, paintSurface); tools[Rectangle_tool].data = new org.eclipse.swt.examples.paint.RectangleTool(toolSettings, paintSurface); tools[RoundedRectangle_tool].data = new org.eclipse.swt.examples.paint.RoundedRectangleTool(toolSettings, paintSurface); tools[Ellipse_tool].data = new org.eclipse.swt.examples.paint.EllipseTool(toolSettings, paintSurface); tools[Text_tool].data = new org.eclipse.swt.examples.paint.TextTool(toolSettings, paintSurface); gridLayout = new org.eclipse.swt.layout.GridLayout(); gridLayout.numColumns = 3; gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; colorFrame.setLayout(gridLayout); activeForegroundColorCanvas = new org.eclipse.swt.widgets.Canvas(colorFrame, SWT.BORDER); gridData = new org.eclipse.swt.layout.GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.heightHint = 24; gridData.widthHint = 24; activeForegroundColorCanvas.setLayoutData(gridData); activeBackgroundColorCanvas = new org.eclipse.swt.widgets.Canvas(colorFrame, SWT.BORDER); gridData = new org.eclipse.swt.layout.GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.heightHint = 24; gridData.widthHint = 24; activeBackgroundColorCanvas.setLayoutData(gridData); final org.eclipse.swt.widgets.Canvas paletteCanvas = new org.eclipse.swt.widgets.Canvas(colorFrame, SWT.BORDER | SWT.NO_BACKGROUND); gridData = new org.eclipse.swt.layout.GridData(GridData.FILL_HORIZONTAL); gridData.heightHint = 24; paletteCanvas.setLayoutData(gridData); paletteCanvas.addListener( SWT.MouseDown, new org.eclipse.swt.widgets.Listener() { public void handleEvent(org.eclipse.swt.widgets.Event e) { org.eclipse.swt.graphics.Rectangle bounds = paletteCanvas.getClientArea(); org.eclipse.swt.graphics.Color color = getColorAt(bounds, e.x, e.y); if (e.button == 1) { setForegroundColor(color); } else { setBackgroundColor(color); } } private org.eclipse.swt.graphics.Color getColorAt( org.eclipse.swt.graphics.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)]; } }); org.eclipse.swt.widgets.Listener refreshListener = new org.eclipse.swt.widgets.Listener() { public void handleEvent(org.eclipse.swt.widgets.Event e) { if (e.gc == null) { return; } org.eclipse.swt.graphics.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); gridLayout = new org.eclipse.swt.layout.GridLayout(); gridLayout.numColumns = 4; gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; toolSettingsFrame.setLayout(gridLayout); org.eclipse.swt.widgets.Label label = new org.eclipse.swt.widgets.Label(toolSettingsFrame, SWT.NONE); label.setText(getResourceString("settings.AirbrushRadius.text")); final org.eclipse.swt.widgets.Scale airbrushRadiusScale = new org.eclipse.swt.widgets.Scale(toolSettingsFrame, SWT.HORIZONTAL); airbrushRadiusScale.setMinimum(5); airbrushRadiusScale.setMaximum(50); airbrushRadiusScale.setSelection(toolSettings.airbrushRadius); airbrushRadiusScale.setLayoutData( new org.eclipse.swt.layout.GridData( GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); airbrushRadiusScale.addSelectionListener( new org.eclipse.swt.events.SelectionAdapter() { public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { toolSettings.airbrushRadius = airbrushRadiusScale.getSelection(); updateToolSettings(); } }); label = new org.eclipse.swt.widgets.Label(toolSettingsFrame, SWT.NONE); label.setText(getResourceString("settings.AirbrushIntensity.text")); final org.eclipse.swt.widgets.Scale airbrushIntensityScale = new org.eclipse.swt.widgets.Scale(toolSettingsFrame, SWT.HORIZONTAL); airbrushIntensityScale.setMinimum(1); airbrushIntensityScale.setMaximum(100); airbrushIntensityScale.setSelection(toolSettings.airbrushIntensity); airbrushIntensityScale.setLayoutData( new org.eclipse.swt.layout.GridData( GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); airbrushIntensityScale.addSelectionListener( new org.eclipse.swt.events.SelectionAdapter() { public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { toolSettings.airbrushIntensity = airbrushIntensityScale.getSelection(); updateToolSettings(); } }); }