List of usage examples for org.eclipse.swt.graphics Color dispose
public void dispose()
From source file:org.eclipse.swt.examples.controlexample.CTabFolderTab.java
/** * Sets the foreground color, background color, and font * of the "Example" widgets to their default settings. * Also sets foreground and background color of the Node 1 * TreeItems to default settings./* w w w. ja v a 2 s. co m*/ */ @Override void resetColorsAndFonts() { super.resetColorsAndFonts(); Color oldColor = selectionForegroundColor; selectionForegroundColor = null; setSelectionForeground(); if (oldColor != null) oldColor.dispose(); oldColor = selectionBackgroundColor; selectionBackgroundColor = null; setSelectionBackground(); if (oldColor != null) oldColor.dispose(); Font oldFont = itemFont; itemFont = null; setItemFont(); if (oldFont != null) oldFont.dispose(); }
From source file:org.eclipse.swt.examples.graphics.GradientDialog.java
/** * Creates the controls of the dialog.// w w w.ja v a 2 s.c o m * */ 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:org.eclipse.swt.snippets.Snippet133.java
void print(Printer printer) { if (printer.startJob("Text")) { // the string is the job name - shows up in the printer's job list Rectangle clientArea = printer.getClientArea(); Rectangle trim = printer.computeTrim(0, 0, 0, 0); Point dpi = printer.getDPI(); leftMargin = dpi.x + trim.x; // one inch from left side of paper rightMargin = clientArea.width - dpi.x + trim.x + trim.width; // one inch from right side of paper topMargin = dpi.y + trim.y; // one inch from top edge of paper bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one inch from bottom edge of paper /* Create a buffer for computing tab width. */ int tabSize = 4; // is tab width a user setting in your UI? StringBuilder tabBuffer = new StringBuilder(tabSize); for (int i = 0; i < tabSize; i++) tabBuffer.append(' '); tabs = tabBuffer.toString();// w ww . ja v a 2s . c om /* Create printer GC, and create and set the printer font & foreground color. */ gc = new GC(printer); Font printerFont = new Font(printer, printerFontData); Color printerForegroundColor = new Color(printer, printerForeground); Color printerBackgroundColor = new Color(printer, printerBackground); gc.setFont(printerFont); gc.setForeground(printerForegroundColor); gc.setBackground(printerBackgroundColor); tabWidth = gc.stringExtent(tabs).x; lineHeight = gc.getFontMetrics().getHeight(); /* Print text to current gc using word wrap */ printText(); printer.endJob(); /* Cleanup graphics resources used in printing */ printerFont.dispose(); printerForegroundColor.dispose(); printerBackgroundColor.dispose(); gc.dispose(); } }
From source file:org.eclipse.swt.examples.controlexample.TableTab.java
/** * Sets the foreground color, background color, and font * of the "Example" widgets to their default settings. * Also sets foreground and background color of TableItem [0] * to default settings.// w w w. j a va2 s .c o m */ @Override void resetColorsAndFonts() { super.resetColorsAndFonts(); Color oldColor = itemForegroundColor; itemForegroundColor = null; setItemForeground(); if (oldColor != null) oldColor.dispose(); oldColor = itemBackgroundColor; itemBackgroundColor = null; setItemBackground(); if (oldColor != null) oldColor.dispose(); Font oldFont = font; itemFont = null; setItemFont(); if (oldFont != null) oldFont.dispose(); oldColor = cellForegroundColor; cellForegroundColor = null; setCellForeground(); if (oldColor != null) oldColor.dispose(); oldColor = cellBackgroundColor; cellBackgroundColor = null; setCellBackground(); if (oldColor != null) oldColor.dispose(); oldFont = font; cellFont = null; setCellFont(); if (oldFont != null) oldFont.dispose(); oldColor = headerBackgroundColor; headerBackgroundColor = null; setHeaderBackground(); if (oldColor != null) oldColor.dispose(); oldColor = headerForegroundColor; headerForegroundColor = null; setHeaderForeground(); if (oldColor != null) oldColor.dispose(); }
From source file:PrintTextWrapPagetation.java
void print(Printer printer) { if (printer.startJob("Text")) { // the string is the job name - shows up in // the printer's job list Rectangle clientArea = printer.getClientArea(); Rectangle trim = printer.computeTrim(0, 0, 0, 0); Point dpi = printer.getDPI(); leftMargin = dpi.x + trim.x; // one inch from left side of paper rightMargin = clientArea.width - dpi.x + trim.x + trim.width; // one inch // from // right // side of // paper topMargin = dpi.y + trim.y; // one inch from top edge of paper bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one // inch // from // bottom // edge // of // paper /* Create a buffer for computing tab width. */ int tabSize = 4; // is tab width a user setting in your UI? StringBuffer tabBuffer = new StringBuffer(tabSize); for (int i = 0; i < tabSize; i++) tabBuffer.append(' '); tabs = tabBuffer.toString();// w w w .ja v a 2 s . c o m /* * Create printer GC, and create and set the printer font & foreground * color. */ gc = new GC(printer); Font printerFont = new Font(printer, printerFontData); Color printerForegroundColor = new Color(printer, printerForeground); Color printerBackgroundColor = new Color(printer, printerBackground); gc.setFont(printerFont); gc.setForeground(printerForegroundColor); gc.setBackground(printerBackgroundColor); tabWidth = gc.stringExtent(tabs).x; lineHeight = gc.getFontMetrics().getHeight(); /* Print text to current gc using word wrap */ printText(); printer.endJob(); /* Cleanup graphics resources used in printing */ printerFont.dispose(); printerForegroundColor.dispose(); printerBackgroundColor.dispose(); gc.dispose(); } }
From source file:org.eclipse.swt.examples.controlexample.CTabFolderTab.java
@Override void changeFontOrColor(int index) { switch (index) { case SELECTION_FOREGROUND_COLOR: { Color oldColor = selectionForegroundColor; if (oldColor == null) oldColor = tabFolder1.getSelectionForeground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open();/*w w w . j a va 2 s .c o m*/ if (rgb == null) return; oldColor = selectionForegroundColor; selectionForegroundColor = new Color(display, rgb); setSelectionForeground(); if (oldColor != null) oldColor.dispose(); } break; case SELECTION_BACKGROUND_COLOR: { Color oldColor = selectionBackgroundColor; if (oldColor == null) oldColor = tabFolder1.getSelectionBackground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = selectionBackgroundColor; selectionBackgroundColor = new Color(display, rgb); setSelectionBackground(); if (oldColor != null) oldColor.dispose(); } break; case ITEM_FONT: { Font oldFont = itemFont; if (oldFont == null) oldFont = tabFolder1.getItem(0).getFont(); fontDialog.setFontList(oldFont.getFontData()); FontData fontData = fontDialog.open(); if (fontData == null) return; oldFont = itemFont; itemFont = new Font(display, fontData); setItemFont(); setExampleWidgetSize(); if (oldFont != null) oldFont.dispose(); } break; default: super.changeFontOrColor(index); } }
From source file:org.eclipse.swt.examples.controlexample.TreeTab.java
/** * Sets the foreground color, background color, and font * of the "Example" widgets to their default settings. * Also sets foreground and background color of the Node 1 * TreeItems to default settings.//from www. j a v a2 s .com */ @Override void resetColorsAndFonts() { super.resetColorsAndFonts(); Color oldColor = itemForegroundColor; itemForegroundColor = null; setItemForeground(); if (oldColor != null) oldColor.dispose(); oldColor = itemBackgroundColor; itemBackgroundColor = null; setItemBackground(); if (oldColor != null) oldColor.dispose(); Font oldFont = font; itemFont = null; setItemFont(); if (oldFont != null) oldFont.dispose(); oldColor = cellForegroundColor; cellForegroundColor = null; setCellForeground(); if (oldColor != null) oldColor.dispose(); oldColor = cellBackgroundColor; cellBackgroundColor = null; setCellBackground(); if (oldColor != null) oldColor.dispose(); oldFont = font; cellFont = null; setCellFont(); if (oldFont != null) oldFont.dispose(); oldColor = headerBackgroundColor; headerBackgroundColor = null; setHeaderBackground(); if (oldColor != null) oldColor.dispose(); oldColor = headerForegroundColor; headerForegroundColor = null; setHeaderForeground(); if (oldColor != null) oldColor.dispose(); }
From source file:org.eclipse.swt.examples.controlexample.TableTab.java
@Override void changeFontOrColor(int index) { switch (index) { case ITEM_FOREGROUND_COLOR: { Color oldColor = itemForegroundColor; if (oldColor == null) oldColor = table1.getItem(0).getForeground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open();/*from ww w.ja v a 2s.c om*/ if (rgb == null) return; oldColor = itemForegroundColor; itemForegroundColor = new Color(display, rgb); setItemForeground(); if (oldColor != null) oldColor.dispose(); } break; case ITEM_BACKGROUND_COLOR: { Color oldColor = itemBackgroundColor; if (oldColor == null) oldColor = table1.getItem(0).getBackground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = itemBackgroundColor; itemBackgroundColor = new Color(display, rgb); setItemBackground(); if (oldColor != null) oldColor.dispose(); } break; case ITEM_FONT: { Font oldFont = itemFont; if (oldFont == null) oldFont = table1.getItem(0).getFont(); fontDialog.setFontList(oldFont.getFontData()); FontData fontData = fontDialog.open(); if (fontData == null) return; oldFont = itemFont; itemFont = new Font(display, fontData); setItemFont(); setExampleWidgetSize(); if (oldFont != null) oldFont.dispose(); } break; case CELL_FOREGROUND_COLOR: { Color oldColor = cellForegroundColor; if (oldColor == null) oldColor = table1.getItem(0).getForeground(1); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = cellForegroundColor; cellForegroundColor = new Color(display, rgb); setCellForeground(); if (oldColor != null) oldColor.dispose(); } break; case CELL_BACKGROUND_COLOR: { Color oldColor = cellBackgroundColor; if (oldColor == null) oldColor = table1.getItem(0).getBackground(1); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = cellBackgroundColor; cellBackgroundColor = new Color(display, rgb); setCellBackground(); if (oldColor != null) oldColor.dispose(); } break; case CELL_FONT: { Font oldFont = cellFont; if (oldFont == null) oldFont = table1.getItem(0).getFont(1); fontDialog.setFontList(oldFont.getFontData()); FontData fontData = fontDialog.open(); if (fontData == null) return; oldFont = cellFont; cellFont = new Font(display, fontData); setCellFont(); setExampleWidgetSize(); if (oldFont != null) oldFont.dispose(); } break; case HEADER_FOREGROUND_COLOR: { Color oldColor = headerForegroundColor; if (oldColor == null) oldColor = table1.getHeaderForeground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = headerForegroundColor; headerForegroundColor = new Color(display, rgb); setHeaderForeground(); if (oldColor != null) oldColor.dispose(); } break; case HEADER_BACKGROUND_COLOR: { Color oldColor = headerBackgroundColor; if (oldColor == null) oldColor = table1.getHeaderBackground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = headerBackgroundColor; headerBackgroundColor = new Color(display, rgb); setHeaderBackground(); if (oldColor != null) oldColor.dispose(); } break; default: super.changeFontOrColor(index); } }
From source file:org.eclipse.swt.examples.controlexample.TreeTab.java
@Override void changeFontOrColor(int index) { switch (index) { case ITEM_FOREGROUND_COLOR: { Color oldColor = itemForegroundColor; if (oldColor == null) oldColor = textNode1.getForeground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open();/*from ww w. j a va2s .c o m*/ if (rgb == null) return; oldColor = itemForegroundColor; itemForegroundColor = new Color(display, rgb); setItemForeground(); if (oldColor != null) oldColor.dispose(); } break; case ITEM_BACKGROUND_COLOR: { Color oldColor = itemBackgroundColor; if (oldColor == null) oldColor = textNode1.getBackground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = itemBackgroundColor; itemBackgroundColor = new Color(display, rgb); setItemBackground(); if (oldColor != null) oldColor.dispose(); } break; case ITEM_FONT: { Font oldFont = itemFont; if (oldFont == null) oldFont = textNode1.getFont(); fontDialog.setFontList(oldFont.getFontData()); FontData fontData = fontDialog.open(); if (fontData == null) return; oldFont = itemFont; itemFont = new Font(display, fontData); setItemFont(); setExampleWidgetSize(); if (oldFont != null) oldFont.dispose(); } break; case CELL_FOREGROUND_COLOR: { Color oldColor = cellForegroundColor; if (oldColor == null) oldColor = textNode1.getForeground(1); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = cellForegroundColor; cellForegroundColor = new Color(display, rgb); setCellForeground(); if (oldColor != null) oldColor.dispose(); } break; case CELL_BACKGROUND_COLOR: { Color oldColor = cellBackgroundColor; if (oldColor == null) oldColor = textNode1.getBackground(1); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = cellBackgroundColor; cellBackgroundColor = new Color(display, rgb); setCellBackground(); if (oldColor != null) oldColor.dispose(); } break; case CELL_FONT: { Font oldFont = cellFont; if (oldFont == null) oldFont = textNode1.getFont(1); fontDialog.setFontList(oldFont.getFontData()); FontData fontData = fontDialog.open(); if (fontData == null) return; oldFont = cellFont; cellFont = new Font(display, fontData); setCellFont(); setExampleWidgetSize(); if (oldFont != null) oldFont.dispose(); } break; case HEADER_FOREGROUND_COLOR: { Color oldColor = headerForegroundColor; if (oldColor == null) oldColor = tree1.getHeaderForeground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = headerForegroundColor; headerForegroundColor = new Color(display, rgb); setHeaderForeground(); if (oldColor != null) oldColor.dispose(); } break; case HEADER_BACKGROUND_COLOR: { Color oldColor = headerBackgroundColor; if (oldColor == null) oldColor = tree1.getHeaderBackground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = headerBackgroundColor; headerBackgroundColor = new Color(display, rgb); setHeaderBackground(); if (oldColor != null) oldColor.dispose(); } default: super.changeFontOrColor(index); } }
From source file:com.planetmayo.debrief.satc_rcp.views.MaintainContributionsView.java
@Override public void dispose() { context.dispose();/*from w w w . j a v a 2 s . c om*/ setActiveSolver(null); solversManager.removeSolverManagerListener(solverManagerListener); // ditch the colors if (assignedColors != null) { Iterator<Color> cIter = assignedColors.values().iterator(); while (cIter.hasNext()) { org.eclipse.swt.graphics.Color entry = cIter.next(); entry.dispose(); } assignedColors = null; } // and our SWT black shade if (!_colorBlack.isDisposed()) _colorBlack.dispose(); super.dispose(); }