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: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);
    }//ww  w  .java2s.  co  m
    return color;
}

From source file:com.google.gdt.eclipse.core.ui.controls.DemoSelectableControlList.java

License:Open Source License

private static Color getRegisteredColor(String name, int r, int g, int b) {
    if (_COLOR_REGISTRY == null) {
        _COLOR_REGISTRY = JFaceResources.getColorRegistry();
    }/*from www.  ja v a  2s . c  om*/
    if (!_COLOR_REGISTRY.hasValueFor(name)) {
        _COLOR_REGISTRY.put(name, new RGB(r, g, b));
    }
    return _COLOR_REGISTRY.get(name);
}

From source file:com.imperial.fiksen.codesimilarity.compare.ParseTreeMergeViewer.java

License:Open Source License

/**
 * Creates a text merge viewer under the given parent control.
 * //from  w  ww.j  av a  2s  .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 ParseTreeMergeViewer(Composite parent, int style, CompareConfiguration configuration) {
    super(style, ResourceBundle.getBundle(BUNDLE_NAME), configuration);

    operationHistoryListener = new IOperationHistoryListener() {
        public void historyNotification(OperationHistoryEvent event) {
            ParseTreeMergeViewer.this.historyNotification(event);
        }
    };
    OperationHistoryFactory.getOperationHistory().addOperationHistoryListener(operationHistoryListener);

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

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

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

        public int getHunkStart() {
            return ParseTreeMergeViewer.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 ParseTreeMergeViewer.this.isIgnoreAncestor();
        }

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

        public boolean isShowPseudoConflicts() {
            return fShowPseudoConflicts;
        }

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

        public boolean isPatchHunkOk() {
            return ParseTreeMergeViewer.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 = getSymbolicFontName();

    fIsMotif = Util.isMotif();
    fIsCarbon = Util.isCarbon();
    fIsMac = Util.isMac();

    if (fIsMotif)
        fMarginWidth = 0;

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

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

        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);

    setColors();

    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 ParseTreeMergeViewer.this.getInput();
        }

        public boolean openSelectedChange() {
            return false;
        }

        public boolean hasChange(int flag) {
            return getNextVisibleDiff(flag == INavigatable.NEXT_CHANGE, false) != null;
        }
    };
    getControl().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:com.imperial.fiksen.codesimilarity.compare.ParseTreeMergeViewer.java

License:Open Source License

private void updateColors(Display display) {

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

    Color bgColor = null;// w w  w  . j av  a2  s.co m
    if (fBackground != null)
        bgColor = getColor(display, fBackground);

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

    Color fgColor = null;
    if (fForeground != null)
        fgColor = getColor(display, fForeground);

    if (fAncestor != null)
        fAncestor.setForegroundColor(fgColor);
    if (fLeft != null)
        fLeft.setForegroundColor(fgColor);
    if (fRight != null)
        fRight.setForegroundColor(fgColor);

    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
    //INFO FIKSEN: OUTGOING is the highlight bar in th margin colour
    OUTGOING = new RGB(180, 180, 0);
    OUTGOING_FILL = new RGB(180, 180, 0);
    OUTGOING_TEXT_FILL = new RGB(180, 180, 0);

    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();
}

From source file:com.imperial.fiksen.codesimilarity.compare.ParseTreeMergeViewer.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.
 * //w ww . ja  va2  s.c om
 * @param event
 */
protected void handleDispose(DisposeEvent event) {
    OperationHistoryFactory.getOperationHistory().removeOperationHistoryListener(operationHistoryListener);

    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 (fBirdsEyeCursor != null) {
        fBirdsEyeCursor.dispose();
        fBirdsEyeCursor = null;
    }

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

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

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

    getCompareConfiguration().setProperty(ChangeCompareFilterPropertyAction.COMPARE_FILTERS_INITIALIZING,
            Boolean.TRUE);
    disposeCompareFilterActions(false);

    if (fSourceViewerDecorationSupport != null) {
        for (Iterator iterator = fSourceViewerDecorationSupport.iterator(); iterator.hasNext();) {
            ((SourceViewerDecorationSupport) iterator.next()).dispose();
        }
        fSourceViewerDecorationSupport = null;
    }

    if (fAncestor != null)
        fAncestor.dispose();
    fAncestor = null;
    if (fLeft != null)
        fLeft.dispose();
    fLeft = null;
    if (fRight != null)
        fRight.dispose();
    fRight = null;

    if (fColors != null) {
        Iterator i = fColors.values().iterator();
        while (i.hasNext()) {
            Color color = (Color) i.next();
            if (!color.isDisposed())
                color.dispose();
        }
        fColors = null;
    }
    // don't add anything here, disposing colors should be done last
    super.handleDispose(event);
}

From source file:com.intel.sgx.dialogs.EnclaveConfigDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    Composite container = (Composite) super.createDialogArea(parent);
    final GridLayout gridLayout = new GridLayout(3, false);
    container.setLayout(gridLayout);//from  w ww.  ja  v  a  2  s  .  c om

    final Group groupLabel1 = new Group(container, SWT.None);
    groupLabel1.setLayout(new GridLayout(3, false));
    GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
    innergrid1.horizontalSpan = 3;
    groupLabel1.setLayoutData(innergrid1);

    Label warningLabel = new Label(groupLabel1, SWT.BEGINNING | SWT.WRAP);
    warningLabel.setText("Note: Use this Menu to change the Enclave settings.");

    statusLabel = new Label(container, SWT.BEGINNING | SWT.WRAP);
    GridData statusGrid = new GridData(GridData.FILL_HORIZONTAL);
    statusGrid.horizontalSpan = 3;
    statusLabel.setLayoutData(statusGrid);
    statusLabel.setText("");
    statusLabel.setForeground(JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR));

    final Group groupLabel2 = new Group(container, SWT.None);
    groupLabel2.setLayout(new GridLayout(3, false));
    groupLabel2.setText("Modify the Enclave Settings here...");
    GridData innergrid = new GridData(GridData.FILL_HORIZONTAL);
    innergrid.horizontalSpan = 3;
    groupLabel2.setLayoutData(innergrid);

    final Label messageLabel0 = new Label(groupLabel2, SWT.NONE);
    messageLabel0.setText("Product ID:");
    messageLabel0.setLayoutData(new GridData(GridData.BEGINNING));

    prodID = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    gridData.widthHint = 400;
    prodID.setLayoutData(gridData);
    prodID.setText(enclaveConfig.prodId);
    prodID.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent modifyEvent) {
            statusLabel.setText("");
            enclaveConfig.prodId = prodID.getText();
        }
    });

    final Label messageLabel1 = new Label(groupLabel2, SWT.NONE);
    messageLabel1.setText("ISV SVN:");
    messageLabel1.setLayoutData(new GridData(GridData.BEGINNING));

    isvSvn = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
    isvSvn.setLayoutData(gridData);
    isvSvn.setText(enclaveConfig.isvSvn);
    isvSvn.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent modifyEvent) {
            statusLabel.setText("");
            enclaveConfig.isvSvn = isvSvn.getText();
        }
    });

    final Label messageLabel2 = new Label(groupLabel2, SWT.NONE);
    messageLabel2.setText("Thread Stack Size:");
    messageLabel2.setLayoutData(new GridData(GridData.BEGINNING));

    threadStackSize = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
    threadStackSize.setLayoutData(gridData);
    threadStackSize.setText(enclaveConfig.threadStackSize);
    threadStackSize.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent modifyEvent) {
            enclaveConfig.threadStackSize = threadStackSize.getText();
            if (!(threadStackSize.getText().matches("0x[0-9a-fA-F]{1,}000"))) {
                statusLabel.setText("Error: The Thread Stack Size value must be Page Aligned.");
            } else {
                if (!(enclaveConfig.globalHeapSize.matches("0x[0-9a-fA-F]{1,}000")))
                    statusLabel.setText("Error: The Global Heap Size value must be Page Aligned.");
                else
                    statusLabel.setText("");
            }
        }
    });

    final Label messageLabel3 = new Label(groupLabel2, SWT.NONE);
    messageLabel3.setText("Global Heap Size:");
    messageLabel3.setLayoutData(new GridData(GridData.BEGINNING));

    globalHeapSize = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
    globalHeapSize.setLayoutData(gridData);
    globalHeapSize.setText(enclaveConfig.globalHeapSize);
    globalHeapSize.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent modifyEvent) {
            enclaveConfig.globalHeapSize = globalHeapSize.getText();
            if (!(globalHeapSize.getText().matches("0x[0-9a-fA-F]{1,}000"))) {
                statusLabel.setText("Error: The Global Heap Size value must be Page Aligned.");
            } else {
                if (!(enclaveConfig.threadStackSize.matches("0x[0-9a-fA-F]{1,}000")))
                    statusLabel.setText("Error: The Thread Stack Size value must be Page Aligned.");
                else
                    statusLabel.setText("");

            }
        }
    });

    final Label messageLabel4 = new Label(groupLabel2, SWT.NONE);
    messageLabel4.setText("TCS Number:");
    messageLabel4.setLayoutData(new GridData(GridData.BEGINNING));

    tcsNum = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
    tcsNum.setLayoutData(gridData);
    tcsNum.setText(enclaveConfig.tcsNum);
    tcsNum.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent modifyEvent) {
            statusLabel.setText("");
            enclaveConfig.tcsNum = tcsNum.getText();
        }
    });

    final Label messageLabel5 = new Label(groupLabel2, SWT.NONE);
    messageLabel5.setText("TCS Policy:");
    messageLabel5.setLayoutData(new GridData(GridData.BEGINNING));

    final String[] items = { "Unbound", "Bound" };
    tcsPolicy = new Combo(groupLabel2, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
    tcsPolicy.setItems(items);
    String item = items[Integer.parseInt(enclaveConfig.tcsPolicy)];
    int index = tcsPolicy.indexOf(item);
    tcsPolicy.select(index < 0 ? 0 : index);
    tcsPolicy.setLayoutData(gridData);
    tcsPolicy.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            statusLabel.setText("");
            enclaveConfig.tcsPolicy = (tcsPolicy.getSelectionIndex() == 0 ? "0" : "1");
        }
    });

    final Label messageLabel6 = new Label(groupLabel2, SWT.NONE);
    messageLabel6.setText("Disable Debug:");
    messageLabel6.setLayoutData(new GridData(GridData.BEGINNING));

    disableDebug = new Button(groupLabel2, SWT.CHECK);
    GridData gridData1 = new GridData(GridData.FILL_HORIZONTAL);
    disableDebug.setLayoutData(gridData1);
    disableDebug.setSelection(enclaveConfig.disableDebug.equals("1") ? true : false);
    disableDebug.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            statusLabel.setText("");
            enclaveConfig.disableDebug = disableDebug.getSelection() ? "1" : "0";
        }
    });

    if (statusLabel.getText() != null) {
        statusLabel.setVisible(true);
    } else {
        statusLabel.setVisible(false);
    }

    return container;
}

