Java Code Examples for org.eclipse.jface.resource.JFaceResources#getImageRegistry()

The following examples show how to use org.eclipse.jface.resource.JFaceResources#getImageRegistry() . 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: UIHelper.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This is a convenience method to get an imgIcon from a URL.
 * 
 * @param bundle
 *            The target bundle
 * @param sPluginRelativePath
 *            The URL for the imgIcon.
 * @param force
 *            If True, still returns a dummy image if the path cannot be
 *            loaded.
 * @return The imgIcon represented by the given URL.
 * 
 * @see #setImageCached(boolean )
 */
public static Image getImage( Bundle bundle, String sPluginRelativePath,
		boolean force )
{
	ImageRegistry registry = JFaceResources.getImageRegistry( );

	String imgKey = sPluginRelativePath;
	if ( bundle != null )
	{
		imgKey = bundle.getSymbolicName( ) + ":" + sPluginRelativePath; //$NON-NLS-1$
	}

	Image image = registry.get( imgKey );
	if ( image == null )
	{
		image = createImage( bundle, sPluginRelativePath, force );
		if ( image != null )
		{
			registry.put( imgKey, image );
		}
	}
	return image;
}
 
Example 2
Source File: LifeCycleHook.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
private static void initializeImage(final String name, final String path) {
	final ImageRegistry imageRegistry = JFaceResources.getImageRegistry();
	if (imageRegistry.get(name) == null) {
		URL imageClockUrl = FileLocator.find(Activator.getDefault().getBundle(), new Path(path), null);
		if (imageClockUrl != null) {
			imageRegistry.put(name, ImageDescriptor.createFromURL(imageClockUrl));
		}
	}
}
 
Example 3
Source File: PlatformImage.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the image for attribute and platform id. Image is cached by {@link JFaceResources}
 * {@link ImageRegistry}
 * 
 * @param attribute
 * @param id
 * @return
 */
public static Image getImageFor(String attribute, String id){
	String key = IMAGE_REG_BASE +attribute+id;
	ImageRegistry imageRegistry = JFaceResources.getImageRegistry();
	Image image = imageRegistry.get(key);
	if(image == null ){
		ImageDescriptor desc = getIconFor(attribute, id);
		if(desc == null ) return null;
		imageRegistry.put(key, getIconFor(attribute, id));
		image = imageRegistry.get(key);
	}
	return image;
}
 
Example 4
Source File: CrosstabUIHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This is a convenience method to get an imgIcon from a URL.
 * 
 * @param sPluginRelativePath
 *            The URL for the imgIcon.
 * @return The imgIcon represented by the given URL.
 * @see #setImageCached( boolean )
 */
public static Image getImage( String sPluginRelativePath )
{
	ImageRegistry registry = JFaceResources.getImageRegistry( );
	Image image = registry.get( sPluginRelativePath );
	if ( image == null )
	{
		image = createImage( sPluginRelativePath );
		registry.put( sPluginRelativePath, image );
	}
	return image;
}
 
Example 5
Source File: UIHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This is a convenience method to get an imgIcon from a URL.
 * 
 * @param sPluginRelativePath
 *            The URL for the imgIcon.
 * @return The imgIcon represented by the given URL.
 * @see #setImageCached( boolean )
 */
public static Image getImage( String sPluginRelativePath )
{
	ImageRegistry registry = JFaceResources.getImageRegistry( );
	Image image = registry.get( sPluginRelativePath );
	if ( image == null )
	{
		image = createImage( sPluginRelativePath );
		registry.put( sPluginRelativePath, image );
	}
	return image;
}
 
Example 6
Source File: UIHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This is a convenience method to get an imgIcon from a URL.
 * 
 * @param sPluginRelativePath
 *            The URL for the imgIcon.
 * @return The imgIcon represented by the given URL.
 * @see #setImageCached( boolean )
 */
public static ImageDescriptor getImageDescriptor( String sPluginRelativePath )
{
	ImageRegistry registry = JFaceResources.getImageRegistry( );
	ImageDescriptor image = registry.getDescriptor( sPluginRelativePath );
	if ( image == null )
	{
		registry.put( sPluginRelativePath,
				createImage( sPluginRelativePath ) );
		image = registry.getDescriptor( sPluginRelativePath );
	}
	return image;
}
 
