List of usage examples for org.eclipse.swt.graphics Color getRGB
public RGB getRGB()
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 w w w.j av a2 s.c o m 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 www . ja va2 s . c o m if (rgb != null) { Color color = new Color(shell.getDisplay(), rgb); System.out.println(color.getRGB()); color.dispose(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet242.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 242"); shell.setBounds(10, 10, 200, 200);//w w w.ja v a 2s . com Canvas canvas = new Canvas(shell, SWT.BORDER); canvas.setBounds(10, 50, 150, 100); canvas.addPaintListener(e -> e.gc.drawString("hide Cursor here", 10, 10)); // create a cursor with a transparent image Color white = display.getSystemColor(SWT.COLOR_WHITE); Color black = display.getSystemColor(SWT.COLOR_BLACK); PaletteData palette = new PaletteData(white.getRGB(), black.getRGB()); ImageData sourceData = new ImageData(16, 16, 1, palette); sourceData.transparentPixel = 0; Cursor cursor = new Cursor(display, sourceData, 0, 0); shell.open(); canvas.setCursor(cursor); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cursor.dispose(); display.dispose(); }
From source file:CursorHideControl.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 200);/*from w w w . j ava 2 s .co m*/ Canvas canvas = new Canvas(shell, SWT.BORDER); canvas.setBounds(10, 50, 150, 100); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawString("hide Cursor here", 10, 10); } }); // create a cursor with a transparent image Color white = display.getSystemColor(SWT.COLOR_WHITE); Color black = display.getSystemColor(SWT.COLOR_BLACK); PaletteData palette = new PaletteData(new RGB[] { white.getRGB(), black.getRGB() }); ImageData sourceData = new ImageData(16, 16, 1, palette); sourceData.transparentPixel = 0; Cursor cursor = new Cursor(display, sourceData, 0, 0); shell.open(); canvas.setCursor(cursor); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cursor.dispose(); display.dispose(); }
From source file:ColorTransparentCreate.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 200);//from w w w . ja v a2 s. c o m // create a cursor with a transparent image Color white = display.getSystemColor(SWT.COLOR_WHITE); Color black = display.getSystemColor(SWT.COLOR_BLACK); PaletteData palette = new PaletteData(new RGB[] { white.getRGB(), black.getRGB() }); final ImageData sourceData = new ImageData(30, 30, 1, palette); sourceData.transparentPixel = 0; Canvas canvas = new Canvas(shell, SWT.BORDER); canvas.setBounds(10, 50, 150, 100); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawString("hide Cursor here", 10, 10); e.gc.drawImage(new Image(display, sourceData), 0, 0); } }); 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 v a2s .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:ImageDataFromPaletteData.java
public static void main(String[] args) { Display display = new Display(); Color white = display.getSystemColor(SWT.COLOR_WHITE); Color black = display.getSystemColor(SWT.COLOR_BLACK); // Create a source ImageData of depth 1 (monochrome) PaletteData palette = new PaletteData(new RGB[] { white.getRGB(), black.getRGB(), }); ImageData sourceData = new ImageData(20, 20, 1, palette); for (int i = 0; i < 10; i++) { for (int j = 0; j < 20; j++) { sourceData.setPixel(i, j, 1); }/* www . ja v a 2 s . c o m*/ } Shell shell = new Shell(display); final Image source = new Image(display, sourceData); shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(source, 0, 0, 20, 20, 60, 10, 20, 20); } }); shell.setSize(150, 150); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } source.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet92.java
public static void main(String[] args) { Display display = new Display(); Color white = display.getSystemColor(SWT.COLOR_WHITE); Color black = display.getSystemColor(SWT.COLOR_BLACK); //Create a source ImageData of depth 1 (monochrome) PaletteData palette = new PaletteData(white.getRGB(), black.getRGB()); ImageData sourceData = new ImageData(20, 20, 1, palette); for (int i = 0; i < 10; i++) { for (int j = 0; j < 20; j++) { sourceData.setPixel(i, j, 1); }//from w w w .j av a2 s .c om } //Create a mask ImageData of depth 1 (monochrome) palette = new PaletteData(white.getRGB(), black.getRGB()); ImageData maskData = new ImageData(20, 20, 1, palette); for (int i = 0; i < 20; i++) { for (int j = 0; j < 10; j++) { maskData.setPixel(i, j, 1); } } //Create cursor Cursor cursor = new Cursor(display, sourceData, maskData, 10, 10); Shell shell = new Shell(display); shell.setText("Snippet 92"); final Image source = new Image(display, sourceData); final Image mask = new Image(display, maskData); //Draw source and mask just to show what they look like shell.addPaintListener(e -> { GC gc = e.gc; gc.drawString("source: ", 10, 10); gc.drawImage(source, 0, 0, 20, 20, 60, 10, 20, 20); gc.drawString("mask: ", 10, 40); gc.drawImage(mask, 0, 0, 20, 20, 60, 40, 20, 20); }); shell.setSize(150, 150); shell.open(); shell.setCursor(cursor); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cursor.dispose(); source.dispose(); mask.dispose(); display.dispose(); }
From source file:Snippet92.java
public static void main(String[] args) { Display display = new Display(); Color white = display.getSystemColor(SWT.COLOR_WHITE); Color black = display.getSystemColor(SWT.COLOR_BLACK); //Create a source ImageData of depth 1 (monochrome) PaletteData palette = new PaletteData(new RGB[] { white.getRGB(), black.getRGB(), }); ImageData sourceData = new ImageData(20, 20, 1, palette); for (int i = 0; i < 10; i++) { for (int j = 0; j < 20; j++) { sourceData.setPixel(i, j, 1); }//from www . j a va 2s .c o m } //Create a mask ImageData of depth 1 (monochrome) palette = new PaletteData(new RGB[] { white.getRGB(), black.getRGB(), }); ImageData maskData = new ImageData(20, 20, 1, palette); for (int i = 0; i < 20; i++) { for (int j = 0; j < 10; j++) { maskData.setPixel(i, j, 1); } } //Create cursor Cursor cursor = new Cursor(display, sourceData, maskData, 10, 10); Shell shell = new Shell(display); final Image source = new Image(display, sourceData); final Image mask = new Image(display, maskData); //Draw source and mask just to show what they look like shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.drawString("source: ", 10, 10); gc.drawImage(source, 0, 0, 20, 20, 50, 10, 20, 20); gc.drawString("mask: ", 10, 40); gc.drawImage(mask, 0, 0, 20, 20, 50, 40, 20, 20); } }); shell.setSize(150, 150); shell.open(); shell.setCursor(cursor); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cursor.dispose(); source.dispose(); mask.dispose(); 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 va2s .c o 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(); }