List of usage examples for org.eclipse.jface.resource ImageDescriptor getImageData
@Deprecated
public ImageData getImageData()
ImageData
object for this image descriptor. From source file:org.locationtech.udig.legend.ui.LegendGraphic.java
License:Open Source License
public void draw(MapGraphicContext context) { IBlackboard blackboard = context.getLayer().getStyleBlackboard(); LegendStyle legendStyle = (LegendStyle) blackboard.get(LegendStyleContent.ID); if (legendStyle == null) { legendStyle = LegendStyleContent.createDefault(); blackboard.put(LegendStyleContent.ID, legendStyle); }/*from w w w. j a v a2 s .c o m*/ Rectangle locationStyle = (Rectangle) blackboard.get(LocationStyleContent.ID); if (locationStyle == null) { locationStyle = new Rectangle(-1, -1, -1, -1); blackboard.put(LocationStyleContent.ID, locationStyle); } FontStyle fontStyle = (FontStyle) blackboard.get(FontStyleContent.ID); if (fontStyle == null) { fontStyle = new FontStyle(); blackboard.put(FontStyleContent.ID, fontStyle); } this.backgroundColour = legendStyle.backgroundColour; this.horizontalMargin = legendStyle.horizontalMargin; this.verticalMargin = legendStyle.verticalMargin; this.horizontalSpacing = legendStyle.horizontalSpacing; this.verticalSpacing = legendStyle.verticalSpacing; this.indentSize = legendStyle.indentSize; this.imageHeight = legendStyle.imageHeight; this.imageWidth = legendStyle.imageWidth; final ViewportGraphics graphics = context.getGraphics(); if (fontStyle.getFont() != null) { graphics.setFont(fontStyle.getFont()); } List<Map<ILayer, LegendEntry[]>> layers = new ArrayList<Map<ILayer, LegendEntry[]>>(); int longestRow = 0; // used to calculate the width of the graphic final int[] numberOfEntries = new int[1]; // total number of entries to // draw numberOfEntries[0] = 0; /* * Set up the layers that we want to draw so we can operate just on * those ones. Layers at index 0 are on the bottom of the map, so we * must iterate in reverse. * * While we are doing this, determine the longest row so we can properly * draw the graphic's border. */ Dimension imageSize = new Dimension(imageWidth, imageHeight); Dimension textSize = new Dimension(0, graphics.getFontHeight()); for (int i = context.getMapLayers().size() - 1; i >= 0; i--) { ILayer layer = context.getMapLayers().get(i); if (!(layer.getGeoResource() instanceof MapGraphicResource) && layer.isVisible()) { if (layer.hasResource(MapGraphic.class)) { // don't include mapgraphics continue; } String layerName = layer.getName(); if (layerName == null) { layerName = null; } LegendEntry layerEntry = new LegendEntry(layerName); FeatureTypeStyle[] styles = locateStyle(layer); LegendEntry[] entries = null; if (styles == null) { // we should have a label but no style entries = new LegendEntry[] { layerEntry }; } else { List<Rule> rules = rules(styles); int ruleCount = rules.size(); if (ruleCount == 1 && layer.getGeoResource().canResolve(GridCoverage.class)) { // grid coverage with single rule; lets see if it is a // theming style List<LegendEntry> cmEntries = ColorMapLegendCreator.findEntries(styles, imageSize, textSize); if (cmEntries != null) { cmEntries.add(0, layerEntry); // add layer legend // entry entries = cmEntries.toArray(new LegendEntry[cmEntries.size()]); } } if (entries == null) { List<LegendEntry> localEntries = new ArrayList<LegendEntry>(); if (ruleCount == 1) { // only one rule so apply this to the layer legend // entry layerEntry.setRule(rules.get(0)); } localEntries.add(layerEntry); // add layer legend entry if (ruleCount > 1) { // we have more than one rule so there is likely // some // themeing going on; add each of these rules for (Rule rule : rules) { LegendEntry rentry = new LegendEntry(rule); localEntries.add(rentry); } } entries = localEntries.toArray(new LegendEntry[localEntries.size()]); } } layers.add(Collections.singletonMap(layer, entries)); // compute maximum length for each entry for (int j = 0; j < entries.length; j++) { StringBuilder sb = new StringBuilder(); for (int k = 0; k < entries[j].getText().length; k++) { sb.append(entries[j].getText()[k]); } Rectangle2D bounds = graphics.getStringBounds(sb.toString()); int length = indentSize + imageWidth + horizontalSpacing + (int) bounds.getWidth(); if (length > longestRow) { longestRow = length; } numberOfEntries[0]++; } } } if (numberOfEntries[0] == 0) { // nothing to draw! return; } final int rowHeight = Math.max(imageHeight, graphics.getFontHeight()); // space // allocated // to // each // layer if (locationStyle.width == 0 || locationStyle.height == 0) { // we want to change the location style as needed // but not change the saved one so we create a copy here locationStyle = new Rectangle(locationStyle); if (locationStyle.width == 0) { // we want to grow to whatever size we need int width = longestRow + horizontalMargin * 2; locationStyle.width = width; } if (locationStyle.height == 0) { // we want to grow to whatever size we need int height = rowHeight * numberOfEntries[0] + verticalMargin * 2; for (int i = 0; i < layers.size(); i++) { Map<ILayer, LegendEntry[]> map = layers.get(i); final LegendEntry[] entries = map.values().iterator().next(); for (int j = 0; j < entries.length; j++) { if (entries[j].getSpacingAfter() == null) { height += verticalSpacing; } else { height += entries[j].getSpacingAfter(); } } } locationStyle.height = height - verticalSpacing; } } // ensure box within the display Dimension displaySize = context.getMapDisplay().getDisplaySize(); if (locationStyle.x < 0) { locationStyle.x = displaySize.width - locationStyle.width + locationStyle.x; } if ((locationStyle.x + locationStyle.width + 6) > displaySize.width) { locationStyle.x = displaySize.width - locationStyle.width - 5; } if (locationStyle.y < 0) { locationStyle.y = displaySize.height - locationStyle.height - 5 + locationStyle.y; } if ((locationStyle.y + locationStyle.height + 6) > displaySize.height) { locationStyle.y = displaySize.height - locationStyle.height - 5; } graphics.setClip( new Rectangle(locationStyle.x, locationStyle.y, locationStyle.width + 1, locationStyle.height + 1)); /* * Draw the box containing the layers/icons */ drawOutline(graphics, context, locationStyle, fontStyle); /* * Draw the layer names/icons */ final int[] rowsDrawn = new int[1]; rowsDrawn[0] = 0; final int[] x = new int[1]; x[0] = locationStyle.x + horizontalMargin; final int[] y = new int[1]; y[0] = locationStyle.y + verticalMargin; if (fontStyle.getFont() != null) { graphics.setFont(fontStyle.getFont()); } for (int i = 0; i < layers.size(); i++) { Map<ILayer, LegendEntry[]> map = layers.get(i); final ILayer layer = map.keySet().iterator().next(); final LegendEntry[] entries = map.values().iterator().next(); try { layer.getGeoResources().get(0).getInfo(null); } catch (Exception ex) { } PlatformGIS.syncInDisplayThread(new Runnable() { public void run() { for (int i = 0; i < entries.length; i++) { BufferedImage awtIcon = null; if (entries[i].getRule() != null) { // generate icon from use ImageDescriptor descriptor = LayerGeneratedGlyphDecorator.generateStyledIcon(layer, entries[i].getRule()); if (descriptor == null) { descriptor = LayerGeneratedGlyphDecorator.generateIcon((Layer) layer); } if (descriptor != null) { awtIcon = AWTSWTImageUtils.convertToAWT(descriptor.getImageData()); } } else if (entries[i].getIcon() != null) { // use set icon awtIcon = AWTSWTImageUtils.convertToAWT(entries[i].getIcon().getImageData()); } else { // no rule, no icon, try default for layer ImageDescriptor descriptor = LayerGeneratedGlyphDecorator.generateIcon((Layer) layer); if (descriptor != null) { awtIcon = AWTSWTImageUtils.convertToAWT(descriptor.getImageData()); } } drawRow(graphics, x[0], y[0], awtIcon, entries[i].getText(), i != 0, entries[i].getTextPosition()); y[0] += rowHeight; if ((rowsDrawn[0] + 1) < numberOfEntries[0]) { if (entries[i].getSpacingAfter() != null) { y[0] += entries[i].getSpacingAfter(); } else { y[0] += verticalSpacing; } } rowsDrawn[0]++; } } }); } // clear the clip so we don't affect other rendering processes graphics.setClip(null); }
From source file:org.locationtech.udig.project.ui.internal.tool.display.CursorProxy.java
License:Open Source License
/** * @return Returns the SWT cursor object. *///from w w w. ja v a 2s . co m public Cursor getCursor() { if (cursor == null) { synchronized (this) { if (cursor == null) { if (imagePath == null) { cursor = getSystemCursor(cursorID); } else { ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(pluginID, imagePath); int x; try { x = Integer.parseInt(hotspotX); } catch (Exception e) { x = 0; } int y; try { y = Integer.parseInt(hotspotY); } catch (Exception e) { y = 0; } if (imageDescriptor == null || imageDescriptor.getImageData() == null) cursor = getSystemCursor(cursorID); else cursor = new Cursor(Display.getDefault(), imageDescriptor.getImageData(), x, y); } } } } return cursor; }
From source file:org.locationtech.udig.style.sld.StyleGlyph.java
License:Open Source License
public static void disable(ImageDescriptor descriptor) { ImageData imageData = descriptor.getImageData(); //PaletteData paletteData = imageData.palette; for (int i = 2; i < DEFAULT_WIDTH - 2; i++) { imageData.setPixel(i, i, 0);/* w w w .j a v a2 s . c o m*/ } }
From source file:org.modelio.ui.gef.SharedCursors2.java
License:Open Source License
@objid("92bf67f1-1eae-11e2-8cad-001ec947c8cc") private static Cursor createCursor(String sourceName, String maskName, int hotX, int hotY) { Bundle bundle = org.eclipse.core.runtime.Platform.getBundle("org.modelio.ui"); URL urlSrc = FileLocator.find(bundle, new Path(sourceName), null); ImageDescriptor src = ImageDescriptor.createFromURL(urlSrc); ImageDescriptor mask = null;/*from w w w . j av a2 s. co m*/ if (maskName != null) { URL urlMask = FileLocator.find(bundle, new Path(maskName), null); mask = ImageDescriptor.createFromURL(urlMask); } return new Cursor(null, src.getImageData(), (mask != null) ? mask.getImageData() : null, hotX, hotY); }
From source file:org.nightlabs.editor2d.ui.custom.EditorCursors.java
License:Open Source License
private static Cursor createCursor(ImageDescriptor desc) { Image image = desc.createImage(); return new Cursor(null, desc.getImageData(), image.getBounds().x, image.getBounds().y); }
From source file:org.nightlabs.editor2d.viewer.ui.render.RendererRegistry.java
License:Open Source License
@Override public void processElement(IExtension extension, IConfigurationElement element) throws Exception { if (renderModeManager == null) renderModeManager = new RenderModeManager(); if (element.getName().equalsIgnoreCase(ELEMENT_REGISTRY)) { try {//from www .ja v a 2s . c o m String mode = element.getAttribute(ATTRIBUTE_MODE); String renderMode = RenderConstants.DEFAULT_MODE; if (checkString(mode)) renderMode = mode; else throw new IllegalArgumentException("Attribute mode must not be null nor empty for " + //$NON-NLS-1$ "DrawComponentClass " + element.getAttribute(ATTRIBUTE_DRAWCOMPONENT_CLASS) + " and " + //$NON-NLS-1$ //$NON-NLS-2$ "Renderer " + element.getAttribute(ATTRIBUTE_RENDERER)); //$NON-NLS-1$ String dcClassName = element.getAttribute(ATTRIBUTE_DRAWCOMPONENT_CLASS); // Class dcClass = null; // try { // dcClass = Platform.getBundle(extension.getNamespaceIdentifier()).loadClass(dcClassName); // } catch (ClassNotFoundException e) { // logger.error("Could not load class "+dcClass+" !"); //$NON-NLS-1$ //$NON-NLS-2$ // return; // } String name = element.getAttribute(ATTRIBUTE_NAME); String description = element.getAttribute(ATTRIBUTE_DESCRIPTION); String icon = element.getAttribute(ATTRIBUTE_ICON); RenderModeDescriptor desc = null; if (checkString(name) && checkString(description) && checkString(icon)) { Bundle bundle = Platform.getBundle(extension.getNamespaceIdentifier()); ImageDescriptor imgDesc = ImageDescriptor.createFromURL(bundle.getEntry(icon)); desc = new RenderModeDescriptor(renderMode, name, description, ImageUtil.convertToAWT(imgDesc.getImageData())); } else if (checkString(name) && checkString(description)) { desc = new RenderModeDescriptor(renderMode, name, description); } else if (checkString(name)) { desc = new RenderModeDescriptor(renderMode, name); } Renderer r = null; if (desc != null) { // r = renderModeManager.addRenderModeDescriptor(desc, dcClass); r = renderModeManager.addRenderModeDescriptor(desc, dcClassName); } if (r != null) { IConfigurationElement[] children = element.getChildren(ELEMENT_RENDER_CONTEXT); for (int i = 0; i < children.length; i++) { processRenderContexts(children[i], r); } } } catch (Exception e) { throw new EPProcessorException(e); } } }
From source file:org.osate.ui.navigator.AadlElementImageDescriptor.java
License:Open Source License
private ImageData getImageData(ImageDescriptor descriptor) { ImageData data = descriptor.getImageData(); if (data == null) { data = new ImageData(6, 6, 1, new PaletteData(new RGB[] { new RGB(255, 0, 0) })); OsateUiPlugin.logErrorMessage("Image data not available: " + descriptor.toString()); }//from w w w. jav a 2 s.c o m return data; }
From source file:org.overture.ide.ui.internal.viewsupport.VdmElementImageDescriptor.java
License:Open Source License
private ImageData getImageData(ImageDescriptor descriptor) { ImageData data = descriptor.getImageData(); // see bug 51965: // getImageData can return // null//from ww w . ja v a 2 s. co m if (data == null) { data = DEFAULT_IMAGE_DATA; VdmUIPlugin.logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$ } return data; }
From source file:org.rssowl.ui.internal.OwlUI.java
License:Open Source License
/** * @param id//w w w . j a v a2 s. co m * @param bytes * @param defaultImage * @param wHint * @param hHint */ public static void storeImage(long id, byte[] bytes, ImageDescriptor defaultImage, int wHint, int hHint) { Assert.isNotNull(defaultImage); Assert.isLegal(wHint > 0); Assert.isLegal(hHint > 0); ImageData imgData = null; /* Bytes Provided */ if (bytes != null && bytes.length > 0) { ByteArrayInputStream inS = null; try { inS = new ByteArrayInputStream(bytes); ImageLoader loader = new ImageLoader(); ImageData[] imageDatas = loader.load(inS); /* Look for the Icon with the best quality */ if (imageDatas != null) imgData = getBestQuality(imageDatas, wHint, hHint); } catch (SWTException e) { /* Ignore any Image-Format exceptions */ } finally { if (inS != null) { try { inS.close(); } catch (IOException e) { if (!(e instanceof MonitorCanceledException)) Activator.getDefault().logError(e.getMessage(), e); } } } } /* Use default Image if img-data is null */ if (imgData == null) imgData = defaultImage.getImageData(); /* Save Image into Cache-Area on File-System */ if (imgData != null) { File imageFile = getImageFile(id); if (imageFile == null) return; /* Scale if required */ if (imgData.width != 16 || imgData.height != 16) imgData = imgData.scaledTo(16, 16); /* Try using native Image Format */ try { if (storeImage(imgData, imageFile, imgData.type)) return; } catch (SWTException e) { /* Ignore any Image-Format exceptions */ } /* Try using various other Image-Formats */ int formats[] = new int[] { SWT.IMAGE_PNG, SWT.IMAGE_ICO, SWT.IMAGE_GIF, SWT.IMAGE_BMP }; for (int format : formats) { if (format != imgData.type) { try { if (storeImage(imgData, imageFile, format)) return; } catch (SWTException e) { /* Ignore any Image-Format exceptions */ } } } } }
From source file:org.rubypeople.rdt.internal.ui.callhierarchy.CallHierarchyImageDescriptor.java
License:Open Source License
private ImageData getImageData(ImageDescriptor descriptor) { ImageData data = descriptor.getImageData(); // see bug 51965: getImageData can return null if (data == null) { data = DEFAULT_IMAGE_DATA;// w ww . j a v a 2 s .c om RubyPlugin.logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$ } return data; }