org.eclipse.jface.resource.ImageDescriptor Java Examples

The following examples show how to use org.eclipse.jface.resource.ImageDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SWTUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static Image getImage(String bundleSymbolicName, String path, ImageDescriptor id)
{
	String computedName = bundleSymbolicName + path;
	Image image = JFaceResources.getImage(computedName);
	if (image != null)
	{
		return image;
	}

	if (id == null)
	{
		id = AbstractUIPlugin.imageDescriptorFromPlugin(bundleSymbolicName, path);
	}

	if (id != null)
	{
		JFaceResources.getImageRegistry().put(computedName, id);
		return JFaceResources.getImage(computedName);
	}
	return null;
}
 
Example #2
Source File: SARLImages.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies the image descriptor for the given element.
 *
 * @param type the type of the SARL element, or {@code null} if unknown.
 * @param isInner indicates if the element is inner.
 * @param isInInterfaceOrAnnotation indicates if the element is defined inside an interface or an annotation.
 * @param flags the adornments.
 * @param useLightIcons indicates of light icons should be used.
 * @return the image descriptor.
 */
public ImageDescriptor getTypeImageDescriptor(
		SarlElementType type,
		boolean isInner, boolean isInInterfaceOrAnnotation, int flags, boolean useLightIcons) {
	final ImageDescriptor desc;
	if (type != null) {
		final StringBuilder iconName = new StringBuilder(IMAGE_NAMES[type.ordinal()]);
		if (Flags.isPackageDefault(flags)) {
			iconName.append("_package"); //$NON-NLS-1$
		} else if (Flags.isProtected(flags)) {
			iconName.append("_protected"); //$NON-NLS-1$
		} else if (Flags.isPrivate(flags)) {
			iconName.append("_private"); //$NON-NLS-1$
		}
		iconName.append(".png"); //$NON-NLS-1$
		desc = this.imageHelper.getImageDescriptor(iconName.toString());
	} else {
		desc = JavaElementImageProvider.getTypeImageDescriptor(isInner, isInInterfaceOrAnnotation, flags, useLightIcons);
	}
	return desc;
}
 
Example #3
Source File: NewAsyncRemoteServiceInterfaceCreationWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public NewAsyncRemoteServiceInterfaceCreationWizardPage(
    ITypeBinding syncTypeBinding) {
  super();
  this.syncTypeBinding = syncTypeBinding;
  syncTypeDialogField = new StringButtonDialogField(
      new IStringButtonAdapter() {
        public void changeControlPressed(DialogField field) {
          // Purposely ignored
        }
      });
  syncTypeDialogField.setButtonLabel("Browse...");
  syncTypeDialogField.setLabelText("Synchronous type:");
  syncTypeDialogField.setEnabled(false);
  syncTypeDialogField.setText(syncTypeBinding.getQualifiedName());
  ImageDescriptor imageDescriptor = GWTPlugin.getDefault().getImageRegistry().getDescriptor(
      GWTImages.NEW_ASYNC_INTERFACE_LARGE);
  setImageDescriptor(imageDescriptor);
  setDescription("Create a new asynchronous remote service interface");
}
 
Example #4
Source File: LivingApplicationPlugin.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static Image getImage(final String imageName) {
    final ImageRegistry reg = getDefault().getImageRegistry();

    Image result = reg.get(imageName);

    if (result != null && !result.isDisposed()) {//prevent from bad dispose
        return result;
    }

    final ImageDescriptor descriptor = ImageDescriptor.createFromURL(getDefault().getBundle().getResource(imageName));
    if (descriptor != null) {
        result = descriptor.createImage();
    }

    reg.remove(imageName);
    if (result != null) {
        reg.put(imageName, result);
    }

    return result;
}
 
Example #5
Source File: CopiedWorkbenchLabelProvider.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Image getImage(Object element) {
    //obtain the base image by querying the element
    IWorkbenchAdapter adapter = getAdapter(element);
    if (adapter == null) {
        return null;
    }
    ImageDescriptor descriptor = adapter.getImageDescriptor(element);
    if (descriptor == null) {
        return null;
    }

    //add any annotations to the image descriptor
    descriptor = decorateImage(descriptor, element);

    try {
        return resourceManager.createImage(descriptor);
    } catch (Exception e) {
        Log.log(e);
        return null;
    }
}
 
Example #6
Source File: BindingLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ImageDescriptor getTypeImageDescriptor(boolean inner, ITypeBinding binding, int flags) {
	if (binding.isEnum())
		return JavaPluginImages.DESC_OBJS_ENUM;
	else if (binding.isAnnotation())
		return JavaPluginImages.DESC_OBJS_ANNOTATION;
	else if (binding.isInterface()) {
		if ((flags & JavaElementImageProvider.LIGHT_TYPE_ICONS) != 0)
			return JavaPluginImages.DESC_OBJS_INTERFACEALT;
		if (inner)
			return getInnerInterfaceImageDescriptor(binding.getModifiers());
		return getInterfaceImageDescriptor(binding.getModifiers());
	} else if (binding.isClass()) {
		if ((flags & JavaElementImageProvider.LIGHT_TYPE_ICONS) != 0)
			return JavaPluginImages.DESC_OBJS_CLASSALT;
		if (inner)
			return getInnerClassImageDescriptor(binding.getModifiers());
		return getClassImageDescriptor(binding.getModifiers());
	} else if (binding.isTypeVariable()) {
		return JavaPluginImages.DESC_OBJS_TYPEVARIABLE;
	}
	// primitive type, wildcard
	return null;
}
 
Example #7
Source File: XBookmarksPlugin.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param imgid IMG_* constant
 * @return Image 
 */
public Image getCachedBookmarkImage(int bookmarkNum) { // 0..9
    if (hmCachedImages == null || bookmarkNum < 0 || bookmarkNum > 9) { 
        return null; // hbz
    }
    Integer key = new Integer(IMGID_BOOKMARKS + bookmarkNum);
    Image img = hmCachedImages.get(key);
    if (img == null) {
        IPath path = new Path(String.format(IMG_SOURCES_BOOKMARKS, bookmarkNum)); 
        URL   url  = FileLocator.find(XBookmarksPlugin.getDefault().getBundle(), path, null);
        if (url != null) {
            img = ImageDescriptor.createFromURL(url).createImage();
        }
        if (img != null) {
            hmCachedImages.put(key, img);
        }
    }
    return img;
}
 
Example #8
Source File: SheetLabelProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public Image getImage(Object element) {
	element = unwrap(element);
	if (element instanceof IGraphicalEditPart) {
		EObject semanticElement = ((IGraphicalEditPart) element)
				.resolveSemanticElement();

		if (semanticElement == null) {
			// Default images
			View view = ((IGraphicalEditPart) element).getNotationView();
			String viewType = view.getType();
			if (ViewType.NOTE.equals(viewType)) {
				return SharedImages.get(SharedImages.IMG_NOTE);
			} else if (ViewType.TEXT.equals(viewType)) {
				return SharedImages.get(SharedImages.IMG_TEXT);
			}
		} else {
			// custom images
			IElementType elementType = ElementTypeRegistry.getInstance()
					.getElementType(semanticElement);
			Image image = DiagramActivator.getDefault().getImageRegistry()
					.get(elementType.getIconURL().toString());
			if (image == null) {
				ImageDescriptor desc = ImageDescriptor
						.createFromURL(elementType.getIconURL());
				DiagramActivator
						.getDefault()
						.getImageRegistry()
						.put(elementType.getIconURL().toString(),
								desc.createImage());
				return DiagramActivator.getDefault().getImageRegistry()
						.get(elementType.getIconURL().toString());
			}
			return image;

		}
	}
	return null;
}
 
Example #9
Source File: AbstractSarlUiTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Assert the given image descriptor is for an image in a bundle.
 *
 * @param filename the name of the image file.
 * @param desc the image descriptor to test.
 */
protected static void assertBundleImage(String filename, ImageDescriptor desc) {
	assertNotNull(desc);
	String s = desc.toString();
	String regex = Pattern.quote("URLImageDescriptor(bundleentry://") //$NON-NLS-1$
			+ "[^/]+" //$NON-NLS-1$
			+ Pattern.quote("/icons/") //$NON-NLS-1$
			+ "([^/]+[/])*" //$NON-NLS-1$
			+ Pattern.quote(filename + ")"); //$NON-NLS-1$
	if (!Pattern.matches(regex, s)) {
		if (desc instanceof JavaElementImageDescriptor) {
			JavaElementImageDescriptor jeid = (JavaElementImageDescriptor) desc;
			try {
				Field field = JavaElementImageDescriptor.class.getDeclaredField("fBaseImage");
				boolean isAcc = field.isAccessible(); 
				field.setAccessible(true);
				try {
					ImageDescriptor id = (ImageDescriptor) field.get(jeid);
					s = id.toString();
					assertTrue("Invalid image: " + filename //$NON-NLS-1$
							+ ". Actual: " + s, Pattern.matches(regex, s)); //$NON-NLS-1$
				} finally {
					field.setAccessible(isAcc);
				}
			} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
				fail("Invalid background image descriptor: " + jeid.getClass().getName());
			}
		}
	}
}
 
Example #10
Source File: LangNavigatorLabelProvider.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public Image getBaseImage(Object element) {
	ImageDescriptor baseImage = getBaseImage_switcher().switchElement(element);
	if(baseImage != null) {
		return registry.get(baseImage);
	}
	
	if(element instanceof IResource) {
		IResource resource = (IResource) element;
		return registry.get(getWorkbenchImageDescriptor(resource));
	}
	return null;
}
 
Example #11
Source File: AbstractLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
protected ImageDescriptor convertToImageDescriptor(Object imageDescription) {
	if (imageDescription instanceof Image) {
		final Image image = (Image) imageDescription;
		return imageDescriptorHelper.getImageDescriptor(image);
	} else if (imageDescription instanceof ImageDescriptor) {
		return (ImageDescriptor) imageDescription;
	} else if (imageDescription instanceof String) {
		return imageDescriptorHelper.getImageDescriptor((String) imageDescription);
	}
	return null;
}
 
Example #12
Source File: GamlImageHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @see org.eclipse.xtext.ui.IImageHelper.IImageDescriptorHelper#getImageDescriptor(org.eclipse.swt.graphics.Image)
 */
@Override
public ImageDescriptor getImageDescriptor(final Image image) {
	for (final Map.Entry<ImageDescriptor, Image> entry : registry.entrySet()) {
		if (entry.getValue().equals(image)) { return entry.getKey(); }
	}
	final ImageDescriptor newDescriptor = ImageDescriptor.createFromImage(image);
	registry.put(newDescriptor, image);
	return newDescriptor;

}
 
Example #13
Source File: JSModelFormatter.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private Image addOverlay(Image base, ImageDescriptor overlay, int location, String key)
{
	ImageRegistry reg = getImageRegistry();
	Image cached = reg.get(key);
	if (cached != null)
	{
		return cached;
	}

	DecorationOverlayIcon decorator = new DecorationOverlayIcon(base, overlay, location);
	Image result = decorator.createImage();
	reg.put(key, result);
	return result;
}
 
Example #14
Source File: ExportRubyAction.java    From http4e with Apache License 2.0 5 votes vote down vote up
public ExportRubyAction( ViewPart view) {
   this.view = view;
   fMenu = null;
   setToolTipText("Export call as Ruby");
   setImageDescriptor(ImageDescriptor.createFromImage(ResourceUtils.getImage(CoreConstants.PLUGIN_UI, CoreImages.RUBY)));
   setText("     Ruby");
}
 
Example #15
Source File: ObjectImageRenderer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ICellRenderer createPrintRenderer(Printer printer) {
    ObjectImageRenderer renderer = new ObjectImageRenderer(printer);
    for (Object o : _keyMap.keySet()) {
        String key = _keyMap.get(o);
        ImageDescriptor imageDesc = getImageRegistry().getDescriptor(key);
        renderer.addObjectImageDescriptorMapping(o, key, imageDesc);
    }
    return renderer;
}
 
Example #16
Source File: JSONLabelProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
ImageDescriptor image(NameValuePair pair) {
	final JSONValue value = pair.getValue();
	// display an object/array icon for name-value pairs if their value are an array
	// or object.
	if (value instanceof JSONArray) {
		return this.image((JSONArray) value);
	} else if (value instanceof JSONObject) {
		return this.image((JSONObject) value);
	}

	return JSONImageDescriptorCache.ImageRef.JSON_VALUE_PAIR.asImageDescriptor().get();
}
 
Example #17
Source File: ExportVbAction.java    From http4e with Apache License 2.0 5 votes vote down vote up
public ExportVbAction( ViewPart view) {
   this.view = view;
   fMenu = null;
   setToolTipText("Export call as Visual Basic");
   setImageDescriptor(ImageDescriptor.createFromImage(ResourceUtils.getImage(CoreConstants.PLUGIN_UI, CoreImages.VB)));
   setText("     Visual Basic");
}
 
Example #18
Source File: PyGeneratorUiPlugin.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the image stored in the current Eclipse plugin.
 *
 * @param imagePath path of the image.
 * @return the image.
 */
public Image getImage(String imagePath) {
	final ImageDescriptor descriptor = getImageDescriptor(imagePath);
	if (descriptor == null) {
		return null;
	}
	return descriptor.createImage();
}
 
Example #19
Source File: WSO2PluginSampleExt.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public Image getImage(String iconLocation, String id, String isFromGit) {
	ImageDescriptor imageDescriptor = null;
	if (!Boolean.parseBoolean(isFromGit)) {
		if (iconLocation != null && !iconLocation.isEmpty()) {
			imageDescriptor =
			                  ImageDescriptor.createFromURL(FileLocator.find(Platform.getBundle(bundleID),
			                                                                 new Path(iconLocation), null));
		} else {
			imageDescriptor =
			                  ImageDescriptor.createFromURL(FileLocator.find(Platform.getBundle(Activator.PLUGIN_ID),
			                                                                 new Path("icons/plugin-icon.png"),
			                                                                 null));
		}
		return imageDescriptor.createImage();
	} else {
		try {
			String gitIconLoc =
			                    WSO2PluginListSelectionPage.tempCloneDir + File.separator + id + File.separator +
			                            "icons" + File.separator + iconLocation;
			imageDescriptor =
			                  ImageDescriptor.createFromURL(new URL(WSO2PluginConstants.FILE_PROTOCOL + gitIconLoc));
			return imageDescriptor.createImage();
		} catch (MalformedURLException e) {
			// log image cannot be found at location
			return null;
		}
	}
}
 
Example #20
Source File: CommonVoiceXMLBrowserTab.java    From JVoiceXML with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Image getImage() {
    try {
        if (icon != null) {
            return icon;
        }
        URL imageURL = new URL(
                "platform:/plugin/org.jvoicexml.eclipse.debug.ui/icons/cview16/VoiceXMLFile.gif"); //$NON-NLS-1$
        ImageDescriptor id = ImageDescriptor.createFromURL(imageURL);
        icon = id.createImage();
        return icon;
    } catch (Exception e) {
        return super.getImage();
    }
}
 
Example #21
Source File: BuildpathIndicatorLabelDecorator.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void decorate(Object element, IDecoration decoration) {
	ImageDescriptor overlay = getOverlay(element);
	if (overlay != null) {
		decoration.addOverlay(overlay, IDecoration.TOP_RIGHT);
	}
}
 
