List of usage examples for org.eclipse.jface.resource ImageDescriptor createFromFile
public static ImageDescriptor createFromFile(Class<?> location, String filename)
From source file:org.eclipse.datatools.sqltools.sqlbuilder.SQLBuilderPlugin.java
License:Open Source License
/** * Returns an image (icon) with the given name. * @param iconName the name of the image to get * @return the image/*w ww . j a v a 2 s. c o m*/ */ public Image getImage(String iconName) { ImageRegistry imageRegistry = getImageRegistry(); if (imageRegistry.get(iconName) != null) { return imageRegistry.get(iconName); } imageRegistry.put(iconName, ImageDescriptor.createFromFile(getClass(), iconName)); return imageRegistry.get(iconName); }
From source file:org.eclipse.draw2d.test.ImageUtilitiesTest.java
License:Open Source License
public void testRotatingImagesWithDifferentDepths() { Image result1 = null, result2 = null, result3 = null, result4 = null; Image img1 = ImageDescriptor.createFromFile(getClass(), "icons/bits1.bmp").createImage(); //$NON-NLS-1$ Image img2 = ImageDescriptor.createFromFile(getClass(), "icons/bits4.bmp").createImage(); //$NON-NLS-1$; Image img3 = ImageDescriptor.createFromFile(getClass(), "icons/bits8.gif").createImage(); //$NON-NLS-1$; Image img4 = ImageDescriptor.createFromFile(getClass(), "icons/bits24.jpg").createImage(); //$NON-NLS-1$; try {// w w w .ja v a2 s . com result1 = ImageUtilities.createRotatedImage(img1); result2 = ImageUtilities.createRotatedImage(img2); result3 = ImageUtilities.createRotatedImage(img3); result4 = ImageUtilities.createRotatedImage(img4); } catch (Throwable error) { fail(error.toString() + "\n" + error.getStackTrace()[0]); //$NON-NLS-1$ } finally { img1.dispose(); img2.dispose(); img3.dispose(); img4.dispose(); if (result1 != null && !result1.isDisposed()) result1.dispose(); if (result2 != null && !result2.isDisposed()) result2.dispose(); if (result3 != null && !result3.isDisposed()) result3.dispose(); if (result4 != null && !result4.isDisposed()) result4.dispose(); } }
From source file:org.eclipse.eclipsemonkey.actions.RecreateMonkeyCoolbarAction.java
License:Open Source License
private Action toolbarAction(String key, final IPath path, String imagePath) { final MenuRunMonkeyScript runner = new MenuRunMonkeyScript(path, window); Action action = new Action(key) { public void run() { try { runner.run("main", new Object[] {}); //$NON-NLS-1$ } catch (RunMonkeyException x) { MessageDialog.openError(window.getShell(), x.exceptionName, x.errorMessage + "\n" + x.fileName + x.optionalLineNumber()); //$NON-NLS-1$ }/*from ww w. j a va2 s . c o m*/ } }; action.setId(key); if (imagePath != null) { IPath newPath = path.removeLastSegments(1).append(imagePath); ImageDescriptor id = ImageDescriptor.createFromFile(null, newPath.toFile().getAbsolutePath()); if (id != null) { action.setImageDescriptor(id); } } return action; }
From source file:org.eclipse.eclipsemonkey.views.scriptsView.ScriptsView.java
License:Open Source License
/** * @param scriptPath/*w w w . jav a2 s. c o m*/ * @param imagePath * @return */ private Image getImageFromMetadata(IPath scriptPath, String imagePath) { IPath newPath = scriptPath.removeLastSegments(1).append(imagePath); String absolutePath = newPath.toFile().getAbsolutePath(); Image i = imageRegistry.get(absolutePath); if (i == null) { ImageDescriptor id = ImageDescriptor.createFromFile(null, absolutePath); if (id != null) { imageRegistry.put(absolutePath, id); i = imageRegistry.get(absolutePath); } } return i; }
From source file:org.eclipse.emf.eef.runtime.EEFRuntimePlugin.java
License:Open Source License
/** * @param key/*from w w w. j a v a 2 s.c om*/ * @param path */ public void registerImage(String key, String path) { if (getImageRegistry().get(key) != null) getImageRegistry().remove(key); getImageRegistry().put(key, ImageDescriptor.createFromFile(null, path)); }
From source file:org.eclipse.equinox.internal.security.ui.storage.view.NodesView.java
License:Open Source License
private void makeActions() { refreshNodesAction = new Action() { public void run() { nodeTreeViewer.refresh();/*www .ja v a 2 s. co m*/ } }; refreshNodesAction.setText(SecUIMessages.refreshNodesCommand); refreshNodesAction.setToolTipText(SecUIMessages.refreshNodesCommandTip); refreshNodesAction.setImageDescriptor( ImageDescriptor.createFromFile(NodesView.class, "/icons/storage/node_refresh.gif")); //$NON-NLS-1$ addNodeAction = new Action() { public void run() { TreeSelection selection = (TreeSelection) nodeTreeViewer.getSelection(); Object selected = selection.getFirstElement(); if (selected instanceof ISecurePreferences) { ISecurePreferences node = (ISecurePreferences) selected; NewNodeDialog nodeDialog = new NewNodeDialog(nodeTreeViewer.getControl().getShell()); if (nodeDialog.open() != Window.OK) return; String name = nodeDialog.getNodeName(); ISecurePreferences child = node.node(name); parentView.modified(); // expand and select new node ISecurePreferences parentNode = child.parent(); if (parentNode != null) nodeTreeViewer.refresh(parentNode, false); else nodeTreeViewer.refresh(false); nodeTreeViewer.expandToLevel(child, 0); nodeTreeViewer.setSelection(new StructuredSelection(child), true); } } }; addNodeAction.setText(SecUIMessages.addNodeCommand); addNodeAction.setToolTipText(SecUIMessages.addNodeCommandTip); addNodeAction .setImageDescriptor(ImageDescriptor.createFromFile(NodesView.class, "/icons/storage/node_new.gif")); //$NON-NLS-1$ removeNodeAction = new Action() { public void run() { TreeSelection selection = (TreeSelection) nodeTreeViewer.getSelection(); Object selected = selection.getFirstElement(); if (selected instanceof ISecurePreferences) { ISecurePreferences node = (ISecurePreferences) selected; ISecurePreferences parentNode = node.parent(); if (parentNode == null) return; // can't remove root node node.removeNode(); parentView.modified(); // refresh parent node and select it nodeTreeViewer.refresh(parentNode, false); nodeTreeViewer.setSelection(new StructuredSelection(parentNode), true); } } }; removeNodeAction.setText(SecUIMessages.removeNodeCommand); removeNodeAction.setToolTipText(SecUIMessages.removeNodeCommandTip); removeNodeAction.setImageDescriptor( ImageDescriptor.createFromFile(NodesView.class, "/icons/storage/node_delete.gif")); //$NON-NLS-1$ }
From source file:org.eclipse.equinox.internal.security.ui.storage.view.ValuesView.java
License:Open Source License
private void makeActions() { addValueAction = new Action() { public void run() { if (selectedNode == null) return; NewValueDialog newValueDialog = new NewValueDialog(selectedNode.keys(), tableViewer.getControl().getShell()); if (newValueDialog.open() != Window.OK) return; String key = newValueDialog.getKey(); String value = newValueDialog.getValue(); boolean encrypt = newValueDialog.encrypt(); try { selectedNode.put(key, value, encrypt); parentView.modified();/*from www . j av a 2 s . co m*/ } catch (StorageException e) { Activator.log(IStatus.ERROR, SecUIMessages.failedEncrypt, null, e); } tableViewer.refresh(); } }; addValueAction.setText(SecUIMessages.addValueCommand); addValueAction.setToolTipText(SecUIMessages.addValueCommandTmp); addValueAction.setImageDescriptor( ImageDescriptor.createFromFile(NodesView.class, "/icons/storage/value_new.gif")); //$NON-NLS-1$ removeValueAction = new Action() { public void run() { if (selectedNode == null) return; StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); Object selected = selection.getFirstElement(); if (!(selected instanceof TableValuesElement)) return; TableValuesElement node = (TableValuesElement) selected; String key = node.getKey(); // "Are you sure?" dialog MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO); dialog.setText(SecUIMessages.removeValueTitle); String msg = NLS.bind(SecUIMessages.removeValueMsg, key); dialog.setMessage(msg); if (dialog.open() != SWT.YES) return; selectedNode.remove(key); parentView.modified(); tableViewer.refresh(); } }; removeValueAction.setText(SecUIMessages.removeValueCommand); removeValueAction.setToolTipText(SecUIMessages.removeValueCommandTmp); removeValueAction.setImageDescriptor( ImageDescriptor.createFromFile(NodesView.class, "/icons/storage/value_delete.gif")); //$NON-NLS-1$ if (inDevelopmentMode) addDevelopmentMenuOptions(); }
From source file:org.eclipse.equinox.internal.security.ui.storage.view.ValuesView.java
License:Open Source License
private void addDevelopmentMenuOptions() { showValueAction = new Action() { public void run() { if (selectedNode == null) return; StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); Object selected = selection.getFirstElement(); if (!(selected instanceof TableValuesElement)) return; TableValuesElement node = (TableValuesElement) selected; String key = node.getKey(); try { String value = selectedNode.get(key, null); MessageBox dialog = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK); dialog.setText(SecUIMessages.showValueTitle); String msg = NLS.bind(SecUIMessages.showValueMsg, key, value); dialog.setMessage(msg);// www.j a v a 2 s . c o m dialog.open(); } catch (StorageException e) { Activator.log(IStatus.ERROR, SecUIMessages.failedDecrypt, null, e); MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK); dialog.setMessage(SecUIMessages.failedDecrypt); dialog.open(); return; } } }; showValueAction.setText(SecUIMessages.showValueCommand); showValueAction.setToolTipText(SecUIMessages.showValueCommandTmp); showValueAction.setImageDescriptor( ImageDescriptor.createFromFile(NodesView.class, "/icons/storage/value_show.gif")); //$NON-NLS-1$ encryptValueAction = new Action() { public void run() { reCodeValue(true); } }; encryptValueAction.setText(SecUIMessages.encryptValueCommand); encryptValueAction.setToolTipText(SecUIMessages.encryptValueCommandTmp); encryptValueAction .setImageDescriptor(ImageDescriptor.createFromFile(NodesView.class, "/icons/storage/encrypt.gif")); //$NON-NLS-1$ decryptValueAction = new Action() { public void run() { reCodeValue(false); } }; decryptValueAction.setText(SecUIMessages.decryptValueCommand); decryptValueAction.setToolTipText(SecUIMessages.decryptValueCommandTmp); decryptValueAction .setImageDescriptor(ImageDescriptor.createFromFile(NodesView.class, "/icons/storage/decrypt.gif")); //$NON-NLS-1$ }
From source file:org.eclipse.gef.BrowserCursorSupportDefaultImpl.java
License:Open Source License
@Override public Cursor createTreeAdd() { String sourceName = "icons/Tree_Add_Transparent.gif"; ImageDescriptor id = ImageDescriptor.createFromFile(Internal.class, sourceName); return new Cursor(id.createImage()); }
From source file:org.eclipse.gef.BrowserCursorSupportDefaultImpl.java
License:Open Source License
@Override public Cursor createPlugNot() { String sourceName = "icons/plugmasknot.gif"; ImageDescriptor id = ImageDescriptor.createFromFile(Internal.class, sourceName); return new Cursor(id.createImage()); }