List of usage examples for org.eclipse.swt.widgets Display getSystemColor
@Override public Color getSystemColor(int id)
From source file:SheerXYDirection.java
public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 110, 60); GC gc = new GC(image); Font font = new Font(display, "Times", 30, SWT.BOLD); gc.setFont(font);//from ww w . j ava 2 s .c o m gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, 110, 60); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.drawText("SWT", 10, 10, true); font.dispose(); gc.dispose(); final Rectangle rect = image.getBounds(); Shell shell = new Shell(display); shell.setText("Matrix Tranformations"); shell.setLayout(new FillLayout()); final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setAdvanced(true); if (!gc.getAdvanced()) { gc.drawText("Advanced graphics not supported", 30, 30, true); return; } // Original image int x = 30, y = 30; gc.drawImage(image, x, y); x += rect.width + 30; Transform transform = new Transform(display); // Shear in the x-direction transform.setElements(1, 0, -1, 1, 0, 0); gc.setTransform(transform); gc.drawImage(image, 300, y); // Shear in y-direction transform.setElements(1, -1, 0, 1, 0, 0); gc.setTransform(transform); gc.drawImage(image, 150, 475); transform.dispose(); } }); shell.setSize(350, 550); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:Rotate45Degrees.java
public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 110, 60); GC gc = new GC(image); Font font = new Font(display, "Times", 30, SWT.BOLD); gc.setFont(font);/*from w w w . j a v a 2 s . c o m*/ gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, 110, 60); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.drawText("SWT", 10, 10, true); font.dispose(); gc.dispose(); final Rectangle rect = image.getBounds(); Shell shell = new Shell(display); shell.setText("Matrix Tranformations"); shell.setLayout(new FillLayout()); final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setAdvanced(true); if (!gc.getAdvanced()) { gc.drawText("Advanced graphics not supported", 30, 30, true); return; } // Original image int x = 30, y = 30; gc.drawImage(image, x, y); x += rect.width + 30; Transform transform = new Transform(display); // Rotate by 45 degrees //float cos45 = (float)Math.cos(45); float cos45 = (float) Math.cos(Math.PI / 4); //float sin45 = (float)Math.sin(45); float sin45 = (float) Math.sin(Math.PI / 4); transform.setElements(cos45, sin45, -sin45, cos45, 0, 0); gc.setTransform(transform); gc.drawImage(image, 350, 100); transform.dispose(); } }); shell.setSize(350, 550); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet244.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 244"); shell.setLayout(new FillLayout()); final StyledText text = new StyledText(shell, SWT.NONE); StyleRange style = new StyleRange(); style.borderColor = display.getSystemColor(SWT.COLOR_RED); style.borderStyle = SWT.BORDER_SOLID; StyleRange[] styles = { style };//from w ww.ja v a 2 s . co m String contents = "This demonstrates drawing a box\naround every occurrence of the word\nbox in the StyledText"; text.setText(contents); int index = contents.indexOf(SEARCH_STRING); while (index != -1) { text.setStyleRanges(0, 0, new int[] { index, SEARCH_STRING.length() }, styles); index = contents.indexOf(SEARCH_STRING, index + 1); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TransformReflectionXYAxis.java
public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 110, 60); GC gc = new GC(image); Font font = new Font(display, "Times", 30, SWT.BOLD); gc.setFont(font);/*from w w w . j a va2 s. c o m*/ gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, 110, 60); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.drawText("SWT", 10, 10, true); font.dispose(); gc.dispose(); final Rectangle rect = image.getBounds(); Shell shell = new Shell(display); shell.setText("Matrix Tranformations"); shell.setLayout(new FillLayout()); final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setAdvanced(true); if (!gc.getAdvanced()) { gc.drawText("Advanced graphics not supported", 30, 30, true); return; } // Original image int x = 30, y = 30; gc.drawImage(image, x, y); x += rect.width + 30; Transform transform = new Transform(display); // Reflect around the y axis. transform.setElements(-1, 0, 0, 1, 0, 0); gc.setTransform(transform); gc.drawImage(image, -1 * x - rect.width, y); x = 30; y += rect.height + 30; // Reflect around the x axis. transform.setElements(1, 0, 0, -1, 0, 0); gc.setTransform(transform); gc.drawImage(image, x, -1 * y - rect.height); transform.dispose(); } }); shell.setSize(350, 550); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:Snippet168.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { int x = 20, y = 20, w = 120, h = 60; GC gc = event.gc;//from www. ja v a 2 s . com gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); gc.setLineWidth(10); int[] caps = { SWT.CAP_FLAT, SWT.CAP_ROUND, SWT.CAP_SQUARE }; for (int i = 0; i < caps.length; i++) { gc.setLineCap(caps[i]); gc.drawLine(x, y, x + w, y); y += 20; } int[] joins = { SWT.JOIN_BEVEL, SWT.JOIN_MITER, SWT.JOIN_ROUND }; for (int i = 0; i < joins.length; i++) { gc.setLineJoin(joins[i]); gc.drawPolygon(new int[] { x, y, x + w / 2, y + h, x + w, y }); y += h + 20; } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
From source file:org.eclipse.swt.snippets.Snippet204.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED); shell.setText("Modify Rise"); FontData data = display.getSystemFont().getFontData()[0]; Font font = new Font(display, data.getName(), 24, SWT.NORMAL); Font smallFont = new Font(display, data.getName(), 8, SWT.NORMAL); GC gc = new GC(shell); gc.setFont(smallFont);/* w ww . j av a 2s . co m*/ FontMetrics smallMetrics = gc.getFontMetrics(); final int smallBaseline = smallMetrics.getAscent() + smallMetrics.getLeading(); gc.setFont(font); FontMetrics metrics = gc.getFontMetrics(); final int baseline = metrics.getAscent() + metrics.getLeading(); gc.dispose(); final TextLayout layout0 = new TextLayout(display); layout0.setText("SubscriptScriptSuperscript"); layout0.setFont(font); TextStyle subscript0 = new TextStyle(smallFont, null, null); TextStyle superscript0 = new TextStyle(smallFont, null, null); superscript0.rise = baseline - smallBaseline; layout0.setStyle(subscript0, 0, 8); layout0.setStyle(superscript0, 15, 25); final TextLayout layout1 = new TextLayout(display); layout1.setText("SubscriptScriptSuperscript"); layout1.setFont(font); TextStyle subscript1 = new TextStyle(smallFont, null, null); subscript1.rise = -smallBaseline; TextStyle superscript1 = new TextStyle(smallFont, null, null); superscript1.rise = baseline; layout1.setStyle(subscript1, 0, 8); layout1.setStyle(superscript1, 15, 25); shell.addListener(SWT.Paint, event -> { Display display1 = event.display; GC gc1 = event.gc; Rectangle rect0 = layout0.getBounds(); rect0.x += 10; rect0.y += 10; gc1.setBackground(display1.getSystemColor(SWT.COLOR_WHITE)); gc1.setForeground(display1.getSystemColor(SWT.COLOR_BLACK)); gc1.fillRectangle(rect0); layout0.draw(gc1, rect0.x, rect0.y); gc1.setForeground(display1.getSystemColor(SWT.COLOR_MAGENTA)); gc1.drawLine(rect0.x, rect0.y, rect0.x + rect0.width, rect0.y); gc1.drawLine(rect0.x, rect0.y + baseline, rect0.x + rect0.width, rect0.y + baseline); gc1.drawLine(rect0.x + rect0.width / 2, rect0.y, rect0.x + rect0.width / 2, rect0.y + rect0.height); Rectangle rect1 = layout1.getBounds(); rect1.x += 10; rect1.y += 20 + rect0.height; gc1.setBackground(display1.getSystemColor(SWT.COLOR_WHITE)); gc1.setForeground(display1.getSystemColor(SWT.COLOR_BLACK)); gc1.fillRectangle(rect1); layout1.draw(gc1, rect1.x, rect1.y); gc1.setForeground(display1.getSystemColor(SWT.COLOR_MAGENTA)); gc1.drawLine(rect1.x, rect1.y + smallBaseline, rect1.x + rect1.width, rect1.y + smallBaseline); gc1.drawLine(rect1.x, rect1.y + baseline + smallBaseline, rect1.x + rect1.width, rect1.y + baseline + smallBaseline); gc1.drawLine(rect1.x + rect1.width / 2, rect1.y, rect1.x + rect1.width / 2, rect1.y + rect1.height); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } layout0.dispose(); layout1.dispose(); smallFont.dispose(); font.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet143.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 143"); Image image = new Image(display, 16, 16); Image image2 = new Image(display, 16, 16); GC gc = new GC(image2); gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); gc.fillRectangle(image2.getBounds()); gc.dispose();//ww w . j a v a 2 s. co m final Tray tray = display.getSystemTray(); if (tray == null) { System.out.println("The system tray is not available"); } else { final TrayItem item = new TrayItem(tray, SWT.NONE); item.setToolTipText("SWT TrayItem"); item.addListener(SWT.Show, event -> System.out.println("show")); item.addListener(SWT.Hide, event -> System.out.println("hide")); item.addListener(SWT.Selection, event -> System.out.println("selection")); item.addListener(SWT.DefaultSelection, event -> System.out.println("default selection")); final Menu menu = new Menu(shell, SWT.POP_UP); for (int i = 0; i < 8; i++) { MenuItem mi = new MenuItem(menu, SWT.PUSH); mi.setText("Item" + i); mi.addListener(SWT.Selection, event -> System.out.println("selection " + event.widget)); if (i == 0) menu.setDefaultItem(mi); } item.addListener(SWT.MenuDetect, event -> menu.setVisible(true)); item.setImage(image2); item.setHighlightImage(image); } shell.setBounds(50, 50, 300, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); image2.dispose(); display.dispose(); }
From source file:Snippet139.java
public static void main(String[] args) { Display display = new Display(); // create an image with the word "hello" on it final Image image0 = new Image(display, 50, 30); GC gc = new GC(image0); gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(image0.getBounds()); gc.drawString("hello", 5, 5, true); gc.dispose();// w w w .ja v a2 s .com ImageData data = image0.getImageData(); // rotate and flip this image final Image image1 = new Image(display, rotate(data, SWT.LEFT)); final Image image2 = new Image(display, rotate(data, SWT.RIGHT)); final Image image3 = new Image(display, rotate(data, SWT.DOWN)); final Image image4 = new Image(display, flip(data, true)); final Image image5 = new Image(display, flip(data, false)); Shell shell = new Shell(display); // draw the results on the shell shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawText("Original Image:", 10, 10, true); e.gc.drawImage(image0, 10, 40); e.gc.drawText("Left, Right, 180:", 10, 80, true); e.gc.drawImage(image1, 10, 110); e.gc.drawImage(image2, 50, 110); e.gc.drawImage(image3, 90, 110); e.gc.drawText("Flipped Vertical, Horizontal:", 10, 170, true); e.gc.drawImage(image4, 10, 200); e.gc.drawImage(image5, 70, 200); } }); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image0.dispose(); image1.dispose(); image2.dispose(); image3.dispose(); image4.dispose(); image5.dispose(); display.dispose(); }
From source file:StyleRangeSetArray.java
License:asdf
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER); styledText.setText("asdfasdfasdfasdf12345678910234567890"); StyleRange[] ranges = new StyleRange[2]; ranges[0] = new StyleRange(0, 3, display.getSystemColor(SWT.COLOR_GREEN), null); ranges[1] = new StyleRange(3, 6, display.getSystemColor(SWT.COLOR_BLUE), null); styledText.setStyleRanges(ranges);//from ww w . ja v a2s . c om styledText.setBounds(10, 10, 500, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ReplaceStyleRanges.java
License:asdf
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER); styledText.setText("asdfasdfasdfasdf12345678910234567890"); StyleRange[] ranges = new StyleRange[2]; ranges[0] = new StyleRange(0, 3, display.getSystemColor(SWT.COLOR_GREEN), null); ranges[1] = new StyleRange(3, 6, display.getSystemColor(SWT.COLOR_BLUE), null); styledText.setStyleRanges(ranges);/* w ww.ja va2 s . c o m*/ styledText.replaceStyleRanges(5, 9, ranges); styledText.setBounds(10, 10, 500, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }