List of usage examples for javax.swing ImageIcon getIconWidth
public int getIconWidth()
From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java
/** * Create the UI for the panel/* www . j a v a 2s. c o m*/ */ protected void createUI() { createForm("Preferences", "Formatting"); //$NON-NLS-1$ //$NON-NLS-2$ UIValidator.setIgnoreAllValidation(this, true); JLabel fontNamesLabel = form.getLabelFor("fontNames"); //$NON-NLS-1$ ValComboBox fontNamesVCB = form.getCompById("fontNames"); //$NON-NLS-1$ JLabel fontSizesLabel = form.getLabelFor("fontSizes"); //$NON-NLS-1$ ValComboBox fontSizesVCB = form.getCompById("fontSizes"); //$NON-NLS-1$ JLabel controlSizesLabel = form.getLabelFor("controlSizes"); //$NON-NLS-1$ ValComboBox controlSizesVCB = form.getCompById("controlSizes"); //$NON-NLS-1$ formTypesCBX = form.getCompById("formtype"); //$NON-NLS-1$ fontNames = fontNamesVCB.getComboBox(); fontSizes = fontSizesVCB.getComboBox(); controlSizes = controlSizesVCB.getComboBox(); testField = form.getCompById("fontTest"); //$NON-NLS-1$ if (testField != null) { testField.setText(UIRegistry.getResourceString("FormattingPrefsPanel.THIS_TEST")); //$NON-NLS-1$ } if (UIHelper.isMacOS_10_5_X()) { fontNamesLabel.setVisible(false); fontNamesVCB.setVisible(false); fontSizesLabel.setVisible(false); fontSizesVCB.setVisible(false); testField.setVisible(false); int inx = -1; int i = 0; Vector<String> controlSizeTitles = new Vector<String>(); for (UIHelper.CONTROLSIZE cs : UIHelper.CONTROLSIZE.values()) { String titleStr = getResourceString(cs.toString()); controlSizeTitles.add(titleStr); controlSizesHash.put(titleStr, cs); controlSizes.addItem(titleStr); if (cs == UIHelper.getControlSize()) { inx = i; } i++; } controlSizes.setSelectedIndex(inx); Font baseFont = UIRegistry.getBaseFont(); if (baseFont != null) { fontNames.addItem(baseFont.getFamily()); fontSizes.addItem(Integer.toString(baseFont.getSize())); fontNames.setSelectedIndex(0); fontSizes.setSelectedIndex(0); } } else { controlSizesLabel.setVisible(false); controlSizesVCB.setVisible(false); Hashtable<String, Boolean> namesUsed = new Hashtable<String, Boolean>(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (Font font : ge.getAllFonts()) { if (namesUsed.get(font.getFamily()) == null) { fontNames.addItem(font.getFamily()); namesUsed.put(font.getFamily(), true); //$NON-NLS-1$ } } for (int i = BASE_FONT_SIZE; i < 22; i++) { fontSizes.addItem(Integer.toString(i)); } Font baseFont = UIRegistry.getBaseFont(); if (baseFont != null) { fontNames.setSelectedItem(baseFont.getFamily()); fontSizes.setSelectedItem(Integer.toString(baseFont.getSize())); if (testField != null) { ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { testField.setFont(new Font((String) fontNames.getSelectedItem(), Font.PLAIN, fontSizes.getSelectedIndex() + BASE_FONT_SIZE)); form.getUIComponent().validate(); clearFontSettings = false; } }; fontNames.addActionListener(al); fontSizes.addActionListener(al); } } } //----------------------------------- // Do DisciplineType Icons //----------------------------------- String iconName = AppPreferences.getRemote().get(getDisciplineImageName(), "CollectionObject"); //$NON-NLS-1$ //$NON-NLS-2$ List<Pair<String, ImageIcon>> list = IconManager.getListByType("disciplines", IconManager.IconSize.Std16); //$NON-NLS-1$ Collections.sort(list, new Comparator<Pair<String, ImageIcon>>() { public int compare(Pair<String, ImageIcon> o1, Pair<String, ImageIcon> o2) { String s1 = UIRegistry.getResourceString(o1.first); String s2 = UIRegistry.getResourceString(o2.first); return s1.compareTo(s2); } }); disciplineCBX = (ValComboBox) form.getCompById("disciplineIconCBX"); //$NON-NLS-1$ final JLabel dispLabel = form.getCompById("disciplineIcon"); //$NON-NLS-1$ JComboBox comboBox = disciplineCBX.getComboBox(); comboBox.setRenderer(new DefaultListCellRenderer() { @SuppressWarnings("unchecked") //$NON-NLS-1$ public Component getListCellRendererComponent(JList listArg, Object value, int index, boolean isSelected, boolean cellHasFocus) { Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) value; JLabel label = (JLabel) super.getListCellRendererComponent(listArg, value, index, isSelected, cellHasFocus); if (item != null) { label.setIcon(item.second); label.setText(UIRegistry.getResourceString(item.first)); } return label; } }); int inx = 0; Pair<String, ImageIcon> colObj = new Pair<String, ImageIcon>("colobj_backstop", //$NON-NLS-1$ IconManager.getIcon("colobj_backstop", IconManager.IconSize.Std16)); //$NON-NLS-1$ comboBox.addItem(colObj); int cnt = 1; for (Pair<String, ImageIcon> item : list) { if (item.first.equals(iconName)) { inx = cnt; } comboBox.addItem(item); cnt++; } comboBox.addActionListener(new ActionListener() { @SuppressWarnings("unchecked") //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { JComboBox cbx = (JComboBox) e.getSource(); Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) cbx.getSelectedItem(); if (item != null) { dispLabel.setIcon(IconManager.getIcon(item.first)); form.getUIComponent().validate(); } } }); comboBox.setSelectedIndex(inx); //----------------------------------- // Date Field //----------------------------------- dateFieldCBX = form.getCompById("scrdateformat"); //$NON-NLS-1$ fillDateFormat(); //----------------------------------- // FormType //----------------------------------- fillFormTypes(); //----------------------------------- // Do App Icon //----------------------------------- final JButton getIconBtn = form.getCompById("GetIconImage"); //$NON-NLS-1$ final JButton clearIconBtn = form.getCompById("ClearIconImage"); //$NON-NLS-1$ final JLabel appLabel = form.getCompById("appIcon"); //$NON-NLS-1$ final JButton resetDefFontBtn = form.getCompById("ResetDefFontBtn"); //$NON-NLS-1$ String imgEncoded = AppPreferences.getRemote().get(iconImagePrefName, ""); //$NON-NLS-1$ ImageIcon innerAppImgIcon = null; if (StringUtils.isNotEmpty(imgEncoded)) { innerAppImgIcon = GraphicsUtils.uudecodeImage("", imgEncoded); //$NON-NLS-1$ if (innerAppImgIcon != null && innerAppImgIcon.getIconWidth() != 32 || innerAppImgIcon.getIconHeight() != 32) { innerAppImgIcon = null; clearIconBtn.setEnabled(false); } else { clearIconBtn.setEnabled(true); } } if (innerAppImgIcon == null) { innerAppImgIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$ clearIconBtn.setEnabled(false); } else { clearIconBtn.setEnabled(true); } appLabel.setIcon(innerAppImgIcon); getIconBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { chooseToolbarIcon(appLabel, clearIconBtn); } }); clearIconBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ImageIcon appIcon = IconManager.getIcon("AppIcon"); IconEntry entry = IconManager.getIconEntryByName(INNER_APPICON_NAME); entry.setIcon(appIcon); if (entry.getIcons().get(IconManager.IconSize.Std32) != null) { entry.getIcons().get(IconManager.IconSize.Std32).setImageIcon(appIcon); } appLabel.setIcon(IconManager.getIcon("AppIcon")); //$NON-NLS-1$ clearIconBtn.setEnabled(false); AppPreferences.getRemote().remove(iconImagePrefName); form.getValidator().dataChanged(null, null, null); } }); resetDefFontBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Font sysDefFont = UIRegistry.getDefaultFont(); ComboBoxModel model = fontNames.getModel(); for (int i = 0; i < model.getSize(); i++) { //System.out.println("["+model.getElementAt(i).toString()+"]["+sysDefFont.getFamily()+"]"); if (model.getElementAt(i).toString().equals(sysDefFont.getFamily())) { fontNames.setSelectedIndex(i); clearFontSettings = true; break; } } if (clearFontSettings) { fontSizes.setSelectedIndex(sysDefFont.getSize() - BASE_FONT_SIZE); clearFontSettings = true; // needs to be redone } form.getValidator().dataChanged(null, null, null); } }); //----------------------------------- // Do Banner Icon Size //----------------------------------- String fmtStr = "%d x %d pixels";//getResourceString("BNR_ICON_SIZE"); bnrIconSizeCBX = form.getCompById("bnrIconSizeCBX"); //$NON-NLS-1$ int size = AppPreferences.getLocalPrefs().getInt(BNR_ICON_SIZE, 20); inx = 0; cnt = 0; for (int pixelSize : pixelSizes) { ((DefaultComboBoxModel) bnrIconSizeCBX.getModel()) .addElement(String.format(fmtStr, pixelSize, pixelSize)); if (pixelSize == size) { inx = cnt; } cnt++; } bnrIconSizeCBX.getComboBox().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { form.getUIComponent().validate(); } }); bnrIconSizeCBX.getComboBox().setSelectedIndex(inx); UIValidator.setIgnoreAllValidation(this, false); fontNamesVCB.setChanged(false); fontSizesVCB.setChanged(false); form.getValidator().validateForm(); }
From source file:components.RootLayeredPaneDemo.java
public RootLayeredPaneDemo(JLayeredPane layeredPane) { super(new GridLayout(1, 1)); //Create and load the duke icon. final ImageIcon icon = createImageIcon("images/dukeWaveRed.gif"); //Create and set up the layered pane. this.layeredPane = layeredPane; layeredPane.addMouseMotionListener(this); //This is the origin of the first label added. Point origin = new Point(10, 100); //This is the offset for computing the origin for the next label. int offset = 35; //Add several overlapping, colored labels to the layered pane //using absolute positioning/sizing. for (int i = 0; i < layerStrings.length; i++) { JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin); layeredPane.add(label, new Integer(layers[i])); origin.x += offset;/*from w w w. j a v a 2s.c o m*/ origin.y += offset; } //Create and add the Duke label to the layered pane. dukeLabel = new JLabel(icon); if (icon != null) { dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight()); } else { System.err.println("Duke icon not found; using black square instead."); dukeLabel.setBounds(15, 225, 30, 30); dukeLabel.setOpaque(true); dukeLabel.setBackground(Color.BLACK); } layeredPane.add(dukeLabel, new Integer(layers[INITIAL_DUKE_LAYER_INDEX]), 0); //Add control pane to this JPanel. add(createControlPanel()); }
From source file:edu.ku.brc.specify.ui.AppBase.java
/** * @param imgEncoded uuencoded image string *//*from w w w . j a va 2 s . com*/ protected void setAppIcon(final String imgEncoded) { String appIconName = "AppIcon"; 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()) { appImgIcon = IconManager.getImage("SpecifyWhite32", IconManager.IconSize.Std32); //$NON-NLS-1$ } CustomDialog.setAppIcon(appImgIcon); CustomFrame.setAppIcon(appImgIcon); IconManager.register(innerAppIconName, appImgIcon, null, IconManager.IconSize.Std32); if (this.topFrame != null) { this.topFrame.setIconImage(appImgIcon.getImage()); } }
From source file:LayeredPaneDemo.java
public LayeredPaneDemo() { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); // Create and load the duke icon. final ImageIcon icon = new ImageIcon("yourFile.gif"); // Create and set up the layered pane. layeredPane = new JLayeredPane(); layeredPane.setPreferredSize(new Dimension(300, 310)); layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke")); layeredPane.addMouseMotionListener(this); // This is the origin of the first label added. Point origin = new Point(10, 20); // This is the offset for computing the origin for the next label. int offset = 35; // Add several overlapping, colored labels to the layered pane // using absolute positioning/sizing. for (int i = 0; i < layerStrings.length; i++) { JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin); layeredPane.add(label, new Integer(i)); origin.x += offset;/* w w w . java2 s . c o m*/ origin.y += offset; } // Create and add the Duke label to the layered pane. dukeLabel = new JLabel(icon); if (icon != null) { dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight()); } else { System.err.println("Duke icon not found; using black square instead."); dukeLabel.setBounds(15, 225, 30, 30); dukeLabel.setOpaque(true); dukeLabel.setBackground(Color.BLACK); } layeredPane.add(dukeLabel, new Integer(2), 0); // Add control pane and layered pane to this JPanel. add(Box.createRigidArea(new Dimension(0, 10))); add(createControlPanel()); add(Box.createRigidArea(new Dimension(0, 10))); add(layeredPane); }
From source file:edu.ku.brc.specify.datamodel.WorkbenchRow.java
/** * @param imageFile// www .ja v a 2s .c o 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:components.LayeredPaneDemo.java
public LayeredPaneDemo() { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); //Create and load the duke icon. final ImageIcon icon = createImageIcon("images/dukeWaveRed.gif"); //Create and set up the layered pane. layeredPane = new JLayeredPane(); layeredPane.setPreferredSize(new Dimension(300, 310)); layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke")); layeredPane.addMouseMotionListener(this); //This is the origin of the first label added. Point origin = new Point(10, 20); //This is the offset for computing the origin for the next label. int offset = 35; //Add several overlapping, colored labels to the layered pane //using absolute positioning/sizing. for (int i = 0; i < layerStrings.length; i++) { JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin); layeredPane.add(label, new Integer(i)); origin.x += offset;//from w ww . j av a2 s .c o m origin.y += offset; } //Create and add the Duke label to the layered pane. dukeLabel = new JLabel(icon); if (icon != null) { dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight()); } else { System.err.println("Duke icon not found; using black square instead."); dukeLabel.setBounds(15, 225, 30, 30); dukeLabel.setOpaque(true); dukeLabel.setBackground(Color.BLACK); } layeredPane.add(dukeLabel, new Integer(2), 0); //Add control pane and layered pane to this JPanel. add(Box.createRigidArea(new Dimension(0, 10))); add(createControlPanel()); add(Box.createRigidArea(new Dimension(0, 10))); add(layeredPane); }
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);/* ww w . j ava 2s .c o m*/ } // 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.//from w ww. jav a 2s. co 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 w ww . ja va2 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;// w w w. j a va2s . c o 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); } }