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

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

Introduction

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

Prototype

public static ImageRegistry getImageRegistry() 

Source Link

Document

Returns the image registry for JFace itself.

Usage

From source file:org.eclipse.gmf.examples.taipan.figures.ShipShape.java

License:Open Source License

protected Image getImageImage(String path) {
    Image image = JFaceResources.getImageRegistry().get(path);
    if (image == null) {
        ImageDescriptor descriptor = AbstractUIPlugin
                .imageDescriptorFromPlugin("org.eclipse.gmf.examples.taipan", path); //$NON-NLS-1$
        if (descriptor == null) {
            descriptor = ImageDescriptor.getMissingImageDescriptor();
        }//from   w w w.  j  ava2s .c  om
        JFaceResources.getImageRegistry().put(path, image = descriptor.createImage());
    }
    return image;
}

From source file:org.eclipse.gyrex.admin.ui.internal.widgets.FilteredTree.java

License:Open Source License

/**
 * Create the button that clears the text.
 * /*from   w  w w  .j a  v a 2  s  .  c  o m*/
 * @param parent
 *            parent <code>Composite</code> of toolbar button
 */
private void createClearTextNew(final Composite parent) {
    // only create the button if the text widget doesn't support one
    // natively
    if ((filterText.getStyle() & SWT.ICON_CANCEL) == 0) {
        final Image inactiveImage = JFaceResources.getImageRegistry().getDescriptor(DISABLED_CLEAR_ICON)
                .createImage();
        final Image activeImage = JFaceResources.getImageRegistry().getDescriptor(CLEAR_ICON).createImage();
        // RAP [bm] IMAGE_GRAY
        //         final Image pressedImage= new Image(getDisplay(), activeImage, SWT.IMAGE_GRAY);
        final Image pressedImage = new Image(getDisplay(), activeImage, SWT.IMAGE_COPY);

        final Label clearButton = new Label(parent, SWT.NONE);
        clearButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
        clearButton.setImage(inactiveImage);
        clearButton.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        clearButton.setToolTipText(WidgetMessages.get().FilteredTree_ClearToolTip);
        clearButton.addMouseListener(new MouseAdapter() {
            private MouseMoveListener fMoveListener;

            private boolean isMouseInButton(final MouseEvent e) {
                final Point buttonSize = clearButton.getSize();
                return (0 <= e.x) && (e.x < buttonSize.x) && (0 <= e.y) && (e.y < buttonSize.y);
            }

            @Override
            public void mouseDown(final MouseEvent e) {
                clearButton.setImage(pressedImage);
                fMoveListener = new MouseMoveListener() {
                    private boolean fMouseInButton = true;

                    @Override
                    public void mouseMove(final MouseEvent e) {
                        final boolean mouseInButton = isMouseInButton(e);
                        if (mouseInButton != fMouseInButton) {
                            fMouseInButton = mouseInButton;
                            clearButton.setImage(mouseInButton ? pressedImage : inactiveImage);
                        }
                    }
                };
                // RAP [bm] mouse move listener
                //               clearButton.addMouseMoveListener(fMoveListener);
            }

            @Override
            public void mouseUp(final MouseEvent e) {
                if (fMoveListener != null) {
                    // RAP [bm] mouse move listener
                    //                  clearButton.removeMouseMoveListener(fMoveListener);
                    fMoveListener = null;
                    final boolean mouseInButton = isMouseInButton(e);
                    clearButton.setImage(mouseInButton ? activeImage : inactiveImage);
                    if (mouseInButton) {
                        clearText();
                        filterText.setFocus();
                    }
                }
            }
        });
        // RAP [bm] MouseTrackListener
        //         clearButton.addMouseTrackListener(new MouseTrackListener() {
        //            public void mouseEnter(MouseEvent e) {
        //               clearButton.setImage(activeImage);
        //            }
        //
        //            public void mouseExit(MouseEvent e) {
        //               clearButton.setImage(inactiveImage);
        //            }
        //
        //            public void mouseHover(MouseEvent e) {
        //            }
        //         });
        clearButton.addDisposeListener(new DisposeListener() {
            @Override
            public void widgetDisposed(final DisposeEvent e) {
                inactiveImage.dispose();
                activeImage.dispose();
                pressedImage.dispose();
            }
        });
        // RAP [bm] Accessibility
        //         clearButton.getAccessible().addAccessibleListener(
        //            new AccessibleAdapter() {
        //               public void getName(AccessibleEvent e) {
        //                  e.result= WidgetMessages.FilteredTree_AccessibleListenerClearButton;
        //               }
        //         });
        //         clearButton.getAccessible().addAccessibleControlListener(
        //            new AccessibleControlAdapter() {
        //               public void getRole(AccessibleControlEvent e) {
        //                  e.detail= ACC.ROLE_PUSHBUTTON;
        //               }
        //         });
        clearButtonControl = clearButton;
    }
}