Example #22
Source File: Images.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static ImageDescriptor descriptor(Group group) {
	if (group == null)
		return null;
	ModelIcon icon = icon(group.type);
	if (icon == null)
		return Icon.FOLDER.descriptor();
	return ImageManager.descriptor(icon);
}
 
Example #23
Source File: ProblemsLabelDecorator.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void decorate(Object element, IDecoration decoration) {
	ImageDescriptor imageDescriptor= computeAdornmentFlags(element);
	if(imageDescriptor != null) {
		decoration.addOverlay(imageDescriptor);
	}
}
 
Example #24
Source File: PatchFileSelectionPage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public PatchFileSelectionPage(String pageName, String title, ImageDescriptor image, IStructuredSelection selection, HashMap statusMap) {
	super(pageName, title, image);
	this.statusMap = statusMap;
	Object[] selectedResources = selection.toArray();
	resources = new IResource[selectedResources.length];
	for (int i = 0; i < selectedResources.length; i++)
		resources[i] = (IResource)selectedResources[i];
	setPageComplete(false);
}
 
Example #25
Source File: ParameterGuesser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Variable(String qualifiedTypeName, String name, int variableType, boolean isAutoboxMatch, int positionScore, char[] triggerChars, ImageDescriptor descriptor) {
	this.qualifiedTypeName= qualifiedTypeName;
	this.name= name;
	this.variableType= variableType;
	this.positionScore= positionScore;
	this.triggerChars= triggerChars;
	this.descriptor= descriptor;
	this.isAutoboxingMatch= isAutoboxMatch;
	this.alreadyMatched= false;
}
 
Example #26
Source File: LangElementImageDescriptor.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static ImageDescriptor getProtectionDecoration_Small(EProtection protection) {
	if(protection == null)
		return null;
	
	switch (protection) {
	
	case PRIVATE: return LangImages.DESC_OVR_PRIVATE_SMALL;
	case PROTECTED: return LangImages.DESC_OVR_PROTECTED_SMALL;
	case PACKAGE: return LangImages.DESC_OVR_DEFAULT_SMALL;
	case PUBLIC:
		default: return null;
	}
}
 
Example #27
Source File: CallHierarchyImageDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ImageData getImageData(ImageDescriptor descriptor) {
	ImageData data= descriptor.getImageData(); // see bug 51965: getImageData can return null
	if (data == null) {
		data= DEFAULT_IMAGE_DATA;
		JavaPlugin.logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$
	}
	return data;
}
 
Example #28
Source File: JavaElementImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ImageDescriptor getInnerEnumImageDescriptor(boolean isInInterfaceOrAnnotation, int flags) {
	if (Flags.isPublic(flags) || isInInterfaceOrAnnotation)
		return JavaPluginImages.DESC_OBJS_ENUM;
	else if (Flags.isPrivate(flags))
		return JavaPluginImages.DESC_OBJS_ENUM_PRIVATE;
	else if (Flags.isProtected(flags))
		return JavaPluginImages.DESC_OBJS_ENUM_PROTECTED;
	else
		return JavaPluginImages.DESC_OBJS_ENUM_DEFAULT;
}
 
Example #29
Source File: Activator.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 提供一个图片文件对插件的相对路径,返回该图片被伸缩变换为16*16像素的描述信息。
 * @param path
 *            the path
 * @return the icon descriptor
 */
public static ImageDescriptor getIconDescriptor(String path) {
	ImageDescriptor image = getImageDescriptor(path);
	ImageData data = image.getImageData();
	data = data.scaledTo(16, 16);
	image = ImageDescriptor.createFromImageData(data);
	return image;
}
 
Example #30
Source File: XtextEditorErrorTickUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
public void scheduleUpdateEditor(final ImageDescriptor titleImageDescription) {
	Display display = PlatformUI.getWorkbench().getDisplay();
	display.asyncExec(new Runnable() {
		@Override
		public void run() {
			if (editor != null) {
				Image image = imageHelper.getImage(titleImageDescription);
				if (editor.getTitleImage() != image) {
					editor.updatedTitleImage(image);
				}
			}
		}
	});
}