List of usage examples for org.eclipse.swt.widgets Display getSystemColor
@Override public Color getSystemColor(int id)
From source file:org.eclipse.swt.snippets.Snippet104.java
public static void main(String[] args) { final Display display = new Display(); final int[] count = new int[] { 4 }; final Image image = new Image(display, 300, 300); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); gc.fillRectangle(image.getBounds()); gc.drawText("Splash Screen", 10, 10); gc.dispose();/*from w w w . j a v a 2s. c o m*/ final Shell splash = new Shell(SWT.ON_TOP); final ProgressBar bar = new ProgressBar(splash, SWT.NONE); bar.setMaximum(count[0]); Label label = new Label(splash, SWT.NONE); label.setImage(image); FormLayout layout = new FormLayout(); splash.setLayout(layout); FormData labelData = new FormData(); labelData.right = new FormAttachment(100, 0); labelData.bottom = new FormAttachment(100, 0); label.setLayoutData(labelData); FormData progressData = new FormData(); progressData.left = new FormAttachment(0, 5); progressData.right = new FormAttachment(100, -5); progressData.bottom = new FormAttachment(100, -5); bar.setLayoutData(progressData); splash.pack(); Rectangle splashRect = splash.getBounds(); Rectangle displayRect = display.getBounds(); int x = (displayRect.width - splashRect.width) / 2; int y = (displayRect.height - splashRect.height) / 2; splash.setLocation(x, y); splash.open(); display.asyncExec(() -> { Shell[] shells = new Shell[count[0]]; for (int i1 = 0; i1 < count[0]; i1++) { shells[i1] = new Shell(display); shells[i1].setSize(300, 300); shells[i1].addListener(SWT.Close, e -> --count[0]); bar.setSelection(i1 + 1); try { Thread.sleep(1000); } catch (Throwable e) { } } splash.close(); image.dispose(); for (int i2 = 0; i2 < count[0]; i2++) { shells[i2].setText("SWT Snippet 104 - " + (i2 + 1)); shells[i2].open(); } }); while (count[0] != 0) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet134.java
public static void main(String[] args) { final Display display = new Display(); // Shell must be created with style SWT.NO_TRIM final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP); shell.setBackground(display.getSystemColor(SWT.COLOR_RED)); // define a region that looks like a key hole Region region = new Region(); region.add(circle(67, 67, 67));//from ww w.j a v a 2 s .c o m region.subtract(circle(20, 67, 50)); region.subtract(new int[] { 67, 50, 55, 105, 79, 105 }); // define the shape of the shell using setRegion shell.setRegion(region); Rectangle size = region.getBounds(); shell.setSize(size.width, size.height); // add ability to move shell around Listener l = new Listener() { Point origin; public void handleEvent(Event e) { switch (e.type) { case SWT.MouseDown: origin = new Point(e.x, e.y); break; case SWT.MouseUp: origin = null; break; case SWT.MouseMove: if (origin != null) { Point p = display.map(shell, null, e.x, e.y); shell.setLocation(p.x - origin.x, p.y - origin.y); } break; } } }; shell.addListener(SWT.MouseDown, l); shell.addListener(SWT.MouseUp, l); shell.addListener(SWT.MouseMove, l); // add ability to close shell Button b = new Button(shell, SWT.PUSH); b.setBackground(shell.getBackground()); b.setText("close"); b.pack(); b.setLocation(10, 68); b.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { shell.close(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } region.dispose(); display.dispose(); }
From source file:SplashScreenCreate.java
public static void main(String[] args) { final Display display = new Display(); final int[] count = new int[] { 4 }; final Image image = new Image(display, 300, 300); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); gc.fillRectangle(image.getBounds()); gc.drawText("Splash Screen", 10, 10); gc.dispose();/* www .j a v a 2 s.com*/ final Shell splash = new Shell(SWT.ON_TOP); final ProgressBar bar = new ProgressBar(splash, SWT.NONE); bar.setMaximum(count[0]); Label label = new Label(splash, SWT.NONE); label.setImage(image); FormLayout layout = new FormLayout(); splash.setLayout(layout); FormData labelData = new FormData(); labelData.right = new FormAttachment(100, 0); labelData.bottom = new FormAttachment(100, 0); label.setLayoutData(labelData); FormData progressData = new FormData(); progressData.left = new FormAttachment(0, 5); progressData.right = new FormAttachment(100, -5); progressData.bottom = new FormAttachment(100, -5); bar.setLayoutData(progressData); splash.pack(); Rectangle splashRect = splash.getBounds(); Rectangle displayRect = display.getBounds(); int x = (displayRect.width - splashRect.width) / 2; int y = (displayRect.height - splashRect.height) / 2; splash.setLocation(x, y); splash.open(); display.asyncExec(new Runnable() { public void run() { Shell[] shells = new Shell[count[0]]; for (int i = 0; i < count[0]; i++) { shells[i] = new Shell(display); shells[i].setSize(300, 300); shells[i].addListener(SWT.Close, new Listener() { public void handleEvent(Event e) { --count[0]; } }); bar.setSelection(i + 1); try { Thread.sleep(1000); } catch (Throwable e) { } } splash.close(); image.dispose(); for (int i = 0; i < count[0]; i++) { shells[i].open(); } } }); while (count[0] != 0) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet180.java
public static void main(String[] args) { Display display = new Display(); final Image image = display.getSystemImage(SWT.ICON_WARNING); //Shell must be created with style SWT.NO_TRIM final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP); shell.setBackground(display.getSystemColor(SWT.COLOR_RED)); //define a region Region region = new Region(); Rectangle pixel = new Rectangle(0, 0, 1, 1); for (int y = 0; y < 200; y += 2) { for (int x = 0; x < 200; x += 2) { pixel.x = x;//www . j a va2 s. c om pixel.y = y; region.add(pixel); } } //define the shape of the shell using setRegion shell.setRegion(region); shell.addPaintListener(e -> { Rectangle bounds = image.getBounds(); Point size = shell.getSize(); e.gc.drawImage(image, 0, 0, bounds.width, bounds.height, 10, 10, size.x - 20, size.y - 20); }); shell.addListener(SWT.KeyDown, e -> { if (e.character == SWT.ESC) { shell.dispose(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } region.dispose(); display.dispose(); }
From source file:NonRectangularTransparency.java
public static void main(String[] args) { Display display = new Display(); final Image image = display.getSystemImage(SWT.ICON_WARNING); // Shell must be created with style SWT.NO_TRIM final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP); shell.setBackground(display.getSystemColor(SWT.COLOR_RED)); // define a region Region region = new Region(); Rectangle pixel = new Rectangle(0, 0, 1, 1); for (int y = 0; y < 200; y += 2) { for (int x = 0; x < 200; x += 2) { pixel.x = x;/*from www. java2 s. co m*/ pixel.y = y; region.add(pixel); } } // define the shape of the shell using setRegion shell.setRegion(region); Rectangle size = region.getBounds(); shell.setSize(size.width, size.height); shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bounds = image.getBounds(); Point size = shell.getSize(); e.gc.drawImage(image, 0, 0, bounds.width, bounds.height, 10, 10, size.x - 20, size.y - 20); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } region.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet168.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 168"); shell.addListener(SWT.Paint, event -> { int x = 20, y = 20, w = 120, h = 60; GC gc = event.gc;//from w w w. j a 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 i1 = 0; i1 < caps.length; i1++) { gc.setLineCap(caps[i1]); gc.drawLine(x, y, x + w, y); y += 20; } int[] joins = { SWT.JOIN_BEVEL, SWT.JOIN_MITER, SWT.JOIN_ROUND }; for (int i2 = 0; i2 < joins.length; i2++) { gc.setLineJoin(joins[i2]); 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(); } display.dispose(); }
From source file:LineCapsSetting.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;/* w w w . ja va2 s . c o m*/ 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; } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ControlListenerAdd.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new RowLayout()); final Composite composite = new Composite(shell, SWT.BORDER); composite.setLayout(new RowLayout()); composite.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); composite.addControlListener(new ControlListener() { public void controlMoved(ControlEvent e) { }// w w w . j av a2s . com public void controlResized(ControlEvent e) { System.out.println("Composite resize."); } }); Button buttonAdd = new Button(shell, SWT.PUSH); buttonAdd.setText("Add new button"); buttonAdd.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button button = new Button(composite, SWT.PUSH); button.setText("Button #" + (count++)); composite.layout(true); composite.pack(); } }); shell.setSize(450, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:LineJoinStyleBevelMiterRound.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 ww w .j av a2 s .co m gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); gc.setLineWidth(10); 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(); } display.dispose(); }
From source file:FocusTraversal.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Composite composite1 = new Composite(shell, SWT.BORDER); composite1.setLayout(new RowLayout()); composite1.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); Button button1 = new Button(composite1, SWT.PUSH); button1.setText("Button1"); Button button3 = new Button(composite1, SWT.PUSH); button3.setText("Button3"); Button radioButton1 = new Button(composite1, SWT.RADIO); radioButton1.setText("radio-1"); Button radioButton2 = new Button(composite1, SWT.RADIO); radioButton2.setText("radio-2"); Composite composite2 = new Composite(shell, SWT.BORDER); composite2.setLayout(new RowLayout()); composite2.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); Button button2 = new Button(composite2, SWT.PUSH); button2.setText("Button2"); Combo combo = new Combo(composite2, SWT.DROP_DOWN); combo.add("combo"); combo.select(0);/*from ww w .java 2s . com*/ composite1.setTabList(new Control[] { button1, button3 }); composite2.setTabList(new Control[] { button2, combo }); shell.setTabList(new Control[] { composite2, composite1 }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }