List of usage examples for org.eclipse.swt.widgets Display getSystemColor
@Override public Color getSystemColor(int id)
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. ja va 2 s . c o m } //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:org.eclipse.swt.snippets.Snippet129.java
public static void main(String[] args) { Display display = new Display(); Color red = display.getSystemColor(SWT.COLOR_RED); Color blue = display.getSystemColor(SWT.COLOR_BLUE); Color white = display.getSystemColor(SWT.COLOR_WHITE); Color gray = display.getSystemColor(SWT.COLOR_GRAY); Shell shell = new Shell(display); shell.setText("Snippet 129"); shell.setLayout(new FillLayout()); Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); table.setBackground(gray);/*www .j a va2s . c om*/ TableColumn column1 = new TableColumn(table, SWT.NONE); TableColumn column2 = new TableColumn(table, SWT.NONE); TableColumn column3 = new TableColumn(table, SWT.NONE); TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { "entire", "row", "red foreground" }); item.setForeground(red); item = new TableItem(table, SWT.NONE); item.setText(new String[] { "entire", "row", "red background" }); item.setBackground(red); item = new TableItem(table, SWT.NONE); item.setText(new String[] { "entire", "row", "white fore/red back" }); item.setForeground(white); item.setBackground(red); item = new TableItem(table, SWT.NONE); item.setText(new String[] { "normal", "blue foreground", "red foreground" }); item.setForeground(1, blue); item.setForeground(2, red); item = new TableItem(table, SWT.NONE); item.setText(new String[] { "normal", "blue background", "red background" }); item.setBackground(1, blue); item.setBackground(2, red); item = new TableItem(table, SWT.NONE); item.setText(new String[] { "white fore/blue back", "normal", "white fore/red back" }); item.setForeground(0, white); item.setBackground(0, blue); item.setForeground(2, white); item.setBackground(2, red); column1.pack(); column2.pack(); column3.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ToolTipRectangle.java
public static void main(String[] args) { Display display = new Display(); final Color[] colors = { display.getSystemColor(SWT.COLOR_RED), display.getSystemColor(SWT.COLOR_GREEN), display.getSystemColor(SWT.COLOR_BLUE), }; final Rectangle[] rects = { new Rectangle(10, 10, 30, 30), new Rectangle(20, 45, 25, 35), new Rectangle(80, 80, 10, 10), }; final Shell shell = new Shell(display); Listener mouseListener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.MouseEnter: case SWT.MouseMove: for (int i = 0; i < rects.length; i++) { if (rects[i].contains(event.x, event.y)) { String text = "ToolTip " + i; if (!(text.equals(shell.getToolTipText()))) { shell.setToolTipText("ToolTip " + i); }//from ww w. jav a2 s. c o m return; } } shell.setToolTipText(null); break; } } }; shell.addListener(SWT.MouseMove, mouseListener); shell.addListener(SWT.MouseEnter, mouseListener); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { GC gc = event.gc; for (int i = 0; i < rects.length; i++) { gc.setBackground(colors[i]); gc.fillRectangle(rects[i]); gc.drawRectangle(rects[i]); } } }); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet36.java
public static void main(String[] args) { Display display = new Display(); Image image = new Image(display, 16, 16); Color color = display.getSystemColor(SWT.COLOR_RED); GC gc = new GC(image); gc.setBackground(color);// ww w . j a v a 2s. c o m gc.fillRectangle(image.getBounds()); gc.dispose(); Shell shell = new Shell(display); shell.setText("Snippet 36"); ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.BORDER); Rectangle clientArea = shell.getClientArea(); toolBar.setLocation(clientArea.x, clientArea.y); for (int i = 0; i < 12; i++) { int style = i % 3 == 2 ? SWT.DROP_DOWN : SWT.PUSH; ToolItem item = new ToolItem(toolBar, style); item.setImage(image); } toolBar.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.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);/*from w w w . java2s . c o m*/ gc.fillRectangle(image.getBounds()); gc.dispose(); Shell shell = new Shell(display); shell.setText("Snippet 112"); 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(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: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);/* w ww . j a v a2 s . c o 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:Snippet21.java
public static void main(String[] args) { Display display = new Display(); final Color red = display.getSystemColor(SWT.COLOR_RED); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); Button b = new Button(shell, SWT.PUSH); b.setBounds(10, 10, 100, 32);//from w ww . j a v a 2 s. c o m b.setText("Button"); shell.setDefaultButton(b); final Canvas c = new Canvas(shell, SWT.BORDER); c.setBounds(10, 50, 100, 32); c.addListener(SWT.Traverse, new Listener() { public void handleEvent(Event e) { switch (e.detail) { /* Do tab group traversal */ case SWT.TRAVERSE_ESCAPE: case SWT.TRAVERSE_RETURN: case SWT.TRAVERSE_TAB_NEXT: case SWT.TRAVERSE_TAB_PREVIOUS: case SWT.TRAVERSE_PAGE_NEXT: case SWT.TRAVERSE_PAGE_PREVIOUS: e.doit = true; break; } } }); c.addListener(SWT.FocusIn, new Listener() { public void handleEvent(Event e) { c.setBackground(red); } }); c.addListener(SWT.FocusOut, new Listener() { public void handleEvent(Event e) { c.setBackground(blue); } }); c.addListener(SWT.KeyDown, new Listener() { public void handleEvent(Event e) { System.out.println("KEY"); for (int i = 0; i < 64; i++) { Color c1 = red, c2 = blue; if (c.isFocusControl()) { c1 = blue; c2 = red; } c.setBackground(c1); c.update(); c.setBackground(c2); } } }); Text t = new Text(shell, SWT.SINGLE | SWT.BORDER); t.setBounds(10, 85, 100, 32); Text r = new Text(shell, SWT.MULTI | SWT.BORDER); r.setBounds(10, 120, 100, 32); c.setFocus(); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:BackgroundColorImageInherit.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new RowLayout(SWT.VERTICAL)); Color color = display.getSystemColor(SWT.COLOR_CYAN); Group group = new Group(shell, SWT.NONE); group.setText("SWT.INHERIT_NONE"); group.setBackground(color);/*from w ww. j a va 2 s. co m*/ group.setBackgroundMode(SWT.INHERIT_NONE); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } 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/*w w w . j a v a 2 s. 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.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/*from w w w . j a va 2 s.com*/ 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(); }