List of usage examples for org.eclipse.swt.graphics Color Color
public Color(Device device, RGB rgb)
From source file:AnimatedGIFWriteFile.java
public static void main(String[] args) { display = new Display(); RGB whiteRGB = new RGB(0xff, 0xff, 0xff); RGB redRGB = new RGB(0xff, 0, 0); RGB greenRGB = new RGB(0, 0xff, 0); RGB blueRGB = new RGB(0, 0, 0xff); palette = new PaletteData(new RGB[] { whiteRGB, // 0 redRGB, // 1 greenRGB, // 2 blueRGB }); // 3 white = new Color(display, whiteRGB); red = new Color(display, redRGB); green = new Color(display, greenRGB); blue = new Color(display, blueRGB); font = new Font(display, "Comic Sans MS", 24, SWT.BOLD); ImageData[] data = new ImageData[4]; data[0] = newFrame("", white, false, 0, 0, 101, 55, SWT.DM_FILL_NONE, 40); data[1] = newFrame("S", red, true, 0, 0, 30, 55, SWT.DM_FILL_NONE, 40); data[2] = newFrame("W", green, true, 28, 0, 39, 55, SWT.DM_FILL_NONE, 40); data[3] = newFrame("T", blue, true, 69, 0, 32, 55, SWT.DM_FILL_BACKGROUND, 200); ImageLoader loader = new ImageLoader(); loader.data = data;//from www .j a va2s. co m loader.backgroundPixel = 0; loader.logicalScreenHeight = data[0].height; loader.logicalScreenWidth = data[0].width; loader.repeatCount = 0; // run forever loader.save("swt.gif", SWT.IMAGE_GIF); white.dispose(); red.dispose(); green.dispose(); blue.dispose(); font.dispose(); display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display display = new Display(); // Create the main window final Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog FontDialog dlg = new FontDialog(shell); Font font = null;// w ww .ja v a 2 s . c o m Color color = null; if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { if (font != null) font.dispose(); if (color != null) color.dispose(); font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); shell.pack(); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet182.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 182"); shell.setLayout(new RowLayout()); Link link = new Link(shell, SWT.BORDER); link.setText("This a very simple <a>link</a> widget."); Button setButton = new Button(shell, SWT.PUSH); setButton.setText("Choose link color"); setButton.addSelectionListener(widgetSelectedAdapter(e -> { System.out.println("default link color " + link.getLinkForeground()); ColorDialog colorDialog = new ColorDialog(shell); RGB color = colorDialog.open();/*from w ww .j a v a2s . c om*/ link.setLinkForeground(new Color(display, color)); System.out.println("user selected link color " + link.getLinkForeground()); })); Button resetButton = new Button(shell, SWT.PUSH); resetButton.setText("Reset link color"); resetButton.addSelectionListener(widgetSelectedAdapter(e -> { System.out.println("link color reset to system default"); link.setLinkForeground(null); })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet357.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 357"); shell.setLayout(new FillLayout()); final StyledText text = new StyledText(shell, SWT.BORDER | SWT.MULTI); text.setText("The quick brown fox jumps over the lazy dog.\nThat's all folks!"); TextStyle textStyle = new TextStyle(new Font(display, "Courier", 12, SWT.BOLD), display.getSystemColor(SWT.COLOR_RED), null); textStyle.strikeout = true;/*from w ww .ja v a2 s. co m*/ textStyle.underline = true; textStyle.underlineStyle = SWT.UNDERLINE_SINGLE; text.setStyleRanges(new int[] { 4, 5 }, new StyleRange[] { new StyleRange(textStyle) }); text.getAccessible().addAccessibleEditableTextListener(new AccessibleEditableTextAdapter() { @Override public void setTextAttributes(AccessibleTextAttributeEvent e) { TextStyle textStyle = e.textStyle; if (textStyle != null) { /* Copy all of the TextStyle fields into the new StyleRange. */ StyleRange style = new StyleRange(textStyle); /* Create new graphics resources because the old ones are only valid during the event. */ if (textStyle.font != null) style.font = new Font(display, textStyle.font.getFontData()); if (textStyle.foreground != null) style.foreground = new Color(display, textStyle.foreground.getRGB()); if (textStyle.background != null) style.background = new Color(display, textStyle.background.getRGB()); if (textStyle.underlineColor != null) style.underlineColor = new Color(display, textStyle.underlineColor.getRGB()); if (textStyle.strikeoutColor != null) style.strikeoutColor = new Color(display, textStyle.strikeoutColor.getRGB()); if (textStyle.borderColor != null) style.borderColor = new Color(display, textStyle.borderColor.getRGB()); /* Set the StyleRange into the StyledText. */ style.start = e.start; style.length = e.end - e.start; text.setStyleRange(style); e.result = ACC.OK; } else { text.setStyleRanges(e.start, e.end - e.start, null, null); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
From source file:Snippet141.java
public static void main(String[] args) { display = new Display(); shell = new Shell(display); shell.setSize(300, 300);/* w w w . jav a 2 s .c o m*/ shell.open(); shellGC = new GC(shell); shellBackground = shell.getBackground(); FileDialog dialog = new FileDialog(shell); dialog.setFilterExtensions(new String[] { "*.gif" }); String fileName = dialog.open(); if (fileName != null) { loader = new ImageLoader(); try { imageDataArray = loader.load(fileName); if (imageDataArray.length > 1) { animateThread = new Thread("Animation") { public void run() { /* Create an off-screen image to draw on, and fill it with the shell background. */ Image offScreenImage = new Image(display, loader.logicalScreenWidth, loader.logicalScreenHeight); GC offScreenImageGC = new GC(offScreenImage); offScreenImageGC.setBackground(shellBackground); offScreenImageGC.fillRectangle(0, 0, loader.logicalScreenWidth, loader.logicalScreenHeight); try { /* Create the first image and draw it on the off-screen image. */ int imageDataIndex = 0; ImageData imageData = imageDataArray[imageDataIndex]; if (image != null && !image.isDisposed()) image.dispose(); image = new Image(display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); /* Now loop through the images, creating and drawing each one * on the off-screen image before drawing it on the shell. */ int repeatCount = loader.repeatCount; while (loader.repeatCount == 0 || repeatCount > 0) { switch (imageData.disposalMethod) { case SWT.DM_FILL_BACKGROUND: /* Fill with the background color before drawing. */ Color bgColor = null; if (useGIFBackground && loader.backgroundPixel != -1) { bgColor = new Color(display, imageData.palette.getRGB(loader.backgroundPixel)); } offScreenImageGC.setBackground(bgColor != null ? bgColor : shellBackground); offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height); if (bgColor != null) bgColor.dispose(); break; case SWT.DM_FILL_PREVIOUS: /* Restore the previous image before drawing. */ offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); break; } imageDataIndex = (imageDataIndex + 1) % imageDataArray.length; imageData = imageDataArray[imageDataIndex]; image.dispose(); image = new Image(display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); /* Draw the off-screen image to the shell. */ shellGC.drawImage(offScreenImage, 0, 0); /* Sleep for the specified delay time (adding commonly-used slow-down fudge factors). */ try { int ms = imageData.delayTime * 10; if (ms < 20) ms += 30; if (ms < 30) ms += 10; Thread.sleep(ms); } catch (InterruptedException e) { } /* If we have just drawn the last image, decrement the repeat count and start again. */ if (imageDataIndex == imageDataArray.length - 1) repeatCount--; } } catch (SWTException ex) { System.out.println("There was an error animating the GIF"); } finally { if (offScreenImage != null && !offScreenImage.isDisposed()) offScreenImage.dispose(); if (offScreenImageGC != null && !offScreenImageGC.isDisposed()) offScreenImageGC.dispose(); if (image != null && !image.isDisposed()) image.dispose(); } } }; animateThread.setDaemon(true); animateThread.start(); } } catch (SWTException ex) { System.out.println("There was an error loading the GIF"); } } while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet141.java
public static void main(String[] args) { display = new Display(); shell = new Shell(display); shell.setText("Snippet 141"); shell.setSize(300, 300);//from w w w.j a v a 2s.com shell.open(); shellGC = new GC(shell); shellBackground = shell.getBackground(); FileDialog dialog = new FileDialog(shell); dialog.setFilterExtensions(new String[] { "*.gif" }); String fileName = dialog.open(); final AtomicBoolean stopAnimation = new AtomicBoolean(false); if (fileName != null) { loader = new ImageLoader(); try { imageDataArray = loader.load(fileName); if (imageDataArray.length > 1) { animateThread = new Thread("Animation") { @Override public void run() { /* Create an off-screen image to draw on, and fill it with the shell background. */ Image offScreenImage = new Image(display, loader.logicalScreenWidth, loader.logicalScreenHeight); GC offScreenImageGC = new GC(offScreenImage); offScreenImageGC.setBackground(shellBackground); offScreenImageGC.fillRectangle(0, 0, loader.logicalScreenWidth, loader.logicalScreenHeight); try { /* Create the first image and draw it on the off-screen image. */ int imageDataIndex = 0; ImageData imageData = imageDataArray[imageDataIndex]; if (image != null && !image.isDisposed()) image.dispose(); image = new Image(display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); /* Now loop through the images, creating and drawing each one * on the off-screen image before drawing it on the shell. */ int repeatCount = loader.repeatCount; while ((loader.repeatCount == 0 || repeatCount > 0) && !stopAnimation.get()) { switch (imageData.disposalMethod) { case SWT.DM_FILL_BACKGROUND: /* Fill with the background color before drawing. */ Color bgColor = null; if (useGIFBackground && loader.backgroundPixel != -1) { bgColor = new Color(display, imageData.palette.getRGB(loader.backgroundPixel)); } offScreenImageGC.setBackground(bgColor != null ? bgColor : shellBackground); offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height); if (bgColor != null) bgColor.dispose(); break; case SWT.DM_FILL_PREVIOUS: /* Restore the previous image before drawing. */ offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); break; } imageDataIndex = (imageDataIndex + 1) % imageDataArray.length; imageData = imageDataArray[imageDataIndex]; image.dispose(); image = new Image(display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); /* Draw the off-screen image to the shell. */ shellGC.drawImage(offScreenImage, 0, 0); /* Sleep for the specified delay time (adding commonly-used slow-down fudge factors). */ try { int ms = imageData.delayTime * 10; if (ms < 20) ms += 30; if (ms < 30) ms += 10; Thread.sleep(ms); } catch (InterruptedException e) { } /* If we have just drawn the last image, decrement the repeat count and start again. */ if (imageDataIndex == imageDataArray.length - 1) repeatCount--; } } catch (SWTException ex) { System.out.println("There was an error animating the GIF"); } finally { if (offScreenImage != null && !offScreenImage.isDisposed()) offScreenImage.dispose(); if (offScreenImageGC != null && !offScreenImageGC.isDisposed()) offScreenImageGC.dispose(); if (image != null && !image.isDisposed()) image.dispose(); } } }; animateThread.setDaemon(true); animateThread.start(); } } catch (SWTException ex) { System.out.println("There was an error loading the GIF"); } } while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } stopAnimation.set(true); display.dispose(); }
From source file:AnimatedGIFDisplay.java
public static void main(String[] args) { display = new Display(); shell = new Shell(display); shell.setSize(300, 300);/*from ww w.j av a 2 s . c om*/ shell.open(); shellGC = new GC(shell); shellBackground = shell.getBackground(); FileDialog dialog = new FileDialog(shell); dialog.setFilterExtensions(new String[] { "*.gif" }); String fileName = dialog.open(); if (fileName != null) { loader = new ImageLoader(); try { imageDataArray = loader.load(fileName); if (imageDataArray.length > 1) { animateThread = new Thread("Animation") { public void run() { /* * Create an off-screen image to draw on, and fill it with the * shell background. */ Image offScreenImage = new Image(display, loader.logicalScreenWidth, loader.logicalScreenHeight); GC offScreenImageGC = new GC(offScreenImage); offScreenImageGC.setBackground(shellBackground); offScreenImageGC.fillRectangle(0, 0, loader.logicalScreenWidth, loader.logicalScreenHeight); try { /* Create the first image and draw it on the off-screen image. */ int imageDataIndex = 0; ImageData imageData = imageDataArray[imageDataIndex]; if (image != null && !image.isDisposed()) image.dispose(); image = new Image(display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); /* * Now loop through the images, creating and drawing each one on * the off-screen image before drawing it on the shell. */ int repeatCount = loader.repeatCount; while (loader.repeatCount == 0 || repeatCount > 0) { switch (imageData.disposalMethod) { case SWT.DM_FILL_BACKGROUND: /* Fill with the background color before drawing. */ Color bgColor = null; if (useGIFBackground && loader.backgroundPixel != -1) { bgColor = new Color(display, imageData.palette.getRGB(loader.backgroundPixel)); } offScreenImageGC.setBackground(bgColor != null ? bgColor : shellBackground); offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height); if (bgColor != null) bgColor.dispose(); break; case SWT.DM_FILL_PREVIOUS: /* Restore the previous image before drawing. */ offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); break; } imageDataIndex = (imageDataIndex + 1) % imageDataArray.length; imageData = imageDataArray[imageDataIndex]; image.dispose(); image = new Image(display, imageData); offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, imageData.y, imageData.width, imageData.height); /* Draw the off-screen image to the shell. */ shellGC.drawImage(offScreenImage, 0, 0); /* * Sleep for the specified delay time (adding commonly-used * slow-down fudge factors). */ try { int ms = imageData.delayTime * 10; if (ms < 20) ms += 30; if (ms < 30) ms += 10; Thread.sleep(ms); } catch (InterruptedException e) { } /* * If we have just drawn the last image, decrement the repeat * count and start again. */ if (imageDataIndex == imageDataArray.length - 1) repeatCount--; } } catch (SWTException ex) { System.out.println("There was an error animating the GIF"); } finally { if (offScreenImage != null && !offScreenImage.isDisposed()) offScreenImage.dispose(); if (offScreenImageGC != null && !offScreenImageGC.isDisposed()) offScreenImageGC.dispose(); if (image != null && !image.isDisposed()) image.dispose(); } } }; animateThread.setDaemon(true); animateThread.start(); } } catch (SWTException ex) { System.out.println("There was an error loading the GIF"); } } while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet365.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet365 - Transparent Background"); RowLayout layout = new RowLayout(SWT.VERTICAL); layout.spacing = 20;/*from ww w. j a v a 2 s .c o m*/ layout.marginWidth = 10; layout.marginHeight = 10; shell.setLayout(layout); // Standard color background for Shell // shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // Gradient background for Shell shell.addListener(SWT.Resize, event -> { Rectangle rect = shell.getClientArea(); Image newImage = new Image(display, Math.max(1, rect.width), 1); GC gc = new GC(newImage); gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false); gc.dispose(); shell.setBackgroundImage(newImage); if (oldImage != null) oldImage.dispose(); oldImage = newImage; }); // Transparent buttonCheckBox = new Button(shell, SWT.CHECK | SWT.None); buttonCheckBox.setText("SET TRANSPARENT"); buttonCheckBox.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); buttonCheckBox.setSelection(false); buttonCheckBox.addSelectionListener(widgetSelectedAdapter(e -> { boolean transparent = ((Button) e.getSource()).getSelection(); if (transparent) { // ContainerGroup containerGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); canvas.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); composite.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); tabFolder.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); for (TabItem item : tabFolder.getItems()) { item.getControl().setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); } // Native nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); toolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); coolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); label.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); link.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); scale.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); radio.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); check.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); group.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); sash.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); slider.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); list.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); // Custom customGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); cLabel.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); cTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT)); gradientCTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT)); sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT)); for (Control control : sashForm.getChildren()) { control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT)); } // Default push.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); combo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); progressBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); dateTime.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); ccombo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); text.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); styledText.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); expandBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); table.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); tree.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); // ItemGroup itemGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); } else { // Native nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); toolBar.setBackground(null); coolBar.setBackground(null); label.setBackground(null); link.setBackground(null); scale.setBackground(null); RGB rgb = display.getSystemColor(SWT.COLOR_CYAN).getRGB(); radio.setBackground(new Color(display, new RGBA(rgb.red, rgb.blue, rgb.green, 255))); check.setBackgroundImage(getBackgroundImage(display)); group.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN)); slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); list.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); text.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // ContainerGroup containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); canvas.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); composite.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); tabFolder.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); for (TabItem item : tabFolder.getItems()) { item.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN)); } // Custom customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); cLabel.setBackground((Color) null); styledText.setBackground((Color) null); sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); for (Control control : sashForm.getChildren()) { control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); } cTab.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); gradientCTab.setBackground(new Color[] { display.getSystemColor(SWT.COLOR_RED), display.getSystemColor(SWT.COLOR_WHITE) }, new int[] { 90 }, true); // Default defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); push.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); dateTime.setBackground(null); progressBar.setBackground(null); expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); table.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // ItemGroup itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); } })); // ContainerGroup containerGroup = new Composite(shell, SWT.NONE); containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); containerGroup.setToolTipText("CONTAINER"); layout = new RowLayout(); layout.spacing = 20; containerGroup.setLayout(layout); // Native nativeGroup = new Composite(shell, SWT.NONE); nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); nativeGroup.setToolTipText("NATIVE"); layout = new RowLayout(); layout.spacing = 20; nativeGroup.setLayout(layout); // Custom customGroup = new Composite(shell, SWT.NONE); customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); customGroup.setToolTipText("CUSTOM"); layout = new RowLayout(); layout.spacing = 20; customGroup.setLayout(layout); // AsDesigned defaultBackgroundGroup = new Composite(shell, SWT.NONE); defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); defaultBackgroundGroup.setToolTipText("Default Background"); layout = new RowLayout(); layout.spacing = 20; defaultBackgroundGroup.setLayout(layout); // ItemGroup itemGroup = new Composite(shell, SWT.NONE); itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); itemGroup.setToolTipText("ITEM"); layout = new RowLayout(); layout.spacing = 20; itemGroup.setLayout(layout); // Label label = new Label(nativeGroup, SWT.NONE); label.setText("Label"); // Radio button radio = new Button(nativeGroup, SWT.RADIO); radio.setText("Radio Button"); radio.setSelection(true); radio.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // Checkbox button with image check = new Button(nativeGroup, SWT.CHECK); check.setText("CheckBox Image"); check.setSelection(true); check.setBackgroundImage(getBackgroundImage(display)); // Push Button push = new Button(defaultBackgroundGroup, SWT.PUSH); push.setText("Push Button"); // Toolbar toolBar = new ToolBar(nativeGroup, SWT.FLAT); toolBar.pack(); ToolItem item = new ToolItem(toolBar, SWT.PUSH); item.setText("ToolBar_Item"); // Coolbar coolBar = new CoolBar(nativeGroup, SWT.BORDER); for (int i = 0; i < 2; i++) { CoolItem item2 = new CoolItem(coolBar, SWT.NONE); Button button = new Button(coolBar, SWT.PUSH); button.setText("Button " + i); Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); item2.setPreferredSize(item2.computeSize(size.x, size.y)); item2.setControl(button); } // Scale scale = new Scale(nativeGroup, SWT.None); scale.setMaximum(100); scale.setSelection(20); // Link link = new Link(nativeGroup, SWT.NONE); link.setText("<a>Sample link</a>"); // List list = new List(nativeGroup, SWT.BORDER); list.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); list.add("List_one"); list.add("List_two"); list.add("List_three"); list.add("List_four"); // Canvas canvas = new Canvas(containerGroup, SWT.NONE); canvas.setToolTipText("Canvas"); canvas.addPaintListener(e -> { GC gc = e.gc; gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); gc.drawRectangle(e.x + 1, e.y + 1, e.width - 2, e.height - 2); gc.drawArc(2, 2, e.width - 4, e.height - 4, 0, 360); }); // Composite composite = new Composite(containerGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); composite.setToolTipText("Composite"); // TabFolder tabFolder = new TabFolder(containerGroup, SWT.BORDER); tabFolder.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); for (int i = 0; i < 2; i++) { TabItem tabItem = new TabItem(tabFolder, SWT.NONE); tabItem.setText("TabItem " + i); Label label = new Label(tabFolder, SWT.PUSH); label.setText("Page " + i); tabItem.setControl(label); tabItem.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN)); } tabFolder.pack(); // Group group = new Group(containerGroup, SWT.NONE); group.setText("Group"); // Sash sash = new Sash(containerGroup, SWT.HORIZONTAL | SWT.BORDER); sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN)); sash.setLayoutData(new RowData(100, 100)); sash.setToolTipText("Sash"); // SashForm sashForm = new SashForm(containerGroup, SWT.HORIZONTAL | SWT.BORDER); Label leftLabel = new Label(sashForm, SWT.NONE); leftLabel.setText("SashForm\nLeft\n...\n...\n...\n...\n..."); Label rightLabel = new Label(sashForm, SWT.NONE); rightLabel.setText("SashForm\nRight\n...\n...\n...\n...\n..."); // DateTime dateTime = new DateTime(defaultBackgroundGroup, SWT.NONE); dateTime.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // Text text = new Text(nativeGroup, SWT.BORDER); text.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); text.setText("text"); // ProgressBar progressBar = new ProgressBar(defaultBackgroundGroup, SWT.NONE); progressBar.setMaximum(100); progressBar.setSelection(80); // Combo combo = new Combo(defaultBackgroundGroup, SWT.BORDER); combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); combo.add("combo"); combo.setText("combo"); // Slider slider = new Slider(nativeGroup, SWT.HORIZONTAL | SWT.BORDER); slider.setSelection(20); slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // CCombo ccombo = new CCombo(defaultBackgroundGroup, SWT.BORDER); ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); ccombo.add("ccombo"); ccombo.setText("ccombo"); // CLable cLabel = new CLabel(customGroup, SWT.NONE); cLabel.setText("CLabel"); // Text styledText = new StyledText(customGroup, SWT.BORDER); styledText.setFont(new Font(display, "Tahoma", 18, SWT.BOLD | SWT.ITALIC)); styledText.setForeground(display.getSystemColor(SWT.COLOR_DARK_BLUE)); styledText.setText("Styled Text"); styledText.append("\n"); styledText.append("Example_string"); styledText.append("\n"); styledText.append("One_Two"); styledText.append("\n"); styledText.append("Two_Three"); // CTabFolder cTab = new CTabFolder(containerGroup, SWT.BORDER); for (int i = 0; i < 2; i++) { CTabItem cTabItem = new CTabItem(cTab, SWT.CLOSE, i); cTabItem.setText("CTabItem " + (i + 1)); } cTab.setSelection(0); // Gradient CTabFolder gradientCTab = new CTabFolder(customGroup, SWT.BORDER); gradientCTab.setBackground( new Color[] { display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_RED) }, new int[] { 90 }, true); for (int i = 0; i < 2; i++) { CTabItem cTabItem = new CTabItem(gradientCTab, SWT.CLOSE, i); cTabItem.setText("CTabItem " + (i + 1)); } gradientCTab.setSelection(0); // Table table = new Table(itemGroup, SWT.V_SCROLL); table.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); table.setLinesVisible(true); table.setHeaderVisible(true); TableItem tableItem = new TableItem(table, SWT.NONE); tableItem.setText("TableItem - One"); tableItem = new TableItem(table, SWT.NONE); tableItem.setText("TableItem - Two"); // Tree tree = new Tree(itemGroup, SWT.NONE); TreeItem treeItem = new TreeItem(tree, SWT.NONE); treeItem.setText("Parent"); TreeItem childItem = new TreeItem(treeItem, SWT.NONE); childItem.setText("Child1"); childItem = new TreeItem(treeItem, SWT.NONE); childItem.setText("Child2"); treeItem.setExpanded(true); tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // ExpandBar expandBar = new ExpandBar(itemGroup, SWT.V_SCROLL); expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); for (int i = 1; i <= 2; i++) { ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE, 0); item1.setText("Expand_Bar_Entry " + i); item1.setExpanded(true); item1.setHeight(20); } shell.open(); shell.pack(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ChooseColor.java
/** * Creates the window contents/*www .j a v a 2 s . c om*/ * * @param shell the parent shell */ private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, false)); // Start with Celtics green color = new Color(shell.getDisplay(), new RGB(0, 255, 0)); // Use a label full of spaces to show the color final Label colorLabel = new Label(shell, SWT.NONE); colorLabel.setText(" "); colorLabel.setBackground(color); Button button = new Button(shell, SWT.PUSH); button.setText("Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog ColorDialog dlg = new ColorDialog(shell); // Set the selected color in the dialog from // user's selected color dlg.setRGB(colorLabel.getBackground().getRGB()); // Change the title bar text dlg.setText("Choose a Color"); // Open the dialog and retrieve the selected color RGB rgb = dlg.open(); if (rgb != null) { // Dispose the old color, create the // new one, and set into the label color.dispose(); color = new Color(shell.getDisplay(), rgb); colorLabel.setBackground(color); } } }); }
From source file:ColorDialogExample.java
ColorDialogExample() { d = new Display(); s = new Shell(d); s.setSize(400, 400);/* ww w .j a va 2 s. c om*/ s.setText("A ColorDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Color"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { ColorDialog cd = new ColorDialog(s); cd.setText("ColorDialog Demo"); cd.setRGB(new RGB(255, 255, 255)); RGB newColor = cd.open(); if (newColor == null) { return; } t.setBackground(new Color(d, newColor)); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }