Example usage for org.eclipse.jface.resource ColorRegistry get

List of usage examples for org.eclipse.jface.resource ColorRegistry get

Introduction

In this page you can find the example usage for org.eclipse.jface.resource ColorRegistry get.

Prototype

public Color get(String symbolicName) 

Source Link

Document

Returns the color associated with the given symbolic color name, or null if no such definition exists.

Usage

From source file:asia.sejong.freedrawing.draw2d.figures.SquareButton.java

License:Apache License

protected Color getSavedColor(int r, int g, int b) {
    String colorString = "SB_DEFAULT:" + r + "-" + g + "-" + b;
    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
    if (!colorRegistry.hasValueFor(colorString)) {
        colorRegistry.put(colorString, new RGB(r, g, b));
    }/*  w w  w  .  ja  v  a2s .  c  o m*/
    return colorRegistry.get(colorString);
}

From source file:ccw.CCWPlugin.java

License:Open Source License

/** 
 * Not thread safe, but should only be called from the UI Thread, so it's
 * not really a problem./*from w  ww .  j  a v a  2  s .  c  o  m*/
 * @param rgb
 * @return The <code>Color</code> instance cached for this rgb value, creating
 *         it along the way if required.
 */
public static Color getColor(RGB rgb) {
    ColorRegistry r = getDefault().getColorCache();
    String rgbString = StringConverter.asString(rgb);
    if (!r.hasValueFor(rgbString)) {
        r.put(rgbString, rgb);
    }
    return r.get(rgbString);
}

From source file:com.abstratt.mdd.internal.ui.editors.source.SyntaxHighlighter.java

License:Open Source License

protected void initialize(String[] keywords) {
    ColorRegistry registry = JFaceResources.getColorRegistry();

    IToken keyword = new Token(new TextAttribute(registry.get(KEYWORD_COLOR), null, SWT.BOLD));
    IToken string = new Token(new TextAttribute(registry.get(STRING_COLOR)));
    IToken number = new Token(new TextAttribute(registry.get(NUMBER_COLOR)));
    IToken annotation = new Token(new TextAttribute(registry.get(ANNOTATION_COLOR)));
    IToken defaultToken = new Token(new TextAttribute(registry.get(DEFAULT_COLOR)));

    List<IRule> rules = new ArrayList<IRule>();

    // strings//from   w  ww .j a  va2 s. co m
    rules.add(new SingleLineRule("\"", "\"", string, '\\'));

    // annotations
    rules.add(new MultiLineRule("[", "]", annotation));

    // numbers
    rules.add(new NumberRule(number));

    // keywords and normal (default) text
    WordRule wordRule = new WordRule(new WordDetector(), defaultToken);
    for (int i = 0; i < keywords.length; i++) {
        wordRule.addWord(keywords[i], keyword);
    }
    rules.add(wordRule);

    setRules(rules.toArray(new IRule[rules.size()]));
}

From source file:com.aptana.ide.editor.css.contentassist.CSSContextInformationValidator.java

License:Open Source License

/**
 * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int,
 *      org.eclipse.jface.text.TextPresentation)
 *//*from   w w w  .j av  a2  s.c  o  m*/
public boolean updatePresentation(int offset, TextPresentation presentation) {
    try {
        String s = this.fContextInformation.getInformationDisplayString();
        if (s.indexOf(COLON) == -1) {
            return false;
        }

        int colonPos = s.indexOf(COLON);

        RGB blackColor = new RGB(0, 0, 0);
        ColorRegistry cm = JFaceResources.getColorRegistry();
        cm.put(BLACK_COLOR, blackColor);
        Color norm = cm.get(BLACK_COLOR); // make this settable

        StyleRange st = new StyleRange(0, colonPos, norm, null, SWT.BOLD);

        presentation.clear();
        presentation.addStyleRange(st);

        return true;
    } catch (Exception e) {
        IdeLog.logError(UnifiedEditorsPlugin.getDefault(),
                Messages.CSSContextInformationValidator_ErrorUpdatingContextInformation, e);
        return true;
    }
}

From source file:com.aptana.ide.editor.js.contentassist.JSContextInformationValidator.java

License:Open Source License

/**
 * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, org.eclipse.jface.text.TextPresentation)
 *///ww w .  ja v a 2 s  .  c  o m
public boolean updatePresentation(int offset, TextPresentation presentation) {
    try {
        String s = this.fContextInformation.getInformationDisplayString();

        int arg = fProcessor.getJSOffsetMapper().getArgIndexAndCalculateMode();

        if (s.indexOf("(") == -1) //$NON-NLS-1$
        {
            return false;
        }

        presentation.clear();

        String[] lines = s.split(ScriptDocHelper.DEFAULT_DELIMITER);
        s = lines[0]; // only look at first line

        // If open/close parens, then no params
        if (s.indexOf("()") > 0) //$NON-NLS-1$
        {
            return false;
        }

        // arg text always starts with brace
        int count = 0;
        int startPos = s.indexOf("("); //$NON-NLS-1$
        int endPos = s.indexOf(","); //$NON-NLS-1$

        // Single parameter case
        if (endPos == -1) {
            endPos = s.indexOf(")"); // arg text always ends with ")" //$NON-NLS-1$
        }

        RGB blackColor = new RGB(0, 0, 0);

        ColorRegistry cm = JFaceResources.getColorRegistry();
        cm.put("black", blackColor); //$NON-NLS-1$
        Color norm = cm.get("black"); // make this settable //$NON-NLS-1$

        StyleRange st = new StyleRange(0, startPos, norm, null, SWT.BOLD);
        presentation.addStyleRange(st);

        while (count < arg) {
            startPos = endPos;
            endPos = s.indexOf(",", startPos + 1); //$NON-NLS-1$

            if (endPos == -1) {
                endPos = s.indexOf(")", startPos); //$NON-NLS-1$
            }

            if (endPos == -1) {
                break;
            }

            count++;
        }

        // + 1 accounts for the leading "("
        startPos += 1;
        st = new StyleRange(startPos, endPos - startPos, norm, null, SWT.BOLD);
        presentation.addStyleRange(st);

        int delimiterLength = ScriptDocHelper.DEFAULT_DELIMITER.length();
        // bold the arg comment names
        if (lines.length > 1) {
            int totalLen = lines[0].length() + delimiterLength; // 1 crlf
            for (int i = 1; i < lines.length; i++) {
                String line = lines[i];
                StyleRange argNameStyle = null;

                if (arg + 1 == i) {
                    argNameStyle = new StyleRange(totalLen, line.length(), norm, null, SWT.BOLD);
                } else {
                    argNameStyle = new StyleRange(totalLen, line.indexOf(":"), norm, null, SWT.NORMAL); //$NON-NLS-1$
                }
                presentation.addStyleRange(argNameStyle);
                totalLen += line.length() + delimiterLength; // 1 crlf            
            }
        }

        return true;
    } catch (Exception e) {
        IdeLog.logError(UnifiedEditorsPlugin.getDefault(),
                Messages.JSContextInformationValidator_ErrorUpdatingCOntext, e);
        return true;
    }
}

From source file:com.aptana.ide.editors.unified.utils.HTML2TextReader.java

License:Open Source License

/**
 * Transforms the HTML text from the reader to formatted text.
 * /*from  www  .ja  va 2 s  . c o  m*/
 * @param reader the reader
 * @param presentation If not <code>null</code>, formattings will be applied to
 * the presentation.
 * @param display 
*/
public HTML2TextReader(Reader reader, TextPresentation presentation, Display display) {
    super(new PushbackReader(reader));
    fTextPresentation = presentation;

    RGB blackColor = new RGB(0, 0, 0);
    RGB linkColor = new RGB(93, 117, 215);
    RGB preColor = new RGB(204, 153, 51);

    ColorRegistry cm = JFaceResources.getColorRegistry();
    cm.put("black", blackColor); //$NON-NLS-1$
    cm.put("link", linkColor); //$NON-NLS-1$
    cm.put("pre", preColor); //$NON-NLS-1$

    fLinkColor = cm.get("link"); //$NON-NLS-1$
    fPreColor = cm.get("pre"); //$NON-NLS-1$
}

From source file:com.archimatetool.editor.ui.ColorFactory.java

License:Open Source License

public static Color get(String rgbValue) {
    if (rgbValue == null) {
        return null;
    }/*from  w  w w. j a  v  a 2 s . c o  m*/

    if (!ColorRegistry.hasValueFor(rgbValue)) {
        RGB rgb = convertStringToRGB(rgbValue);
        if (rgb != null) {
            ColorRegistry.put(rgbValue, rgb);
        }
    }

    return ColorRegistry.get(rgbValue);
}

From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.VulnerabilityDetailsPage.java

License:Open Source License

private CTabFolder createTabFolder(Composite parent) {
    CTabFolder folder = new CTabFolder(parent, SWT.NO_REDRAW_RESIZE | SWT.FLAT);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    folder.setLayoutData(gd);/*w  w w .j a v  a 2  s.  c  o m*/
    ColorRegistry reg = JFaceResources.getColorRegistry();
    Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"),
            c2 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END");
    folder.setSelectionBackground(new Color[] { c1, c2 }, new int[] { 100 }, true);
    folder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR"));
    folder.setSimple(PlatformUI.getPreferenceStore()
            .getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS));
    folder.setBorderVisible(true);
    folder.setFont(parent.getFont());
    return folder;
}

From source file:com.google.appraise.eclipse.ui.editor.DiffAttributeEditor.java

License:Open Source License

/**
 * Starts a new {@link StyleRange} given a specific line type.
 *///from   w w  w. j  a  v a2 s.  com
private StyleRange initDiffStyleRangeForLineType(DiffLineType lineType, int startTextOffset) {
    ColorRegistry reg = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
    StyleRange range = new StyleRange();
    range.start = startTextOffset;
    switch (lineType) {
    case ADD:
        range.foreground = reg.get(THEME_DiffAddForegroundColor);
        range.background = reg.get(THEME_DiffAddBackgroundColor);
        break;
    case REMOVE:
        range.foreground = reg.get(THEME_DiffRemoveForegroundColor);
        range.background = reg.get(THEME_DiffRemoveBackgroundColor);
        break;
    case HUNK:
        range.foreground = reg.get(THEME_DiffHunkForegroundColor);
        range.background = reg.get(THEME_DiffHunkBackgroundColor);
        break;
    case HEADLINE:
        range.foreground = reg.get(THEME_DiffHeadlineForegroundColor);
        range.background = reg.get(THEME_DiffHeadlineBackgroundColor);
        FontRegistry fontReg = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
        range.font = fontReg.get(THEME_DiffHeadlineFont);
        break;
    default:
        break;
    }
    return range;
}

From source file:com.google.eclipse.elt.emulator.textcanvas.StyleMap.java

License:Open Source License

private Color getColor(RGB colorData) {
    String name = PREFIX + colorData.red + "-" + colorData.green + "-" + colorData.blue;
    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
    Color color = colorRegistry.get(name);
    if (color == null) {
        colorRegistry.put(name, colorData);
        color = colorRegistry.get(name);
    }/*from  ww  w  . j a va 2 s. c  o m*/
    return color;
}