Example usage for org.eclipse.jface.resource StringConverter asRGB

List of usage examples for org.eclipse.jface.resource StringConverter asRGB

Introduction

In this page you can find the example usage for org.eclipse.jface.resource StringConverter asRGB.

Prototype

public static RGB asRGB(String value) throws DataFormatException 

Source Link

Document

Converts the given value into an SWT RGB color value.

Usage

From source file:ccw.editors.clojure.scanners.ClojureTokenScanner.java

License:Open Source License

/**
 * Copy constructor plus the new value. Generates a new {@link IToken}
 * @param token A token./* ww w  .  ja v a  2s  .  c o  m*/
 * @param key The property key.
 * @param newValue The new value.
 * @return A ColorizableToken, never null.
 */
public static @NonNull IToken adaptToken(IToken token, String key, Object newValue) {
    TextAttribute textAttribute = (TextAttribute) token.getData();

    Boolean isBold = (textAttribute.getStyle() & SWT.BOLD) == SWT.BOLD;
    Boolean isItalic = (textAttribute.getStyle() & SWT.ITALIC) == SWT.ITALIC;
    RGB rgb = textAttribute.getForeground().getRGB();
    boolean newValueProcessed = false;

    if (PreferenceConstants.isBoldPreferenceKey(key) == Boolean.TRUE) {
        if (newValue instanceof Boolean) {
            isBold = (Boolean) newValue;
            newValueProcessed = true;
        } else if (newValue instanceof String) {
            isBold = Boolean.valueOf((String) newValue);
            newValueProcessed = true;
        }
    }

    if (!newValueProcessed && PreferenceConstants.isItalicPreferenceKey(key) == Boolean.TRUE) {
        if (newValue instanceof Boolean) {
            isItalic = (Boolean) newValue;
            newValueProcessed = true;
        } else if (newValue instanceof String) {
            isItalic = Boolean.valueOf((String) newValue);
            newValueProcessed = true;
        }
    }

    if (!newValueProcessed) {
        if (newValue instanceof RGB) {
            rgb = ((RGB) newValue);
        } else if (newValue instanceof String) {
            rgb = StringConverter.asRGB((String) newValue);
        }
    }
    return new org.eclipse.jface.text.rules.Token(TokenScannerUtils.createTokenData(rgb, isBold, isItalic));
}

From source file:com.amalto.workbench.widgets.composites.ElementFKInfoColorProvider.java

License:Open Source License

public IToken getToken(String prefKey) {
    Token token = (Token) tokenTable.get(prefKey);
    if (token == null) {
        String colorName = store.getString(prefKey);
        if (colorName == null || colorName.isEmpty()) {
            if (prefKey.equals(ElementFKInfoConfiguration.PREF_COLOR_DEFAULT)) {
                colorName = "0,128,0"; //$NON-NLS-1$
            } else if (prefKey.equals(ElementFKInfoConfiguration.PREF_COLOR_STRING)) {
                colorName = "0,0,255"; //$NON-NLS-1$
            } else if (prefKey.equals(ElementFKInfoConfiguration.PREF_COLOR_KEYWORD)) {
                colorName = "0,0,128"; //$NON-NLS-1$
            }/*from w  ww.ja  v  a 2  s  .c  o  m*/

        }
        RGB rgb = StringConverter.asRGB(colorName);
        token = new Token(new TextAttribute(getColor(rgb)));
        tokenTable.put(prefKey, token);
    }
    return token;
}

From source file:com.amalto.workbench.widgets.composites.ElementFKInfoColorProvider.java

License:Open Source License

public Color getColor(String prefKey) {
    String colorName = store.getString(prefKey);
    RGB rgb = StringConverter.asRGB(colorName);
    return getColor(rgb);
}

From source file:com.amalto.workbench.widgets.composites.ElementFKInfoColorProvider.java

License:Open Source License

public void handlePreferenceStoreChanged(PropertyChangeEvent event) {
    String prefKey = event.getProperty();
    Token token = (Token) tokenTable.get(prefKey);
    if (token != null) {
        String colorName = store.getString(prefKey);
        RGB rgb = StringConverter.asRGB(colorName);
        token.setData(new TextAttribute(getColor(rgb)));
    }/*w  w w  .  j  av a2 s .c o  m*/
}

From source file:com.aptana.ide.core.ui.ColorPair.java

License:Open Source License

/**
 * Converts the given value into an SWT RGB color value. This method fails if the value does not
 * represent an RGB color value.//from   w  w w  . ja v  a2  s. c  om
 * <p>
 * A valid RGB color value representation is a string of the form
 * <code><it>red</it>,<it>green</it></code>,<it>blue</it></code> where <code><it>red</it></code>,
 * <it>green</it></code>, and <code><it>blue</it></code> are valid ints. ColorPairs are a
 * combination of two colors, separated (in string form), be a ';'
 * </p>
 * 
 * @param value
 *            the value to be converted
 * @return the value as an RGB color value
 * @exception DataFormatException
 *                if the given value does not represent an RGB color value
 */
