Example usage for org.eclipse.jface.resource ImageDescriptor createFromFile

List of usage examples for org.eclipse.jface.resource ImageDescriptor createFromFile

Introduction

In this page you can find the example usage for org.eclipse.jface.resource ImageDescriptor createFromFile.

Prototype

public static ImageDescriptor createFromFile(Class<?> location, String filename) 

Source Link

Document

Creates and returns a new image descriptor from a file.

Usage

From source file:org.eclipse.gef.examples.logicdesigner.LogicWizardPage1.java

License:Open Source License

public LogicWizardPage1(IWorkbench aWorkbench, IStructuredSelection selection) {
    super("sampleLogicPage1", selection); //$NON-NLS-1$
    this.setTitle(LogicMessages.CreateLogicPage1_Title);
    this.setDescription(LogicMessages.CreateLogicPage1_Description);
    this.setImageDescriptor(ImageDescriptor.createFromFile(getClass(), "icons/logicbanner.gif")); //$NON-NLS-1$
    this.workbench = aWorkbench;
}

From source file:org.eclipse.gef.examples.shapes.ShapesEditorPaletteFactory.java

License:Open Source License

/** Create the "Tools" group. */
private static PaletteContainer createToolsGroup(PaletteRoot palette) {
    PaletteToolbar toolbar = new PaletteToolbar("Tools");

    // Add a selection tool to the group
    ToolEntry tool = new PanningSelectionToolEntry();
    toolbar.add(tool);/*from  w  w w  . j a v a2s . co  m*/
    palette.setDefaultEntry(tool);

    // Add a marquee tool to the group
    toolbar.add(new MarqueeToolEntry());

    // Add (solid-line) connection tool
    tool = new ConnectionCreationToolEntry("Solid connection", "Create a solid-line connection",
            new CreationFactory() {
                public Object getNewObject() {
                    return null;
                }

                // see ShapeEditPart#createEditPolicies()
                // this is abused to transmit the desired line style
                public Object getObjectType() {
                    return Connection.SOLID_CONNECTION;
                }
            }, ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_s16.gif"),
            ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_s24.gif"));
    toolbar.add(tool);

    // Add (dashed-line) connection tool
    tool = new ConnectionCreationToolEntry("Dashed connection", "Create a dashed-line connection",
            new CreationFactory() {
                public Object getNewObject() {
                    return null;
                }

                // see ShapeEditPart#createEditPolicies()
                // this is abused to transmit the desired line style
                public Object getObjectType() {
                    return Connection.DASHED_CONNECTION;
                }
            }, ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_d16.gif"),
            ImageDescriptor.createFromFile(ShapesPlugin.class, "icons/connection_d24.gif"));
    toolbar.add(tool);

    return toolbar;
}

From source file:org.eclipse.gmf.examples.runtime.diagram.logic.internal.actions.IncrementDecrementAction.java

License:Open Source License

/**
 * @see org.eclipse.gmf.runtime.common.ui.internal.action.IDisposableAction#init()
 *//*  ww  w.jav a2s  .c  o  m*/
public void init() {
    super.init();
    if (actionId.equals(ACTION_INCREMENT_VALUE)) {
        setId("Increment"); //$NON-NLS-1$
        setText("Increment"); //$NON-NLS-1$
        setToolTipText("Increment LED"); //$NON-NLS-1$
        setImageDescriptor(ImageDescriptor.createFromFile(LogicDiagramPlugin.class, "icons/plus.gif")); //$NON-NLS-1$
    } else if (actionId.equals(ACTION_DECREMENT_VALUE)) {
        setId("Decrement"); //$NON-NLS-1$
        setText("Decrement"); //$NON-NLS-1$
        setToolTipText("Decrement LED"); //$NON-NLS-1$
        setImageDescriptor(ImageDescriptor.createFromFile(LogicDiagramPlugin.class, "icons/minus.gif")); //$NON-NLS-1$
    }
}

From source file:org.eclipse.jface.snippets.dialogs.Snippet012DialogWithImageButtons.java

License:Open Source License

public Snippet012DialogWithImageButtons(final Shell shell) {

    Dialog dia = new Dialog(shell) {
        private ImageDescriptor getImageDescriptor(String path) {
            if (registry == null) {
                registry = new ImageRegistry(shell.getDisplay());
            }//from  w w w  .jav  a2 s . c o  m

            ImageDescriptor desc = registry.getDescriptor(path);
            if (desc == null) {
                desc = ImageDescriptor.createFromFile(Snippet012DialogWithImageButtons.class, path);
                registry.put(path, desc);
            }

            return desc;
        }

        @Override
        protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
            Button b = super.createButton(parent, id, label, defaultButton);
            if (id == IDialogConstants.OK_ID) {
                b.setImage(getImageDescriptor("filesave.png").createImage()); //$NON-NLS-1$
                // reset the button layout
                setButtonLayoutData(b);
            } else {
                b.setImage(getImageDescriptor("cancel.png").createImage()); //$NON-NLS-1$
                // reset the button layout
                setButtonLayoutData(b);
                return b;
            }

            return b;
        }

        @Override
        protected Control createContents(Composite parent) {
            Label label = new Label(parent, SWT.CENTER);
            label.setText("Update Snippet012DialogWithImageButtons ...");
            label.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
            return super.createContents(parent);
        }
    };
    dia.open();
}

From source file:org.eclipse.jface.snippets.resources.Snippet057FileImageDescriptors.java

License:Open Source License

public Snippet057FileImageDescriptors(final Shell shell) {

    Dialog dia = new Dialog(shell) {
        private ImageDescriptor getImageDescriptorFromClass(String path) {
            ImageDescriptor desc = getDescriptorBasedOn(shell, path);
            if (desc == null) {
                desc = ImageDescriptor.createFromFile(Snippet057FileImageDescriptors.class, path);
                registry.put(path, desc);
            }/*from w  w w. j a v a  2  s  .  c om*/

            return desc;
        }

        private ImageDescriptor getImageDescriptorFromFile(String path) {
            ImageDescriptor desc = getDescriptorBasedOn(shell, path);
            if (desc == null) {
                URL classPath = Snippet057FileImageDescriptors.class.getResource(path);
                Class<?> bogus = null;
                desc = ImageDescriptor.createFromFile(bogus, classPath.getFile());

                registry.put(path, desc);
            }
            return desc;
        }

        private ImageDescriptor getDescriptorBasedOn(final Shell shell, String path) {
            if (registry == null) {
                registry = new ImageRegistry(shell.getDisplay());
            }
            return registry.getDescriptor(path);
        }

        @Override
        protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
            Button b = super.createButton(parent, id, label, defaultButton);
            if (id == IDialogConstants.OK_ID) {
                b.setImage(getImageDescriptorFromClass("filesave.png").createImage()); //$NON-NLS-1$
                // reset the button layout
                setButtonLayoutData(b);
            } else {
                b.setImage(getImageDescriptorFromFile("cancel.png").createImage()); //$NON-NLS-1$
                // reset the button layout
                setButtonLayoutData(b);
                return b;
            }

            return b;
        }

        @Override
        protected Control createContents(Composite parent) {
            Label label = new Label(parent, SWT.CENTER);
            label.setText("Snippet057FileImageDescriptors");
            label.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
            return super.createContents(parent);
        }
    };
    dia.open();
}

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 w  w  w  . ja  v a 2s  .  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.linuxtools.internal.rpm.ui.editor.wizards.NoExecutableWizardPage.java

License:Open Source License

protected NoExecutableWizardPage() {
    super(Messages.NoExecutableWizardPage_0);
    this.setImageDescriptor(ImageDescriptor.createFromFile(getClass(), "/icons/rpm.gif")); //$NON-NLS-1$
}

From source file:org.eclipse.linuxtools.internal.rpm.ui.RPMNewProject.java

License:Open Source License

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    super.addPages();
    namePage = new NewProjectCreationPage(Messages.getString("RPMNewProject.0")); //$NON-NLS-1$
    namePage.setTitle(Messages.getString("RPMNewProject.1")); //$NON-NLS-1$
    namePage.setDescription(Messages.getString("RPMNewProject.2")); //$NON-NLS-1$
    namePage.setImageDescriptor(ImageDescriptor.createFromFile(getClass(), "/icons/rpm.gif")); //$NON-NLS-1$
    addPage(namePage);//w w  w .j a  v a2  s.  com
    namePage.init(selection);
}

From source file:org.eclipse.linuxtools.rpm.ui.RPMNewProject.java

License:Open Source License

public void init(IWorkbench workbench, IStructuredSelection selection) {
    super.addPages();
    namePage = new NewProjectCreationPage(Messages.getString("RPMNewProject.0")); //$NON-NLS-1$
    namePage.setTitle(Messages.getString("RPMNewProject.1")); //$NON-NLS-1$
    namePage.setDescription(Messages.getString("RPMNewProject.2")); //$NON-NLS-1$
    namePage.setImageDescriptor(ImageDescriptor.createFromFile(getClass(), "/icons/rpm.gif")); //$NON-NLS-1$
    addPage(namePage);// w  w w. j a va 2  s . c  o  m
}

From source file:org.eclipse.nebula.snippets.grid.viewer.GridViewerSnippet6.java

License:Open Source License

/**
 * @param args/*  www.jav  a2 s  .  co  m*/
 */
public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    final ImageRegistry reg = new ImageRegistry(display);
    reg.put("ICON", ImageDescriptor.createFromFile(GridViewerSnippet6.class, "th_vertical.gif"));

    GridTableViewer v = new GridTableViewer(shell, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    v.getGrid().setLinesVisible(true);
    v.getGrid().setHeaderVisible(true);
    v.setContentProvider(new MyContentProvider());
    v.getGrid().setRowHeaderVisible(true);
    v.setRowHeaderLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setImage(reg.get("ICON"));
            cell.setText(cell.getElement().toString());
        }

    });
    ColumnViewerToolTipSupport.enableFor(v, ToolTip.NO_RECREATE);

    CellLabelProvider labelProvider = new CellLabelProvider() {

        public String getToolTipText(Object element) {
            return "Tooltip (" + element + ")";
        }

        public Point getToolTipShift(Object object) {
            return new Point(5, 5);
        }

        public int getToolTipDisplayDelayTime(Object object) {
            return 2000;
        }

        public int getToolTipTimeDisplayed(Object object) {
            return 5000;
        }

        public void update(ViewerCell cell) {
            cell.setText(cell.getElement().toString());

        }
    };

    GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
    column.setLabelProvider(labelProvider);
    column.getColumn().setText("Column 1");
    column.getColumn().setWidth(100);

    v.setInput("");

    shell.setSize(200, 200);
    shell.open();

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

    display.dispose();
}