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

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

Introduction

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

Prototype

public static ImageDescriptor createFromImage(Image img) 

Source Link

Document

Creates and returns a new image descriptor for the given image.

Usage

From source file:org.eclipse.team.internal.ui.synchronize.patch.PatchWorkbenchAdapter.java

License:Open Source License

public ImageDescriptor getImageDescriptor(Object object) {
    if (object instanceof DiffNode) {
        Image image = ((DiffNode) object).getImage();
        return ImageDescriptor.createFromImage(image);
    }/*  w  w  w  . j  ava2  s .  c  o  m*/
    return null;
}

From source file:org.eclipse.titan.log.viewer.Activator.java

License:Open Source License

/**
 * Returns the image descriptor for the given image
 * //from w  w w .j a  v  a 2s. c o  m
 * @param path the path to the image (icon)
 * @return the image descriptor for the given image
 */
public ImageDescriptor getCachedImageDescriptor(final String path) {
    return ImageDescriptor.createFromImage(Activator.getDefault().getIcon(path));
}

From source file:org.eclipse.titan.log.viewer.views.MSCView.java

License:Open Source License

/**
 * Creates the coolBar icon depending on the actions supported by the 
 * Message Sequence Chart provider<br>
 * - Navigation buttons are displayed if ISDPovider.HasPaging return true<br>
 * - Navigation buttons are enabled depending on the value
 * return by ISDPovider.HasNext and HasPrev<br>
 *//*  w  w w  .j  a v  a2  s .c o  m*/
protected void createCoolbarContent() {
    IActionBars bar = getViewSite().getActionBars();

    bar.getToolBarManager().removeAll();

    createMenuGroups();

    this.openValueView = new OpenValueViewAction(this, true);
    this.openValueView
            .setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_DETAILS_VIEW));
    this.silentOpenValueView = new OpenValueViewAction(this, false);
    this.silentOpenValueView
            .setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_DETAILS_VIEW));

    this.openTextTable = new OpenTextTableAction(this);
    this.openTextTable.setImageDescriptor(
            Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_TEXT_TABLE_VIEW));

    this.openSource = new OpenSourceAction(this, false, true);
    this.openSource.setImageDescriptor(
            Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_TEXT_TABLE_VIEW));
    this.silentOpenSource = new OpenSourceAction(this, true, false);
    this.silentOpenSource.setImageDescriptor(
            Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_TEXT_TABLE_VIEW));

    IAction switchToTextTable = new Action() {
        @Override
        public void run() {
            if (logFileMetaData == null) {
                return;
            }

            TextTableViewHelper.open(logFileMetaData.getProjectName(), logFileMetaData.getProjectRelativePath(),
                    getSelectedRecordNumber());
        }
    };
    switchToTextTable.setImageDescriptor(
            Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_TEXT_TABLE_VIEW));
    switchToTextTable.setText("Switch to Table view");
    switchToTextTable.setToolTipText(switchToTextTable.getText());
    bar.getToolBarManager().appendToGroup(Constants.ID_SWITCH_VIEW_GROUP, switchToTextTable);

    this.jumpToPreviousSetverdict = new JumpToPreviousSetverdictAction(this);
    this.jumpToPreviousSetverdict.setId("jumpToNextSetVerdict"); //$NON-NLS-1$
    this.jumpToPreviousSetverdict.setText(Messages.getString("MSCView.11")); //$NON-NLS-1$
    this.jumpToPreviousSetverdict.setToolTipText(Messages.getString("MSCView.12")); //$NON-NLS-1$
    this.jumpToPreviousSetverdict.setImageDescriptor(ImageDescriptor
            .createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_JUMP_TO_PREVIOUS)));
    this.jumpToPreviousSetverdict.setEnabled(false);
    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, this.jumpToPreviousSetverdict);

    this.jumpToNextSetverdict = new JumpToNextSetverdictAction(this);
    this.jumpToNextSetverdict.setId("jumpToNextSetVerdict"); //$NON-NLS-1$
    this.jumpToNextSetverdict.setText(Messages.getString("MSCView.13")); //$NON-NLS-1$
    this.jumpToNextSetverdict.setToolTipText(Messages.getString("MSCView.14")); //$NON-NLS-1$
    this.jumpToNextSetverdict.setImageDescriptor(
            ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_JUMP_TO_NEXT)));
    this.jumpToNextSetverdict.setEnabled(false);
    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, this.jumpToNextSetverdict);

    this.refresh = new RefreshMSCViewAction(this);
    this.refresh.setId("refreshMSCView"); //$NON-NLS-1$
    this.refresh.setToolTipText(Messages.getString("MSCView.1")); //$NON-NLS-1$
    this.refresh.setImageDescriptor(
            ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_REFRESH)));
    IActionBars actionBar = getViewSite().getActionBars();
    actionBar.setGlobalActionHandler(ActionFactory.REFRESH.getId(), this.refresh);
    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, this.refresh);

    IAction closeAllAction = new Action() {
        @Override
        public void run() {
            IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IViewReference[] viewReferences = activePage.getViewReferences();

            for (IViewReference reference : viewReferences) {
                IViewPart view = reference.getView(false);
                // memento restored views that never have had focus are null!!!
                if (view == null) {
                    activePage.hideView(reference);
                } else if (view instanceof MSCView) {
                    activePage.hideView(reference);
                }
            }

            // Clear Details view if needed
            DetailsView detailsView = (DetailsView) activePage.findView(Constants.DETAILS_VIEW_ID);
            if (detailsView != null) {
                detailsView.setData(null, false);
            }
        }
    };

    closeAllAction.setImageDescriptor(
            ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_DELETE)));
    closeAllAction.setId("closeMSC"); //$NON-NLS-1$
    closeAllAction.setToolTipText(Messages.getString("MSCView.2")); //$NON-NLS-1$
    closeAllAction.setEnabled(true);
    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, closeAllAction);

    ZoomAction resetZoom = new ZoomAction(this);
    resetZoom.setId(MSCConstants.ID_RESET_ZOOM);
    resetZoom.setText(Messages.getString("MSCView.3")); //$NON-NLS-1$
    resetZoom.setToolTipText(Messages.getString("MSCView.4")); //$NON-NLS-1$
    resetZoom.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(MSCConstants.ICON_RESET_ZOOM));
    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, resetZoom);

    ZoomAction noZoom = new ZoomAction(this);
    noZoom.setChecked(true);
    noZoom.setId(MSCConstants.ID_NO_ZOOM);
    noZoom.setText(Messages.getString("MSCView.5")); //$NON-NLS-1$
    noZoom.setToolTipText(Messages.getString("MSCView.6")); //$NON-NLS-1$
    noZoom.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(MSCConstants.ICON_MOVE));
    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, noZoom);

    ZoomAction zoomIn = new ZoomAction(this);
    zoomIn.setId(MSCConstants.ID_ZOOM_IN);
    zoomIn.setText(Messages.getString("MSCView.7")); //$NON-NLS-1$
    zoomIn.setToolTipText(Messages.getString("MSCView.8")); //$NON-NLS-1$
    zoomIn.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(MSCConstants.ICON_ZOOM_IN));
    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, zoomIn);

    ZoomAction zoomOut = new ZoomAction(this);
    zoomOut.setId(MSCConstants.ID_ZOOM_OUT);
    zoomOut.setText(Messages.getString("MSCView.9")); //$NON-NLS-1$
    zoomOut.setToolTipText(Messages.getString("MSCView.10")); //$NON-NLS-1$
    zoomOut.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(MSCConstants.ICON_ZOOM_OUT));
    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, zoomOut);

    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, filterAction);

    Action decipheringAction = new Action() {
        @Override
        public void run() {
            final List<String> rulesets = DecipheringPreferenceHandler.getAvailableRuleSets();

            ElementListSelectionDialog dialog = new ElementListSelectionDialog(
                    MSCView.this.getSite().getShell(), new LabelProvider());
            dialog.setTitle("Message name deciphering");
            dialog.setMessage("Select a deciphering ruleset");
            dialog.setHelpAvailable(false);
            dialog.setElements(rulesets.toArray());

            if (dialog.open() == Window.CANCEL || dialog.getFirstResult() == null) {
                return;
            }

            MSCView.this.model.setDecipheringRuleset((String) dialog.getFirstResult());
            mscWidget.redraw();
        }

    };
    decipheringAction.setImageDescriptor(Activator.getImageDescriptor(Constants.ICONS_MSC_DECIPHERING));
    decipheringAction.setToolTipText("Select a message name deciphering ruleset");
    bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, decipheringAction);

    bar.updateActionBars();
}

From source file:org.eclipse.titan.log.viewer.views.StatisticalView.java

License:Open Source License

/**
 * Create a close all action in the tool bar
 *//* www.j a  v a  2 s.c  o m*/