public static ColorPair asColorPair(String value) throws DataFormatException {
    if (value == null) {
        throw new DataFormatException("Null doesn't represent a valid ColorPair"); //$NON-NLS-1$
    }

    StringTokenizer stok = new StringTokenizer(value, ";"); //$NON-NLS-1$

    try {
        String color1 = stok.nextToken();
        String color2 = null;
        if (stok.hasMoreTokens()) {
            color2 = stok.nextToken();
            return new ColorPair(StringConverter.asRGB(color1), StringConverter.asRGB(color2));
        } else {
            return new ColorPair(StringConverter.asRGB(color1), null);
        }

    } catch (NoSuchElementException e) {
        throw new DataFormatException(e.getMessage());
    }
}

From source file:com.aptana.theme.internal.ThemeManager.java

License:Open Source License

private void setCompareColors(String nodeName, boolean override) {
    IEclipsePreferences instancePrefs = EclipseUtil.instanceScope().getNode(nodeName);

    if (override) {
        RGB bg = getCurrentTheme().getBackground();
        RGB inverted = new RGB(255 - bg.red, 255 - bg.green, 255 - bg.blue);

        JFaceResources.getColorRegistry().put("INCOMING_COLOR", inverted); //$NON-NLS-1$
        JFaceResources.getColorRegistry().put("OUTGOING_COLOR", inverted); //$NON-NLS-1$
        instancePrefs.put("INCOMING_COLOR", StringConverter.asString(inverted)); //$NON-NLS-1$
        instancePrefs.put("OUTGOING_COLOR", StringConverter.asString(inverted)); //$NON-NLS-1$
    } else {//w  ww.  ja v a 2  s  .co  m
        // Revert to defaults if we have them
        IEclipsePreferences defPrefs = EclipseUtil.defaultScope().getNode(nodeName);
        String value = defPrefs.get("OUTGOING_COLOR", null); //$NON-NLS-1$
        if (value != null) {
            try {
                RGB rgb = StringConverter.asRGB(value);
                if (rgb != null) {
                    JFaceResources.getColorRegistry().put("OUTGOING_COLOR", rgb); //$NON-NLS-1$
                }
            } catch (DataFormatException e) {
                // ignore
            }
        }
        value = defPrefs.get("INCOMING_COLOR", null); //$NON-NLS-1$
        if (value != null) {
            try {
                RGB rgb = StringConverter.asRGB(value);
                if (rgb != null) {
                    JFaceResources.getColorRegistry().put("INCOMING_COLOR", rgb); //$NON-NLS-1$
                }
            } catch (DataFormatException e) {
                // ignore
            }
        }

        // Now remove the instance prefs
        instancePrefs.remove("INCOMING_COLOR"); //$NON-NLS-1$
        instancePrefs.remove("OUTGOING_COLOR"); //$NON-NLS-1$
    }

    try {
        instancePrefs.flush();
    } catch (BackingStoreException e) {
        IdeLog.logError(ThemePlugin.getDefault(), e);
    }
}

From source file:com.axmor.eclipse.typescript.editor.parser.TypeScriptSyntaxScanner.java

License:Open Source License

private void adaptToColorChange(PropertyChangeEvent event, Token token) {
    RGB rgb = null;//w w w  .  j ava 2s  .co  m

    Object value = event.getNewValue();
    if (value instanceof RGB) {
        rgb = (RGB) value;
    } else if (value instanceof String && !((String) value).isEmpty()) {
        rgb = StringConverter.asRGB((String) value);
    }

    if (rgb != null) {
        TextAttribute attr = (TextAttribute) token.getData();
        token.setData(new TextAttribute(ColorManager.getDefault().getColor(rgb), attr.getBackground(),
                attr.getStyle()));
    }
}

From source file:com.boothen.jsonedit.text.JsonConstantWordScanner.java

License:Open Source License

private Color getPreferenceColor(String preferenceValue) {
    return jsonColorProvider.getColor(
            StringConverter.asRGB(JsonPreferenceStore.getIPreferenceStore().getString(preferenceValue)));
}

From source file:com.byterefinery.rmbench.extension.TableThemeExtension.java

License:Open Source License

private RGB parseColor(String rgbString) {
    try {/*  ww w .j  a  v  a2  s  .c  om*/
        return StringConverter.asRGB(rgbString);
    } catch (Exception x) {
        RMBenchPlugin.logError("could not parse RGB value " + rgbString);
        return null;
    }
}

From source file:com.cisco.yangide.editor.editors.AbstractYangScanner.java

License:Open Source License

private void adaptToColorChange(Token token, PropertyChangeEvent event) {
    RGB rgb = null;/*from   w w  w  .j  av  a  2s . com*/

    Object value = event.getNewValue();
    if (value instanceof RGB)
        rgb = (RGB) value;
    else if (value instanceof String)
        rgb = StringConverter.asRGB((String) value);

    if (rgb != null) {

        String property = event.getProperty();
        Color color = fColorManager.getColor(property);

        if ((color == null || !rgb.equals(color.getRGB())) && fColorManager instanceof IColorManagerExtension) {
            IColorManagerExtension ext = (IColorManagerExtension) fColorManager;

            ext.unbindColor(property);
            ext.bindColor(property, rgb);

            color = fColorManager.getColor(property);
        }

        Object data = token.getData();
        if (data instanceof TextAttribute) {
            TextAttribute oldAttr = (TextAttribute) data;
            token.setData(new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle()));
        }
    }
}