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:org.eclipse.nebula.widgets.pagination.Resources.java

License:Open Source License

/**
 * Create or get instance of SWT {@link Color} from the given {@link RGB}.
 * //from   w w w  . j  a v  a  2  s  .  c  o  m
 * @param rgb
 * @return
 */
public static Color getColor(RGB rgb) {
    String key = rgb.toString();
    Color color = JFaceResources.getColorRegistry().get(key);
    if (color == null) {
        JFaceResources.getColorRegistry().put(key, rgb);
    }
    return JFaceResources.getColorRegistry().get(key);
}

From source file:org.eclipse.nebula.widgets.richtext.painter.ResourceHelper.java

License:Open Source License

public static Color getColor(String rgbString) {
    if (!JFaceResources.getColorRegistry().hasValueFor(rgbString)) {
        // rgb string in format rgb(r, g, b)
        String rgbValues = rgbString.substring(rgbString.indexOf('(') + 1, rgbString.lastIndexOf(')'));
        String[] values = rgbValues.split(",");
        try {//from  w  ww  .j  a va 2 s .  co m
            int red = Integer.valueOf(values[0].trim());
            int green = Integer.valueOf(values[1].trim());
            int blue = Integer.valueOf(values[2].trim());

            JFaceResources.getColorRegistry().put(rgbString, new RGB(red, green, blue));
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }
    return JFaceResources.getColorRegistry().get(rgbString);
}

From source file:org.eclipse.php.internal.ui.compare.TextMergeViewer.java

License:Open Source License

/**
 * Creates a text merge viewer under the given parent control.
 * /*from w  ww  . j a va 2  s  .  co  m*/
 * @param parent
 *            the parent control
 * @param style
 *            SWT style bits for top level composite of this viewer
 * @param configuration
 *            the configuration object
 */
public TextMergeViewer(Composite parent, int style, CompareConfiguration configuration) {
    super(style, ResourceBundle.getBundle(BUNDLE_NAME), configuration);

    fMerger = new DocumentMerger(new IDocumentMergerInput() {
        public ITokenComparator createTokenComparator(String line) {
            return TextMergeViewer.this.createTokenComparator(line);
        }

        public CompareConfiguration getCompareConfiguration() {
            return TextMergeViewer.this.getCompareConfiguration();
        }

        public IDocument getDocument(char contributor) {
            switch (contributor) {
            case LEFT_CONTRIBUTOR:
                return fLeft.getDocument();
            case RIGHT_CONTRIBUTOR:
                return fRight.getDocument();
            case ANCESTOR_CONTRIBUTOR:
                return fAncestor.getDocument();
            }
            return null;
        }

        public int getHunkStart() {
            return TextMergeViewer.this.getHunkStart();
        }

        public Position getRegion(char contributor) {
            switch (contributor) {
            case LEFT_CONTRIBUTOR:
                return fLeft.getRegion();
            case RIGHT_CONTRIBUTOR:
                return fRight.getRegion();
            case ANCESTOR_CONTRIBUTOR:
                return fAncestor.getRegion();
            }
            return null;
        }

        public boolean isHunkOnLeft() {
            ITypedElement left = ((ICompareInput) getInput()).getRight();
            return left != null && Utilities.getAdapter(left, IHunk.class) != null;
        }

        public boolean isIgnoreAncestor() {
            return TextMergeViewer.this.isIgnoreAncestor();
        }

        public boolean isPatchHunk() {
            return TextMergeViewer.this.isPatchHunk();
        }

        public boolean isShowPseudoConflicts() {
            return fShowPseudoConflicts;
        }

        public boolean isThreeWay() {
            return TextMergeViewer.this.isThreeWay();
        }

        public boolean isPatchHunkOk() {
            return TextMergeViewer.this.isPatchHunkOk();
        }

    });

    int inheritedStyle = parent.getStyle();
    if ((inheritedStyle & SWT.LEFT_TO_RIGHT) != 0)
        fInheritedDirection = SWT.LEFT_TO_RIGHT;
    else if ((inheritedStyle & SWT.RIGHT_TO_LEFT) != 0)
        fInheritedDirection = SWT.RIGHT_TO_LEFT;
    else
        fInheritedDirection = SWT.NONE;

    if ((style & SWT.LEFT_TO_RIGHT) != 0)
        fTextDirection = SWT.LEFT_TO_RIGHT;
    else if ((style & SWT.RIGHT_TO_LEFT) != 0)
        fTextDirection = SWT.RIGHT_TO_LEFT;
    else
        fTextDirection = SWT.NONE;

    fSymbolicFontName = getClass().getName();

    String platform = SWT.getPlatform();
    fIsMotif = "motif".equals(platform); //$NON-NLS-1$
    fIsCarbon = "carbon".equals(platform); //$NON-NLS-1$

    if (fIsMotif)
        fMarginWidth = 0;

    Display display = parent.getDisplay();

    fPreferenceChangeListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            TextMergeViewer.this.handlePropertyChangeEvent(event);
        }
    };

    fPreferenceStore = createChainedPreferenceStore();
    if (fPreferenceStore != null) {
        fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);

        checkForColorUpdate(display);

        fLeftIsLocal = Utilities.getBoolean(getCompareConfiguration(), "LEFT_IS_LOCAL", false); //$NON-NLS-1$
        fSynchronizedScrolling = fPreferenceStore.getBoolean(ComparePreferencePage.SYNCHRONIZE_SCROLLING);
        fShowPseudoConflicts = fPreferenceStore.getBoolean(ComparePreferencePage.SHOW_PSEUDO_CONFLICTS);
        // fUseSplines=
        // fPreferenceStore.getBoolean(ComparePreferencePage.USE_SPLINES);
        fUseSingleLine = fPreferenceStore.getBoolean(ComparePreferencePage.USE_SINGLE_LINE);
        fHighlightTokenChanges = fPreferenceStore.getBoolean(ComparePreferencePage.HIGHLIGHT_TOKEN_CHANGES);
        // fUseResolveUI=
        // fPreferenceStore.getBoolean(ComparePreferencePage.USE_RESOLVE_UI);
    }

    buildControl(parent);

    INavigatable nav = new INavigatable() {
        public boolean selectChange(int flag) {
            if (flag == INavigatable.FIRST_CHANGE || flag == INavigatable.LAST_CHANGE) {
                selectFirstDiff(flag == INavigatable.FIRST_CHANGE);
                return false;
            }
            return navigate(flag == INavigatable.NEXT_CHANGE, false, false);
        }

        public Object getInput() {
            return TextMergeViewer.this.getInput();
        }

        public boolean openSelectedChange() {
            return false;
        }

        public boolean hasChange(int flag) {
            return getNextVisibleDiff(flag == INavigatable.NEXT_CHANGE, false) != null;
        }
    };
    fComposite.setData(INavigatable.NAVIGATOR_PROPERTY, nav);

    fBirdsEyeCursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);

    JFaceResources.getFontRegistry().addListener(fPreferenceChangeListener);
    JFaceResources.getColorRegistry().addListener(fPreferenceChangeListener);
    updateFont();
}

