コード例 #1
0
 private static mxGraphModel getMxGraphModel(String gxml) {
   mxCodec codec = new mxCodec();
   org.w3c.dom.Document doc = mxXmlUtils.parseXml(gxml);
   codec = new mxCodec(doc);
   mxGraphModel model = (mxGraphModel) codec.decode(doc.getDocumentElement());
   return model;
 }
コード例 #2
0
  @Test
  public void testPng() throws Exception {
    String path =
        ProcessDefManagerTest.class.getClassLoader().getResource("graphsub.xml").getPath();
    String value = FileUtils.readFileToString(new File(path));
    mxCodec codec = new mxCodec();
    org.w3c.dom.Document doc = mxXmlUtils.parseXml(value);
    codec = new mxCodec(doc);
    mxGraphModel model = (mxGraphModel) codec.decode(doc.getDocumentElement());
    mxGraph graph = new mxGraph();
    graph.setModel(model);
    BufferedImage image =
        mxCellRenderer.createBufferedImage(graph, null, 1, Color.WHITE, true, null);
    byte[] ret = null;
    ByteArrayOutputStream outputStream = null;
    try {
      outputStream = new ByteArrayOutputStream();
      ImageIO.write(image, "png", outputStream);
      ret = outputStream.toByteArray();
      FileUtils.writeByteArrayToFile(new File("/Users/lihao/Downloads/graph.png"), ret);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }