Example usage for org.eclipse.jface.resource JFaceResources getColorRegistry

List of usage examples for org.eclipse.jface.resource JFaceResources getColorRegistry

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getColorRegistry.

Prototype

public static ColorRegistry getColorRegistry() 

Source Link

Document

Returns the color registry for JFace itself.

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));
    }//from   w  ww .  ja v  a 2s .c  o  m
    return colorRegistry.get(colorString);
}

From source file:at.bestsolution.code.swt.services.internal.ThemeTextAttributeFactory.java

License:Open Source License

@Override
public TextAttribute getAttribute(String language, String tokenName) {
    if (currentTheme != null) {
        RGB rgb = currentTheme.getColor(language + "." + tokenName);
        if (rgb != null) {
            Color c = JFaceResources.getColorRegistry().get(rgb.toString());
            if (c == null) {
                JFaceResources.getColorRegistry().put(rgb.toString(), rgb);
                c = JFaceResources.getColorRegistry().get(rgb.toString());
            }//  w  w  w. jav  a2  s.  co  m
            int style = SWT.NORMAL;

            if (currentTheme.boldFont(language + "." + tokenName)) {
                style |= SWT.BOLD;
            }
            if (currentTheme.italicFont(language + "." + tokenName)) {
                style |= SWT.ITALIC;
            }

            return new TextAttribute(c, null, style);
        }
    }
    return new TextAttribute(null);
}

From source file:bndtools.utils.MessagesPopupDialog.java

License:Open Source License

@SuppressWarnings("unused")
@Override// ww w . j av  a  2  s  .  c o m
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new GridLayout(1, false));

    for (int i = 0; i < messages.length; i++) {
        if (i > 0) {
            Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
            separator.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1));
        }

        // Message Type Image Label
        Composite pnlTitle = new Composite(composite, SWT.NONE);
        pnlTitle.setLayout(new GridLayout(2, false));
        Label lblImage = new Label(pnlTitle, SWT.NONE);
        lblImage.setImage(getMessageImage(messages[i].getMessageType()));

        // Message Label
        StringBuilder builder = new StringBuilder();
        if (messages[i].getPrefix() != null) {
            builder.append(messages[i].getPrefix());
        }
        builder.append(messages[i].getMessage());
        Label lblText = new Label(pnlTitle, SWT.WRAP);
        lblText.setText(builder.toString());
        lblText.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DIALOG_FONT));
        lblText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        // Fix actions, if present
        Object data = messages[i].getData();
        IAction[] fixes;
        if (data instanceof IAction) {
            fixes = new IAction[] { (IAction) data };
        } else if (data instanceof IAction[]) {
            fixes = (IAction[]) data;
        } else {
            fixes = null;
        }

        if (fixes != null) {
            // new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
            Composite pnlFixes = new Composite(composite, SWT.NONE);
            pnlFixes.setLayout(new GridLayout(3, false));

            Label lblFixes = new Label(pnlFixes, SWT.NONE);
            lblFixes.setText("Available Fixes:");
            lblFixes.setForeground(JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR));

            for (int j = 0; j < fixes.length; j++) {
                if (j > 0)
                    new Label(pnlFixes, SWT.NONE); // Spacer

                new Label(pnlFixes, SWT.NONE).setImage(bulletImg);

                final IAction fix = fixes[j];
                Hyperlink fixLink = new Hyperlink(pnlFixes, SWT.NONE);
                hyperlinkGroup.add(fixLink);
                fixLink.setText(fix.getText());
                fixLink.setHref(fix);
                fixLink.addHyperlinkListener(new HyperlinkAdapter() {
                    @Override
                    public void linkActivated(HyperlinkEvent e) {
                        fix.run();
                        close();
                        // part.getSite().getPage().activate(part);
                        part.setFocus();
                    }
                });
                fixLink.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
            }
        }
    }

    return composite;
}

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 w  w.j a  v  a2  s .c  om*/
    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.abstratt.mdd.internal.ui.editors.source.SyntaxHighlighter.java

License:Open Source License

ITokenScanner getCommentScanner() {
    // lazy init/*from ww  w.j  ava2s .  c  om*/
    if (this.commentScanner == null) {
        final Token comment = new Token(
                new TextAttribute(JFaceResources.getColorRegistry().get(COMMENT_COLOR)));
        // no rules needed, because this will apply to comment partition only
        final RuleBasedScanner ruleBasedScanner = new RuleBasedScanner();
        // this will apply the syntax
        ruleBasedScanner.setDefaultReturnToken(comment);
        this.commentScanner = ruleBasedScanner;
    }
    return commentScanner;
}

From source file:com.agynamix.platform.frontend.gui.ApplicationStatusLineManager.java

License:Open Source License

public ApplicationStatusLineManager() {
    ColorRegistry cr = JFaceResources.getColorRegistry();
    cr.put(JFacePreferences.ERROR_COLOR, new RGB(205, 2, 4)); // schoen rot
}

From source file:com.aptana.editor.common.contentassist.CompletionProposalPopup.java

License:Open Source License

/**
 * Returns the background color to use./*from w  ww. jav  a2s  . com*/
 * 
 * @param control
 *            the control to get the display from
 * @return the background color
 * @since 3.2
 */
private Color getBackgroundColor(Control control) {
    Color c = fContentAssistant.getProposalSelectorBackground();
    if (c == null)
        c = JFaceResources.getColorRegistry().get(JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR);
    return c;
}

From source file:com.aptana.editor.common.contentassist.CompletionProposalPopup.java

License:Open Source License

/**
 * Returns the foreground color to use.//from  w  w  w  .  java  2s. c  o m
 * 
 * @param control
 *            the control to get the display from
 * @return the foreground color
 * @since 3.2
 */
private Color getForegroundColor(Control control) {
    Color c = fContentAssistant.getProposalSelectorForeground();
    if (c == null)
        c = JFaceResources.getColorRegistry().get(JFacePreferences.CONTENT_ASSIST_FOREGROUND_COLOR);
    return c;
}

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)
 */// w  w w  .j a v  a  2  s .co  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)
 *//*from  w  w  w. j  a v a2 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;
    }
}