List of usage examples for org.eclipse.jface.resource ImageDescriptor createFromImage
public static ImageDescriptor createFromImage(Image img)
From source file:nexcore.tool.uml.ui.realization.sequencediagram.editor.palette.SequenceDiagramPaletteFactory.java
License:Open Source License
/** * // w w w . jav a 2 s . c o m * * @param nameKey * @param messageKey * @param objectTemlateType * @param objectType * @param imageName * @param messageSort * @param interactionOperatorKind * @return CreationToolEntry */ @SuppressWarnings("unchecked") private static CreationToolEntry createToolEntryForSequenceDiagram(String nameKey, String messageKey, Class objectTemlateType, Class objectType, String imageName, MessageSort messageSort, InteractionOperatorKind interactionOperatorKind, String operandType) { ImageDescriptor largeImage = ImageDescriptor .createFromImage(IConstantImageRegistry.eInstance.getLargeIcon(imageName)); ImageDescriptor smallImage = ImageDescriptor .createFromImage(IConstantImageRegistry.eInstance.getSmallIcon(imageName)); CreationToolEntry toolEntry; ModelCreatorOfSequenceDiagram creationFactory; if (messageSort == null) { if (interactionOperatorKind == null) { creationFactory = new ModelCreatorOfSequenceDiagram(objectType); } else { creationFactory = new ModelCreatorOfSequenceDiagram(objectType, interactionOperatorKind, operandType); } } else { creationFactory = new ModelCreatorOfSequenceDiagram(objectType, messageSort); } if (null == objectTemlateType) { toolEntry = new ConnectionCreationToolEntry(nameKey, messageKey, creationFactory, smallImage, largeImage); toolEntry.setToolClass(MessageCreationToolForSequenceDiagramRelationship.class); } else if (org.eclipse.uml2.uml.Lifeline.class == objectTemlateType) { toolEntry = new CombinedTemplateCreationEntry(nameKey, messageKey, objectTemlateType, creationFactory, smallImage, largeImage); toolEntry.setToolClass(LifeLineCreationToolWithAdditionalInformation.class); } else { toolEntry = new CombinedTemplateCreationEntry(nameKey, messageKey, objectTemlateType, creationFactory, smallImage, largeImage); } return toolEntry; }
From source file:org.apertium.api.translate.model.MTParticipantAdapterFactory.java
License:Open Source License
public MTParticipantAdapterFactory() { /**//from ww w .ja va2 s.c o m * Participants adapter. */ participantAdapter = new IWorkbenchAdapter() { public Object[] getChildren(Object o) { return new Object[0]; // No child } public ImageDescriptor getImageDescriptor(Object object) { IParticipant participant = (IParticipant) object; Image im1 = null, im2 = null; if (Role.MODERATOR.equals(participant.getRole())) { if (participant.hasSpecialPrivilege(ParticipantSpecialPrivileges.SCRIBE) && participant.hasSpecialPrivilege(ParticipantSpecialPrivileges.VOTER)) { im1 = UiPlugin.getDefault() .getImageDescriptor(IImageResourcesMT.ICON_MODERATOR_SCRIBE_VOTER).createImage(); im2 = getFlag(participant); return concatImage(im1, im2); } else if (participant.hasSpecialPrivilege(ParticipantSpecialPrivileges.SCRIBE)) { im1 = UiPlugin.getDefault().getImageDescriptor(IImageResourcesMT.ICON_MODERATOR_SCRIBE) .createImage(); im2 = getFlag(participant); return concatImage(im1, im2); } else if (participant.hasSpecialPrivilege(ParticipantSpecialPrivileges.VOTER)) { im1 = UiPlugin.getDefault().getImageDescriptor(IImageResourcesMT.ICON_MODERATOR_VOTER) .createImage(); im2 = getFlag(participant); return concatImage(im1, im2); } im1 = UiPlugin.getDefault().getImageDescriptor(IImageResourcesMT.ICON_USER_MODERATOR) .createImage(); im2 = getFlag(participant); return concatImage(im1, im2); } else if (Status.JOINED.equals(participant.getStatus())) { if (participant.hasSpecialPrivilege(ParticipantSpecialPrivileges.SCRIBE) && participant.hasSpecialPrivilege(ParticipantSpecialPrivileges.VOTER)) { im1 = UiPlugin.getDefault().getImageDescriptor(IImageResourcesMT.ICON_SCRIBE_VOTER) .createImage(); im2 = getFlag(participant); return concatImage(im1, im2); } else if (participant.hasSpecialPrivilege(ParticipantSpecialPrivileges.SCRIBE)) { im1 = UiPlugin.getDefault().getImageDescriptor(IImageResourcesMT.ICON_SCRIBE).createImage(); im2 = getFlag(participant); return concatImage(im1, im2); } else if (participant.hasSpecialPrivilege(ParticipantSpecialPrivileges.VOTER)) { im1 = UiPlugin.getDefault().getImageDescriptor(IImageResourcesMT.ICON_VOTER).createImage(); im2 = getFlag(participant); return concatImage(im1, im2); } im1 = UiPlugin.getDefault().getImageDescriptor(IImageResourcesMT.ICON_USER_ACTIVE) .createImage(); im2 = getFlag(participant); return concatImage(im1, im2); } else if (Status.FROZEN.equals(participant.getStatus())) return UiPlugin.getDefault().getImageDescriptor(IImageResourcesMT.ICON_USER_FROZEN); else // NOT_JOINED otherwise return UiPlugin.getDefault().getImageDescriptor(IImageResourcesMT.ICON_USER_OFFLINE); } public Image getFlag(IParticipant participant) { UserLanguages lang = UserLanguages.getInstance(); HashMap<String, String> languages = lang.get_languages(); Image im2 = null; if ((languages.containsKey(participant.getId())) && (languages.get(participant.getId()) != null)) { im2 = new Image(null, 22, 10); String value = languages.get(participant.getId()); if (value.equalsIgnoreCase("ar")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_AR) .createImage(); } else if (value.equalsIgnoreCase("bn")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_BN) .createImage(); } else if (value.equalsIgnoreCase("en")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_EN) .createImage(); } else if (value.equalsIgnoreCase("es")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_ES) .createImage(); } else if (value.equalsIgnoreCase("fr")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_FR) .createImage(); } else if (value.equalsIgnoreCase("de")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_GE) .createImage(); } else if (value.equalsIgnoreCase("hi")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_HI) .createImage(); } else if (value.equalsIgnoreCase("it")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_IT) .createImage(); } else if (value.equalsIgnoreCase("ja")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_JA) .createImage(); } else if (value.equalsIgnoreCase("pl")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_PL) .createImage(); } else if (value.equalsIgnoreCase("pt")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_PT) .createImage(); } else if (value.equalsIgnoreCase("ru")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_RU) .createImage(); } else if (value.equalsIgnoreCase("th")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_TH) .createImage(); } else if (value.equalsIgnoreCase("tr")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_TR) .createImage(); } else if (value.equalsIgnoreCase("zh")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_ZH) .createImage(); } else if (value.equalsIgnoreCase("ko")) { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_KO) .createImage(); } else { im2 = TranslatePlugin.getDefault().getImageDescriptor(IImageResourcesMT.FLAG_DEF) .createImage(); } } return im2; } public ImageDescriptor concatImage(Image im1, Image im2) { if (im2 == null) { return ImageDescriptor.createFromImage(im1); } else { Image bigImage = new Image(null, im1.getImageData().width + im2.getImageData().width, im1.getImageData().height); GC gc = new GC(bigImage); gc.drawImage(im1, 0, 0); gc.drawImage(im2, im1.getImageData().width, 0); gc.dispose(); return ImageDescriptor.createFromImage(bigImage); } } public String getLabel(Object o) { IParticipant p = (IParticipant) o; if (p.getPersonalStatus() != null && !p.getPersonalStatus().equals("")) return String.format("%s (%s)", p.getNickName(), p.getPersonalStatus()); else return p.getNickName(); } public Object getParent(Object o) { return null; } }; }
From source file:org.aw20.mongoworkbench.eclipse.view.MAbstractView.java
License:Open Source License
protected void setActionImage(Action action, String imageFileName) { Image image = MSwtUtil.getImage(parent.getShell().getDisplay(), imageFileName); action.setImageDescriptor(ImageDescriptor.createFromImage(image)); }
From source file:org.caleydo.core.gui.OpenOnlineHelpAction.java
License:Open Source License
public OpenOnlineHelpAction(String url, boolean useSmallIcon) { this.url = url; setText(LABEL);//from w w w.ja v a2 s . c o m setToolTipText(LABEL); setImageDescriptor(ImageDescriptor.createFromImage(useSmallIcon ? GeneralManager.get().getResourceLoader().getImage(PlatformUI.getWorkbench().getDisplay(), ICON) : JFaceResources.getImage(Dialog.DLG_IMG_HELP))); setChecked(false); }
From source file:org.caleydo.data.loader.ResourceLoader.java
License:Open Source License
public final ImageDescriptor getImageDescriptor(Display display, String res) { return ImageDescriptor.createFromImage(getImage(display, res)); }
From source file:org.csstudio.dal.ui.util.CustomMediaFactory.java
License:Open Source License
/** * Load the <code>Image</code> from the given path in the given plugin. * Usually, this is the image found via the the given plug-in relative path. * But this implementation also supports a hack for testing: If no plugin is * running, because for example this is an SWT-only test, the path is used * as is, i.e. relative to the current directory. * * @param plugin/*w w w .j a v a2 s . c o m*/ * The plugin that contains the requested image. * @param pluginId * The id of the plugin. * @param relativePath * The image's relative path to the root of the plugin. * @return The <code>Image</code> from the given path in the given plugin. */ public Image getImageFromPlugin(final Plugin plugin, final String pluginId, final String relativePath) { String key = pluginId + "." + relativePath; //$NON-NLS-1$ // does image exist if (_imageRegistry.get(key) == null) { if (plugin != null) { ImageDescriptor descr = AbstractUIPlugin.imageDescriptorFromPlugin(pluginId, relativePath); _imageRegistry.put(key, descr); } else { final Display display = Display.getCurrent(); final Image img = new Image(display, relativePath); _imageRegistry.put(key, ImageDescriptor.createFromImage(img)); } } return _imageRegistry.get(key); }
From source file:org.csstudio.opibuilder.util.OPIColor.java
License:Open Source License
@Override public <T> T getAdapter(Class<T> adapter) { if (adapter == IWorkbenchAdapter.class) return adapter.cast(new IWorkbenchAdapter() { @Override/* w w w . j ava2s.com*/ public Object getParent(Object o) { return null; } @Override public String getLabel(Object o) { return getColorName(); } @Override public ImageDescriptor getImageDescriptor(Object object) { Image image = imageRegistry.get(getID()); if (image == null) { image = createIcon(getRGBValue()); if (imageCount >= MAX_IMG_COUNT) { imageRegistry.dispose(); imageCount = 0; } imageRegistry.put(getID(), image); imageCount++; } return ImageDescriptor.createFromImage(image); } @Override public Object[] getChildren(Object o) { return new Object[0]; } }); return null; }
From source file:org.csstudio.swt.chart.Activator.java
License:Open Source License
/** Returns an image descriptor for the image file. * <p>/*from w ww . j a va 2s.co m*/ * Usually, this is the image found via the the given plug-in * relative path. * But this implementation also supports a hack for testing: * If no plugin is running, because for example this is an SWT-only * test, the path is used as is, i.e. relative to the current * directory. * * @param path the path * @return the image descriptor */ @SuppressWarnings("nls") public static ImageDescriptor getImageDescriptor(String path) { // If the plugin is running, get descriptor from the bundle if (plugin != null) return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path); // ... otherwise, this is an SWT-only test without the plugin: try { final Display display = Display.getCurrent(); final Image img = new Image(display, path); return ImageDescriptor.createFromImage(img); } catch (Exception e) { getLogger().log(Level.SEVERE, "Cannot load image '" + path + "'", e); } return null; }
From source file:org.csstudio.swt.rtplot.Activator.java
License:Open Source License
public static ImageDescriptor getIcon(final String base_name) { String path = "icons/" + base_name + ".png"; try {//from w ww .ja v a 2s. c o m final Bundle bundle = Platform.getBundle(ID); final URL image_url = bundle.getEntry(path); return ImageDescriptor.createFromURL(image_url); } catch (Throwable ex) { // ... otherwise, this is an SWT-only test without the plugin. // Might be run within the org.csstudio.ui.rtplot plugin directory // or the org.csstudio.ui.rtplot.test fragment dir, so // always go back to the plugin dir. path = "../" + ID + "/" + path; try { final Display display = Display.getCurrent(); final Image img = new Image(display, path); return ImageDescriptor.createFromImage(img); } catch (Exception e) { logger.log(Level.SEVERE, "Cannot load image '" + path + "'", e); } } return null; }
From source file:org.cubictest.ui.gef.view.CubicTestImageRegistry.java
License:Open Source License
public static ImageDescriptor getNotDescriptor(String key) { return ImageDescriptor.createFromImage(getNot(key)); }