List of usage examples for org.eclipse.jface.resource ImageDescriptor createFromImageData
@Deprecated public static ImageDescriptor createFromImageData(ImageData data)
From source file:org.eclipse.edt.ide.rui.visualeditor.internal.widget.WidgetDescriptorFactory.java
License:Open Source License
private void processWidgetSmallIcon(Annotation widgetAnnotation, WidgetDescriptor widgetDescriptor) { String widgetValue = (String) widgetAnnotation.getValue(WIDGET_SMALLICON); if (!isEmpty(widgetValue)) { try {//from w ww. j av a2 s .com IResource member = project.findMember(widgetValue); if (member != null && member.getType() == IResource.FILE) { URL url = member.getLocationURI().toURL(); ImageDescriptor iconSmall = ImageDescriptor.createFromURL(url); widgetDescriptor._iconSmall = iconSmall; } else if (eglarFile != null) { ZipEntry iconEntry = eglarFile.getEntry(widgetValue); if (iconEntry != null) { ImageDescriptor iconSmall = ImageDescriptor .createFromImageData(new ImageData(eglarFile.getInputStream(iconEntry))); widgetDescriptor._iconSmall = iconSmall; } } } catch (Exception e) { Activator.getDefault().getLog() .log(new Status(Status.ERROR, Activator.PLUGIN_ID, "Error processing small icon", e)); } } else { widgetDescriptor._iconSmall = Activator.getImageDescriptor(EvConstants.ICON_DEFAULT_WIDGET_SMALL); } if (DEBUG) { System.out.println("Widget Icon Small: " + widgetValue); } }
From source file:org.eclipse.edt.ide.rui.visualeditor.internal.widget.WidgetDescriptorFactory.java
License:Open Source License
private void processWidgetLargeIcon(Annotation widgetAnnotation, WidgetDescriptor widgetDescriptor) { String widgetValue = (String) widgetAnnotation.getValue(WIDGET_LARGEICON); if (!isEmpty(widgetValue)) { try {// www . j a v a 2s . co m IResource member = project.findMember(widgetValue); if (member != null && member.getType() == IResource.FILE) { URL url = member.getLocationURI().toURL(); ImageDescriptor iconLarge = ImageDescriptor.createFromURL(url); widgetDescriptor._iconLarge = iconLarge; } else if (eglarFile != null) { ZipEntry iconEntry = eglarFile.getEntry(widgetValue); if (iconEntry != null) { ImageDescriptor iconLarge = ImageDescriptor .createFromImageData(new ImageData(eglarFile.getInputStream(iconEntry))); widgetDescriptor._iconLarge = iconLarge; } } } catch (Exception e) { Activator.getDefault().getLog() .log(new Status(Status.ERROR, Activator.PLUGIN_ID, "Error processing large icon", e)); } } else { widgetDescriptor._iconLarge = Activator.getImageDescriptor(EvConstants.ICON_DEFAULT_WIDGET_LARGE); } if (DEBUG) { System.out.println("Widget Icon Large: " + widgetValue); } }
From source file:org.eclipse.egit.ui.internal.components.CheckboxLabelProvider.java
License:Open Source License
private static Image createCheckboxImage(final ResourceManager resourceManager, final Control control, boolean checked, boolean enabled) { String checkboxhack = System.getProperty("egit.swt.checkboxhack"); //$NON-NLS-1$ if (checkboxhack == null) if (Platform.getOS().equals(Platform.OS_MACOSX)) checkboxhack = "hardwired"; //$NON-NLS-1$ else/*from w w w. j a v a 2s . c o m*/ checkboxhack = "screenshot"; //$NON-NLS-1$ if (checkboxhack == "hardwired") { //$NON-NLS-1$ if (enabled) { if (checked) return UIIcons.CHECKBOX_ENABLED_CHECKED.createImage(); return UIIcons.CHECKBOX_ENABLED_UNCHECKED.createImage(); } if (checked) return UIIcons.CHECKBOX_DISABLED_CHECKED.createImage(); return UIIcons.CHECKBOX_DISABLED_UNCHECKED.createImage(); } // else if checkboxhack = "screenshot"; // FIXME: Shawn says that blinking shell caused by below code is very // annoying...(at least on Mac) - anyone knows better workaround? final Shell s = new Shell(control.getShell(), SWT.NO_TRIM); // Hopefully no platform uses exactly this color because we'll make // it transparent in the image. final Color greenScreen = resourceManager.createColor(new RGB(222, 223, 224)); // otherwise we have a default gray color s.setBackground(greenScreen); final Button b = new Button(s, SWT.CHECK); b.setSelection(checked); b.setEnabled(enabled); b.setBackground(greenScreen); // otherwise an image is located in a corner b.setLocation(0, 0); final Point bSize = b.computeSize(SWT.DEFAULT, SWT.DEFAULT); // otherwise an image is stretched by width bSize.x = Math.max(bSize.x, bSize.y); bSize.y = Math.max(bSize.x, bSize.y); b.setSize(bSize); s.setSize(bSize); s.open(); final GC gc = new GC(b); final Image image = new Image(control.getShell().getDisplay(), bSize.x, bSize.y); gc.copyArea(image, 0, 0); gc.dispose(); s.close(); final ImageData imageData = image.getImageData(); imageData.transparentPixel = imageData.palette.getPixel(greenScreen.getRGB()); final Image checkboxImage = resourceManager.createImage(ImageDescriptor.createFromImageData(imageData)); image.dispose(); return checkboxImage; }
From source file:org.eclipse.equinox.jmx.internal.client.ui.util.ByteImageRegistry.java
License:Open Source License
public static ImageDescriptor createImageDescriptorFromByteArray(byte[] imageData) throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(imageData); ImageDescriptor desc = ImageDescriptor.createFromImageData(new ImageData(is)); is.close();/*from w ww . j a v a2 s . c om*/ return desc; }
From source file:org.eclipse.gmf.runtime.diagram.ui.editpolicies.DiagramPopupBarEditPolicy.java
License:Open Source License
private Image convert(Image srcImage) { int height = srcImage.getBounds().height; int width = srcImage.getBounds().width; ImageData srcImageData = srcImage.getImageData(); RGB backgroundRGB = ((GraphicalEditPart) getHost()).getFigure().getBackgroundColor().getRGB(); int backgroundColor = srcImageData.palette.getPixel(backgroundRGB); // Set the transparent pixels to the background color int count = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (((srcImageData.maskData[count >> 3] >> (7 - (count % 8))) & 1) == 0) { srcImageData.setPixel(x, y, backgroundColor); }//from w ww . ja v a 2s . c o m count++; } } srcImageData.maskData = null; Image convertedImage = ImageDescriptor.createFromImageData(srcImageData).createImage(srcImage.getDevice()); imagesToBeDisposed.add(convertedImage); return convertedImage; }
From source file:org.eclipse.graphiti.ui.internal.services.impl.ImageService.java
License:Open Source License
/** * This method fixes a problem for ImageDescriptors. It returns a corrected * ImageDescriptor for problematic ImageDescriptors. * <p>/*from w w w . ja v a 2 s . c om*/ * There is a problem with transparent GIFs. If the RGB value of the * transparent color index is identical to the RGB value of other colors * indices in the palette, then all those color indices are considered as * transparent. So as a result the transparency seems to be on an RGB value * instead of a color index. */ private ImageDescriptor fixImageDescriptor(ImageDescriptor descriptor) { // Typically the incoming ImageDescriptor is an URLImageDescriptor. The following lines create an ImageDataImageDescriptor // from it, which basically describes the same image. But that one works. So there seems to be an error in the // URLImageDescriptor. ImageData data = descriptor.getImageData(); return ImageDescriptor.createFromImageData(data); }
From source file:org.eclipse.jst.jsf.taglibprocessing.attributevalues.ColorType.java
License:Open Source License
private ImageDescriptor createImage(int color) { PaletteData pd = getPaletteData(color); return ImageDescriptor.createFromImageData(new ImageData(16, 16, 1, pd)); }
From source file:org.eclipse.mylyn.internal.commons.identity.ui.PersonLabelProvider.java
License:Open Source License
@Override public Image getImage(Object object) { if (object instanceof PeopleCategory) { return WorkbenchImages.getImage(ISharedImages.IMG_OBJ_FOLDER); } else if (object instanceof IIdentity) { IIdentity identity = (IIdentity) object; Image image = registry.get(identity.getId().toString()); if (image == null) { Future<IProfileImage> result = identity.requestImage(IMAGE_SIZE, IMAGE_SIZE); if (result.isDone()) { try { IProfileImage profileImage = result.get(0, TimeUnit.SECONDS); if (profileImage != null) { ImageData data = new ImageData(new ByteArrayInputStream(profileImage.getData())); if (data.width != IMAGE_SIZE || data.height != IMAGE_SIZE) { data = data.scaledTo(IMAGE_SIZE, IMAGE_SIZE); }/* ww w.java2s .c o m*/ registry.put(identity.getId().toString(), ImageDescriptor.createFromImageData(data)); image = registry.get(identity.getId().toString()); } } catch (Exception e) { // ignore } } } return image; } return null; }
From source file:org.eclipse.mylyn.internal.commons.ui.identity.PersonLabelProvider.java
License:Open Source License
@Override public Image getImage(Object object) { if (object instanceof PeopleCategory) { return WorkbenchImages.getImage(ISharedImages.IMG_OBJ_FOLDER); } else if (object instanceof IIdentity) { IIdentity identity = (IIdentity) object; Image image = registry.get(identity.getId().toString()); if (image == null) { Future<IProfileImage> result = identity.requestImage(IMAGE_SIZE, IMAGE_SIZE); if (result.isDone()) { try { IProfileImage profileImage = result.get(0, TimeUnit.SECONDS); if (profileImage != null) { ImageData data = new ImageData(new ByteArrayInputStream(profileImage.getData())); if (data.width != IMAGE_SIZE || data.height != IMAGE_SIZE) { data = data.scaledTo(IMAGE_SIZE, IMAGE_SIZE); }//from w ww. j av a 2 s . c o m registry.put(identity.getId().toString(), ImageDescriptor.createFromImageData(data)); image = registry.get(identity.getId().toString()); } } catch (Exception e) { // ignore } } } return image; } else if (object instanceof Account) { Account account = (Account) object; Image image = TasksUiPlugin.getDefault().getBrandingIcon(account.getKind()); return image; } return null; }
From source file:org.eclipse.mylyn.internal.tasks.ui.util.RepositoryConnectorUiExtensionReader.java
License:Open Source License
private void registerFromAdaptable(final AbstractRepositoryConnector connector) { SafeRunner.run(new ISafeRunnable() { @Override//from w ww .j ava 2 s .co m public void run() throws Exception { AbstractRepositoryConnectorUi connectorUi = loadAdapter(connector, AbstractRepositoryConnectorUi.class); if (connectorUi != null) { TasksUiPlugin.getDefault().addRepositoryConnectorUi(connectorUi); } RepositoryConnectorBranding branding = loadAdapter(connector, RepositoryConnectorBranding.class); if (branding != null) { InputStream brandingImageData = branding.getBrandingImageData(); if (brandingImageData != null) { try { TasksUiPlugin.getDefault().addBrandingIcon(connector.getConnectorKind(), getImage(brandingImageData)); } finally { closeQuietly(brandingImageData); } } InputStream overlayImageData = branding.getOverlayImageData(); if (overlayImageData != null) { try { TasksUiPlugin.getDefault().addOverlayIcon(connector.getConnectorKind(), getImageDescriptor(overlayImageData)); } finally { closeQuietly(brandingImageData); } } } } private void closeQuietly(InputStream in) { try { in.close(); } catch (IOException e) { // ignore } } @SuppressWarnings("unchecked") public <T> T loadAdapter(final AbstractRepositoryConnector connector, Class<T> klass) { T adapter = null; if (connector instanceof IAdaptable) { adapter = (T) ((IAdaptable) connector).getAdapter(klass); } if (adapter == null) { adapter = (T) Platform.getAdapterManager().loadAdapter(connector, klass.getName()); } return adapter; } private ImageDescriptor getImageDescriptor(InputStream in) { return ImageDescriptor.createFromImageData(new ImageData(in)); } private Image getImage(InputStream in) { return CommonImages.getImage(getImageDescriptor(in)); } @Override public void handleException(Throwable e) { StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, NLS.bind("Loading of connector ui for kind ''{0}'' failed.", connector.getConnectorKind()), //$NON-NLS-1$ e)); } }); }