List of usage examples for org.eclipse.jface.resource ImageDescriptor createFromImageData
@Deprecated public static ImageDescriptor createFromImageData(ImageData data)
From source file:org.eclipse.mylyn.internal.wikitext.ui.viewer.ImageManager.java
License:Open Source License
@SuppressWarnings("unchecked") private void updateImage(String imgSrc, ImageData imageData) { if (display.isDisposed() || viewer.getTextWidget().isDisposed()) { return;/*from w w w .j ava2 s .c o m*/ } Image image = imageData == null ? imageCache.getMissingImage() : ImageDescriptor.createFromImageData(imageData).createImage(); imageCache.putImage(imgSrc, image); Set<ImageAnnotation> modifiedAnnotations = new HashSet<>(); AnnotationModel annotationModel = (AnnotationModel) viewer.getAnnotationModel(); Object annotationLockObject = annotationModel.getLockObject(); if (annotationLockObject == null) { annotationLockObject = annotationModel; } synchronized (annotationLockObject) { Iterator<Annotation> iterator = annotationModel.getAnnotationIterator(); while (iterator.hasNext()) { Annotation annotation = iterator.next(); if (annotation instanceof ImageAnnotation) { ImageAnnotation imageAnnotation = (ImageAnnotation) annotation; if (imgSrc.equals(imageAnnotation.getUrl())) { imageAnnotation.setImage(image); modifiedAnnotations.add(imageAnnotation); } } } } if (!modifiedAnnotations.isEmpty()) { computingChanges = true; try { boolean rangesAdjusted = false; List<StyleRange> ranges = new ArrayList<>(); Iterator<?> allStyleRangeIterator = viewer.getTextPresentation().getAllStyleRangeIterator(); while (allStyleRangeIterator.hasNext()) { StyleRange range = (StyleRange) allStyleRangeIterator.next(); ranges.add((StyleRange) range.clone()); } GC gc = new GC(viewer.getTextWidget()); try { viewer.getTextWidget().setRedraw(false); TextPresentation textPresentation = viewer.getTextPresentation(); // textPresentation. for (ImageAnnotation annotation : modifiedAnnotations) { int height = annotation.getImage().getBounds().height; Position position = annotationModel.getPosition(annotation); String widgetText = viewer.getTextWidget().getText(); Font font = null; if (widgetText.length() > 0 && widgetText.length() > position.offset) { StyleRange styleRange = viewer.getTextWidget().getStyleRangeAtOffset(position.offset); if (styleRange != null) { font = styleRange.font; } } if (font == null) { font = viewer.getTextWidget().getFont(); } gc.setFont(font); Point extent = gc.textExtent("\n"); //$NON-NLS-1$ if (extent.y > 0) { int numNewlines = (int) Math.ceil(((double) height) / ((double) extent.y)); final int originalNewlines = numNewlines; IDocument document = viewer.getDocument(); try { for (int x = position.offset; x < document.getLength(); ++x) { if (document.getChar(x) == '\n') { if (x != position.offset && Util.annotationsIncludeOffset(viewer.getAnnotationModel(), x)) { break; } --numNewlines; } else { break; } } if (numNewlines > 0) { String newlines = ""; //$NON-NLS-1$ for (int x = 0; x < numNewlines; ++x) { newlines += "\n"; //$NON-NLS-1$ } document.replace(position.offset + 1, 0, newlines); } else if (numNewlines < 0) { document.replace(position.offset, -numNewlines, ""); //$NON-NLS-1$ } if (numNewlines != 0) { // no need to fixup other annotation positions, since the annotation model is hooked into the document. // fix up styles for (StyleRange range : ranges) { if (range.start > position.offset) { range.start += numNewlines; rangesAdjusted = true; } else if (range.start + range.length > position.offset) { range.length += numNewlines; rangesAdjusted = true; } } } // bug# 248643: update the annotation size to reflect the full size of the image // so that it gets repainted when some portion of the image is exposed // as a result of scrolling if (position.getLength() != originalNewlines) { annotationModel.modifyAnnotationPosition(annotation, new Position(position.offset, originalNewlines)); } } catch (BadLocationException e) { // ignore } } } if (rangesAdjusted) { TextPresentation presentation = new TextPresentation(); if (textPresentation.getDefaultStyleRange() != null) { StyleRange defaultStyleRange = (StyleRange) textPresentation.getDefaultStyleRange() .clone(); if (viewer.getDocument() != null) { if (defaultStyleRange.length < viewer.getDocument().getLength()) { defaultStyleRange.length = viewer.getDocument().getLength(); } } presentation.setDefaultStyleRange(defaultStyleRange); } for (StyleRange range : ranges) { presentation.addStyleRange(range); } viewer.setTextPresentation(presentation); viewer.invalidateTextPresentation(); } } finally { viewer.getTextWidget().setRedraw(true); gc.dispose(); } viewer.getTextWidget().redraw(); } finally { computingChanges = false; } } }
From source file:org.eclipse.nebula.widgets.nattable.util.GUIHelper.java
License:Open Source License
public static Image getImage(ImageData data) { if (JFaceResources.getImage(data.toString()) == null) { JFaceResources.getImageRegistry().put(data.toString(), ImageDescriptor.createFromImageData(data)); }// ww w . ja v a 2s . co m return JFaceResources.getImage(data.toString()); }
From source file:org.eclipse.osee.framework.ui.data.model.editor.utility.ImageUtility.java
License:Open Source License
public static Image bytesToImage(byte[] rawData) { ImageLoader imageLoader = new ImageLoader(); ImageData[] images = imageLoader.load(new ByteArrayInputStream(rawData)); if (images != null && images.length > 0) { return ImageDescriptor.createFromImageData(images[0]).createImage(); }/* www.j av a 2 s .c om*/ return null; }
From source file:org.eclipse.osee.framework.ui.plugin.OseeUiActivator.java
License:Open Source License
public ImageDescriptor getImageDescriptorForProgram(String extenstion) { ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(extenstion); if (imageDescriptor == null && extenstion != null) { Program program = Program.findProgram(extenstion); if (program == null || program.getImageData() == null) { // provide no image (i.e. leave null) } else {/*from w w w .ja v a2 s . co m*/ imageDescriptor = ImageDescriptor.createFromImageData(program.getImageData()); getImageRegistry().put(extenstion, imageDescriptor); } } return imageDescriptor; }
From source file:org.eclipse.osee.framework.ui.skynet.BaseImage.java
License:Open Source License
@Override public ImageDescriptor createImageDescriptor() { return ImageDescriptor.createFromImageData(new ImageData(new ByteArrayInputStream(imageData))); }
From source file:org.eclipse.osee.framework.ui.swt.ProgramImage.java
License:Open Source License
@Override public ImageDescriptor createImageDescriptor() { Program program = Program.findProgram(extension); if (program == null || program.getImageData() == null) { return null; }/*from ww w . jav a 2 s . c o m*/ return ImageDescriptor.createFromImageData(program.getImageData()); }
From source file:org.eclipse.papyrus.diagram.common.Activator.java
License:Open Source License
/** * Find the image (SWT) in registry Store image in registry if it is not * found//www . ja v a2s. co m * * @param umlImage * to retrieve as SWT Image in registry * @return the stored SWT image */ public static Image getImageInRegistry(org.eclipse.uml2.uml.Image umlImage, VisibilityKind visibility) { // Retrieve registry ImageRegistry papyrusRegistry = getDefault().getImageRegistry(); // Get image id for registry String image_id = ImageUtil.getImageId(umlImage); if (visibility != null) { image_id = image_id + "_" + visibility.getLiteral(); } // Get SWT image for shape in the registry Image image = papyrusRegistry.get(image_id); // If image was not found in registry, // try to find an image and to update registry if (image == null) { try { // Try to retrieve image from UML Image content property image = ImageUtil.getContent(umlImage); } catch (Exception e) { // Activator.log.error(e); } // If no image was found in Content // Try to retrieve image from UML Image location property if (image == null) { image = ImageUtil.getImageFromLocation(umlImage); } // Add visibility decorator if (visibility != null) { getDefault(); ImageDescriptor visDesc = Activator.getImageDescriptor( UML_VIS_ICONS_16x16 + "VisibilityKind_" + visibility.getLiteral() + ".gif"); // Overlay custom image over base image OverlayVisibilityIcon overlayIcon = new OverlayVisibilityIcon(image, visDesc); image = overlayIcon.getImage(); } if (image != null) { // Store image in registry ImageData imdata = image.getImageData(); papyrusRegistry.put(image_id, ImageDescriptor.createFromImageData(imdata)); image = papyrusRegistry.get(image_id); } } return image; }
From source file:org.eclipse.pde.internal.ui.util.SharedLabelProvider.java
License:Open Source License
public Image getImageFromPlugin(IPluginModelBase model, String relativePath) { String platform = "platform:/plugin/"; //$NON-NLS-1$ if (relativePath.startsWith(platform)) { relativePath = relativePath.substring(platform.length()); int index = relativePath.indexOf('/'); if (index == -1) return null; model = PluginRegistry.findModel(relativePath.substring(0, index)); if (model == null) return null; relativePath = relativePath.substring(index + 1); }// w w w. j a va 2 s. c o m String location = model.getInstallLocation(); if (location == null) return null; File pluginLocation = new File(location); InputStream stream = null; ZipFile jarFile = null; try { if (pluginLocation.isDirectory()) { File file = new File(pluginLocation, relativePath); if (file.exists()) stream = new FileInputStream(file); else if (relativePath.length() > 5 && relativePath.startsWith("$nl$/")) { //$NON-NLS-1$ file = new File(pluginLocation, relativePath.substring(5)); if (file.exists()) stream = new FileInputStream(file); } } else { jarFile = new ZipFile(pluginLocation, ZipFile.OPEN_READ); ZipEntry manifestEntry = jarFile.getEntry(relativePath); if (manifestEntry != null) { stream = jarFile.getInputStream(manifestEntry); } else if (relativePath.length() > 5 && relativePath.startsWith("$nl$/")) { //$NON-NLS-1$ manifestEntry = jarFile.getEntry(relativePath.substring(5)); if (manifestEntry != null) { stream = jarFile.getInputStream(manifestEntry); } } } if (stream != null) { ImageDescriptor desc = ImageDescriptor.createFromImageData(new ImageData(stream)); return get(desc); } } catch (FileNotFoundException e) { } catch (IOException e) { } finally { try { if (stream != null) stream.close(); if (jarFile != null) jarFile.close(); } catch (IOException e) { } } return getBlankImage(); }
From source file:org.eclipse.sapphire.ui.forms.swt.SwtUtil.java
License:Open Source License
public static ImageDescriptor toImageDescriptor(final org.eclipse.sapphire.ImageData data) { if (data != null) { final ImageData swtImageData = new ImageData(data.contents()); return ImageDescriptor.createFromImageData(swtImageData); }//from w w w.ja v a 2s .c o m return null; }
From source file:org.eclipse.sapphire.ui.renderers.swt.SwtRendererUtil.java
License:Open Source License
public static ImageDescriptor toImageDescriptor(final org.eclipse.sapphire.modeling.ImageData data) { if (data != null) { final ImageData swtImageData = new ImageData(data.contents()); return ImageDescriptor.createFromImageData(swtImageData); }/* w w w .j av a2 s .com*/ return null; }