List of usage examples for org.eclipse.swt.graphics Color getRGB
public RGB getRGB()
From source file:ImageFromByteArray.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); Color yellow = display.getSystemColor(SWT.COLOR_YELLOW); Color red = display.getSystemColor(SWT.COLOR_RED); Color green = display.getSystemColor(SWT.COLOR_GREEN); Color blue = display.getSystemColor(SWT.COLOR_BLUE); // Create a source ImageData of depth 4 PaletteData palette = new PaletteData(new RGB[] { black.getRGB(), white.getRGB(), yellow.getRGB(), red.getRGB(), blue.getRGB(), green.getRGB() }); ImageData sourceData = new ImageData(16, 16, 4, palette, 1, srcData); Shell shell = new Shell(display); final Image source = new Image(display, sourceData); shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc;/* w w w . j a v a 2 s .co m*/ gc.drawImage(source, 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.Snippet119.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); Color yellow = display.getSystemColor(SWT.COLOR_YELLOW); Color red = display.getSystemColor(SWT.COLOR_RED); Color green = display.getSystemColor(SWT.COLOR_GREEN); Color blue = display.getSystemColor(SWT.COLOR_BLUE); //Create a source ImageData of depth 4 PaletteData palette = new PaletteData(black.getRGB(), white.getRGB(), yellow.getRGB(), red.getRGB(), blue.getRGB(), green.getRGB()); ImageData sourceData = new ImageData(16, 16, 4, palette, 1, srcData); //Create a mask ImageData of depth 1 (monochrome) palette = new PaletteData(black.getRGB(), white.getRGB()); ImageData maskData = new ImageData(16, 16, 1, palette, 1, mskData); //Set mask//w w w.j av a 2 s. co m sourceData.maskData = maskData.data; sourceData.maskPad = maskData.scanlinePad; //Create cursor Cursor cursor = new Cursor(display, sourceData, 10, 10); //Remove mask to draw them separately just to show what they look like sourceData.maskData = null; sourceData.maskPad = -1; Shell shell = new Shell(display); shell.setText("Snippet 119"); final Image source = new Image(display, sourceData); final Image mask = new Image(display, maskData); shell.addPaintListener(e -> { GC gc = e.gc; int x = 10, y = 10; String stringSource = "source: "; String stringMask = "mask: "; gc.drawString(stringSource, x, y); gc.drawString(stringMask, x, y + 30); x += Math.max(gc.stringExtent(stringSource).x, gc.stringExtent(stringMask).x); gc.drawImage(source, x, y); gc.drawImage(mask, x, y + 30); }); 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:Snippet119.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); Color yellow = display.getSystemColor(SWT.COLOR_YELLOW); Color red = display.getSystemColor(SWT.COLOR_RED); Color green = display.getSystemColor(SWT.COLOR_GREEN); Color blue = display.getSystemColor(SWT.COLOR_BLUE); // Create a source ImageData of depth 4 PaletteData palette = new PaletteData(new RGB[] { black.getRGB(), white.getRGB(), yellow.getRGB(), red.getRGB(), blue.getRGB(), green.getRGB() }); ImageData sourceData = new ImageData(16, 16, 4, palette, 1, srcData); // Create a mask ImageData of depth 1 (monochrome) palette = new PaletteData(new RGB[] { black.getRGB(), white.getRGB(), }); ImageData maskData = new ImageData(16, 16, 1, palette, 1, mskData); // Set mask/*from w w w .j a va2s . c om*/ sourceData.maskData = maskData.data; sourceData.maskPad = maskData.scanlinePad; // Create cursor Cursor cursor = new Cursor(display, sourceData, 10, 10); // Remove mask to draw them separately just to show what they look like sourceData.maskData = null; sourceData.maskPad = -1; Shell shell = new Shell(display); final Image source = new Image(display, sourceData); final Image mask = new Image(display, maskData); shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; int x = 10, y = 10; String stringSource = "source: "; String stringMask = "mask: "; gc.drawString(stringSource, x, y); gc.drawString(stringMask, x, y + 30); x += Math.max(gc.stringExtent(stringSource).x, gc.stringExtent(stringMask).x); gc.drawImage(source, x, y); gc.drawImage(mask, x, y + 30); } }); 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:org.eclipse.swt.examples.controlexample.LinkTab.java
@Override void changeFontOrColor(int index) { switch (index) { case LINK_FOREGROUND_COLOR: { Color oldColor = linkForegroundColor; if (oldColor == null) oldColor = link1.getLinkForeground(); colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open();//ww w.j a va2 s .c o m if (rgb == null) return; oldColor = linkForegroundColor; linkForegroundColor = new Color(display, rgb); setLinkForeground(); if (oldColor != null) oldColor.dispose(); } break; default: super.changeFontOrColor(index); } }
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();// www. j av a 2s .c om 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.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 www. j a v a2s . 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 = 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 w w w. j av a2 s . 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:org.eclipse.swt.examples.controlexample.Tab.java
void changeFontOrColor(int index) { switch (index) { case FOREGROUND_COLOR: { Color oldColor = foregroundColor; if (oldColor == null) { Control[] controls = getExampleControls(); if (controls.length > 0) oldColor = controls[0].getForeground(); }/* w w w. j av a 2s . c o m*/ if (oldColor != null) colorDialog.setRGB(oldColor.getRGB()); // seed dialog with current color RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = foregroundColor; // save old foreground color to dispose when done foregroundColor = new Color(display, rgb); setExampleWidgetForeground(); if (oldColor != null) oldColor.dispose(); } break; case BACKGROUND_COLOR: { Color oldColor = backgroundColor; if (oldColor == null) { Control[] controls = getExampleControls(); if (controls.length > 0) oldColor = controls[0].getBackground(); // seed dialog with current color } if (oldColor != null) colorDialog.setRGB(oldColor.getRGB()); RGB rgb = colorDialog.open(); if (rgb == null) return; oldColor = backgroundColor; // save old background color to dispose when done backgroundColor = new Color(display, rgb); setExampleWidgetBackground(); if (oldColor != null) oldColor.dispose(); } break; case FONT: { Font oldFont = font; if (oldFont == null) { Control[] controls = getExampleControls(); if (controls.length > 0) oldFont = controls[0].getFont(); } if (oldFont != null) fontDialog.setFontList(oldFont.getFontData()); // seed dialog with current font FontData fontData = fontDialog.open(); if (fontData == null) return; oldFont = font; // dispose old font when done font = new Font(display, fontData); setExampleWidgetFont(); setExampleWidgetSize(); if (oldFont != null) oldFont.dispose(); } break; } }
From source file:TableTree.java
void createImages() { int itemHeight = sizeImage.getBounds().height; // Calculate border around image. // At least 9 pixels are needed to draw the image // Leave at least a 6 pixel border. int indent = Math.min(6, (itemHeight - 9) / 2); indent = Math.max(0, indent); int size = Math.max(10, itemHeight - 2 * indent); size = ((size + 1) / 2) * 2; // size must be an even number int midpoint = indent + size / 2; Color foreground = getForeground(); Color plusMinus = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); Color background = getBackground(); /* Plus image */ PaletteData palette = new PaletteData( new RGB[] { foreground.getRGB(), background.getRGB(), plusMinus.getRGB() }); ImageData imageData = new ImageData(itemHeight, itemHeight, 4, palette); imageData.transparentPixel = 1;/*w w w . j a v a 2 s. c om*/ plusImage = new Image(getDisplay(), imageData); GC gc = new GC(plusImage); gc.setBackground(background); gc.fillRectangle(0, 0, itemHeight, itemHeight); gc.setForeground(plusMinus); gc.drawRectangle(indent, indent, size, size); gc.setForeground(foreground); gc.drawLine(midpoint, indent + 2, midpoint, indent + size - 2); gc.drawLine(indent + 2, midpoint, indent + size - 2, midpoint); gc.dispose(); /* Minus image */ palette = new PaletteData(new RGB[] { foreground.getRGB(), background.getRGB(), plusMinus.getRGB() }); imageData = new ImageData(itemHeight, itemHeight, 4, palette); imageData.transparentPixel = 1; minusImage = new Image(getDisplay(), imageData); gc = new GC(minusImage); gc.setBackground(background); gc.fillRectangle(0, 0, itemHeight, itemHeight); gc.setForeground(plusMinus); gc.drawRectangle(indent, indent, size, size); gc.setForeground(foreground); gc.drawLine(indent + 2, midpoint, indent + size - 2, midpoint); gc.dispose(); }
From source file:CustomControlExample.java
/** * Creates the "Colors" group.// w ww. j a va2s. c o m */ void createColorGroup() { super.createColorGroup(); itemGroup = new Group(colorGroup, SWT.NONE); itemGroup.setText(ControlExample.getResourceString("Tree_Item_Colors")); GridData data = new GridData(); data.horizontalSpan = 2; itemGroup.setLayoutData(data); itemGroup.setLayout(new GridLayout(2, false)); new Label(itemGroup, SWT.NONE).setText(ControlExample.getResourceString("Foreground_Color")); itemForegroundButton = new Button(itemGroup, SWT.PUSH); new Label(itemGroup, SWT.NONE).setText(ControlExample.getResourceString("Background_Color")); itemBackgroundButton = new Button(itemGroup, SWT.PUSH); itemFontButton = new Button(itemGroup, SWT.PUSH); itemFontButton.setText(ControlExample.getResourceString("Font")); itemFontButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); Shell shell = colorGroup.getShell(); final ColorDialog foregroundDialog = new ColorDialog(shell); final ColorDialog backgroundDialog = new ColorDialog(shell); final FontDialog fontDialog = new FontDialog(shell); int imageSize = 12; Display display = shell.getDisplay(); itemForegroundImage = new Image(display, imageSize, imageSize); itemBackgroundImage = new Image(display, imageSize, imageSize); /* Add listeners to set the colors and font */ itemForegroundButton.setImage(itemForegroundImage); itemForegroundButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Color oldColor = itemForegroundColor; if (oldColor == null) oldColor = textNode1.getForeground(); foregroundDialog.setRGB(oldColor.getRGB()); RGB rgb = foregroundDialog.open(); if (rgb == null) return; oldColor = itemForegroundColor; itemForegroundColor = new Color(event.display, rgb); setItemForeground(); if (oldColor != null) oldColor.dispose(); } }); itemBackgroundButton.setImage(itemBackgroundImage); itemBackgroundButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Color oldColor = itemBackgroundColor; if (oldColor == null) oldColor = textNode1.getBackground(); backgroundDialog.setRGB(oldColor.getRGB()); RGB rgb = backgroundDialog.open(); if (rgb == null) return; oldColor = itemBackgroundColor; itemBackgroundColor = new Color(event.display, rgb); setItemBackground(); if (oldColor != null) oldColor.dispose(); } }); itemFontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { 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(event.display, fontData); setItemFont(); setExampleWidgetSize(); if (oldFont != null) oldFont.dispose(); } }); shell.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent event) { if (itemBackgroundImage != null) itemBackgroundImage.dispose(); if (itemForegroundImage != null) itemForegroundImage.dispose(); if (itemBackgroundColor != null) itemBackgroundColor.dispose(); if (itemForegroundColor != null) itemForegroundColor.dispose(); if (itemFont != null) itemFont.dispose(); itemBackgroundColor = null; itemForegroundColor = null; itemFont = null; } }); }