Java Code Examples for org.eclipse.jface.resource.ImageRegistry#put()

The following examples show how to use org.eclipse.jface.resource.ImageRegistry#put() . 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: BasicSymbolProviderPreferencePage.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Image getImage(Object element) {
    if (element instanceof IMappingFile) {
        // Add binary/mapping icons to the image registry if needed
        ImageRegistry registry = Activator.getDefault().getImageRegistry();
        Image binImage = registry.get(BIN_ICON.toString());
        if (binImage == null) {
            registry.put(BIN_ICON.toString(), BIN_ICON);
            binImage = registry.get(BIN_ICON.toString());
        }
        Image txtImage = registry.get(TXT_ICON.toString());
        if (txtImage == null) {
            registry.put(TXT_ICON.toString(), TXT_ICON);
            txtImage = registry.get(TXT_ICON.toString());
        }

        return ((IMappingFile) element).isBinaryFile() ? binImage : txtImage;
    }

    return null;
}
 
Example 2
Source File: ScriptingUIPlugin.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the image on the specified path.
 * 
 * @param path
 *            the path to the image
 * @return Image the image object
 */
public static Image getImage(String path)
{
	ImageRegistry registry = getDefault().getImageRegistry();

	if (registry.get(path) == null)
	{
		ImageDescriptor id = getImageDescriptor(path);

		if (id != null)
		{
			registry.put(path, id);
		}
	}

	return registry.get(path);
}
 
Example 3
Source File: StaticHTMLPrviewPlugin.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void registerImage( ImageRegistry registry, String key,
		String fileName )
{
	try
	{
		IPath path = new Path( "icons/" + fileName ); //$NON-NLS-1$
		URL url = find( path );
		if ( url != null )
		{
			ImageDescriptor desc = ImageDescriptor.createFromURL( url );
			registry.put( key, desc );
		}
	}
	catch ( Exception e )
	{
	}
}
 
Example 4
Source File: SVNUIPlugin.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
protected void initializeImageRegistry(ImageRegistry reg) {
	super.initializeImageRegistry(reg);
	reg.put(ISVNUIConstants.IMG_PROPERTIES, getImageDescriptor(ISVNUIConstants.IMG_PROPERTIES));
	reg.put(ISVNUIConstants.IMG_FILEADD_PENDING, getImageDescriptor(ISVNUIConstants.IMG_FILEADD_PENDING));
	reg.put(ISVNUIConstants.IMG_SYNCPANE, getImageDescriptor(ISVNUIConstants.IMG_SYNCPANE));
	reg.put(ISVNUIConstants.IMG_FILEDELETE_PENDING, getImageDescriptor(ISVNUIConstants.IMG_FILEDELETE_PENDING));
	reg.put(ISVNUIConstants.IMG_FILEMODIFIED_PENDING, getImageDescriptor(ISVNUIConstants.IMG_FILEMODIFIED_PENDING));
	reg.put(ISVNUIConstants.IMG_FOLDERADD_PENDING, getImageDescriptor(ISVNUIConstants.IMG_FOLDERADD_PENDING));
	reg.put(ISVNUIConstants.IMG_FOLDERDELETE_PENDING, getImageDescriptor(ISVNUIConstants.IMG_FOLDERDELETE_PENDING));
	reg.put(ISVNUIConstants.IMG_FOLDERMODIFIED_PENDING, getImageDescriptor(ISVNUIConstants.IMG_FOLDERMODIFIED_PENDING));
	reg.put(ISVNUIConstants.IMG_FOLDER, getImageDescriptor(ISVNUIConstants.IMG_FOLDER));
	reg.put(ISVNUIConstants.IMG_AFFECTED_PATHS_COMPRESSED_MODE, getImageDescriptor(ISVNUIConstants.IMG_AFFECTED_PATHS_COMPRESSED_MODE));
	reg.put(ISVNUIConstants.IMG_AFFECTED_PATHS_FLAT_MODE, getImageDescriptor(ISVNUIConstants.IMG_AFFECTED_PATHS_FLAT_MODE));
	reg.put(ISVNUIConstants.IMG_AFFECTED_PATHS_TREE_MODE, getImageDescriptor(ISVNUIConstants.IMG_AFFECTED_PATHS_TREE_MODE));
	reg.put(ISVNUIConstants.IMG_UPDATE_ALL, getImageDescriptor(ISVNUIConstants.IMG_UPDATE_ALL));
	reg.put(ISVNUIConstants.IMG_COMMIT_ALL, getImageDescriptor(ISVNUIConstants.IMG_COMMIT_ALL));
	reg.put(ISVNUIConstants.IMG_PROPERTY_CONFLICTED, getImageDescriptor(ISVNUIConstants.IMG_PROPERTY_CONFLICTED));
}
 
Example 5
Source File: SVGPlugin.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * getImage
 * 
 * @param path
 * @return
 */
public static Image getImage(String path)
{
	ImageRegistry registry = plugin.getImageRegistry();
	Image image = registry.get(path);

	if (image == null)
	{
		ImageDescriptor id = getImageDescriptor(path);

		if (id != null)
		{
			registry.put(path, id);
			image = registry.get(path);
		}
	}

	return image;
}
 
Example 6
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 7
Source File: CamelDesignerPlugin.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
@Override
protected void initializeImageRegistry(ImageRegistry reg) {
    super.initializeImageRegistry(reg);
    reg.put(BEAN_WIZ_ICON, createImageDescriptor(BEAN_WIZ_ICON).createImage());

    reg.put(DEPEN_ICON, createImageDescriptor(DEPEN_ICON).createImage());
    reg.put(BUNDLE_CP_ICON, createImageDescriptor(BUNDLE_CP_ICON).createImage());
    reg.put(REQUIRE_BD_ICON, createImageDescriptor(REQUIRE_BD_ICON).createImage());
    reg.put(IMPORT_PKG_ICON, createImageDescriptor(IMPORT_PKG_ICON).createImage());
    reg.put(REFRESH_ICON, createImageDescriptor(REFRESH_ICON).createImage());
    reg.put(GRAY_REM_ICON, createImageDescriptor(GRAY_REM_ICON).createImage());
    reg.put(HIGHLIGHT_REM_ICON, createImageDescriptor(HIGHLIGHT_REM_ICON).createImage());
    reg.put(OPTIONAL_OVERLAY_ICON, createImageDescriptor(OPTIONAL_OVERLAY_ICON).createImage());
    reg.put(IMPORT_PACKAGE_OVERLAY_ICON, getOptionalOverlayIcon(getImage(IMPORT_PKG_ICON)));
    reg.put(REQUIRE_BUNDLE_OVERLAY_ICON, getOptionalOverlayIcon(getImage(REQUIRE_BD_ICON)));
}
 
Example 8
Source File: Pics.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 AbstractUIPlugin plugin) {
    if (plugin == null) {
        return null;
    }
    final ImageRegistry reg = plugin.getImageRegistry();

    Image result = reg.get(imageName);

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

    final ImageDescriptor descriptor = getImageDescriptor(imageName, plugin);
    if (descriptor != null) {
        result = descriptor.createImage();
    }

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

    return result;
}
 
Example 9
Source File: CorrosionPlugin.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
private final static void declareRegistryImage(ImageRegistry reg, String image) {
	ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
	URL url = null;
	Bundle bundle = plugin.getBundle();
	if (bundle != null) {
		url = FileLocator.find(bundle, new Path(image), null);
		if (url != null) {
			desc = ImageDescriptor.createFromURL(url);
		}
	}
	reg.put(image, desc);
}
 
Example 10
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 11
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 12
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 13
Source File: CrossflowNavigatorLabelProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private Image getImage(String key, IElementType elementType) {
	ImageRegistry imageRegistry = CrossflowDiagramEditorPlugin.getInstance().getImageRegistry();
	Image image = imageRegistry.get(key);
	if (image == null && elementType != null && CrossflowElementTypes.isKnownElementType(elementType)) {
		image = CrossflowElementTypes.getImage(elementType);
		imageRegistry.put(key, image);
	}

	if (image == null) {
		image = imageRegistry.get("Navigator?ImageNotFound"); //$NON-NLS-1$
		imageRegistry.put(key, image);
	}
	return image;
}
 
Example 14
Source File: HivesPlugin.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void initializeImageRegistry ( final ImageRegistry reg )
{
    super.initializeImageRegistry ( reg );
    reg.put ( ImageConstants.IMG_ERROR, imageDescriptorFromPlugin ( PLUGIN_ID, "icons/error.gif" ) ); //$NON-NLS-1$
    reg.put ( ImageConstants.IMG_STOPPED, imageDescriptorFromPlugin ( PLUGIN_ID, "icons/stopped.gif" ) ); //$NON-NLS-1$
    reg.put ( ImageConstants.IMG_RUNNING, imageDescriptorFromPlugin ( PLUGIN_ID, "icons/running.gif" ) ); //$NON-NLS-1$
}
 
Example 15
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void initializeImageRegistry ( final ImageRegistry reg )
{
    super.initializeImageRegistry ( reg );
    reg.put ( IMG_BLOCK_DEFAULT, ImageDescriptor.getMissingImageDescriptor () );
    reg.put ( IMG_BLOCK_LOCKED, ImageDescriptor.createFromFile ( Activator.class, "icons/locked.gif" ) ); //$NON-NLS-1$
    reg.put ( IMG_BLOCK_UNLOCKED, ImageDescriptor.createFromFile ( Activator.class, "icons/unlocked.gif" ) ); //$NON-NLS-1$
}
 
Example 16
Source File: AbstractGeneratorConfigurationBlock.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the image descriptor.
 *
 * @param imagePath the image path.
 * @return the image descriptor.
 */