From source file:org.eclipse.gyrex.admin.ui.internal.widgets.FilteredTree.java

License:Open Source License

/**
 * Create the button that clears the text.
 * /*from   ww  w.  j  a v a  2  s. co  m*/
 * @param parent
 *            parent <code>Composite</code> of toolbar button
 */
private void createClearTextOld(final Composite parent) {
    // only create the button if the text widget doesn't support one
    // natively
    if ((filterText.getStyle() & SWT.ICON_CANCEL) == 0) {
        filterToolBar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
        filterToolBar.createControl(parent);

        final IAction clearTextAction = new Action("", IAction.AS_PUSH_BUTTON) {//$NON-NLS-1$
            /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.jface.action.Action#run()
             */
            @Override
            public void run() {
                clearText();
            }
        };

        clearTextAction.setToolTipText(WidgetMessages.get().FilteredTree_ClearToolTip);
        clearTextAction.setImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(CLEAR_ICON));
        clearTextAction.setDisabledImageDescriptor(
                JFaceResources.getImageRegistry().getDescriptor(DISABLED_CLEAR_ICON));

        filterToolBar.add(clearTextAction);
    }
}

From source file:org.eclipse.gyrex.admin.ui.internal.widgets.FilteredTree.java

License:Open Source License

private void initializeImageDescriptors() {
    final ImageRegistry registry = JFaceResources.getImageRegistry();
    ImageDescriptor descriptor = AdminUiActivator.getImageDescriptor("$nl$/icons/etool16/clear_co.gif"); //$NON-NLS-1$
    if ((descriptor != null) && (registry.getDescriptor(CLEAR_ICON) == null)) {
        registry.put(CLEAR_ICON, descriptor);
    }//from ww  w .j  a  va2  s  .c  o  m
    descriptor = AdminUiActivator.getImageDescriptor("$nl$/icons/dtool16/clear_co.gif"); //$NON-NLS-1$
    if ((descriptor != null) && (registry.getDescriptor(DISABLED_CLEAR_ICON) == null)) {
        registry.put(DISABLED_CLEAR_ICON, descriptor);
    }
}

From source file:org.eclipse.ice.client.widgets.moose.CheckboxCellContentProvider.java

License:Open Source License

/**
 * If the enabled/disabled checked/unchecked checkbox <code>Image</code>s
 * have not already been created and added to the JFace
 * <code>ImageRegistry</code>, this method generates and registers them.
 * This produces platform-specific images at run-time.
 * /*from   w  w w  . ja va2s .c o m*/
 * @param display
 *            The <code>Display</code> shared with the underlying
 *            <code>ColumnViewer</code>.
 * @param background
 *            The background of the <code>ColumnViewer</code>'s cells.
 */
private static void registerImages(final Display display, Color background) {

    if (display != null && IMAGES_REGISTERED.compareAndSet(false, true)) {

        // Get the ImageRegistry for JFace images. We will load up images
        // for each combination of checkbox enabled/disabled and
        // checked/unchecked.
        ImageRegistry jfaceImages = JFaceResources.getImageRegistry();

        // Create a temporary shell and checkbox Button to generate
        // platform-specific images of checkboxes.
        Shell shell = new Shell(display, SWT.NO_TRIM);
        Button checkbox = new Button(shell, SWT.CHECK);

        // Set the widget's background to the viewer's cell background.
        checkbox.setBackground(background);

        // Reduce the size of the shell to a square (checkboxes are supposed
        // to be square!!!).
        Point size = checkbox.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        // int width = Math.min(size.x, size.y);
        checkbox.setSize(size);
        // checkbox.setLocation(width - size.x, width - size.y);
        // shell.setSize(width, width);
        shell.setSize(size);

        // Open the shell to enable widget drawing.
        shell.open();

        // Create the enabled/unchecked image.
        jfaceImages.put(ENABLED_UNCHECKED, createImage(checkbox));
        // Create the enabled/checked image.
        checkbox.setSelection(true);
        jfaceImages.put(ENABLED_CHECKED, createImage(checkbox));
        // Create the disabled/checked image.
        checkbox.setEnabled(false);
        jfaceImages.put(DISABLED_CHECKED, createImage(checkbox));
        // Create the disabled/unchecked image.
        checkbox.setSelection(false);
        jfaceImages.put(DISABLED_UNCHECKED, createImage(checkbox));

        // Release any remaining resources.
        // gc.dispose();
        shell.close();
    }

    return;
}

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/*ww w.j  a v  a  2 s . c o m*/
        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.common.ui.internal.utils.PluginImageHelper.java

License:Open Source License

/**
 * Returns the image registry for this plugin.
 * //  w  w  w .  j a va2s. c o  m
 * @return ImageRegistry - image registry for this plugin
 */
private ImageRegistry getImageRegistry() {
    return JFaceResources.getImageRegistry();
}

From source file:org.eclipse.linuxtools.internal.docker.ui.utils.UIUtils.java

