List of usage examples for javax.swing ImageIcon getIconHeight
public int getIconHeight()
From source file:edu.ku.brc.specify.datamodel.WorkbenchRow.java
/** * @param imageFile/*from w w w .ja va 2s . co m*/ * @return * @throws IOException */ public synchronized byte[] readAndScaleCardImage(final File imageFile) throws IOException { if (imageFile == null) { throw new NullPointerException("Provided File must be non-null"); } if (!imageFile.exists()) { loadStatus = LoadStatus.Error; loadException = new IOException(); throw (IOException) loadException; } byte[] imgBytes = null; try { // read the original byte[] bytes = GraphicsUtils.readImage(imageFile); ImageIcon img = new ImageIcon(bytes); // determine if we need to scale int origWidth = img.getIconWidth(); int origHeight = img.getIconHeight(); boolean scale = false; if (origWidth > this.maxWidth || origHeight > maxHeight) { scale = true; } if (scale) { imgBytes = GraphicsUtils.scaleImage(bytes, this.maxHeight, this.maxWidth, true, false); } else { // since we don't need to scale the image, just grab its bytes imgBytes = bytes; } } catch (javax.imageio.IIOException ex) { UIRegistry.showLocalizedError("WB_IMG_BAD_FMT"); loadStatus = LoadStatus.Error; loadException = ex; return null; } return imgBytes; }
From source file:com.t3.model.Token.java
private Asset createAssetFromIcon(ImageIcon icon) { if (icon == null) return null; // Make sure there is a buffered image for it Image image = icon.getImage(); if (!(image instanceof BufferedImage)) { image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), Transparency.TRANSLUCENT); Graphics2D g = ((BufferedImage) image).createGraphics(); icon.paintIcon(null, g, 0, 0);//from w w w. j a v a2s. com } // Create the asset Asset asset = null; try { asset = new Asset(name, ImageUtil.imageToBytes((BufferedImage) image)); if (!AssetManager.hasAsset(asset)) AssetManager.putAsset(asset); } catch (IOException e) { e.printStackTrace(); } return asset; }
From source file:WorldMapGraphDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features./* ww w . java 2s. c o m*/ * */ public WorldMapGraphDemo() { setLayout(new BorderLayout()); map.put("TYO", new String[] { "35 40 N", "139 45 E" }); map.put("PEK", new String[] { "39 55 N", "116 26 E" }); map.put("MOW", new String[] { "55 45 N", "37 42 E" }); map.put("JRS", new String[] { "31 47 N", "35 13 E" }); map.put("CAI", new String[] { "30 03 N", "31 15 E" }); map.put("CPT", new String[] { "33 55 S", "18 22 E" }); map.put("PAR", new String[] { "48 52 N", "2 20 E" }); map.put("LHR", new String[] { "51 30 N", "0 10 W" }); map.put("HNL", new String[] { "21 18 N", "157 51 W" }); map.put("NYC", new String[] { "40 77 N", "73 98 W" }); map.put("SFO", new String[] { "37 62 N", "122 38 W" }); map.put("AKL", new String[] { "36 55 S", "174 47 E" }); map.put("BNE", new String[] { "27 28 S", "153 02 E" }); map.put("HKG", new String[] { "22 15 N", "114 10 E" }); map.put("KTM", new String[] { "27 42 N", "85 19 E" }); map.put("IST", new String[] { "41 01 N", "28 58 E" }); map.put("STO", new String[] { "59 20 N", "18 03 E" }); map.put("RIO", new String[] { "22 54 S", "43 14 W" }); map.put("LIM", new String[] { "12 03 S", "77 03 W" }); map.put("YTO", new String[] { "43 39 N", "79 23 W" }); cityList = new ArrayList<String>(map.keySet()); // create a simple graph for the demo graph = new DirectedSparseMultigraph<String, Number>(); createVertices(); createEdges(); ImageIcon mapIcon = null; String imageLocation = "/images/political_world_map.jpg"; try { mapIcon = new ImageIcon(getClass().getResource(imageLocation)); } catch (Exception ex) { System.err.println("Can't load \"" + imageLocation + "\""); } final ImageIcon icon = mapIcon; Dimension layoutSize = new Dimension(2000, 1000); Layout<String, Number> layout = new StaticLayout<String, Number>(graph, new ChainedTransformer(new Transformer[] { new CityTransformer(map), new LatLonPixelTransformer(new Dimension(2000, 1000)) })); layout.setSize(layoutSize); vv = new VisualizationViewer<String, Number>(layout, new Dimension(800, 400)); if (icon != null) { vv.addPreRenderPaintable(new VisualizationViewer.Paintable() { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform oldXform = g2d.getTransform(); AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.LAYOUT).getTransform(); AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.VIEW).getTransform(); AffineTransform at = new AffineTransform(); at.concatenate(g2d.getTransform()); at.concatenate(vat); at.concatenate(lat); g2d.setTransform(at); g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), vv); g2d.setTransform(oldXform); } public boolean useTransform() { return false; } }); } vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red, Color.white, Color.blue, vv.getPickedVertexState(), false)); // add my listeners for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.setEdgeToolTipTransformer(new Transformer<Number, String>() { public String transform(Number edge) { return "E" + graph.getEndpoints(edge).toString(); } }); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); add(panel); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); final ScalingControl scaler = new CrossoverScalingControl(); // vv.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity(); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(reset); add(controls, BorderLayout.SOUTH); }
From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java
public void updateBackgroundImage(final ImageIcon icon, final int x, final int y) { if (paintableAssociatedToBackgroundImage != null) vv.removePreRenderPaintable(paintableAssociatedToBackgroundImage); paintableAssociatedToBackgroundImage = null; if (icon != null) { this.paintableAssociatedToBackgroundImage = new VisualizationViewer.Paintable() { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform oldXform = g2d.getTransform(); AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.LAYOUT).getTransform(); AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.VIEW).getTransform(); AffineTransform at = new AffineTransform(); at.concatenate(g2d.getTransform()); at.concatenate(vat);//from ww w . java 2 s .co m at.concatenate(lat); g2d.setTransform(at); g.drawImage(icon.getImage(), x, y, icon.getIconWidth(), icon.getIconHeight(), vv); g2d.setTransform(oldXform); } public boolean useTransform() { return false; } }; vv.addPreRenderPaintable(paintableAssociatedToBackgroundImage); } }
From source file:co.foldingmap.mapImportExport.SvgExporter.java
private void writeImage(BufferedWriter outputStream, IconStyle style, Coordinate c, String id) { BufferedImage bi;/*from w ww.j a va2 s . co m*/ byte[] imageBytes; ByteArrayOutputStream baos; float x, y, height, width; ImageIcon image; OutputStream os64; Point2D.Float point; String imageEnc; try { point = c.getCenterPoint(); if (style.getImageFile() == null) { //No image outputStream.write(getIndent()); outputStream.write("<circle cx=\""); outputStream.write(Float.toString(point.x - 2)); outputStream.write("\" cy=\""); outputStream.write(Float.toString(point.y - 2)); outputStream.write("\" r=\"2\" stroke=\"#"); outputStream.write(getHexColor(style.getOutlineColor())); outputStream.write("\" stroke-width=\"1\" fill=\""); outputStream.write(getHexColor(style.getFillColor())); outputStream.write("\"/>\n"); } else { //Has image //first encode image into a string baos = new ByteArrayOutputStream(); bi = ImageIO.read(style.getImageFile()); ImageIO.write(bi, "PNG", baos); imageBytes = baos.toByteArray(); imageEnc = Base64.encodeBase64String(imageBytes); baos.close(); image = style.getObjectImage(); height = image.getIconHeight(); width = image.getIconWidth(); x = point.x - (width / 2.0f); y = point.y - (height / 2.0f); outputStream.write(getIndent()); outputStream.write("<image\n"); addIndent(); //y coordiante outputStream.write(getIndent()); outputStream.write("y=\""); outputStream.write(Float.toString(y)); outputStream.write("\"\n"); //x coordiante outputStream.write(getIndent()); outputStream.write("x=\""); outputStream.write(Float.toString(x)); outputStream.write("\"\n"); //id outputStream.write(getIndent()); outputStream.write("id=\""); outputStream.write(id); outputStream.write("\"\n"); //xlink outputStream.write(getIndent()); outputStream.write("xlink:href=\"data:image/png;base64,"); outputStream.write(imageEnc); outputStream.write("\"\n"); //x coordiante outputStream.write(getIndent()); outputStream.write("height=\""); outputStream.write(Float.toString(height)); outputStream.write("\"\n"); //y coordiante outputStream.write(getIndent()); outputStream.write("width=\""); outputStream.write(Float.toString(width)); outputStream.write("\" />\n"); } } catch (Exception e) { Logger.log(Logger.ERR, "Error in SvgExporter.writeImage() - " + e); } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.ImageFrame.java
protected void showImage() { if (row == null) { return;//from w w w. j a v a 2 s .co m } Set<WorkbenchRowImage> rowImages = row.getWorkbenchRowImages(); if (rowImages == null || rowImages.size() == 0) { noImagesLinked(); return; } // adjust the imageIndex to be within the proper bounds (in order to avoid a few error possibilities) if (imageIndex < 0) { imageIndex = 0; tray.setSelectedIndex(imageIndex); } else if (imageIndex > rowImages.size() - 1) { imageIndex = rowImages.size() - 1; tray.setSelectedIndex(imageIndex); } // try to get the appropriate WorkbenchRowImage WorkbenchRowImage rowImage = row.getRowImage(imageIndex); if (rowImage == null) { // What do we do here? // This should never happen. // There were images available, but none of them had the right index. // Just give the first one, I guess. rowImage = rowImages.iterator().next(); imageIndex = 0; tray.setSelectedIndex(imageIndex); statusBar.setWarningMessage("Unable to locate an image with the proper index. Showing first image."); // XXX i18n } // at this point, we know at least one image is available // update the title and status bar String fullFilePath = rowImage.getCardImageFullPath(); String filename = FilenameUtils.getName(fullFilePath); setTitle(String.format(getResourceString("WB_IMAGE_X_OF_Y"), imageIndex + 1, rowImages.size()) + ((filename != null) ? ": " + filename : "")); setStatusBarText(fullFilePath); ImageIcon image = null; Integer lastDisplayedSize = rowToImageSizeHash.get(row.hashCode()); if (lastDisplayedSize == null || lastDisplayedSize == REDUCED_SIZE) { image = rowImage.getReducedImage(); reduceMI.setSelected(true); } else { image = rowImage.getFullSizeImage(); origMI.setSelected(true); } cardImageLabel.setIcon(image); if (image == null) // no image available { statusBar.setErrorMessage("Unable to load image"); // XXX i18n } else // we've got an image { // this method is simpler than tracking what we're showing and changing to the correct view mainPane.remove(noRowSelectedMessagePanel); mainPane.remove(noCardImageMessagePanel); mainPane.remove(cardImageLabel); mainPane.add(cardImageLabel); int w = image.getIconWidth(); int h = image.getIconHeight(); cardImageLabel.setText(null); cardImageLabel.setSize(w, h); mainPane.setSize(w, h); mainPane.setPreferredSize(new Dimension(w, h)); enableMenus(true); mainPane.validate(); mainPane.repaint(); } }
From source file:edu.ku.brc.specify.Specify.java
/** * @param imgEncoded uuencoded image string *///w ww. j a v a2 s . c om protected void setAppIcon(final String imgEncoded) { String appIconName = getIconName(); String innerAppIconName = "InnerAppIcon"; ImageIcon appImgIcon = null; if (StringUtils.isNotEmpty(imgEncoded)) { appImgIcon = GraphicsUtils.uudecodeImage("", imgEncoded); //$NON-NLS-1$ if (appImgIcon != null && appImgIcon.getIconWidth() == 32 && appImgIcon.getIconHeight() == 32) { appIcon.setIcon(appImgIcon); CustomDialog.setAppIcon(appImgIcon); CustomFrame.setAppIcon(appImgIcon); IconManager.register(innerAppIconName, appImgIcon, null, IconManager.IconSize.Std32); return; } } appImgIcon = IconManager.getImage(appIconName, IconManager.IconSize.Std32); //$NON-NLS-1$ appIcon.setIcon(appImgIcon); if (!UIHelper.isMacOS()) { ImageIcon otherAppIcon = IconManager.getImage(getOpaqueIconName(), IconManager.IconSize.Std32); //$NON-NLS-1$ if (otherAppIcon != null) { appImgIcon = otherAppIcon; } } CustomDialog.setAppIcon(appImgIcon); CustomFrame.setAppIcon(appImgIcon); IconManager.register(innerAppIconName, appImgIcon, null, IconManager.IconSize.Std32); this.topFrame.setIconImage(appImgIcon.getImage()); }
From source file:net.sf.dvstar.transmission.TransmissionView.java
private void setAdditionalButtons() { ResizableIcon ri = new ArrowResizableIcon(9, SwingConstants.SOUTH); JCommandButton dropDownButton = new JCommandButton("Text Button", ri); ImageIcon imco = globalResourceMap.getImageIcon("btExit.icon"); Dimension idim = new Dimension(imco.getIconWidth(), imco.getIconHeight()); idim = new Dimension(40, 40); Image im = imco.getImage();// w w w .j av a 2 s.c o m ImageWrapperResizableIcon iwri = ImageWrapperResizableIcon.getIcon(im, idim); JCommandButton taskbarButtonPaste = new JCommandButton("", iwri); taskbarButtonPaste.setHorizontalAlignment(SwingConstants.LEFT); taskbarButtonPaste.setCommandButtonKind(CommandButtonKind.ACTION_AND_POPUP_MAIN_POPUP); //taskbarButtonPaste.setPopupOrientationKind(CommandButtonPopupOrientationKind.DOWNWARD); taskbarButtonPaste.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); taskbarButtonPaste.setDisplayState(TILE_36); // !!!! //taskbarButtonPaste.setPreferredSize(new Dimension(80, 48)); System.out.println("Pref " + taskbarButtonPaste.getPreferredSize()); System.out.println("Maxi " + taskbarButtonPaste.getMaximumSize()); System.out.println("Mini " + taskbarButtonPaste.getMinimumSize()); System.out.println("Size " + taskbarButtonPaste.getSize()); Dimension d = new Dimension(taskbarButtonPaste.getPreferredSize().width, 48); taskbarButtonPaste.setMaximumSize(d); taskbarButtonPaste.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Taskbar Paste activated"); } }); taskbarButtonPaste.setPopupCallback(new PopupPanelCallback() { @Override public JPopupPanel getPopupPanel(JCommandButton commandButton) { return new SamplePopupMenu(); } }); taskbarButtonPaste.setActionRichTooltip(new RichTooltip("Paste", "Paste the contents of the Clipboard")); taskbarButtonPaste.setPopupRichTooltip(new RichTooltip("Paste", "Click here for more options such as pasting only the values or formatting")); taskbarButtonPaste.setActionKeyTip("1"); //maiToolBar.add( rb ); /* JRibbonBand rb = new JRibbonBand("", new EmptyResizableIcon(1)); rb.addCommandButton(dropDownButton, RibbonElementPriority.MEDIUM); * JButton dropDownButton = DropDownButtonFactory.createDropDownButton( resourceMap.getIcon("btConnect.icon"), popup); */ //dropDownButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(2,2,2,2)); //dropDownButton.setBorderPainted( false ); //btConnect = taskbarButtonPaste; maiToolBar.add(taskbarButtonPaste); }
From source file:nl.softwaredesign.exporter.ODTExportFormat.java
/** * {@inheritDoc}/*from ww w . j a v a 2s. com*/ */ @Override public void writeImage(ImageIcon image, boolean scaleToPage) throws DocumentExportException { if (scaleToPage) { logger.debug("Add image " + image); } else { logger.debug("Add scaled image " + image); } try { if (currentParagraph == null) { newParagraph(0, Alignment.CENTER, null, 0.0f, 0.0f, LineSpacing.SINGLE); } // Again, we have to do this by hand. Go ODF toolkit :( OdfFileDom odfFileDom = (OdfFileDom) currentParagraph.getOdfElement().getOwnerDocument(); OdfDrawFrame frame = odfFileDom.newOdfElement(OdfDrawFrame.class); int imgWidth = 0; int imgHeight = 0; if (scaleToPage) { frame.setTextAnchorTypeAttribute("paragraph"); int pgWidth = (int) currentSectionStyle.getPageSize().getWidthPoints(72.0f); int pgHeight = (int) currentSectionStyle.getPageSize().getHeightPoints(72.0f); if (currentSectionStyle.getOrientation() == Orientation.LANDSCAPE || currentSectionStyle.getOrientation() == Orientation.REVERSE_LANDSCAPE) { // Landscape, switch width and height int tmp = pgWidth; pgWidth = pgHeight; pgHeight = tmp; } Dimension page = new Dimension(pgWidth, pgHeight); Insets margins = new Insets((int) (currentSectionStyle.getMarginTop()), (int) (currentSectionStyle.getMarginLeft()), (int) (currentSectionStyle.getMarginBottom()), (int) (currentSectionStyle.getMarginRight())); Dimension pic = new Dimension(image.getIconWidth(), image.getIconHeight()); // TODO Correct scaling??? } else { frame.setTextAnchorTypeAttribute("as-char"); imgWidth = image.getIconWidth(); imgHeight = image.getIconHeight(); } frame.setSvgWidthAttribute("" + DistanceUnit.IN.fromPoints(imgWidth) + "in"); frame.setSvgHeightAttribute("" + DistanceUnit.IN.fromPoints(imgHeight) + "in"); OdfDrawImage imageElement = (OdfDrawImage) frame.newDrawImageElement(); byte[] bytes = imageToBytes(image, "png", Color.white, imgWidth, imgHeight); imageCounter++; imageElement.newImage(new ByteArrayInputStream(bytes), "Pictures/image" + imageCounter + ".png", "image/png"); currentParagraph.getOdfElement().appendChild(frame); } catch (Exception e) { throw new DocumentExportException("Could not write image", e); } }
From source file:org.apache.cocoon.reading.ImageReader.java
protected void processStream(InputStream inputStream) throws IOException, ProcessingException { if (hasTransform()) { if (getLogger().isDebugEnabled()) { getLogger().debug("image " + ((width == 0) ? "?" : Integer.toString(width)) + "x" + ((height == 0) ? "?" : Integer.toString(height)) + " expires: " + expires); }/* w w w. j a va 2 s.co m*/ /* * NOTE (SM): * Due to Bug Id 4502892 (which is found in *all* JVM implementations from * 1.2.x and 1.3.x on all OS!), we must buffer the JPEG generation to avoid * that connection resetting by the peer (user pressing the stop button, * for example) crashes the entire JVM (yes, dude, the bug is *that* nasty * since it happens in JPEG routines which are native!) * I'm perfectly aware of the huge memory problems that this causes (almost * doubling memory consuption for each image and making the GC work twice * as hard) but it's *far* better than restarting the JVM every 2 minutes * (since this is the average experience for image-intensive web application * such as an image gallery). * Please, go to the <a href="http://developer.java.sun.com/developer/bugParade/bugs/4502892.html">Sun Developers Connection</a> * and vote this BUG as the one you would like fixed sooner rather than * later and all this hack will automagically go away. * Many deep thanks to Michael Hartle <mhartle@hartle-klug.com> for tracking * this down and suggesting the workaround. * * UPDATE (SM): * This appears to be fixed on JDK 1.4 */ try { byte content[] = readFully(inputStream); ImageIcon icon = new ImageIcon(content); BufferedImage original = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); BufferedImage currentImage = original; currentImage.getGraphics().drawImage(icon.getImage(), 0, 0, null); if (width > 0 || height > 0) { double ow = icon.getImage().getWidth(null); double oh = icon.getImage().getHeight(null); if (usePercent) { if (width > 0) { width = Math.round((int) (ow * width) / 100); } if (height > 0) { height = Math.round((int) (oh * height) / 100); } } AffineTransformOp filter = new AffineTransformOp(getTransform(ow, oh, width, height), AffineTransformOp.TYPE_BILINEAR); WritableRaster scaledRaster = filter.createCompatibleDestRaster(currentImage.getRaster()); filter.filter(currentImage.getRaster(), scaledRaster); currentImage = new BufferedImage(original.getColorModel(), scaledRaster, true, null); } if (null != grayscaleFilter) { grayscaleFilter.filter(currentImage, currentImage); } if (null != colorFilter) { colorFilter.filter(currentImage, currentImage); } // JVM Bug handling if (JVMBugFixed) { JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam p = encoder.getDefaultJPEGEncodeParam(currentImage); p.setQuality(this.quality[0], true); encoder.setJPEGEncodeParam(p); encoder.encode(currentImage); } else { ByteArrayOutputStream bstream = new ByteArrayOutputStream(); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bstream); JPEGEncodeParam p = encoder.getDefaultJPEGEncodeParam(currentImage); p.setQuality(this.quality[0], true); encoder.setJPEGEncodeParam(p); encoder.encode(currentImage); out.write(bstream.toByteArray()); } out.flush(); } catch (ImageFormatException e) { throw new ProcessingException( "Error reading the image. " + "Note that only JPEG images are currently supported."); } finally { // Bugzilla Bug 25069, close inputStream in finally block // this will close inputStream even if processStream throws // an exception inputStream.close(); } } else { // only read the resource - no modifications requested if (getLogger().isDebugEnabled()) { getLogger().debug("passing original resource"); } super.processStream(inputStream); } }