List of usage examples for org.eclipse.swt.widgets Display getSystemImage
public Image getSystemImage(int id)
SWT
. From source file:org.eclipse.swt.snippets.Snippet219.java
public static void main(String[] args) { final Display display = new Display(); final Image image = display.getSystemImage(SWT.ICON_INFORMATION); final Shell shell = new Shell(display, SWT.NO_TRIM); shell.setText("Snippet 219"); Region region = new Region(); final ImageData imageData = image.getImageData(); if (imageData.alphaData != null) { Rectangle pixel = new Rectangle(0, 0, 1, 1); for (int y = 0; y < imageData.height; y++) { for (int x = 0; x < imageData.width; x++) { if (imageData.getAlpha(x, y) == 255) { pixel.x = imageData.x + x; pixel.y = imageData.y + y; region.add(pixel);/*from ww w . j a v a 2 s. co m*/ } } } } else { ImageData mask = imageData.getTransparencyMask(); Rectangle pixel = new Rectangle(0, 0, 1, 1); for (int y = 0; y < mask.height; y++) { for (int x = 0; x < mask.width; x++) { if (mask.getPixel(x, y) != 0) { pixel.x = imageData.x + x; pixel.y = imageData.y + y; region.add(pixel); } } } } shell.setRegion(region); Listener l = new Listener() { /** The x/y of the MouseDown, relative to top-left of the shell. */ int startX, startY; @Override public void handleEvent(Event e) { if (e.type == SWT.KeyDown && e.character == SWT.ESC) { shell.dispose(); } if (e.type == SWT.MouseDown && e.button == 1) { Point p = shell.toDisplay(e.x, e.y); Point loc = shell.getLocation(); startX = p.x - loc.x; startY = p.y - loc.y; } if (e.type == SWT.MouseMove && (e.stateMask & SWT.BUTTON1) != 0) { Point p = shell.toDisplay(e.x, e.y); p.x -= startX; p.y -= startY; shell.setLocation(p); } if (e.type == SWT.Paint) { e.gc.drawImage(image, imageData.x, imageData.y); } } }; shell.addListener(SWT.KeyDown, l); shell.addListener(SWT.MouseDown, l); shell.addListener(SWT.MouseMove, l); shell.addListener(SWT.Paint, l); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } region.dispose(); image.dispose(); display.dispose(); }
From source file:TreeEventMeasurePaintErase.java
public static void main(String[] args) { Display display = new Display(); final Image image = display.getSystemImage(SWT.ICON_INFORMATION); Shell shell = new Shell(display); shell.setText("Images on the right side of the TreeItem"); shell.setLayout(new FillLayout()); Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION); tree.setHeaderVisible(true);/* w ww . j a v a 2 s .co m*/ tree.setLinesVisible(true); int columnCount = 4; for (int i = 0; i < columnCount; i++) { TreeColumn column = new TreeColumn(tree, SWT.NONE); column.setText("Column " + i); } int itemCount = 3; for (int i = 0; i < itemCount; i++) { TreeItem item1 = new TreeItem(tree, SWT.NONE); item1.setText("item " + i); for (int c = 1; c < columnCount; c++) { item1.setText(c, "item [" + i + "-" + c + "]"); } for (int j = 0; j < itemCount; j++) { TreeItem item2 = new TreeItem(item1, SWT.NONE); item2.setText("item [" + i + " " + j + "]"); for (int c = 1; c < columnCount; c++) { item2.setText(c, "item [" + i + " " + j + "-" + c + "]"); } for (int k = 0; k < itemCount; k++) { TreeItem item3 = new TreeItem(item2, SWT.NONE); item3.setText("item [" + i + " " + j + " " + k + "]"); for (int c = 1; c < columnCount; c++) { item3.setText(c, "item [" + i + " " + j + " " + k + "-" + c + "]"); } } } } /* * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. * Therefore, it is critical for performance that these methods be as * efficient as possible. */ Listener paintListener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.MeasureItem: { Rectangle rect = image.getBounds(); event.width += rect.width; event.height = Math.max(event.height, rect.height + 2); break; } case SWT.PaintItem: { int x = event.x + event.width; Rectangle rect = image.getBounds(); int offset = Math.max(0, (event.height - rect.height) / 2); event.gc.drawImage(image, x, event.y + offset); break; } } } }; tree.addListener(SWT.MeasureItem, paintListener); tree.addListener(SWT.PaintItem, paintListener); for (int i = 0; i < columnCount; i++) { tree.getColumn(i).pack(); } shell.setSize(500, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet355.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED); shell.setText("Snippet 355"); final Image image = display.getSystemImage(SWT.ICON_QUESTION); shell.addListener(SWT.Paint, e -> { Rectangle rect = image.getBounds(); int width = rect.width; int height = rect.height; GC gc = e.gc;/* w w w. ja v a 2s. c om*/ int x = 10, y = 10; gc.drawImage(image, 0, 0, width, height, x, y, width, height); gc.drawImage(image, 0, 0, width, height, x + width, y, (int) Math.round(width * 0.5), (int) Math.round(height * 0.5)); gc.drawImage(image, 0, 0, width, height, x + width + (int) Math.round(width * 0.5), y, width * 2, height * 2); }); shell.setSize(600, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:SystemIconImage.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Label label = new Label(shell, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(shell, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(shell, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(shell, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(shell, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(shell, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(shell, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(shell, SWT.NONE); label.setText("SWT.ICON_QUESTION"); shell.setSize(400, 350);/* w w w.j a v a2s.co m*/ shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet279.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED); shell.setText("Snippet 279"); shell.setLayout(new FillLayout()); final Image image = display.getSystemImage(SWT.ICON_QUESTION); shell.addListener(SWT.Paint, e -> { Rectangle rect = image.getBounds(); GC gc = e.gc;//from www.j a v a2 s . c om int x = 10, y = 10; gc.drawImage(image, x, y); Transform tr = new Transform(e.display); tr.setElements(1, 0, 0, -1, 1, 2 * (y + rect.height)); gc.setTransform(tr); gc.drawImage(image, x, y); gc.setTransform(null); Color background = gc.getBackground(); Pattern p = new Pattern(e.display, x, y + rect.height, x, y + (2 * rect.height), background, 0, background, 255); gc.setBackgroundPattern(p); gc.fillRectangle(x, y + rect.height, rect.width, rect.height); p.dispose(); tr.dispose(); }); shell.setSize(600, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet258.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 258"); shell.setLayout(new GridLayout(2, false)); final Text text = new Text(shell, SWT.SEARCH | SWT.ICON_CANCEL); Image image = null;//from w w w . j a v a 2 s . c om if ((text.getStyle() & SWT.ICON_CANCEL) == 0) { image = display.getSystemImage(SWT.ICON_ERROR); ToolBar toolBar = new ToolBar(shell, SWT.FLAT); ToolItem item = new ToolItem(toolBar, SWT.PUSH); item.setImage(image); item.addSelectionListener(widgetSelectedAdapter(e -> { text.setText(""); System.out.println("Search cancelled"); })); } text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.setText("Search text"); text.addSelectionListener(widgetSelectedAdapter(e -> { if (e.detail == SWT.CANCEL) { System.out.println("Search cancelled"); } else { System.out.println("Searching for: " + text.getText() + "..."); } })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet223.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = display.getSystemImage(SWT.ICON_QUESTION); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;//from w ww . j av a2 s .c om composite.setLayout(layout); Button button = new Button(composite, SWT.PUSH); button.setText("SWT.PUSH"); button = new Button(composite, SWT.RADIO); button.setText("SWT.RADIO"); button = new Button(composite, SWT.CHECK); button.setText("SWT.CHECK"); button = new Button(composite, SWT.TOGGLE); button.setText("SWT.TOGGLE"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); // Second item composite = new Composite(bar, SWT.NONE); layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10; composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_QUESTION"); ExpandItem item1 = new ExpandItem(bar, SWT.NONE, 1); item1.setText("What is your favorite icon"); item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item1.setControl(composite); item1.setImage(image); // Third item composite = new Composite(bar, SWT.NONE); layout = new GridLayout(2, true); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10; composite.setLayout(layout); label = new Label(composite, SWT.NONE); label.setText("Scale"); new Scale(composite, SWT.NONE); label = new Label(composite, SWT.NONE); label.setText("Spinner"); new Spinner(composite, SWT.BORDER); label = new Label(composite, SWT.NONE); label.setText("Slider"); new Slider(composite, SWT.NONE); ExpandItem item2 = new ExpandItem(bar, SWT.NONE, 2); item2.setText("What is your favorite range widget"); item2.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item2.setControl(composite); item2.setImage(image); item1.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet298.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 298"); shell.addListener(SWT.Paint, event -> { int[] icons = new int[] { SWT.ICON_ERROR, SWT.ICON_WARNING, SWT.ICON_INFORMATION, SWT.ICON_QUESTION, SWT.ICON_WORKING };//from w w w. j ava2 s . c o m int x = 10; for (int i = 0; i < icons.length; i++) { Image image = display.getSystemImage(icons[i]); if (image != null) { Transform t = new Transform(display); t.translate(x, 10); t.shear(1, 0); GC gc = event.gc; gc.setTransform(t); t.dispose(); gc.drawImage(image, 0, 0); x += image.getBounds().width + 10; } } }); shell.setSize(260, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet212.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 212"); shell.setLayout(new GridLayout()); styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER); styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); styledText.setText(text);/*from w w w. j a v a 2s .c o m*/ int offset = text.indexOf("\uFFFC", 0); addImage(display.getSystemImage(SWT.ICON_QUESTION), offset); offset = text.indexOf("\uFFFC", offset + 1); addImage(display.getSystemImage(SWT.ICON_INFORMATION), offset); // use a verify listener to dispose the images styledText.addVerifyListener(event -> { if (event.start == event.end) return; String text = styledText.getText(event.start, event.end - 1); int index = text.indexOf('\uFFFC'); while (index != -1) { StyleRange style = styledText.getStyleRangeAtOffset(event.start + index); if (style != null) { Image image = (Image) style.data; if (image != null) image.dispose(); } index = text.indexOf('\uFFFC', index + 1); } }); // draw images on paint event styledText.addPaintObjectListener(event -> { StyleRange style = event.style; Image image = (Image) style.data; if (!image.isDisposed()) { int x = event.x; int y = event.y + event.ascent - style.metrics.ascent; event.gc.drawImage(image, x, y); } }); styledText.addListener(SWT.Dispose, event -> { StyleRange[] styles = styledText.getStyleRanges(); for (int i = 0; i < styles.length; i++) { StyleRange style = styles[i]; if (style.data != null) { Image image = (Image) style.data; if (image != null) image.dispose(); } } }); Button button = new Button(shell, SWT.PUSH); button.setText("Add Image"); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); button.addListener(SWT.Selection, event -> { FileDialog dialog = new FileDialog(shell); String filename = dialog.open(); if (filename != null) { try { Image image = new Image(display, filename); int offset1 = styledText.getCaretOffset(); styledText.replaceTextRange(offset1, 0, "\uFFFC"); addImage(image, offset1); } catch (Exception e) { e.printStackTrace(); } } }); shell.setSize(400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet225.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 225"); Image image = null;//from ww w .java2 s . c o m final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION); tip.setMessage( "Here is a message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind."); Tray tray = display.getSystemTray(); if (tray != null) { TrayItem item = new TrayItem(tray, SWT.NONE); image = display.getSystemImage(SWT.ICON_INFORMATION); item.setImage(image); tip.setText("Notification from a tray item"); item.setToolTip(tip); } else { tip.setText("Notification from anywhere"); tip.setLocation(400, 400); } Button button = new Button(shell, SWT.PUSH); button.setText("Press for balloon tip"); button.addListener(SWT.Selection, event -> tip.setVisible(true)); Rectangle clientArea = shell.getClientArea(); button.setLocation(clientArea.x, clientArea.y); button.pack(); shell.setBounds(50, 50, 300, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }