List of usage examples for org.eclipse.jface.resource JFaceResources getImageRegistry
public static ImageRegistry getImageRegistry()
From source file:ch.elexis.core.icons.Images.java
License:Open Source License
private static boolean addImageDescriptor(String name) { try {//from w w w . j a va 2 s. c o m ResourceBundle iconsetProperties = ResourceBundle.getBundle("iconset"); String fileName = iconsetProperties.getString(name); ImageDescriptor id = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, fileName); JFaceResources.getImageRegistry().put(name, id); } catch (MissingResourceException e) { return false; } catch (IllegalArgumentException e) { return false; } return true; }
From source file:ch.elexis.core.ui.icons.Images.java
License:Open Source License
/** * Opportunistic lookup for a probably existing key.<br> * There may exist keys within the <code>iconset.properties</code> file which are not managed by * this Enumeration. This method allows an opportunistic lookup of such registered images. * /*w w w . j a v a 2 s. c o m*/ * @param iconKey * @return <code>null</code> if no such image is existent */ public static Image lookupImage(String iconKey, ImageSize is) { Image image = JFaceResources.getImageRegistry().get(iconKey + is.name); if (image == null) { boolean ret = addIconImageDescriptor(iconKey, is); if (!ret) return null; image = JFaceResources.getImageRegistry().get(iconKey); } return image; }
From source file:ch.elexis.core.ui.icons.Images.java
License:Open Source License
/** * Returns an image. Clients do not need to dispose the image, it will be disposed * automatically.//from ww w. jav a 2s . c om * * @return an {@link Image} */ public synchronized Image getImage(ImageSize is) { Image image = JFaceResources.getImageRegistry().get(this.name() + is.name); if (image == null) { addIconImageDescriptor(this.name(), is); image = JFaceResources.getImageRegistry().get(this.name() + is.name); } return image; }
From source file:ch.elexis.core.ui.icons.Images.java
License:Open Source License
/** * resolve the image// ww w.j ava 2 s .com * * @param imageName * @param is * @return */ private static ImageDescriptor getImageDescriptor(String imageName, ImageSize is) { ImageDescriptor id = null; id = JFaceResources.getImageRegistry().getDescriptor(imageName + is.name); if (id == null) { addIconImageDescriptor(imageName, is); id = JFaceResources.getImageRegistry().getDescriptor(imageName + is.name); } return id; }
From source file:ch.elexis.core.ui.icons.Images.java
License:Open Source License
/** * Add an image descriptor for a specific key and {@link IconSize} to the global * {@link ImageRegistry}/*w ww .ja v a2 s. c om*/ * * @param name * @param is * @return <code>true</code> if successfully added, else <code>false</code> */ private static boolean addIconImageDescriptor(String name, ImageSize is) { String fileName; try { ResourceBundle iconsetProperties = ResourceBundle.getBundle("iconset"); fileName = iconsetProperties.getString(name); } catch (MissingResourceException | IllegalArgumentException e) { fileName = name; } Path path = new Path("icons/" + is.name + "/" + fileName); URL fileLocation = FileLocator.find(Activator.getContext().getBundle(), path, null); if (fileLocation == null) return false; ImageDescriptor id = ImageDescriptor.createFromURL(fileLocation); JFaceResources.getImageRegistry().put(name + is.name, id); return true; }
From source file:com.amalto.workbench.widgets.FilteredCheckboxTree.java
License:Open Source License
/** * Create the button that clears the text. * /*from ww w . j a va 2 s .co m*/ * @param parent parent <code>Composite</code> of toolbar button */ private void createClearText(Composite parent) { // only create the button if the text widget doesn't support one natively if ((filterText.getStyle() & SWT.CANCEL) == 0) { filterToolBar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL); filterToolBar.createControl(parent); IAction clearTextAction = new Action("", IAction.AS_PUSH_BUTTON) {//$NON-NLS-1$ /* * (non-Javadoc) * * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { clearText(); } }; clearTextAction.setToolTipText(""); clearTextAction.setImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(CLEAR_ICON)); clearTextAction .setDisabledImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(DCLEAR_ICON)); filterToolBar.add(clearTextAction); } }
From source file:com.aptana.ide.core.ui.SWTUtils.java
License:Open Source License
/** * Finds and caches the image from the image descriptor for this particular bundle * // www . ja v a 2s.c om * @param bundle * The bundle to search * @param path * The path to the image * @return The image, or null if not found */ public static Image getImage(Bundle bundle, String path) { if (path.charAt(0) != '/') { path = "/" + path; //$NON-NLS-1$ } String computedName = bundle.getSymbolicName() + path; Image image = JFaceResources.getImage(computedName); if (image != null) { return image; } ImageDescriptor id = AbstractUIPlugin.imageDescriptorFromPlugin(bundle.getSymbolicName(), path); if (id != null) { JFaceResources.getImageRegistry().put(computedName, id); return JFaceResources.getImage(computedName); } else { return null; } }
From source file:com.aptana.ide.ui.io.ImageUtils.java
License:Open Source License
public static ImageDescriptor getImageDescriptor(File file) { if (file.isFile()) { ImageDescriptor imageDescriptor = PlatformUI.getWorkbench().getEditorRegistry() .getImageDescriptor(file.getName()); if (imageDescriptor != null) { return imageDescriptor; }/*from w w w . j av a2s . co m*/ } if (file.exists()) { if (jFileChooser == null) { jFileChooser = new javax.swing.JFileChooser(); } String fileType = jFileChooser.getTypeDescription(file); if (fileType == null || fileType.length() == 0 || "Directory".equals(fileType) //$NON-NLS-1$ || "System Folder".equals(fileType) || "Generic File".equals(fileType)) { //$NON-NLS-1$ //$NON-NLS-2$ String name = file.getName(); try { name = file.getCanonicalFile().getName(); } catch (IOException e) { name = file.getName(); } if (name.equals((new Path(DESKTOP)).lastSegment())) { fileType = "Desktop"; //$NON-NLS-1$ } else if (!file.isDirectory()) { int index = name.lastIndexOf('.'); if (index >= 0 && index < name.length() - 1) { fileType = name.substring(index + 1); } else { fileType = "unknown"; //$NON-NLS-1$ } } else if ("Directory".equals(fileType) || name.length() == 0) { //$NON-NLS-1$ fileType = file.getAbsolutePath(); } else if ("System Folder".equals(fileType)) { //$NON-NLS-1$ if (file.getAbsolutePath().equals(USER_HOME)) { fileType = "UserHome"; //$NON-NLS-1$ } } } String imageKey = "os.fileType_" + fileType; //$NON-NLS-1$ ImageRegistry imageRegistry = JFaceResources.getImageRegistry(); if (resetMap.get(imageKey) != null && resetMap.get(imageKey)) { imageRegistry.remove(imageKey); resetMap.remove(imageKey); } ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(imageKey); if (imageDescriptor != null) { return imageDescriptor; } Icon icon; if (ON_WINDOWS) { icon = FileSystemView.getFileSystemView().getSystemIcon(file); } else { icon = jFileChooser.getIcon(file); } if (icon != null) { String existingImageKey = iconToKeyMap.get(icon); if (existingImageKey != null) { imageDescriptor = imageRegistry.getDescriptor(existingImageKey); if (imageDescriptor != null) { return imageDescriptor; } } ImageData imageData = awtImageIconToSWTImageData(icon, null); if (imageData != null) { imageDescriptor = ImageDescriptor.createFromImageData(imageData); imageRegistry.put(imageKey, imageDescriptor); iconToKeyMap.put(icon, imageKey); resetMap.put(imageKey, false); return imageRegistry.getDescriptor(imageKey); } } } return getImageDescriptor(file.getName()); }
From source file:com.aptana.ide.ui.io.ImageUtils.java
License:Open Source License
private static ImageDescriptor getExtensionImageDescriptor(String extension) { ImageRegistry imageRegistry = JFaceResources.getImageRegistry(); String imageKey = "extension_" + extension; //$NON-NLS-1$ ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(imageKey); if (imageDescriptor == null) { Program program = Program.findProgram(extension); if (program != null) { imageDescriptor = new ExternalProgramImageDescriptor(program); } else {/* www .ja v a 2 s .c o m*/ return null; } imageRegistry.put(imageKey, imageDescriptor); imageDescriptor = imageRegistry.getDescriptor(imageKey); } return imageDescriptor; }
From source file:com.aptana.ui.util.SWTUtils.java
License:Open Source License
/** * Finds and caches the image from the image descriptor for this particular bundle. * // ww w . j a va 2s.c o m * @param bundle * the bundle to search * @param path * the path to the image * @return the image, or null if not found */ public static Image getImage(Bundle bundle, String path) { if (path.charAt(0) != '/') { path = "/" + path; //$NON-NLS-1$ } String computedName = bundle.getSymbolicName() + path; Image image = JFaceResources.getImage(computedName); if (image != null) { return image; } ImageDescriptor id = AbstractUIPlugin.imageDescriptorFromPlugin(bundle.getSymbolicName(), path); if (id != null) { JFaceResources.getImageRegistry().put(computedName, id); return JFaceResources.getImage(computedName); } return null; }