mxCodec codec = new mxCodec(); String xml = mxXmlUtils.getXml(codec.encode(graph.getModel()));
/** * Encoding of cell hierarchies is built-into the core, but is a * higher-level function that needs to be explicitely used by the * respective object encoders (eg. mxModelCodec, mxChildChangeCodec * and mxRootChangeCodec). This implementation writes the given cell * and its children as a (flat) sequence into the given node. The * children are not encoded if the optional includeChildren is false. * The function is in charge of adding the result into the given node * and has no return value. * * @param cell mxCell to be encoded. * @param node Parent XML node to add the encoded cell into. * @param includeChildren Boolean indicating if the method * should include all descendents. */ public void encodeCell(mxICell cell, Node node, boolean includeChildren) { node.appendChild(encode(cell)); if (includeChildren) { int childCount = cell.getChildCount(); for (int i = 0; i < childCount; i++) { encodeCell(cell.getChildAt(i), node, includeChildren); } } }
/** * Writes the given value as a child node of the given node. */ protected void writeComplexAttribute(mxCodec enc, Object obj, String attr, Object value, Node node) { Node child = enc.encode(value); if (child != null) { if (attr != null) { mxCodec.setAttribute(child, "as", attr); } node.appendChild(child); } else { System.err.println("mxObjectCodec.encode: No node for " + getName() + "." + attr + ": " + value); } }
/** * Encoding of cell hierarchies is built-into the core, but is a * higher-level function that needs to be explicitely used by the * respective object encoders (eg. mxModelCodec, mxChildChangeCodec * and mxRootChangeCodec). This implementation writes the given cell * and its children as a (flat) sequence into the given node. The * children are not encoded if the optional includeChildren is false. * The function is in charge of adding the result into the given node * and has no return value. * * @param cell mxCell to be encoded. * @param node Parent XML node to add the encoded cell into. * @param includeChildren Boolean indicating if the method * should include all descendents. */ public void encodeCell(mxICell cell, Node node, boolean includeChildren) { node.appendChild(encode(cell)); if (includeChildren) { int childCount = cell.getChildCount(); for (int i = 0; i < childCount; i++) { encodeCell(cell.getChildAt(i), node, includeChildren); } } }
/** * Writes the given value as a child node of the given node. */ protected void writeComplexAttribute(mxCodec enc, Object obj, String attr, Object value, Node node) { Node child = enc.encode(value); if (child != null) { if (attr != null) { mxCodec.setAttribute(child, "as", attr); } node.appendChild(child); } else { log.log(Level.FINEST, "mxObjectCodec.encode: No node for " + getName() + "." + attr + ": " + value); } }
/** * 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" ); } }
String xml = mxXmlUtils.getXml(codec.encode(graph.getModel())); mxUtils.writeFile(xml, filename);
/** * 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" ); } }
String xml = mxXmlUtils.getXml(codec.encode(graph.getModel())); mxUtils.writeFile(xml, filename);