Example 7
Source File: UIHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This is a convenience method to get an imgIcon from a URL.
 * 
 * @param sPluginRelativePath
 *            The URL for the imgIcon.
 * @return The imgIcon represented by the given URL.
 * @see #setImageCached( boolean )
 */
public static Image getImage( String sPluginRelativePath )
{
	ImageRegistry registry = JFaceResources.getImageRegistry( );
	String resourcePath = ChartUIPlugin.ID + "/" + sPluginRelativePath; //$NON-NLS-1$
	Image image = registry.get( resourcePath );
	if ( image == null )
	{
		image = createImage( sPluginRelativePath );
		registry.put( resourcePath, image );
	}
	return image;
}
 
Example 8
Source File: UIHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This is a convenience method to get an imgIcon from a URL.
 * 
 * @param sPluginRelativePath
 *            The URL for the imgIcon.
 * @return The imgIcon represented by the given URL.
 * @throws IOException
 * @see #setImageCached(boolean )
 */
public static Image getImage( String sPluginRelativePath )
		throws IOException
{
	ImageRegistry registry = JFaceResources.getImageRegistry( );
	Image image = registry.get( sPluginRelativePath );
	if ( image == null )
	{
		image = createImage( sPluginRelativePath );
		registry.put( sPluginRelativePath, image );
	}
	return image;
}
 
Example 9
Source File: UIHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This is a convenience method to get an imgIcon from a URL.
 * 
 * @param sPluginRelativePath
 *            The URL for the imgIcon.
 * @return The imgIcon represented by the given URL.
 * @see #setImageCached( boolean )
 */
public static Image getImage( String sPluginRelativePath )
{
	ImageRegistry registry = JFaceResources.getImageRegistry( );
	Image image = registry.get( sPluginRelativePath );
	if ( image == null )
	{
		image = createImage( sPluginRelativePath );
		registry.put( sPluginRelativePath, image );
	}
	return image;
}
 
Example 10
Source File: UIHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static Image getImage( String imgKey, ImageDescriptor descriptor )
{
	ImageRegistry registry = JFaceResources.getImageRegistry( );
	Image image = registry.get( imgKey );
	if ( image == null )
	{
		image = descriptor.createImage( );
		if ( image != null )
		{
			registry.put( imgKey, image );
		}
	}
	return image;
}
 
Example 11
Source File: UIHelper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This is a convenience method to get an imgIcon from a URL.
 * 
 * @param sPluginRelativePath
 *            The URL for the imgIcon.
 * @return The imgIcon represented by the given URL.
 * @see #setImageCached( boolean )
 */
public static Image getImage( String sPluginRelativePath )
{
	ImageRegistry registry = JFaceResources.getImageRegistry( );
	String resourcePath = CoreUIPlugin.ID + "/" + sPluginRelativePath; //$NON-NLS-1$
	Image image = registry.get( resourcePath );
	if ( image == null )
	{
		image = createImage( sPluginRelativePath );
		registry.put( resourcePath, image );
	}
	return image;
}
 
Example 12
Source File: TypeScriptImagesRegistry.java    From typescript.java with MIT License 4 votes vote down vote up
private static void registerImageDescriptor(String key, ImageDescriptor descriptor) {
	ImageRegistry imageRegistry = JFaceResources.getImageRegistry();
	imageRegistry.put(key, descriptor);
}
 
Example 13
Source File: CheckboxCellContentProvider.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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.
 * 
 * @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;
}
 
Example 14
Source File: TypeScriptImagesRegistry.java    From typescript.java with MIT License 2 votes vote down vote up
/**
 * Returns the image from the image registry with the given key.
 * 
 * @param key
 *            of the image
 * @return the image from the image registry with the given key.
 */
public static Image getImage(String key) {
	ImageRegistry imageRegistry = JFaceResources.getImageRegistry();
	return imageRegistry.get(key);
}
 
Example 15
Source File: TypeScriptImagesRegistry.java    From typescript.java with MIT License 2 votes vote down vote up
/**
 * Returns the image descriptor from the image registry with the given key.
 * 
 * @param key
 *            of the image
 * @return the image descriptor from the image registry with the given key.
 */
public static ImageDescriptor getImageDescriptor(String key) {
	ImageRegistry imageRegistry = JFaceResources.getImageRegistry();
	return imageRegistry.getDescriptor(key);
}