private void createToolbar() {

    IActionBars actionBars = getViewSite().getActionBars();
    IToolBarManager mgr = actionBars.getToolBarManager();

    IAction closeAllAction = new Action() {
        @Override
        public void run() {

            IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IViewReference[] viewReferences = activePage.getViewReferences();

            for (IViewReference reference : viewReferences) {
                IViewPart view = reference.getView(false);

                // memento restored views that never have had focus are
                // null!!!
                if (view == null) {
                    activePage.hideView(reference);
                } else if (view instanceof StatisticalView) {
                    activePage.hideView(reference);
                }
            }
        }
    };

    closeAllAction.setImageDescriptor(
            ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_DELETE)));
    closeAllAction.setId(Messages.getString("StatisticalView.27")); //$NON-NLS-1$
    closeAllAction.setToolTipText(Messages.getString("StatisticalView.26")); //$NON-NLS-1$
    closeAllAction.setEnabled(true);

    mgr.add(closeAllAction);
    actionBars.updateActionBars();
}

From source file:org.eclipse.titan.log.viewer.views.text.table.CloseAllAction.java

License:Open Source License

public CloseAllAction() {
    super("", ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_DELETE)));
    setId("closeTextTable");
    setToolTipText(Messages.getString("TextTableView.6"));
}

From source file:org.eclipse.titan.log.viewer.views.text.table.FilterAction.java

License:Open Source License

public FilterAction(TextTableView textTableView) {
    super("Filter", ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_FILTER)));
    this.textTableView = textTableView;
    setId("filterTextTable");
}

From source file:org.eclipse.titan.log.viewer.views.text.table.SwitchToMscAction.java

License:Open Source License

public SwitchToMscAction(TextTableView textTableView) {
    super("", ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_VIEW)));
    this.textTableView = textTableView;
    setId("switchToMSC");
    setToolTipText("Switch to MSC view");
}

From source file:org.eclipse.triquetrum.workflow.editor.shapes.ptolemy.ImageDrawingStrategy.java

License:Open Source License

private ImageDescriptor buildImageDescriptor(ImageAttribute imageAttr) throws IllegalActionException {
    ImageDescriptor imgDescr = ImageDescriptor.createFromURL(imageAttr.source.asURL());
    double scale = ((DoubleToken) imageAttr.scale.getToken()).doubleValue();
    // Use GC.drawImage to scale which gives better result on Mac

    Image oldImg = imgDescr.createImage();
    int oldWidth = oldImg.getBounds().width;
    int oldHeight = oldImg.getBounds().height;
    int newWidth = (int) Math.round(oldWidth * (scale / 100));
    int newHeight = (int) Math.round(oldHeight * (scale / 100));
    Image newImg = new Image(Display.getCurrent(), newWidth, newHeight);

    GC gc = new GC(newImg);
    gc.drawImage(oldImg, 0, 0, oldWidth, oldHeight, 0, 0, newWidth, newHeight);

    ImageDescriptor result = ImageDescriptor.createFromImage(newImg);

    oldImg.dispose();//from  w ww.j a  va  2 s. c  o  m
    gc.dispose();
    return result;
}

From source file:org.eclipse.ui.internal.DefaultSaveable.java

License:Open Source License

public ImageDescriptor getImageDescriptor() {
    Image image = part.getTitleImage();
    if (image == null) {
        return null;
    }//  w  w w  .  java2 s .c om
    return ImageDescriptor.createFromImage(image);
}

From source file:org.eclipse.ui.internal.dialogs.cpd.CustomizePerspectiveDialog.java

License:Open Source License

