List of usage examples for org.eclipse.jface.resource ImageDescriptor ImageDescriptor
protected ImageDescriptor()
From source file:net.refractions.udig.ui.graphics.Glyph.java
License:Open Source License
/** * Complex render of Geometry allowing presentation of point, line and polygon styles. * <p>//from w w w. ja va 2 s . c o m * Layout:<pre><code> * 1 2 3 4 5 6 7 8 9101112131415 * 0 * 1 LL L * 2 L L L * 3 L L L * 4 L L L * 5 L L L * 6 L L L * 7 L L L * 8 L L L * 9 L L L * 10 L L L * 11 L L L * 12 L L L * 13 L L L * 14 L LL * 15 * </code><pre> * </p> * @param style * @return Icon representing geometry style */ public static ImageDescriptor line(final Rule rule) { final SimpleFeature feature = d.feature(d.line(new int[] { 1, 14, 6, 0, 11, 14, 15, 1 })); return new ImageDescriptor() { public ImageData getImageData() { Image image = null; try { Display display = PlatformUI.getWorkbench().getDisplay(); image = new Image(display, DEFAULT_WIDTH, DEFAULT_HEIGHT); d.drawDirect(image, display, feature, rule); return extractImageDataAndDispose(image); } catch (RuntimeException ex) { if (image != null && !image.isDisposed()) { image.dispose(); } throw ex; } } }; }
From source file:net.refractions.udig.ui.graphics.Glyph.java
License:Open Source License
/** * Icon for linestring in the provided color and width. * <p>/*from w w w. java 2 s. c o m*/ * XXX: Suggest line( SLD style ) at a later time. * </p> * @param black * @return Icon */ public static ImageDescriptor line(Color color, int width) { Color color2 = color; int width2 = width; if (color2 == null) { color2 = Color.BLACK; } if (width2 <= 0) { width2 = 1; } final int finalWidth = width2; final Color finalColor = color2; return new ImageDescriptor() { public ImageData getImageData() { Image swtImage = null; try { Display display = PlatformUI.getWorkbench().getDisplay(); swtImage = new Image(display, DEFAULT_WIDTH, DEFAULT_HEIGHT); GC gc = new GC(swtImage); gc.setAntialias(SWT.ON); gc.setLineCap(SWT.CAP_SQUARE); gc.setLineStyle(SWT.LINE_SOLID); gc.setForeground(color(finalColor)); gc.setAlpha(finalColor.getAlpha()); gc.setLineWidth(finalWidth); gc.drawLine(1, 13, 6, 2); gc.drawLine(6, 2, 9, 13); gc.drawLine(9, 13, 14, 2); ImageData clone = (ImageData) swtImage.getImageData().clone(); swtImage.dispose(); return clone; } catch (RuntimeException ex) { if (swtImage != null && !swtImage.isDisposed()) { swtImage.dispose(); } throw ex; } } }; }
From source file:net.refractions.udig.ui.graphics.Glyph.java
License:Open Source License
/** * Complex render of Geometry allowing presentation of point, line and polygon styles. * <p>/* w ww . ja va 2s . c o m*/ * Layout:<pre><code> * 1 2 3 4 5 6 7 8 9101112131415 * 0 * 1 * 2 * 3 L L * 4 p L L PPPPPP * 5 L L PPPPP L p * 6 L LPPPP L p * 7 L PPPL L p * 8 L PP L L p * 9 L P L L P * 10 L P L L P * 11 L P L L P * 12 L P L P * 13 p P * 14 PPPPPPPPPPPPPPPPPPPPPPPP * 15 * </code><pre> * </p> * @param style * @return Icon representing geometry style */ public static ImageDescriptor geometry(final Rule rule) { return new ImageDescriptor() { public ImageData getImageData() { Image image = null; try { Display display = PlatformUI.getWorkbench().getDisplay(); image = new Image(display, DEFAULT_WIDTH, DEFAULT_HEIGHT); d.drawDirect(image, display, d.feature(d.line(new int[] { 0, 12, 6, 3, 11, 12, 15, 3 })), rule); d.drawDirect(image, display, d.feature(d.point(4, 4)), rule); return extractImageDataAndDispose(image); } catch (RuntimeException ex) { if (image != null && !image.isDisposed()) { image.dispose(); } throw ex; } } }; }
From source file:net.refractions.udig.ui.graphics.Glyph.java
License:Open Source License
/** * Icon for generic Geometry or Geometry Collection. * @param color /*from w w w. j av a 2 s . c o m*/ * @param fill * * @return Icon */ public static ImageDescriptor geometry(final Color color, final Color fill) { return new ImageDescriptor() { public ImageData getImageData() { Image swtImage = null; try { Display display = PlatformUI.getWorkbench().getDisplay(); swtImage = new Image(display, DEFAULT_WIDTH, DEFAULT_HEIGHT); GC gc = new GC(swtImage); gc.setAntialias(SWT.ON); gc.setLineCap(SWT.CAP_SQUARE); gc.setLineStyle(SWT.LINE_SOLID); gc.setLineWidth(1); Color c = color; Color f = fill; if (c == null && f == null) { // only need default if both are empty c = Color.BLACK; f = Color.LIGHT_GRAY; } if (f != null) { gc.setBackground(color(f)); gc.setAlpha(f.getAlpha()); gc.fillRoundRectangle(2, 1, 13, 13, 2, 2); } if (c != null) { gc.setForeground(color(c)); gc.setAlpha(c.getAlpha()); gc.drawRoundRectangle(2, 1, 13, 13, 2, 2); } ImageData clone = (ImageData) swtImage.getImageData().clone(); swtImage.dispose(); return clone; } catch (RuntimeException ex) { if (swtImage != null && !swtImage.isDisposed()) { swtImage.dispose(); } throw ex; } } }; }
From source file:net.refractions.udig.ui.graphics.Glyph.java
License:Open Source License
/** * Render of a polygon allowing style./*from w w w . jav a2s .com*/ * <p> * Layout:<pre><code> * 1 2 3 4 5 6 7 8 9101112131415 * 0 * 1 * 2 PPPPPPPP * 3 PPPPPP P * 4 PPPPPP P * 5 PPP p * 6 PP p * 7 P p * 8 P p * 9 P P * 10 P P * 11 P P * 12 P P * 13 P P * 14 PPPPPPPPPPPPPPPPPPPPPPPPPPPP * 15 * </code><pre> * </p> * @param style * @return Icon representing geometry style */ public static ImageDescriptor polygon(final Rule rule) { return new ImageDescriptor() { public ImageData getImageData() { final Image[] image = new Image[1]; try { final Display display = PlatformUI.getWorkbench().getDisplay(); PlatformGIS.syncInDisplayThread(display, new Runnable() { public void run() { image[0] = new Image(display, DEFAULT_WIDTH, DEFAULT_HEIGHT); try { d.drawDirect(image[0], display, d.feature( d.polygon(new int[] { 1, 14, 3, 9, 4, 6, 6, 4, 9, 3, 14, 1, 14, 14 })), rule); } catch (Throwable npe) { // unavailable } } }); return extractImageDataAndDispose(image[0]); } catch (RuntimeException ex) { if (image[0] != null && !image[0].isDisposed()) { image[0].dispose(); } throw ex; } } }; }
From source file:net.refractions.udig.ui.graphics.Glyph.java
License:Open Source License
/** * Icon for polygon in provided border, fill and width * * @param black/*ww w .j av a 2 s.c om*/ * @param gray * @param i * @return */ public static ImageDescriptor polygon(final Color color, final Color fill, final int width) { return new ImageDescriptor() { public ImageData getImageData() { Image swtImage = null; try { Display display = PlatformUI.getWorkbench().getDisplay(); swtImage = new Image(display, DEFAULT_WIDTH, DEFAULT_HEIGHT); GC gc = new GC(swtImage); gc.setAntialias(SWT.ON); gc.setLineCap(SWT.CAP_SQUARE); gc.setLineStyle(SWT.LINE_SOLID); org.eclipse.swt.graphics.Color t = null; Color c = color; Color f = fill; int w = width > 0 ? width : 1; if (c == null && f == null) { // only need default if both are empty c = Color.BLACK; f = Color.LIGHT_GRAY; } if (f != null) { gc.setBackground(t = color(f)); t.dispose(); } if (c != null) { gc.setForeground(t = color(c)); t.dispose(); } gc.setLineWidth(w); int[] points = { 1, 14, 3, 9, 4, 6, 6, 4, 9, 3, 14, 1, 14, 14 }; gc.setAlpha(f.getAlpha()); gc.fillPolygon(points); gc.setAlpha(c.getAlpha()); gc.drawPolygon(points); ImageData clone = (ImageData) swtImage.getImageData().clone(); swtImage.dispose(); return clone; } finally { if (swtImage != null && !swtImage.isDisposed()) swtImage.dispose(); } } }; }
From source file:net.refractions.udig.ui.graphics.Glyph.java
License:Open Source License
/** * Icon for grid data, small grid made up of provided colors. * <p>/*from w w w . ja v a 2 s . c om*/ * Layout:<pre><code> * 0 1 2 3 4 5 6 7 8 9 101112131415 * 0 * 1 AAAAAAAAAAAAABBBBBBBBBBBBBB * 2 AAAAAAAAAAAAABBBBBBBBBBBBBB * 3 AAAAAAAAAAAAABBBBBBBBBBBBBB * 4 AAAAAAAAAAAAABBBBBBBBBBBBBB * 5 AAAAAAAAAAAAABBBBBBBBBBBBBB * 6 AAAAAAAAAAAAABBBBBBBBBBBBBB * 7 AAAAAAAAAAAAABBBBBBBBBBBBBB * 8 CCCCCCCCCCCCCDDDDDDDDDDDDDD * 9 CCCCCCCCCCCCCDDDDDDDDDDDDDD * 10 CCCCCCCCCCCCCDDDDDDDDDDDDDD * 11 CCCCCCCCCCCCCDDDDDDDDDDDDDD * 12 CCCCCCCCCCCCCDDDDDDDDDDDDDD * 13 CCCCCCCCCCCCCDDDDDDDDDDDDDD * 14 CCCCCCCCCCCCCDDDDDDDDDDDDDD * 15 * </code><pre> * </p> * @param a * @param b * @param c * @param d1 * @return Icon representing a grid * */ public static ImageDescriptor grid(Color a, Color b, Color c, Color d1) { if (a == null) { a = Color.BLACK; } if (b == null) { b = Color.DARK_GRAY; } if (c == null) { c = Color.LIGHT_GRAY; } if (d1 == null) { d1 = Color.WHITE; } final Color finalA = a; final Color finalB = b; final Color finalC = c; final Color finalD = d1; return new ImageDescriptor() { public ImageData getImageData() { Display display = PlatformUI.getWorkbench().getDisplay(); Image swtImage = new Image(display, DEFAULT_WIDTH, DEFAULT_HEIGHT); GC gc = new GC(swtImage); gc.setAntialias(SWT.ON); org.eclipse.swt.graphics.Color c = null; gc.setBackground(c = color(finalA)); gc.fillRectangle(0, 0, 7, 7); c.dispose(); gc.setBackground(c = color(finalB)); gc.fillRectangle(7, 0, 15, 7); c.dispose(); gc.setBackground(c = color(finalC)); gc.fillRectangle(0, 7, 7, 15); c.dispose(); gc.setBackground(c = color(finalD)); gc.fillRectangle(7, 7, 15, 15); c.dispose(); gc.setForeground(c = color(Color.BLACK)); gc.drawRectangle(0, 0, 7, 7); gc.drawRectangle(0, 0, 15, 7); gc.drawRectangle(0, 7, 7, 15); gc.drawRectangle(0, 7, 15, 15); c.dispose(); ImageData clone = (ImageData) swtImage.getImageData().clone(); swtImage.dispose(); return clone; } }; }
From source file:net.refractions.udig.ui.graphics.Glyph.java
License:Open Source License
/** * Render of a color swatch allowing style. * <p>/* ww w. ja v a 2s . c om*/ * Layout:<pre><code> * 0 1 2 3 4 5 6 7 8 9 101112131415 * 0 * 1 dddddddddddddddddddddddddddd * 2 dCCCCCCCCCCCCCCCCCCCCCcCCCCCCd * 3 dCCCCCCCCCCCCCCCCCCCCCCcCCCCCd * 4 dCCCCCCCCCCCCCCCCCCCCCCCcCCCCd * 5 dCCCCCCCCCCCCCCCCCCCCCCCCcCCCd * 6 dCCCCCCCCCCCCCCCCCCCCCCCCCcCCd * 7 dCCCCCCCCCCCCCCCCCCCCCCCCCCcCd * 8 dCcCCCCCCCCCCCCCCCCCCCCCCCCCCd * 9 dCCcCCCCCCCCCCCCCCCCCCCCCCCCCd * 10 dCCCcCCCCCCCCCCCCCCCCCCCCCCCCd * 11 dCCCCcCCCCCCCCCCCCCCCCCCCCCCCd * 12 dCCCCCcCCCCCCCCCCCCCCCCCCCCCCd * 13 ddCCCCCcCCCCCCCCCCCCCCCCCCCCdd * 14 ddddddddddddddddddddddddddd * 15 * </code><pre> * </p> * @param style * @return Icon representing geometry style */ public static ImageDescriptor swatch(Color c) { Color c2 = c; if (c == null) { c2 = Color.GRAY; } else { c2 = c; } final Color color = c2; int saturation = color.getRed() + color.getGreen() + color.getBlue(); final Color contrast = saturation < 384 ? c.brighter() : c.darker(); return new ImageDescriptor() { public ImageData getImageData() { Display display = PlatformUI.getWorkbench().getDisplay(); Image swtImage = new Image(display, DEFAULT_WIDTH, DEFAULT_HEIGHT); GC gc = new GC(swtImage); gc.setAntialias(SWT.ON); org.eclipse.swt.graphics.Color swtColor = color(color); try { gc.setBackground(swtColor); gc.fillRoundRectangle(0, 0, 14, 14, 2, 2); } finally { swtColor.dispose(); } try { swtColor = color(contrast); gc.setForeground(swtColor); gc.drawRoundRectangle(0, 0, 14, 14, 2, 2); } finally { swtColor.dispose(); } ImageData clone = (ImageData) swtImage.getImageData().clone(); swtImage.dispose(); return clone; } }; }
From source file:net.refractions.udig.ui.graphics.Glyph.java
License:Open Source License
/** * Icon for grid data, small grid made up of provided colors. * Layout:<pre><code>//w ww. j a va 2 s .co m * 0 1 2 3 4 5 6 7 8 9 101112131415 * 0 * 1 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 2 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 3 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 4 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 5 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 6 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 7 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 8 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 9 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 10 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 11 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 12 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 14 AABBCDEEFfGgHhIiJjKkllmmnnoopp * 15 * </code><pre> * </p> * @param c palette of colors * @return Icon representing a palette * */ public static ImageDescriptor palette(Color c[]) { final Color[] colors = new Color[16]; Color color = Color.GRAY; if (c == null) { for (int i = 0; i < 16; i++) color = Color.GRAY; } else { for (int i = 0; i < 16; i++) { int lookup = (i * c.length) / 16; if (c[lookup] != null) color = c[lookup]; colors[i] = color; } } return new ImageDescriptor() { public ImageData getImageData() { Display display = PlatformUI.getWorkbench().getDisplay(); Image swtImage = new Image(display, DEFAULT_WIDTH, DEFAULT_HEIGHT); GC gc = new GC(swtImage); gc.setAntialias(SWT.ON); org.eclipse.swt.graphics.Color swtColor = null; for (int i = 0; i < 16; i++) { try { swtColor = color(colors[i]); gc.setForeground(swtColor); gc.drawLine(i, 0, i, 15); } finally { swtColor.dispose(); } } try { swtColor = color(Color.GRAY); gc.setForeground(swtColor); gc.drawRoundRectangle(0, 0, 14, 14, 2, 2); } finally { swtColor.dispose(); } ImageData clone = (ImageData) swtImage.getImageData().clone(); swtImage.dispose(); return clone; } }; }
From source file:net.refractions.udig.ui.graphics.NonAdvancedSWTGraphics.java
License:Open Source License
public static ImageDescriptor createImageDescriptor(final RenderedImage image, final boolean transparent) { return new ImageDescriptor() { public ImageData getImageData() { return createImageData(image, transparent); }/*from ww w . j a va 2s. co m*/ }; }