From source file:com.mentor.nucleus.bp.model.compare.contentmergeviewer.ModelContentMergeViewer.java

License:Open Source License

public void updateColors() {
    ColorRegistry registry = JFaceResources.getColorRegistry();

    RGB bg = getBackground(PlatformUI.getWorkbench().getDisplay());

    INCOMING_BASE = registry.getRGB(INCOMING_COLOR);
    if (INCOMING_BASE == null) {
        INCOMING_BASE = new RGB(0, 0, 255);
        registry.put(INCOMING_COLOR, INCOMING_BASE);
    }//  w  w w.  j  ava2  s  .  c  o m
    INCOMING = interpolate(INCOMING_BASE, bg, 0.6);
    OUTGOING_BASE = registry.getRGB(OUTGOING_COLOR);
    if (OUTGOING_BASE == null) {
        OUTGOING_BASE = new RGB(0, 0, 0); // BLACK
        registry.put(OUTGOING_COLOR, OUTGOING_BASE);
    }
    OUTGOING = interpolate(OUTGOING_BASE, bg, 0.6);

    CONFLICT_BASE = registry.getRGB(CONFLICTING_COLOR);
    if (CONFLICT_BASE == null) {
        CONFLICT_BASE = new RGB(255, 0, 0);
        registry.put(CONFLICTING_COLOR, CONFLICT_BASE); // RED
    }
    CONFLICT = interpolate(CONFLICT_BASE, bg, 0.6);

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

From source file:com.mentor.nucleus.bp.ui.search.providers.DecoratingModelSearchLabelProvider.java

License:Open Source License

@Override
public void initialize(ColumnViewer viewer, ViewerColumn column) {
    PlatformUI.getPreferenceStore().addPropertyChangeListener(this);
    JFaceResources.getColorRegistry().addListener(this);

    setOwnerDrawEnabled(showColoredLabels());

    super.initialize(viewer, column);
}

From source file:com.mmkarton.mx7.reportgenerator.util.ColorManager.java

License:Open Source License

/**
 * This map stores color name - Color pairs, used to quickly lookup a Color
 * of a predefined color./* w w  w .  j  av a 2  s.  c  om*/
 * 
 * @param rgb
 *            RGB value of color
 */
public static Color getColor(RGB rgb) {
    if (rgb == null) {
        return null;
    }

    String key = rgb.toString();
    Color color = JFaceResources.getColorRegistry().get(key);
    if (color == null) {
        JFaceResources.getColorRegistry().put(key, rgb);
        color = JFaceResources.getColorRegistry().get(key);
    }
    return color;
}

From source file:com.netxforge.netxstudio.screens.f1.support.MonitoringTreeLabelProvider.java

License:Open Source License

private void backGroundForRag(ViewerCell cell, int ragValue, String symbolicName) {
    // Determine if R, A or G from the RAG status, set the styler.
    if (ragValue > 0) {
        // remember the previous background.
        cell.setBackground(JFaceResources.getColorRegistry().get(symbolicName));
    } else {/*from www  .j  a v  a 2  s  . c  o  m*/
        cell.setBackground(null);
    }
}