private DynamicContributionItem createMenuEntry(DisplayItem parent,
        Map<IContributionItem, IContributionItem> findDynamics, DynamicContributionItem dynamicEntry,
        MMenuElement menuItem) {//from   w w  w. j  a v  a 2  s.  com
    String text = menuItem.getLocalizedLabel();
    if (text == null || text.length() == 0) {
        text = menuItem.getLabel();
    }
    if ((text != null && text.length() != 0) || (menuItem instanceof MHandledMenuItem)
            || menuItem.getWidget() != null) {
        IContributionItem contributionItem;
        if (menuItem instanceof MMenu) {
            contributionItem = menuMngrRenderer.getManager((MMenu) menuItem);
        } else {
            contributionItem = menuMngrRenderer.getContribution(menuItem);
        }
        if (contributionItem == null) {
            return dynamicEntry;
        }
        if (dynamicEntry != null && contributionItem.equals(dynamicEntry.getIContributionItem())) {
            // If the last item added is the item meant to go before the
            // given dynamic entry, add the dynamic entry so it is in
            // the correct order.
            dynamicEntry.addCurrentItem((MenuItem) menuItem.getWidget());
            // TODO: might not work
        } else {
            ImageDescriptor iconDescriptor = null;
            String iconURI = menuItem.getIconURI();
            if (iconURI != null && iconURI.length() > 0) {
                iconDescriptor = resUtils.imageDescriptorFromURI(URI.createURI(iconURI));
            }

            if (menuItem.getWidget() instanceof MenuItem) {
                MenuItem item = (MenuItem) menuItem.getWidget();
                if (text == null) {
                    if ("".equals(item.getText())) { //$NON-NLS-1$
                        return dynamicEntry;
                    }
                    text = item.getText();
                }
                if (iconDescriptor == null) {
                    Image image = item.getImage();
                    if (image != null) {
                        iconDescriptor = ImageDescriptor.createFromImage(image);
                    }
                }
            } else if (menuItem instanceof MHandledMenuItem) {
                MHandledMenuItem hmi = (MHandledMenuItem) menuItem;
                final String i18nLabel = hmi.getLocalizedLabel();
                if (i18nLabel != null) {
                    text = i18nLabel;
                } else if (hmi.getWbCommand() != null) {
                    try {
                        text = hmi.getWbCommand().getName();
                    } catch (NotDefinedException e) {
                        // we'll just ignore a failure
                    }
                }
            }
            DisplayItem menuEntry = new DisplayItem(text, contributionItem);

            if (iconDescriptor != null) {
                menuEntry.setImageDescriptor(iconDescriptor);
            }
            menuEntry.setActionSet(idToActionSet.get(getActionSetID(menuItem)));
            parent.addChild(menuEntry);

            if (ActionFactory.NEW.getId().equals(contributionItem.getId())) {
                initializeNewWizardsMenu(menuEntry);
                wizards = menuEntry;
            } else if (SHORTCUT_CONTRIBUTION_ITEM_ID_OPEN_PERSPECTIVE.equals(contributionItem.getId())) {
                initializePerspectivesMenu(menuEntry);
                perspectives = menuEntry;
            } else if (SHORTCUT_CONTRIBUTION_ITEM_ID_SHOW_VIEW.equals(contributionItem.getId())) {
                initializeViewsMenu(menuEntry);
                views = menuEntry;
            } else {
                if (menuItem instanceof MMenu) {// TODO:menuItem any
                    // other instance
                    createMenuEntries((MMenu) menuItem, menuEntry);
                }
            }

            if (menuEntry.getChildren().isEmpty()) {
                menuEntry.setCheckState(getMenuItemIsVisible(menuEntry));
            }

            if (iconDescriptor == null) {
                if (parent.getParent() == null) {
                    menuEntry.setImageDescriptor(menuImageDescriptor);
                } else if (menuEntry.getChildrenCount() > 0) {
                    menuEntry.setImageDescriptor(submenuImageDescriptor);
                }
            }
        }
        if (findDynamics.containsKey(contributionItem)) {
            IContributionItem item = findDynamics.get(contributionItem);
            dynamicEntry = new DynamicContributionItem(item);
            dynamicEntry.setCheckState(getMenuItemIsVisible(dynamicEntry));
            dynamicEntry.setActionSet(idToActionSet.get(getActionSetID(contributionItem)));
            parent.addChild(dynamicEntry);
        } else {
            return dynamicEntry;
        }
    } else if (OpaqueElementUtil.isOpaqueMenuItem(menuItem)) {
        IContributionItem contributionItem = menuMngrRenderer.getContribution(menuItem);
        if (contributionItem instanceof ActionContributionItem) {
            final IAction action = ((ActionContributionItem) contributionItem).getAction();
            DisplayItem menuEntry = new DisplayItem(action.getText(), contributionItem);
            menuEntry.setImageDescriptor(action.getImageDescriptor());
            menuEntry.setActionSet(idToActionSet.get(getActionSetID(contributionItem)));
            parent.addChild(menuEntry);
            if (menuEntry.getChildren().isEmpty()) {
                menuEntry.setCheckState(getMenuItemIsVisible(menuEntry));
            }
        }
    } else {
        return dynamicEntry;
    }
    return dynamicEntry;
}