License:Open Source License

/**
 * Replaces an image with the given key by the given image descriptor.
 * //from  www  .  j  a va  2s  .  co m
 * @param imageKey
 *            the image key
 * @param imageDescriptor
 *            the image descriptor
 */
public static void replaceInJfaceImageRegistry(final String imageKey, final ImageDescriptor imageDescriptor) {
    Assert.isNotNull(imageKey);
    Assert.isNotNull(imageDescriptor);

    JFaceResources.getImageRegistry().remove(imageKey);
    JFaceResources.getImageRegistry().put(imageKey, imageDescriptor);
}

From source file:org.eclipse.mylyn.commons.workbench.search.TextSearchControl.java

License:Open Source License

@SuppressWarnings("restriction")
public TextSearchControl(Composite parent, boolean automaticFind, SearchHistoryPopupDialog historyDialog) {
    super(parent, getCompositeStyle(automaticFind, parent));
    this.automaticFind = automaticFind;

    int textStyle = SWT.SINGLE;
    int numColumns = 1;
    if (useNativeSearchField(automaticFind, parent)) {
        if (automaticFind) {
            textStyle |= SWT.SEARCH | ICON_CANCEL;
        } else {/*  ww w . j  a  v  a 2s .c  o  m*/
            textStyle |= SWT.SEARCH | ICON_SEARCH | ICON_CANCEL;
        }
    } else {
        super.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        super.setFont(parent.getFont());
        numColumns = 2;
        if (!automaticFind) {
            numColumns += 1;
        }
    }
    GridLayoutFactory.swtDefaults().margins(0, 0).extendedMargins(0, 0, 0, 0).spacing(0, 1)
            .numColumns(numColumns).applyTo(this);

    textControl = new Text(this, textStyle);

    GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    textControl.setLayoutData(gridData);

    if (useNativeSearchField == null || !useNativeSearchField) {
        findControl = createLabelButtonControl(this, textControl,
                JFaceResources.getImageRegistry().getDescriptor(FIND_ICON),
                Messages.TextControl_AccessibleListenerFindButton, Messages.TextControl_FindToolTip,
                ICON_SEARCH);
        clearControl = createLabelButtonControl(this, textControl,
                JFaceResources.getImageRegistry().getDescriptor(CLEAR_ICON),
                WorkbenchMessages.FilteredTree_ClearToolTip, //FilteredTree_AccessibleListenerClearButton,
                WorkbenchMessages.FilteredTree_ClearToolTip, ICON_CANCEL);
        addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                updateButtonVisibilityAndEnablement();

            }
        });
        updateButtonVisibilityAndEnablement();
    }

    if (historyDialog != null) {
        historyDialog.attach(this);
        hasHistorySupport = true;
    }

    registerListeners();
}

From source file:org.eclipse.mylyn.internal.provisional.commons.ui.TextSearchControl.java

License:Open Source License

@SuppressWarnings("restriction")
public TextSearchControl(Composite parent, boolean automaticFind, SearchHistoryPopUpDialog historyDialog) {
    super(parent, getCompositeStyle(automaticFind, parent));
    this.automaticFind = automaticFind;

    int textStyle = SWT.SINGLE;
    int numColumns = 1;
    if (useNativeSearchField(automaticFind, parent)) {
        if (automaticFind) {
            textStyle |= SWT.SEARCH | ICON_CANCEL;
        } else {/*from  w ww .j  av  a  2 s . c o m*/
            textStyle |= SWT.SEARCH | ICON_SEARCH | ICON_CANCEL;
        }
    } else {
        super.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        super.setFont(parent.getFont());
        numColumns = 2;
        if (!automaticFind) {
            numColumns += 1;
        }
    }
    GridLayoutFactory.swtDefaults().margins(0, 0).extendedMargins(0, 0, 0, 0).spacing(0, 1)
            .numColumns(numColumns).applyTo(this);

    textControl = new Text(this, textStyle);

    GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    textControl.setLayoutData(gridData);

    if (useNativeSearchField == null || !useNativeSearchField) {
        findControl = createLabelButtonControl(this, textControl,
                JFaceResources.getImageRegistry().getDescriptor(FIND_ICON),
                Messages.TextControl_AccessibleListenerFindButton, Messages.TextControl_FindToolTip,
                ICON_SEARCH);
        clearControl = createLabelButtonControl(this, textControl,
                JFaceResources.getImageRegistry().getDescriptor(CLEAR_ICON),
                WorkbenchMessages.FilteredTree_ClearToolTip, //FilteredTree_AccessibleListenerClearButton,
                WorkbenchMessages.FilteredTree_ClearToolTip, ICON_CANCEL);
        addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                updateButtonVisibilityAndEnablement();

            }
        });
        updateButtonVisibilityAndEnablement();
    }

    if (historyDialog != null) {
        historyDialog.attach(this);
        hasHistorySupport = true;
    }

    registerListeners();
}