From source file:org.eclipse.php.internal.ui.compare.TextMergeViewer.java

License:Open Source License

private void updateColors(Display display) {

    if (display == null)
        display = fComposite.getDisplay();

    Color color = null;// ww w  .ja v  a2  s. c om
    if (fBackground != null)
        color = getColor(display, fBackground);

    if (fAncestor != null)
        fAncestor.setBackgroundColor(color);
    if (fLeft != null)
        fLeft.setBackgroundColor(color);
    if (fRight != null)
        fRight.setBackgroundColor(color);

    ColorRegistry registry = JFaceResources.getColorRegistry();

    RGB bg = getBackground(display);
    SELECTED_INCOMING = registry.getRGB(INCOMING_COLOR);
    if (SELECTED_INCOMING == null)
        SELECTED_INCOMING = new RGB(0, 0, 255); // BLUE
    INCOMING = interpolate(SELECTED_INCOMING, bg, 0.6);
    INCOMING_FILL = interpolate(SELECTED_INCOMING, bg, 0.97);
    INCOMING_TEXT_FILL = interpolate(SELECTED_INCOMING, bg, 0.85);

    SELECTED_OUTGOING = registry.getRGB(OUTGOING_COLOR);
    if (SELECTED_OUTGOING == null)
        SELECTED_OUTGOING = new RGB(0, 0, 0); // BLACK
    OUTGOING = interpolate(SELECTED_OUTGOING, bg, 0.6);
    OUTGOING_FILL = interpolate(SELECTED_OUTGOING, bg, 0.97);
    OUTGOING_TEXT_FILL = interpolate(SELECTED_OUTGOING, bg, 0.85);

    SELECTED_CONFLICT = registry.getRGB(CONFLICTING_COLOR);
    if (SELECTED_CONFLICT == null)
        SELECTED_CONFLICT = new RGB(255, 0, 0); // RED
    CONFLICT = interpolate(SELECTED_CONFLICT, bg, 0.6);
    CONFLICT_FILL = interpolate(SELECTED_CONFLICT, bg, 0.97);
    CONFLICT_TEXT_FILL = interpolate(SELECTED_CONFLICT, bg, 0.85);

    RESOLVED = registry.getRGB(RESOLVED_COLOR);
    if (RESOLVED == null)
        RESOLVED = new RGB(0, 255, 0); // GREEN

    updatePresentation(display);
}

From source file:org.eclipse.php.internal.ui.compare.TextMergeViewer.java

License:Open Source License

/**
 * Called on the viewer disposal. Unregisters from the compare
 * configuration. Clients may extend if they have to do additional cleanup.
 * /*from   w w w.  ja va2  s .  c om*/
 * @param event
 */
protected void handleDispose(DisposeEvent event) {

    if (fHandlerService != null)
        fHandlerService.dispose();

    Object input = getInput();
    removeFromDocumentManager(ANCESTOR_CONTRIBUTOR, input);
    removeFromDocumentManager(LEFT_CONTRIBUTOR, input);
    removeFromDocumentManager(RIGHT_CONTRIBUTOR, input);

    if (DEBUG)
        DocumentManager.dump();

    if (fPreferenceChangeListener != null) {
        JFaceResources.getFontRegistry().removeListener(fPreferenceChangeListener);
        JFaceResources.getColorRegistry().removeListener(fPreferenceChangeListener);
        if (fPreferenceStore != null)
            fPreferenceStore.removePropertyChangeListener(fPreferenceChangeListener);
        fPreferenceChangeListener = null;
    }

    fLeftCanvas = null;
    fRightCanvas = null;
    fVScrollBar = null;
    fBirdsEyeCanvas = null;
    fSummaryHeader = null;

    fAncestorContributor.unsetDocument(fAncestor);
    fLeftContributor.unsetDocument(fLeft);
    fRightContributor.unsetDocument(fRight);

    disconnect(fLeftContributor);
    disconnect(fRightContributor);
    disconnect(fAncestorContributor);

    if (fColors != null) {
        Iterator i = fColors.values().iterator();
        while (i.hasNext()) {
            Color color = (Color) i.next();
            if (!color.isDisposed())
                color.dispose();
        }
        fColors = null;
    }

    if (fBirdsEyeCursor != null) {
        fBirdsEyeCursor.dispose();
        fBirdsEyeCursor = null;
    }

    if (showWhitespaceAction != null)
        showWhitespaceAction.dispose();

    if (toggleLineNumbersAction != null)
        toggleLineNumbersAction.dispose();

    if (fIgnoreWhitespace != null)
        fIgnoreWhitespace.dispose();

    super.handleDispose(event);
}

From source file:org.eclipse.reddeer.jface.test.viewer.PrepareTreeWithStyledItems.java

License:Open Source License

@Before
public void setUp() {
    org.eclipse.reddeer.common.util.Display.syncExec(new Runnable() {
        @Override/*w ww  .j ava  2 s .c om*/
        public void run() {
            JFaceResources.getColorRegistry().put(JFacePreferences.COUNTER_COLOR, new RGB(0, 127, 174));

            Shell shell = new Shell(Display.getDefault(), SWT.CLOSE | SWT.RESIZE);
            shell.setText(title);
            shell.setSize(400, 450);
            shell.setLayout(new GridLayout(1, true));

            Composite composite = createPartControl(shell);
            composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

            shell.open();
        }
    });
}

From source file:org.eclipse.scada.core.ui.styles.ColorUpdater.java

License:Open Source License

public ColorUpdater(final String name, final ResourceManager manager, final ColorDescriptor defaultColor) {
    this.name = name;
    this.manager = manager;
    this.defaultColor = defaultColor;
    JFaceResources.getColorRegistry().addListener(this);
    refresh();//from ww w  . ja v a  2 s  . co  m
}

From source file:org.eclipse.scada.core.ui.styles.ColorUpdater.java

License:Open Source License

public void dispose() {
    JFaceResources.getColorRegistry().removeListener(this);
}

From source file:org.eclipse.scada.core.ui.styles.ColorUpdater.java

License:Open Source License

private void refresh() {
    if (this.color != null) {
        // we may not dispose, the manager has to do that
        this.color = null;
    }//w ww.  j  av  a2  s.com
    if (this.activeColor != null) {
        this.manager.destroyColor(this.activeColor);
        this.activeColor = null;
    }

    this.activeColor = JFaceResources.getColorRegistry().getColorDescriptor(this.name, this.defaultColor);
    if (this.activeColor != null) {
        this.color = this.manager.createColor(this.activeColor);
    }
}

From source file:org.eclipse.scada.core.ui.styles.generator.SimpleRuleStyleGenerator.java

License:Open Source License

public SimpleRuleStyleGenerator() {
    this.resourceManager = new LocalResourceManager(JFaceResources.getResources());

    this.colorBgDisconnected = new ColorUpdater("org.eclipse.scada.core.ui.styles.alarming.disconnected.bg", //$NON-NLS-1$
            this.resourceManager, COLOR_DISCONNECTED_BG);
    this.colorBgError = new ColorUpdater("org.eclipse.scada.core.ui.styles.alarming.error.bg", //$NON-NLS-1$
            this.resourceManager, COLOR_ERROR_BG);
    this.colorBgAlarm = new ColorUpdater("org.eclipse.scada.core.ui.styles.alarming.alarm.bg", //$NON-NLS-1$
            this.resourceManager, COLOR_ALARM_BG);
    this.colorBgWarning = new ColorUpdater("org.eclipse.scada.core.ui.styles.alarming.warning.bg", //$NON-NLS-1$
            this.resourceManager, COLOR_WARNING_BG);
    this.colorBgManual = new ColorUpdater("org.eclipse.scada.core.ui.styles.alarming.manual.bg", //$NON-NLS-1$
            this.resourceManager, COLOR_MANUAL_BG);
    this.colorBgBlock = new ColorUpdater("org.eclipse.scada.core.ui.styles.alarming.block.bg", //$NON-NLS-1$
            this.resourceManager, COLOR_BLOCK_BG);

    this.colorFgBlock = new ColorUpdater("org.eclipse.scada.core.ui.styles.alarming.block.fg", //$NON-NLS-1$
            this.resourceManager, COLOR_BLOCK_FG);

    JFaceResources.getColorRegistry().addListener(this.listener);
}