List of usage examples for org.eclipse.swt.graphics Color dispose
public void dispose()
From source file:ColorDialogSetInitColor.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); ColorDialog dlg = new ColorDialog(shell); dlg.setRGB(new RGB(0, 0, 255)); RGB rgb = dlg.open();/*from ww w. j a v a2 s .c om*/ if (rgb != null) { Color color = new Color(shell.getDisplay(), rgb); System.out.println(color.getRGB()); color.dispose(); } display.dispose(); }
From source file:ColorDialogCreateGetColor.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); ColorDialog dlg = new ColorDialog(shell); RGB rgb = dlg.open();/*from ww w .j a v a2 s . com*/ if (rgb != null) { Color color = new Color(shell.getDisplay(), rgb); System.out.println(color.getRGB()); color.dispose(); } display.dispose(); }
From source file:Snippet112.java
public static void main(String[] args) { Display display = new Display(); final Image image = new Image(display, 20, 20); Color color = display.getSystemColor(SWT.COLOR_RED); GC gc = new GC(image); gc.setBackground(color);//www .ja v a2 s . co m gc.fillRectangle(image.getBounds()); gc.dispose(); color.dispose(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Group group = new Group(shell, SWT.NONE); group.setLayout(new FillLayout()); group.setText("a square"); Canvas canvas = new Canvas(group, SWT.NONE); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image, 0, 0); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet316.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 316"); shell.setLayout(new FillLayout()); StyledText text = new StyledText(shell, SWT.V_SCROLL | SWT.H_SCROLL); text.setText("StyledText with margins."); Font font = new Font(display, "Tahoma", 14, SWT.ITALIC); text.setText(/*from w w w. j a v a2s .co m*/ "\"If you go down to the woods today\nYou'd better not go alone\nIt's lovely down in the woods today\nBut safer to stay at home\""); StyleRange italic = new StyleRange(); italic.font = font; text.setStyleRanges(new int[] { 0, text.getCharCount() }, new StyleRange[] { italic }); text.setMargins(30, 30, 30, 30); Color color = new Color(display, 138, 226, 255); text.setMarginColor(color); shell.setSize(500, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } font.dispose(); color.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet280.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.NO_BACKGROUND); shell.setText("Snippet 280"); shell.setLayout(new FillLayout()); shell.addListener(SWT.Paint, e -> { GC gc = e.gc;/* w ww.j a v a 2s. c o m*/ Rectangle rect = shell.getClientArea(); Color color1 = new Color(display, 234, 246, 253); Color color2 = new Color(display, 217, 240, 252); gc.setForeground(color1); gc.setBackground(color2); gc.fillGradientRectangle(rect.x, rect.y, rect.width, rect.height / 2, true); color1.dispose(); color2.dispose(); Color color3 = new Color(display, 190, 230, 253); Color color4 = new Color(display, 167, 217, 245); gc.setForeground(color3); gc.setBackground(color4); gc.fillGradientRectangle(rect.x, rect.y + (rect.height / 2), rect.width, rect.height / 2 + 1, true); color3.dispose(); color4.dispose(); }); shell.setSize(200, 64); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ColorDialogButtonActionSetLabelBackground.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Color Chooser"); shell.setLayout(new GridLayout(2, false)); final Label colorLabel = new Label(shell, SWT.NONE); colorLabel.setText("Color"); Button button = new Button(shell, SWT.PUSH); button.setText("Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Color color = new Color(shell.getDisplay(), new RGB(0, 255, 0)); ColorDialog dlg = new ColorDialog(shell); dlg.setRGB(colorLabel.getBackground().getRGB()); dlg.setText("Choose a Color"); RGB rgb = dlg.open();//w w w. ja va 2 s.c o m if (rgb != null) { color.dispose(); color = new Color(shell.getDisplay(), rgb); colorLabel.setBackground(color); color.dispose(); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display display = new Display(); // Create the main window final Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog FontDialog dlg = new FontDialog(shell); Font font = null;/*from w w w .j a va 2 s. c om*/ Color color = null; if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { if (font != null) font.dispose(); if (color != null) color.dispose(); font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); shell.pack(); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FontDialogColorFontData.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Font Chooser"); shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Font font = null;/*from w w w . j a v a 2 s . co m*/ Color color = null; FontDialog dlg = new FontDialog(shell); if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { if (font != null) font.dispose(); if (color != null) color.dispose(); font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); shell.pack(); if (font != null) font.dispose(); if (color != null) color.dispose(); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet281.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.NO_BACKGROUND); shell.setText("Snippet 281"); shell.setLayout(new FillLayout()); shell.addListener(SWT.Paint, e -> { GC gc = e.gc;/*w w w . j a va 2s . c o m*/ Rectangle rect = shell.getClientArea(); Color color1 = new Color(display, 234, 246, 253); Color color2 = new Color(display, 217, 240, 252); Color color3 = new Color(display, 190, 230, 253); Color color4 = new Color(display, 167, 217, 245); Pattern p1 = new Pattern(display, 0, 0, 0, rect.height / 2, color1, color2); gc.setBackgroundPattern(p1); gc.fillRectangle(rect.x, rect.y, rect.width, rect.height / 2); Pattern p2 = new Pattern(display, 0, rect.height / 2, 0, rect.height, color3, color4); gc.setBackgroundPattern(p2); gc.fillRectangle(rect.x, rect.y + (rect.height / 2), rect.width, rect.height / 2 + 1); p1.dispose(); p2.dispose(); color1.dispose(); color2.dispose(); color3.dispose(); color4.dispose(); }); shell.setSize(200, 64); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet141.java
public static void main(String[] args) { display = new Display(); shell = new Shell(display); shell.setSize(300, 300);/*from ww w . j a v a 2s . c o m*/ shell.open(); shellGC = new GC(shell); shellBackground = shell.getBackground(); FileDialog dialog = new FileDialog(shell); dialog.setFilterExtensions(new String[] { "*.gif" }); String fileName = dialog.open(); if (fileName != null) { loader = new ImageLoader(); try { imageDataArray = loader.load(fileName); if (imageDataArray.length > 1) { animateThread = new Thread("Animation") { public void run() { /* Create an off-screen image to draw on, and fill it with the shell background. */ Image offScreenImage = new Image(display, loader.logicalScreenWidth, loader.logicalScreenHeight); GC offScreenImageGC = new GC(offScreenImage); offScreenImageGC.setBackground(shellBackground); offScreenImageGC.fillRectangle(0, 0, loader.logicalScreenWidth, loader.logicalScreenHeight); try { /* Create the first image and draw it on the off-screen image. */ int imageDataIndex = 0; ImageData imageData = imageDataArray[imageDataIndex]; if (image != null && !image.isDisposed()) image.dispose(); image = new Image(display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); /* Now loop through the images, creating and drawing each one * on the off-screen image before drawing it on the shell. */ int repeatCount = loader.repeatCount; while (loader.repeatCount == 0 || repeatCount > 0) { switch (imageData.disposalMethod) { case SWT.DM_FILL_BACKGROUND: /* Fill with the background color before drawing. */ Color bgColor = null; if (useGIFBackground && loader.backgroundPixel != -1) { bgColor = new Color(display, imageData.palette.getRGB(loader.backgroundPixel)); } offScreenImageGC.setBackground(bgColor != null ? bgColor : shellBackground); offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height); if (bgColor != null) bgColor.dispose(); break; case SWT.DM_FILL_PREVIOUS: /* Restore the previous image before drawing. */ offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); break; } imageDataIndex = (imageDataIndex + 1) % imageDataArray.length; imageData = imageDataArray[imageDataIndex]; image.dispose(); image = new Image(display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); /* Draw the off-screen image to the shell. */ shellGC.drawImage(offScreenImage, 0, 0); /* Sleep for the specified delay time (adding commonly-used slow-down fudge factors). */ try { int ms = imageData.delayTime * 10; if (ms < 20) ms += 30; if (ms < 30) ms += 10; Thread.sleep(ms); } catch (InterruptedException e) { } /* If we have just drawn the last image, decrement the repeat count and start again. */ if (imageDataIndex == imageDataArray.length - 1) repeatCount--; } } catch (SWTException ex) { System.out.println("There was an error animating the GIF"); } finally { if (offScreenImage != null && !offScreenImage.isDisposed()) offScreenImage.dispose(); if (offScreenImageGC != null && !offScreenImageGC.isDisposed()) offScreenImageGC.dispose(); if (image != null && !image.isDisposed()) image.dispose(); } } }; animateThread.setDaemon(true); animateThread.start(); } } catch (SWTException ex) { System.out.println("There was an error loading the GIF"); } } while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }