List of usage examples for org.eclipse.jface.resource ColorDescriptor createFrom
public static ColorDescriptor createFrom(RGB toCreate)
From source file:com.byterefinery.rmbench.util.ColorRegistry.java
License:Open Source License
public ColorDescriptor getColorDescriptor(String symbolicName) { return ColorDescriptor.createFrom(getRGB(symbolicName)); }
From source file:net.enilink.komma.edit.ui.provider.ExtendedColorRegistry.java
License:Open Source License
public Color getColor(Color foregroundColor, Color backgroundColor, Object object) { if (object instanceof Color) { return (Color) object; } else {/* w ww. j a v a 2 s . co m*/ Collection<Object> key = new ArrayList<Object>(2); key.add(foregroundColor); key.add(backgroundColor); key.add(object); Display display = Display.getCurrent(); Color result = null; Map<Collection<?>, Color> cache = null; if (display != null) { synchronized (display) { cache = colors.get(display); if (cache == null) { hookDisplayDispose(display); cache = new HashMap<Collection<?>, Color>(); colors.put(display, cache); } result = cache.get(object); } } if (result == null) { if (object instanceof ColorDescriptor) { ColorDescriptor colorDescriptor = (ColorDescriptor) object; try { result = colorDescriptor.createColor(display); } catch (DeviceResourceException exception) { KommaEditUIPlugin.INSTANCE.log(exception); } } else if (object instanceof URI) { URI colorURI = (URI) object; if (!"color".equals(colorURI.scheme())) { throw new IllegalArgumentException("Only 'color' scheme is recognized" + colorURI); } RGB colorData; if ("rgb".equals(colorURI.authority())) { int red = Integer.parseInt(colorURI.segment(0)); int green = Integer.parseInt(colorURI.segment(1)); int blue = Integer.parseInt(colorURI.segment(2)); colorData = new RGB(red, green, blue); } else if ("hsb".equals(colorURI.authority())) { float[] hsb = new float[3]; for (int i = 0; i < 3; ++i) { String segment = colorURI.segment(i); hsb[i] = "".equals(segment) || "foreground".equals(segment) ? foregroundColor.getRGB().getHSB()[i] : "background".equals(segment) ? backgroundColor.getRGB().getHSB()[i] : Float.parseFloat(segment); } colorData = new RGB(hsb[0], hsb[1], hsb[2]); } else { throw new IllegalArgumentException( "Only 'rgb' and 'hsb' authority are recognized" + colorURI); } try { result = ColorDescriptor.createFrom(colorData).createColor(display); } catch (DeviceResourceException exception) { KommaEditUIPlugin.INSTANCE.log(exception); } } if (result != null && display != null) { synchronized (display) { cache.put(key, result); } } } return result; } }
From source file:net.yatomiya.e4.ui.util.UIResourceManager.java
License:Open Source License
@Override public Color getColor(RGB rgb) { return resMgr.createColor(ColorDescriptor.createFrom(rgb)); }
From source file:net.yatomiya.e4.ui.util.UIResourceManager.java
License:Open Source License
public Color getColor(int r, int g, int b) { return resMgr.createColor(ColorDescriptor.createFrom(new RGB(r, g, b))); }
From source file:org.eclipse.e4mf.edit.ui.provider.ExtendedColorRegistry.java
License:Open Source License
public Color getColor(Color foregroundColor, Color backgroundColor, Object object) { if (object instanceof Color) { return (Color) object; } else {/*from w ww. j av a 2 s . c o m*/ Collection<Object> key = new ArrayList<Object>(2); key.add(foregroundColor); key.add(backgroundColor); key.add(object); Color result = table.get(key); if (result == null) { if (object instanceof ColorDescriptor) { ColorDescriptor colorDescriptor = (ColorDescriptor) object; try { result = colorDescriptor.createColor(display); } catch (DeviceResourceException exception) { EMFEditUIPlugin.INSTANCE.log(exception); } } else if (object instanceof URI) { URI colorURI = (URI) object; if (!"color".equals(colorURI.scheme())) { throw new IllegalArgumentException("Only 'color' scheme is recognized" + colorURI); } RGB colorData; if ("rgb".equals(colorURI.authority())) { int red = Integer.parseInt(colorURI.segment(0)); int green = Integer.parseInt(colorURI.segment(1)); int blue = Integer.parseInt(colorURI.segment(2)); colorData = new RGB(red, green, blue); } else if ("hsb".equals(colorURI.authority())) { float[] hsb = new float[3]; for (int i = 0; i < 3; ++i) { String segment = colorURI.segment(i); hsb[i] = "".equals(segment) || "foreground".equals(segment) ? foregroundColor.getRGB().getHSB()[i] : "background".equals(segment) ? backgroundColor.getRGB().getHSB()[i] : Float.parseFloat(segment); } colorData = new RGB(hsb[0], hsb[1], hsb[2]); } else { throw new IllegalArgumentException( "Only 'rgb' and 'hsb' authority are recognized" + colorURI); } try { result = ColorDescriptor.createFrom(colorData).createColor(display); } catch (DeviceResourceException exception) { EMFEditUIPlugin.INSTANCE.log(exception); } } if (result != null) { table.put(key, result); } } return result; } }
From source file:org.eclipse.ease.ui.view.ScriptShell.java
License:Open Source License
/** * /* w ww . j a va2 s .c o m*/ * @param style * style to use (see JavaScriptShell.STYLE_* constants) * @param start * start of text to be styled * @param length * length of text to be styled * @return StyleRange for text */ private StyleRange getStyle(final int style, final int start, final int length) { final StyleRange styleRange = new StyleRange(); styleRange.start = start; styleRange.length = length; switch (style) { case TYPE_RESULT: styleRange.foreground = mResourceManager.createColor(ColorDescriptor .createFrom(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY))); break; case TYPE_COMMAND: styleRange.foreground = mResourceManager.createColor(ColorDescriptor .createFrom(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE))); styleRange.fontStyle = SWT.BOLD; break; case TYPE_ERROR: styleRange.foreground = mResourceManager.createColor(ColorDescriptor .createFrom(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED))); styleRange.fontStyle = SWT.ITALIC; break; case TYPE_OUTPUT: styleRange.foreground = mResourceManager.createColor(ColorDescriptor .createFrom(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK))); break; default: break; } return styleRange; }
From source file:org.eclipse.egit.ui.internal.commit.DiffViewer.java
License:Open Source License
private ColorDescriptor createEditorColorDescriptor(String key) { return ColorDescriptor.createFrom(PreferenceConverter.getColor(EditorsUI.getPreferenceStore(), key)); }
From source file:org.eclipse.emf.ecp.internal.ui.view.emf.ExtendedColorRegistry.java
License:Open Source License
public Color getColor(Color foregroundColor, Color backgroundColor, Object object) { if (object instanceof Color) { return (Color) object; } else {/* w ww. j a v a2 s .c o m*/ final Collection<Object> key = new ArrayList<Object>(2); key.add(foregroundColor); key.add(backgroundColor); key.add(object); Color result = table.get(key); if (result == null) { if (object instanceof ColorDescriptor) { final ColorDescriptor colorDescriptor = (ColorDescriptor) object; try { result = colorDescriptor.createColor(display); } catch (final DeviceResourceException exception) { Activator.log(exception); } } else if (object instanceof URI) { final URI colorURI = (URI) object; if (!"color".equals(colorURI.scheme())) { throw new IllegalArgumentException("Only 'color' scheme is recognized" + colorURI); } RGB colorData; if ("rgb".equals(colorURI.authority())) { final int red = Integer.parseInt(colorURI.segment(0)); final int green = Integer.parseInt(colorURI.segment(1)); final int blue = Integer.parseInt(colorURI.segment(2)); colorData = new RGB(red, green, blue); } else if ("hsb".equals(colorURI.authority())) { final float[] hsb = new float[3]; for (int i = 0; i < 3; ++i) { final String segment = colorURI.segment(i); hsb[i] = "".equals(segment) || "foreground".equals(segment) ? foregroundColor.getRGB().getHSB()[i] : "background".equals(segment) ? backgroundColor.getRGB().getHSB()[i] : Float.parseFloat(segment); } colorData = new RGB(hsb[0], hsb[1], hsb[2]); } else { throw new IllegalArgumentException( "Only 'rgb' and 'hsb' authority are recognized" + colorURI); } try { result = ColorDescriptor.createFrom(colorData).createColor(display); } catch (final DeviceResourceException exception) { Activator.log(exception); } } if (result != null) { table.put(key, result); } } return result; } }
From source file:org.eclipse.scada.chart.swt.SWTGraphics.java
License:Open Source License
@Override public void setBackground(final RGB color) { if (color != null) { this.gc.setBackground((Color) this.resourceManager.get(ColorDescriptor.createFrom(color))); } else {//ww w . j a v a2s .c o m this.gc.setBackground(this.gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); } }
From source file:org.eclipse.scada.chart.swt.SWTGraphics.java
License:Open Source License
@Override public void setForeground(final RGB color) { if (color != null) { this.gc.setForeground((Color) this.resourceManager.get(ColorDescriptor.createFrom(color))); } else {//ww w. jav a2 s. c om this.gc.setForeground(this.gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); } }