@SuppressWarnings("static-method")
protected ImageDescriptor getImageDescriptor(String imagePath) {
	final LangActivator activator = LangActivator.getInstance();
	final ImageRegistry registry = activator.getImageRegistry();
	ImageDescriptor descriptor = registry.getDescriptor(imagePath);
	if (descriptor == null) {
		descriptor = ResourceLocator.imageDescriptorFromBundle(activator.getBundle().getSymbolicName(), imagePath).orElse(null);
		if (descriptor != null) {
			registry.put(imagePath, descriptor);
		}
	}
	return descriptor;
}
 
Example 17
Source File: TesterUiActivator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void initializeImageRegistry(ImageRegistry reg) {
	reg.put(ICON_TEST, imageDescriptor(ICON_TEST));
	reg.put(ICON_TEST_SKIPPED, imageDescriptor(ICON_TEST_SKIPPED));
	reg.put(ICON_TEST_SKIPPED_NOT_IMPLEMENTED_YET, imageDescriptor(ICON_TEST_SKIPPED_NOT_IMPLEMENTED_YET));
	reg.put(ICON_TEST_PASSED, imageDescriptor(ICON_TEST_PASSED));
	reg.put(ICON_TEST_FAILED, imageDescriptor(ICON_TEST_FAILED));
	reg.put(ICON_TEST_ERROR, imageDescriptor(ICON_TEST_ERROR));
	reg.put(ICON_TEST_RUNNING, imageDescriptor(ICON_TEST_RUNNING));
	reg.put(ICON_SUITE, imageDescriptor(ICON_SUITE));
	reg.put(ICON_SUITE_SKIPPED, imageDescriptor(ICON_SUITE_SKIPPED));
	reg.put(ICON_SUITE_PASSED, imageDescriptor(ICON_SUITE_PASSED));
	reg.put(ICON_SUITE_FAILED, imageDescriptor(ICON_SUITE_FAILED));
	reg.put(ICON_SUITE_ERROR, imageDescriptor(ICON_SUITE_ERROR));
	reg.put(ICON_SUITE_RUNNING, imageDescriptor(ICON_SUITE_RUNNING));
	reg.put(ICON_LOCK, imageDescriptor(ICON_LOCK));
	reg.put(ICON_LAUNCHCONFIG, imageDescriptor(ICON_LAUNCHCONFIG));
	reg.put(ICON_RELAUNCH, imageDescriptor(ICON_RELAUNCH));
	reg.put(ICON_RELAUNCH_FAILED, imageDescriptor(ICON_RELAUNCH_FAILED));
	reg.put(ICON_STOP, imageDescriptor(ICON_STOP));
	reg.put(ICON_HISTORY, imageDescriptor(ICON_HISTORY));
	reg.put(ICON_TH_HORIZONTAL, imageDescriptor(ICON_TH_HORIZONTAL));
	reg.put(ICON_TH_VERTICAL, imageDescriptor(ICON_TH_VERTICAL));
	reg.put(ICON_TH_AUTOMATIC, imageDescriptor(ICON_TH_AUTOMATIC));
	reg.put(ICON_SHOW_FAILURES_ONLY, imageDescriptor(ICON_SHOW_FAILURES_ONLY));
	reg.put(ICON_SHOW_SKIPPED_ONLY, imageDescriptor(ICON_SHOW_SKIPPED_ONLY));
}
 
Example 18
Source File: CodewindUIPlugin.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void registerImage(ImageRegistry registry, String key, String partialURL) {
    try {
        ImageDescriptor id = ImageDescriptor.createFromURL(new URL(ICON_BASE_URL, partialURL));
        registry.put(key, id);
        imageDescriptors.put(key, id);
    } catch (Exception e) {
        Logger.logError("Error registering image", e);
    }
}
 
Example 19
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 20
Source File: GridViewerSnippet7.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	try {
		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 ContentProvider("birthday", "commits",
				"bugs"));
		v.getGrid().setRowHeaderVisible(true);
		v.setRowHeaderLabelProvider(new ColumnLabelProvider() {
			@Override
			public String getText(Object element) {
				String propertyName = ((Mediator) element)
						.getPropertyName();
				return propertyName;
			}

		});

		List<Committer> committers = new ArrayList<Committer>();
		committers.add(new Committer("Tom Schindl", new Date(), 10, 5));
		committers
				.add(new Committer("Boris Bokowski", new Date(), 1000, 35));

		int i = 0;
		for (Committer committer : committers) {
			GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
			column.setEditingSupport(new EditingSupportImpl(v, i));
			column.setLabelProvider(new LabelProviderImpl(i));
			column.getColumn().setText(committer.getName());
			column.getColumn().setWidth(200);
			i++;
		}

		v.setInput(committers);

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

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

		display.dispose();
	} catch (Exception e) {
		e.printStackTrace();
	}
}