Document doc = mxXmlUtils.parseXml(erXmlString); mxGraph graph = new mxGraph(); mxCodec codec = new mxCodec(doc); codec.decode(doc.getDocumentElement(), graph.getModel()); mxGraphComponent graphComponent = new mxGraphComponent(graph); BufferedImage image = mxCellRenderer.createBufferedImage(graphComponent.getGraph(), null, 1, Color.WHITE, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image); param.setCompressedText(new String[] { "mxGraphModel", erXmlString }); FileOutputStream outputStream = new FileOutputStream(new File(filename)); mxPngImageEncoder encoder = new mxPngImageEncoder(outputStream, param); if (image != null) { encoder.encode(image); return image; } outputStream.close(); return null; }
/** * */ public ImageIcon createTransferableImage(mxGraphComponent graphComponent, Object[] cells) { ImageIcon icon = null; Color bg = (transferImageBackground != null) ? transferImageBackground : graphComponent.getBackground(); Image img = mxCellRenderer.createBufferedImage( graphComponent.getGraph(), cells, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); if (img != null) { icon = new ImageIcon(img); } return icon; }
/** * */ public ImageIcon createTransferableImage(mxGraphComponent graphComponent, Object[] cells) { ImageIcon icon = null; Color bg = (transferImageBackground != null) ? transferImageBackground : graphComponent.getBackground(); Image img = mxCellRenderer.createBufferedImage( graphComponent.getGraph(), cells, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); if (img != null) { icon = new ImageIcon(img); } return icon; }
/** * Saves XML+PNG format. * @param frame */ protected void saveXmlPng(TrackSchemeFrame frame, String filename, Color bg) throws IOException { final mxGraphComponent graphComponent = trackScheme.getGUI().graphComponent; final mxGraph graph = trackScheme.getGraph(); // Creates the image for the PNG file BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); // Creates the URL-encoded XML data mxCodec codec = new mxCodec(); String xml = URLEncoder.encode(mxXmlUtils.getXml(codec.encode(graph.getModel())), "UTF-8"); mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image); param.setCompressedText(new String[] { "mxGraphModel", xml }); // Saves as a PNG file try (FileOutputStream outputStream = new FileOutputStream( new File( filename ) )) { mxPngImageEncoder encoder = new mxPngImageEncoder( outputStream, param ); if ( image != null ) encoder.encode( image ); else JOptionPane.showMessageDialog( graphComponent, "No Image Data" ); } }
saveXmlPng(trackScheme.getGUI(), filename, bg); } else { BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas());
/** * Saves XML+PNG format. * @param frame */ protected void saveXmlPng(TrackSchemeFrame frame, String filename, Color bg) throws IOException { final mxGraphComponent graphComponent = trackScheme.getGUI().graphComponent; final mxGraph graph = trackScheme.getGraph(); // Creates the image for the PNG file BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); // Creates the URL-encoded XML data mxCodec codec = new mxCodec(); String xml = URLEncoder.encode(mxXmlUtils.getXml(codec.encode(graph.getModel())), "UTF-8"); mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image); param.setCompressedText(new String[] { "mxGraphModel", xml }); // Saves as a PNG file try (FileOutputStream outputStream = new FileOutputStream( new File( filename ) )) { mxPngImageEncoder encoder = new mxPngImageEncoder( outputStream, param ); if ( image != null ) encoder.encode( image ); else JOptionPane.showMessageDialog( graphComponent, "No Image Data" ); } }
saveXmlPng(trackScheme.getGUI(), filename, bg); } else { BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas());
/** * */ public void updateDragImage(Object[] cells) { dragImage = null; if (cells != null && cells.length > 0) { Image img = mxCellRenderer.createBufferedImage( graphComponent.getGraph(), cells, graphComponent.getGraph() .getView().getScale(), null, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); if (img != null) { dragImage = new ImageIcon(img); previewBounds.setSize(dragImage.getIconWidth(), dragImage.getIconHeight()); } } }
/** * */ public void updateDragImage(Object[] cells) { dragImage = null; if (cells != null && cells.length > 0) { Image img = mxCellRenderer.createBufferedImage( graphComponent.getGraph(), cells, graphComponent.getGraph() .getView().getScale(), null, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); if (img != null) { dragImage = new ImageIcon(img); previewBounds.setSize(dragImage.getIconWidth(), dragImage.getIconHeight()); } } }
if (graphComponent.isAntiAlias())
if (graphComponent.isAntiAlias())
if (graphComponent.isAntiAlias())
if (graphComponent.isAntiAlias())