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.epp.internal.logging.aeri.ui.notifications.NotificationPopup.java

License:Open Source License

@Override
protected void createContentArea(Composite parent) {
    Composite contentComposite = new Composite(parent, SWT.NO_FOCUS);
    GridLayout gridLayout = new GridLayout(2, false);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(contentComposite);
    contentComposite.setLayout(gridLayout);

    // icon label:
    new Label(contentComposite, SWT.NO_FOCUS);

    final Label labelText = new Label(contentComposite, SWT.WRAP | SWT.NO_FOCUS);
    labelText.setForeground(CommonColors.TEXT_QUOTED);

    labelText.setText(abbreviate(notification.getLabel(), MAX_LABEL_CHAR_LENGTH));
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(labelText);
    String description = notification.getDescription();
    if (isNotBlank(description)) {
        Label descriptionText = new Label(contentComposite, SWT.WRAP);
        descriptionText.setText(abbreviate(description, MAX_DESCRIPTION_CHAR_LENGTH));
        GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).grab(true, false).align(SWT.FILL, SWT.TOP)
                .applyTo(descriptionText);
    }//from ww w . j  av  a  2s  .c om
    if (notification instanceof Notification) {
        Notification executableNotification = notification;
        Composite linksComposite = new Composite(contentComposite, SWT.NO_FOCUS | SWT.RIGHT);
        GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).grab(true, false).align(SWT.END, SWT.TOP)
                .applyTo(linksComposite);
        GridLayoutFactory.fillDefaults().numColumns(executableNotification.getActions().size())
                .applyTo(linksComposite);
        for (final NotificationAction action : executableNotification.getActions()) {
            final ScalingHyperlink actionLink = new ScalingHyperlink(linksComposite, SWT.RIGHT | SWT.NO_FOCUS);
            GridDataFactory.fillDefaults().grab(true, false).applyTo(actionLink);
            Color linkColor = JFaceResources.getColorRegistry().get(JFacePreferences.HYPERLINK_COLOR);
            actionLink.setForeground(linkColor);
            actionLink.registerMouseTrackListener();
            actionLink.setText(action.getName());
            actionLink.addHyperlinkListener(new HyperlinkAdapter() {
                @Override
                public void linkActivated(HyperlinkEvent e) {
                    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    if (window != null) {
                        Shell windowShell = window.getShell();
                        if (windowShell != null) {
                            if (windowShell.getMinimized()) {
                                windowShell.setMinimized(false);
                            }
                            windowShell.open();
                            windowShell.forceActive();
                        }
                    }
                    action.execute();
                }
            });
            links.add(actionLink);
        }
    }
}

From source file:org.eclipse.equinox.internal.p2.ui.discovery.util.ControlListItem.java

License:Open Source License

/**
 * Set the color base on the index//from w  w w .  j ava 2  s .  c o  m
 * 
 * @param index
 */
public void updateColors(int index) {
    currentIndex = index;

    if (selected) {
        setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
        setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
    } else {
        if (index % 2 == 0) {
            setBackground(JFaceResources.getColorRegistry().get(DARK_COLOR_KEY));
        } else {
            setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        }
        setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
    }
}

From source file:org.eclipse.etrice.core.ui.labeling.RoomLabelProvider.java

License:Open Source License

@Inject
public RoomLabelProvider(AdapterFactoryLabelProvider delegate) {
    super(delegate);

    JFaceResources.getColorRegistry().put(KEYWORD_COLOR, new RGB(50, 50, 50));
}

From source file:org.eclipse.jface.snippets.viewers.Snippet049StyledCellLabelProvider.java

License:Open Source License

public static void main(String[] args) {

    JFaceResources.getColorRegistry().put(JFacePreferences.COUNTER_COLOR, new RGB(0, 127, 174));

    Shell shell = new Shell(DISPLAY, SWT.CLOSE | SWT.RESIZE);
    shell.setSize(SHELL_WIDTH, 400);//w  ww . ja v  a 2 s .  co m
    shell.setLayout(new GridLayout(1, false));

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

    shell.open();

    while (!shell.isDisposed()) {
        if (!DISPLAY.readAndDispatch()) {
            DISPLAY.sleep();
        }
    }
    DISPLAY.dispose();
}

From source file:org.eclipse.jface.snippets.viewers.Snippet050DelegatingStyledCellLabelProvider.java

License:Open Source License

public static void main(String[] args) {

    JFaceResources.getColorRegistry().put(JFacePreferences.COUNTER_COLOR, new RGB(0, 127, 174));

    Shell shell = new Shell(DISPLAY, SWT.CLOSE | SWT.RESIZE);
    shell.setSize(SHELL_WIDTH, 300);/*from w ww .j  a  va2s.  c  om*/
    shell.setLayout(new GridLayout(1, false));

    Snippet050DelegatingStyledCellLabelProvider example = new Snippet050DelegatingStyledCellLabelProvider();
    example.createPartControl(shell);

    shell.open();

    while (!shell.isDisposed()) {
        if (!DISPLAY.readAndDispatch()) {
            DISPLAY.sleep();
        }
    }
    DISPLAY.dispose();
}

From source file:org.eclipse.jface.snippets.window.Snippet020CustomizedControlTooltips.java

License:Open Source License

public Snippet020CustomizedControlTooltips(final Shell parent) {
    JFaceResources.getColorRegistry().put(MyToolTip.HEADER_BG_COLOR, new RGB(255, 255, 255));
    JFaceResources.getFontRegistry().put(MyToolTip.HEADER_FONT, JFaceResources.getFontRegistry()
            .getBold(JFaceResources.getDefaultFont().getFontData()[0].getName()).getFontData());

    JFaceResources.getImageRegistry().put(MyToolTip.HEADER_CLOSE_ICON,
            ImageDescriptor.createFromFile(Snippet020CustomizedControlTooltips.class, "showerr_tsk.gif"));
    JFaceResources.getImageRegistry().put(MyToolTip.HEADER_HELP_ICON,
            ImageDescriptor.createFromFile(Snippet020CustomizedControlTooltips.class, "linkto_help.gif"));

    Text text = new Text(parent, SWT.BORDER);
    text.setText("Hello World");

    MyToolTip myTooltipLabel = new MyToolTip(text) {

        @Override//from  ww  w  . j  a  va2s .c om
        protected Composite createContentArea(Composite parent) {
            Composite comp = super.createContentArea(parent);
            comp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            FillLayout layout = new FillLayout();
            layout.marginWidth = 5;
            comp.setLayout(layout);
            Link l = new Link(comp, SWT.NONE);
            l.setText(
                    "This a custom tooltip you can: \n- pop up any control you want\n- define delays\n - ... \nGo and get Eclipse from <a>http://www.eclipse.org</a>");
            l.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            l.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    openURL();
                }
            });
            return comp;
        }

        protected void openURL() {
            MessageBox box = new MessageBox(parent, SWT.ICON_INFORMATION);
            box.setText("Eclipse.org");
            box.setMessage("Here is where we'd open the URL.");
            box.open();
        }

        @Override
        protected void openHelp() {
            MessageBox box = new MessageBox(parent, SWT.ICON_INFORMATION);
            box.setText("Info");
            box.setMessage("Here is where we'd show some information.");
            box.open();
        }

    };
    myTooltipLabel.setShift(new Point(-5, -5));
    myTooltipLabel.setHideOnMouseDown(false);
    myTooltipLabel.activate();

    text = new Text(parent, SWT.BORDER);
    text.setText("Hello World");
    DefaultToolTip toolTip = new DefaultToolTip(text);
    toolTip.setText("Hello World\nHello World");
    toolTip.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_RED));

    Button b = new Button(parent, SWT.PUSH);
    b.setText("Popup on press");

    final DefaultToolTip toolTipDelayed = new DefaultToolTip(b, ToolTip.RECREATE, true);
    toolTipDelayed.setText("Hello World\nHello World");
    toolTipDelayed.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
    toolTipDelayed.setHideDelay(2000);

    b.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            toolTipDelayed.show(new Point(0, 0));
        }
    });

}

From source file:org.eclipse.jst.jsf.facesconfig.ui.preference.ColorFontFieldEditor.java

License:Open Source License

/**
 * /*from ww  w .j av  a  2  s  .com*/
 * Updates the change font button and the previewer to reflect the
 * 
 * newly selected font.
 * 
 */

private void updateFont(FontData font[]) {
    FontData[] bestFont = JFaceResources.getFontRegistry().filterData(font, valueControl.getDisplay());

    // if we have nothing valid do as best we can
    if (bestFont == null)
        bestFont = getDefaultFontData();
    // Now cache this value in the receiver
    this.chosenFont = bestFont;
    if (valueControl != null) {
        if (fontRGB != null) {
            ColorRegistry registry = JFaceResources.getColorRegistry();
            Color color = registry.get(fontRGB.toString());
            if (color == null) {
                registry.put(fontRGB.toString(), fontRGB);
                color = registry.get(fontRGB.toString());
            }
            valueControl.setForeground(color);
        }
        valueControl.setText(StringConverter.asString(chosenFont[0]));
    }

    if (previewer != null) {
        previewer.setFont(bestFont);
    }
}

From source file:org.eclipse.jst.jsf.facesconfig.ui.preference.GEMPreferences.java

License:Open Source License

/**
 * @param store/* w  ww.  ja  va 2s .co  m*/
 * @param property
 * @return the color property for the key 'property'
 */
public static Color getColor(IPreferenceStore store, String property) {
    boolean useSystemColors = store.getBoolean(USE_SYSTEM_COLORS);

    Color c = ColorConstants.black;
    if (useSystemColors) {
        if (GRID_COLOR.equals(property))
            // c = ColorConstants.buttonDarkest;
            c = ColorConstants.button;
        if (LINE_COLOR.equals(property))
            c = ColorConstants.listForeground;
        if (LINE_LABEL_FONT_COLOR.equals(property))
            c = ColorConstants.listForeground;
        if (LINE_LABEL_COLOR.equals(property))
            c = ColorConstants.listBackground;
        if (CANVAS_COLOR.equals(property))
            c = ColorConstants.listBackground;
        if (INPUT_PORT_COLOR.equals(property))
            c = ColorConstants.listForeground;
        if (OUTPUT_PORT_COLOR.equals(property))
            c = ColorConstants.listForeground;
        if (FIGURE_LABEL_FONT_COLOR.equals(property))
            c = ColorConstants.listForeground;
    } else {
        // CR392586: resource leaks
        RGB rgb = PreferenceConverter.getColor(store, property);
        ColorRegistry registry = JFaceResources.getColorRegistry();
        if (registry.get(rgb.toString()) != null)
            return registry.get(rgb.toString());
        registry.put(rgb.toString(), rgb);
        c = registry.get(rgb.toString());
    }
    return c;
}

From source file:org.eclipse.linuxtools.internal.gprof.view.GmonView.java

License:Open Source License

@Override
protected void createTitle(Composite parent) {
    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
    Color background = colorRegistry.get("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START"); //$NON-NLS-1$
    label = new Label(parent, SWT.WRAP);
    if (background != null) {
        label.setBackground(background);
    }/*from  www  .  j ava2s.  c o m*/
    GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 1, 1);
    label.setLayoutData(data);
    fFilterText = new Text(parent, SWT.BORDER | SWT.SINGLE | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
    fFilterText.setMessage(Messages.GmonView_type_filter_text);
    fFilterText.setToolTipText(Messages.GmonView_filter_by_name);
    fFilterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    fFilterText.addModifyListener(e -> {
        String text = fFilterText.getText();
        fViewerFilter.setMatchingText(text);
    });
}

From source file:org.eclipse.linuxtools.internal.gprof.view.GmonView.java

License:Open Source License

public static Color getBackground(Object element) {
    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();

    // FIXME: Not sure if color1-color4 are ever used...picked colors found in JFacesResources ColorRegistry
    // not tied to any particular language (e.g. didn't choose CDT or Java colors)
    // Color5 seems to work ok as bg in the one dark theme I tried (Nissl-Adwaita-dark-4) and as well
    // in default light adwaita, but it is much simpler to just return null and let the table color default
    // appropriately.
    Color color1 = colorRegistry.get("org.eclipse.ui.editors.currentLineColor"); //$NON-NLS-1$
    Color color2 = colorRegistry.get("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START"); //$NON-NLS-1$
    Color color3 = colorRegistry.get("org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_END"); //$NON-NLS-1$
    Color color4 = colorRegistry.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"); //$NON-NLS-1$
    //        Color color5 = colorRegistry.get("org.eclipse.ui.workbench.INACTIVE_TAB_BG_START"); //$NON-NLS-1$

    if (element instanceof CGCategory) {
        CGCategory cat = (CGCategory) element;
        if (CGCategory.CHILDREN.equals(cat.category)) {
            return color1 == null ? BLUE1 : color1;
        } else {/*from ww w.  ja va2  s.  co m*/
            return color2 == null ? GREEN1 : color2;
        }
    } else if (element instanceof CGArc) {
        CGArc arc = (CGArc) element;
        CGCategory cat = (CGCategory) arc.getParent();
        if (CGCategory.CHILDREN.equals(cat.category)) {
            return color3 == null ? BLUE2 : color3;
        } else {
            return color4 == null ? GREEN2 : color4;
        }
    }
    return null; // default background
    //        return color5 == null ? DEFAULT_BG : color5;
}