List of usage examples for org.eclipse.jface.resource ImageDescriptor createFromImageData
@Deprecated public static ImageDescriptor createFromImageData(ImageData data)
From source file:org.eclipse.scout.rt.ui.rap.util.RwtIconLocator.java
License:Open Source License
protected ImageDescriptor createImageDescriptor(String name) { ImageDescriptor desc = null;/* www . j a va2s. co m*/ IconSpec spec = m_iconLocator.getIconSpec(name); if (spec != null) { desc = ImageDescriptor.createFromImageData(new ImageData(new ByteArrayInputStream(spec.getContent()))); if (LOG.isDebugEnabled()) { LOG.debug("image found '" + name + "'."); } } else { LOG.warn("image '" + name + "' could not be found!"); m_missingImages.add(name); } return desc; }
From source file:org.eclipse.tm.terminal.view.ui.local.showin.DynamicContributionItems.java
License:Open Source License
@Override protected IContributionItem[] getContributionItems() { List<IContributionItem> items = new ArrayList<IContributionItem>(); if (delegate != null) { List<Map<String, String>> l = ExternalExecutablesManager.load(); if (l != null && !l.isEmpty()) { for (Map<String, String> executableData : l) { String name = executableData.get(IExternalExecutablesProperties.PROP_NAME); String path = executableData.get(IExternalExecutablesProperties.PROP_PATH); String args = executableData.get(IExternalExecutablesProperties.PROP_ARGS); String icon = executableData.get(IExternalExecutablesProperties.PROP_ICON); String strTranslate = executableData.get(IExternalExecutablesProperties.PROP_TRANSLATE); boolean translate = strTranslate != null ? Boolean.parseBoolean(strTranslate) : false; if (name != null && !"".equals(name) && path != null && !"".equals(path)) { //$NON-NLS-1$ //$NON-NLS-2$ IAction action = createAction(name, path, args, translate); ImageData id = icon != null ? ExternalExecutablesManager.loadImage(icon) : null; if (id != null) { ImageDescriptor desc = ImageDescriptor.createFromImageData(id); if (desc != null) action.setImageDescriptor(desc); }/*from w w w. j ava 2s.c om*/ IContributionItem item = new ActionContributionItem(action); items.add(item); } } } } return items.toArray(new IContributionItem[items.size()]); }
From source file:org.eclipse.tm.terminal.view.ui.preferences.PreferencePage.java
License:Open Source License
@Override protected Control createContents(final Composite parent) { final GC gc = new GC(parent); gc.setFont(JFaceResources.getDialogFont()); Composite panel = new Composite(parent, SWT.NONE); panel.setLayout(new GridLayout()); GridData layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); panel.setLayoutData(layoutData);/* w ww . j av a 2s.co m*/ Label label = new Label(panel, SWT.HORIZONTAL); label.setText(Messages.PreferencePage_label); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); if (!Platform.OS_WIN32.equals(Platform.getOS())) { Group group = new Group(panel, SWT.NONE); group.setText(Messages.PreferencePage_command_label); group.setLayout(new GridLayout(2, false)); group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); command = new Text(group, SWT.SINGLE | SWT.BORDER); command.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); command.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { boolean valid = true; String message = null; String text = command.getText(); if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ IPath p = new Path(text.trim()); valid = p.toFile().isFile() && p.toFile().canRead() && p.toFile().canExecute(); if (!valid) message = Messages.PreferencePage_command_invalid; } setValid(valid); setErrorMessage(message); } }); commandBrowseButton = new Button(group, SWT.PUSH); commandBrowseButton.setText(Messages.PreferencePage_command_button_browse); layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 14); commandBrowseButton.setLayoutData(layoutData); commandBrowseButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(parent.getShell(), SWT.OPEN); String text = command.getText(); if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ IPath p = new Path(text); if (p.toFile().isFile() || !p.toFile().exists()) { dialog.setFilterPath(p.removeLastSegments(1).toOSString()); dialog.setFileName(p.lastSegment()); } else if (p.toFile().isDirectory()) { dialog.setFilterPath(p.toOSString()); } } String selected = dialog.open(); if (selected != null) { IPath sp = new Path(selected); command.setText(sp.toOSString()); } } }); String cmd = UIPlugin.getScopedPreferences() .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX); if (cmd != null && !"".equals(cmd)) { //$NON-NLS-1$ command.setText(new Path(cmd).toOSString()); } Composite argsPanel = new Composite(group, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; argsPanel.setLayout(layout); layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); layoutData.horizontalSpan = 2; argsPanel.setLayoutData(layoutData); label = new Label(argsPanel, SWT.NONE); label.setText(Messages.PreferencePage_command_arguments_label); arguments = new Text(argsPanel, SWT.SINGLE | SWT.BORDER); arguments.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); String args = UIPlugin.getScopedPreferences() .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS); if (args != null && !"".equals(args)) { //$NON-NLS-1$ arguments.setText(args); } NoteCompositeHelper.createNoteComposite(group.getFont(), group, Messages.PreferencePage_command_note_label, Messages.PreferencePage_command_note_text); } Group group = new Group(panel, SWT.NONE); group.setText(Messages.PreferencePage_workingDir_label); group.setLayout(new GridLayout(hasVariablesButton ? 3 : 2, false)); group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); workingDir = new Combo(group, SWT.DROP_DOWN); Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { workingDir.setItems(new String[] { Messages.PreferencePage_workingDir_userhome_label, Messages.PreferencePage_workingDir_eclipsehome_label, Messages.PreferencePage_workingDir_eclipsews_label }); } else { workingDir.setItems(new String[] { Messages.PreferencePage_workingDir_userhome_label, Messages.PreferencePage_workingDir_eclipsehome_label }); } workingDir.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); workingDir.select(0); workingDir.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { boolean valid = true; String message = null; String text = workingDir.getText(); if (text != null && !"".equals(text.trim()) //$NON-NLS-1$ && !Messages.PreferencePage_workingDir_userhome_label.equals(text) && !Messages.PreferencePage_workingDir_eclipsehome_label.equals(text) && !Messages.PreferencePage_workingDir_eclipsews_label.equals(text)) { try { // Resolve possible dynamic variables IStringVariableManager vm = VariablesPlugin.getDefault().getStringVariableManager(); String resolved = vm.performStringSubstitution(text.trim()); IPath p = new Path(resolved); valid = p.toFile().canRead() && p.toFile().isDirectory(); if (!valid) message = Messages.PreferencePage_workingDir_invalid; } catch (CoreException ex) { valid = false; message = ex.getLocalizedMessage(); } } setValid(valid); setErrorMessage(message); } }); browseButton = new Button(group, SWT.PUSH); browseButton.setText(Messages.PreferencePage_workingDir_button_browse); layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 14); browseButton.setLayoutData(layoutData); browseButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IPath uh = null; IPath eh = null; IPath ew = null; // HOME String home = System.getProperty("user.home"); //$NON-NLS-1$ if (home != null && !"".equals(home)) //$NON-NLS-1$ uh = new Path(home); // ECLIPSE_HOME String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$ if (eclipseHomeLocation != null) { try { URI uri = URIUtil.fromString(eclipseHomeLocation); File f = URIUtil.toFile(uri); eh = new Path(f.getAbsolutePath()); } catch (URISyntaxException ex) { /* ignored on purpose */ } } // ECLIPSE_WORKSPACE Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$ if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) { if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() .getLocation() != null) { ew = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation(); } } DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.OPEN); // Determine the filter path String text = workingDir.getText(); if (Messages.PreferencePage_workingDir_userhome_label.equals(text)) { dialog.setFilterPath(uh.toOSString()); } else if (Messages.PreferencePage_workingDir_eclipsehome_label.equals(text)) { dialog.setFilterPath(eh.toOSString()); } else if (Messages.PreferencePage_workingDir_eclipsews_label.equals(text)) { dialog.setFilterPath(ew.toOSString()); } else if (text != null && !"".equals(text.trim())) { //$NON-NLS-1$ try { // Resolve possible dynamic variables IStringVariableManager vm = VariablesPlugin.getDefault().getStringVariableManager(); String resolved = vm.performStringSubstitution(text.trim()); dialog.setFilterPath(resolved); } catch (CoreException ex) { if (Platform.inDebugMode()) { UIPlugin.getDefault().getLog().log(ex.getStatus()); } } } String selected = dialog.open(); if (selected != null) { IPath sp = new Path(selected); if (uh.equals(sp)) { workingDir.select(0); } else if (eh.equals(sp)) { workingDir.select(1); } else if (ew.equals(sp)) { workingDir.select(2); } else { workingDir.setText(sp.toOSString()); } } } }); if (hasVariablesButton) { variablesButton = new Button(group, SWT.PUSH); variablesButton.setText(Messages.PreferencePage_workingDir_button_variables); layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 14); variablesButton.setLayoutData(layoutData); variablesButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { org.eclipse.debug.ui.StringVariableSelectionDialog dialog = new org.eclipse.debug.ui.StringVariableSelectionDialog( getShell()); dialog.open(); String expression = dialog.getVariableExpression(); if (expression != null) { if ("${eclipse_home}".equals(expression)) { //$NON-NLS-1$ workingDir.select(1); } else if ("${workspace_loc}".equals(expression)) { //$NON-NLS-1$ workingDir.select(2); } else { workingDir.setText(expression); } } } }); } String initialCwd = UIPlugin.getScopedPreferences() .getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD); if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd) || "".equals(initialCwd.trim())) { //$NON-NLS-1$ workingDir.select(0); } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd) || "${eclipse_home}".equals(initialCwd)) { //$NON-NLS-1$ workingDir.select(1); } else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd) || "${workspace_loc}".equals(initialCwd)) { //$NON-NLS-1$ workingDir.select(2); } else { workingDir.setText(new Path(initialCwd).toOSString()); } NoteCompositeHelper.createNoteComposite(group.getFont(), group, Messages.PreferencePage_workingDir_note_label, Messages.PreferencePage_workingDir_note_text); group = new Group(panel, SWT.NONE); group.setText(Messages.PreferencePage_executables_label); group.setLayout(new GridLayout(2, false)); group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); viewer = new TableViewer(group, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); Table table = viewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); TableColumn column = new TableColumn(table, SWT.LEFT); column.setText(Messages.PreferencePage_executables_column_name_label); column = new TableColumn(table, SWT.LEFT); column.setText(Messages.PreferencePage_executables_column_path_label); ColumnViewerToolTipSupport.enableFor(viewer); TableLayout tableLayout = new TableLayout(); tableLayout.addColumnData(new ColumnWeightData(35)); tableLayout.addColumnData(new ColumnWeightData(65)); table.setLayout(tableLayout); layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); layoutData.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 10); table.setLayoutData(layoutData); Composite buttonsPanel = new Composite(group, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttonsPanel.setLayout(layout); buttonsPanel.setLayoutData(new GridData(SWT.LEAD, SWT.BEGINNING, false, false)); addButton = new Button(buttonsPanel, SWT.PUSH); addButton.setText(Messages.PreferencePage_executables_button_add_label); layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 10); addButton.setLayoutData(layoutData); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ExternalExecutablesDialog dialog = new ExternalExecutablesDialog(PreferencePage.this.getShell(), false); if (dialog.open() == Window.OK) { // Get the executable properties and add it to the the list Map<String, String> executableData = dialog.getExecutableData(); if (executableData != null && !executables.contains(executableData)) { executables.add(executableData); viewer.refresh(); } } } }); editButton = new Button(buttonsPanel, SWT.PUSH); editButton.setText(Messages.PreferencePage_executables_button_edit_label); layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 10); editButton.setLayoutData(layoutData); editButton.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e) { ISelection s = viewer.getSelection(); if (s instanceof IStructuredSelection && !s.isEmpty()) { Object element = ((IStructuredSelection) s).getFirstElement(); if (element instanceof Map) { final Map<String, String> m = (Map<String, String>) element; ExternalExecutablesDialog dialog = new ExternalExecutablesDialog( PreferencePage.this.getShell(), true); dialog.setExecutableData(m); if (dialog.open() == Window.OK) { Map<String, String> executableData = dialog.getExecutableData(); if (executableData != null) { m.clear(); m.putAll(executableData); viewer.refresh(); } } } } } }); removeButton = new Button(buttonsPanel, SWT.PUSH); removeButton.setText(Messages.PreferencePage_executables_button_remove_label); layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); layoutData.widthHint = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), 10); removeButton.setLayoutData(layoutData); removeButton.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e) { ISelection s = viewer.getSelection(); if (s instanceof IStructuredSelection && !s.isEmpty()) { Iterator<?> iterator = ((IStructuredSelection) s).iterator(); while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof Map) { Map<String, Object> m = (Map<String, Object>) element; executables.remove(m); } viewer.refresh(); } } } }); viewer.setContentProvider(new IStructuredContentProvider() { @Override public Object[] getElements(Object inputElement) { if (inputElement instanceof List && !((List<?>) inputElement).isEmpty()) { return ((List<?>) inputElement).toArray(); } return NO_ELEMENTS; } @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } @Override public void dispose() { } }); viewer.setLabelProvider(new ITableLabelProvider() { @SuppressWarnings("unchecked") @Override public String getColumnText(Object element, int columnIndex) { if (element instanceof Map) { Map<String, Object> m = (Map<String, Object>) element; switch (columnIndex) { case 0: return (String) m.get(IExternalExecutablesProperties.PROP_NAME); case 1: return (String) m.get(IExternalExecutablesProperties.PROP_PATH); } } return null; } @SuppressWarnings("unchecked") @Override public Image getColumnImage(Object element, int columnIndex) { Image i = null; if (element instanceof Map) { switch (columnIndex) { case 0: Map<String, Object> m = (Map<String, Object>) element; String icon = (String) m.get(IExternalExecutablesProperties.PROP_ICON); if (icon != null) { i = images.get(icon); if (i == null) { ImageData id = ExternalExecutablesManager.loadImage(icon); if (id != null) { ImageDescriptor d = ImageDescriptor.createFromImageData(id); if (d != null) i = d.createImage(); if (i != null) images.put(icon, i); } } } break; case 1: break; } } return i; } @Override public void removeListener(ILabelProviderListener listener) { } @Override public boolean isLabelProperty(Object element, String property) { return false; } @Override public void dispose() { } @Override public void addListener(ILabelProviderListener listener) { } }); List<Map<String, String>> l = ExternalExecutablesManager.load(); if (l != null) executables.addAll(l); viewer.setInput(executables); viewer.addPostSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { updateButtons(); } }); updateButtons(); gc.dispose(); return panel; }
From source file:org.eclipse.vorto.perspective.view.GeneratorItem.java
License:Open Source License
/** * Create the composite.//from www.ja v a2 s. c o m * * @param parent * @param style */ public GeneratorItem(final Composite parent, int style, final ModelResource model, final GeneratorResource codegen) { super(parent, SWT.BORDER | SWT.NO_FOCUS); setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); setSize(500, 120); Label lblIcon = new Label(this, SWT.NONE); lblIcon.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); lblIcon.setAlignment(SWT.CENTER); lblIcon.setBounds(27, 21, 36, 36); ImageDescriptor generatorImage = ImageDescriptor.createFromImageData( new ImageData(new Base64InputStream(new ByteArrayInputStream(codegen.getImage32x32().getBytes())))); lblIcon.setImage(generatorImage.createImage()); Label lblName = new Label(this, SWT.NONE); lblName.setAlignment(SWT.CENTER); lblName.setBounds(10, 63, 70, 15); lblName.setText(codegen.getName()); lblName.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); StyledText txtDescription = new StyledText(this, SWT.READ_ONLY | SWT.WRAP); txtDescription.setBounds(96, 10, 390, 75); txtDescription.setText(codegen.getDescription()); txtDescription.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); Label lblCreatedBy = new Label(this, SWT.NONE); lblCreatedBy.setBounds(96, 91, 60, 15); lblCreatedBy.setText("Created by "); lblCreatedBy.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); Label lblAuthor = new Label(this, SWT.NONE); lblAuthor.setBounds(157, 91, 131, 15); lblAuthor.setText(codegen.getCreator()); lblAuthor.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); Label lblStarImage = new Label(this, SWT.NONE); lblStarImage.setAlignment(SWT.CENTER); lblStarImage.setBounds(10, 83, 70, 23); lblStarImage.setText("Rating: " + formatRating(codegen.getRating())); lblStarImage.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); lblGenerated.setBounds(320, 91, 85, 15); lblGenerated.setText(""); lblGenerated.setAlignment(SWT.RIGHT); lblGenerated.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); final Button btnGenerate = new Button(this, SWT.NONE); btnGenerate.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { lblGenerated.setText("Generating..."); final IModelRepository modelRepo = ModelRepositoryFactory.getModelRepository(); final Attachment attachment = modelRepo.generateCode(model.getId(), codegen.getKey()); CodeGenerationHelper.createEclipseProject(model.getId(), codegen.getKey(), toGenerationResult(attachment)); lblGenerated.setText("Generated."); btnGenerate.setEnabled(false); } }); btnGenerate.setBounds(411, 86, 75, 25); btnGenerate.setText("Generate"); }
From source file:org.eclipse.wazaabi.ide.ui.editors.ImagesUtils.java
License:Open Source License
public static void registerImageData(ImageRegistry registry, String key, String path) { ImageData data = getImageData(path); if (data != null) registry.put(key, ImageDescriptor.createFromImageData(data)); }
From source file:org.eclipse.wst.xml.ui.internal.editor.CMImageUtil.java
License:Open Source License
private static ImageDescriptor getImageDescriptor(String imageURLString) { ImageDescriptor descriptor = getImageRegistry().getDescriptor(imageURLString); if (descriptor == null) { try {/*from w w w .j a v a 2 s. c o m*/ URL imageURL = new URL(imageURLString); InputStream inputStream = JarUtilities.getInputStream(imageURL); try { if (inputStream != null) { ImageData data = new ImageData(inputStream); descriptor = ImageDescriptor.createFromImageData(data); getImageRegistry().put(imageURLString, descriptor); } } catch (SWTException e) { /* * There was a problem loading image from stream * (corrupt, missing, etc.) */ if (inputStream != null) inputStream.close(); } } catch (MalformedURLException e) { descriptor = null; } catch (IOException e) { descriptor = null; } } return descriptor; }
From source file:org.emftext.refactoring.registry.rolemapping.impl.BasicRoleMappingRegistry.java
License:Open Source License
private void registerIconsForMappings(RoleMappingModel roleMapping, IConfigurationElement config) { IContributor contributor = config.getContributor(); Bundle plugin = Platform.getBundle(contributor.getName()); // first look for default icon ImageDescriptor defaultImage = null; String defaultIconString = config.getAttribute(IRoleMappingExtensionPoint.DEFAULT_ICON_ATTRIBUTE); URL defaultIconBundleURL = null; if (defaultIconString != null) { ImageData defaultImageData = getImageData(defaultIconString, plugin); if (defaultImageData != null) { defaultImage = ImageDescriptor.createFromImageData(defaultImageData); IPath path = new Path(defaultIconString); defaultIconBundleURL = FileLocator.find(plugin, path, Collections.EMPTY_MAP); }//from ww w . j a v a 2s .c o m } // then look for specific icons for (RoleMapping mapping : roleMapping.getMappings()) { IConfigurationElement[] children = config.getChildren(); boolean found = false; for (IConfigurationElement element : children) { if (element.getName().equals(IRoleMappingExtensionPoint.SUB_MAPPING_ICON_ID)) { String mappingName = element.getAttribute(IRoleMappingExtensionPoint.SUB_MAPPING_NAME); if (mappingName.equals(mapping.getName())) { String mappingIcon = element.getAttribute(IRoleMappingExtensionPoint.SUB_ICON_RESOURCE); ImageData iconData = getImageData(mappingIcon, plugin); ImageDescriptor iconDescriptor = null; if (iconData != null) { iconDescriptor = ImageDescriptor.createFromImageData(iconData); iconMap.put(mapping, iconDescriptor); IPath path = new Path(mappingIcon); URL iconBundlePath = FileLocator.find(plugin, path, Collections.EMPTY_MAP); iconBundlePathMap.put(mapping, iconBundlePath); found = true; } } } } // register default icon only if no specific icon was found if (!found && defaultImage != null) { defaultIconMap.put(mapping, defaultImage); if (defaultIconBundleURL != null) { iconBundlePathMap.put(mapping, defaultIconBundleURL); } } } }
From source file:org.github.avatar.ui.AvatarWorkbenchAdapter.java
License:Open Source License
/** * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object) *//*w w w . java2 s . c om*/ public ImageDescriptor getImageDescriptor(Object object) { AvatarStore store = AvatarPlugin.getDefault().getAvatars(); String hash = store.getAdaptedHash(object); Avatar avatar = store.getAvatarByHash(hash); return avatar != null ? ImageDescriptor.createFromImageData(new AvatarImage(avatar).getData()) : super.getImageDescriptor(object); }
From source file:org.isandlatech.plugins.rest.RestPlugin.java
License:Open Source License
/** * Makes a new image which is a 45 counter-clockwise rotation of the given * one//from w ww . ja v a 2s .c o m * * @param aImage * Base image * @return A rotated image */ public static ImageDescriptor rotateImage(final Image aImage) { ImageData srcData = aImage.getImageData(); if (srcData == null) { return null; } ImageData destData = new ImageData(srcData.height, srcData.width, srcData.depth, srcData.palette); /* rotate by rearranging the pixels */ for (int i = 0; i < srcData.width; i++) { for (int j = 0; j < srcData.height; j++) { // Color int pixel = srcData.getPixel(i, j); destData.setPixel(j, srcData.width - 1 - i, pixel); // Transparency int alpha = srcData.getAlpha(i, j); destData.setAlpha(j, srcData.width - 1 - i, alpha); } } return ImageDescriptor.createFromImageData(destData); }
From source file:org.jcryptool.fileexplorer.views.factories.ImageFactory.java
License:Open Source License
public static ImageDescriptor getIconForFile(IFileStore file) { try {/*from w w w. j a v a2s .com*/ if (Pattern.matches("[a-zA-Z]:\\\\", file.toLocalFile(EFS.NONE, null).getAbsolutePath())) { //$NON-NLS-1$ // CD or DVD if (!file.toLocalFile(EFS.NONE, null).canWrite()) { if (file.toLocalFile(EFS.NONE, null).canRead()) { return FileExplorerPlugin.getImageDescriptor(ImageFactory.ICON_DEVICE_CD_DVD); } return FileExplorerPlugin.getImageDescriptor(ImageFactory.ICON_DEVICE_CD_DVD_NOACCESS); } // HDD if (!file.toLocalFile(EFS.NONE, null).canRead()) { return FileExplorerPlugin.getImageDescriptor(ImageFactory.ICON_DEVICE_NOACCESS); } return FileExplorerPlugin.getImageDescriptor(ImageFactory.ICON_DEVICE); } } catch (CoreException ex) { LogUtil.logError(FileExplorerPlugin.PLUGIN_ID, ex); } // handle directories if (file.fetchInfo().isDirectory()) { return FileExplorerPlugin.getImageDescriptor(ImageFactory.ICON_FOLDER); } // handled directories here are unaccessible try { if (file.toLocalFile(EFS.NONE, null).isDirectory()) { return FileExplorerPlugin.getImageDescriptor(ImageFactory.ICON_FOLDER_NOACCESS); } } catch (CoreException ex) { LogUtil.logError(FileExplorerPlugin.PLUGIN_ID, ex); } // handle by extension int dot = file.getName().indexOf('.'); if (dot > 0) { String extension = file.getName().substring(dot); Program program = Program.findProgram(extension); ImageData imageData = (program == null ? null : program.getImageData()); // handle if a program defines an icon if (imageData != null) { return ImageDescriptor.createFromImageData(imageData); } // handle the bin extension for the hex editor if (extension.equalsIgnoreCase(".bin")) { //$NON-NLS-1$ return FileExplorerPlugin.getImageDescriptor(ImageFactory.ICON_FILE_BINARY); } } // assign a default icon return FileExplorerPlugin.getImageDescriptor(ImageFactory.ICON_FILE); }