1   package demo.yext.graphml;
2   
3   import org.graphdrawing.graphml.GraphMLConstants;
4   import org.graphdrawing.graphml.writer.GraphElementProvider;
5   import yext.graphml.compat.ReadEdgeLayoutHandler;
6   import yext.graphml.compat.ReadNodeLayoutHandler;
7   import yext.graphml.compat.WriteEdgeLayoutHandler;
8   import yext.graphml.compat.WriteNodeLayoutHandler;
9   import yext.graphml.compat.WritePortLayoutHandler;
10  import yext.graphml.compat.DotnetGraphElementProvider;
11  import yext.graphml.compat.DotnetGraphElementFactory;
12  import yext.graphml.compat.ReadPortLayoutHandler;
13  import yext.graphml.graph2D.GraphMLIOHandler;
14  import yext.graphml.reader.YGraphElementFactory;
15  
16  import javax.swing.JMenu;
17  
18  import y.view.Graph2D;
19  
20  /**
21   * Simple demo that shows how to read and write basic layout information in .NET GraphML dialect.
22   */
23  public class DotnetCompatDemo extends GraphMLDemo {
24  
25    protected GraphMLIOHandler createGraphMLIOHandler() {
26      return new DotnetCompatGraphMLIOHandler();
27    }
28  
29    /**
30     * Launches this demo.
31     */
32    public static void main(String[] args) {
33      initLnF();
34      final DotnetCompatDemo demo = new DotnetCompatDemo();
35      demo.start();
36    }
37  }
38  
39  class DotnetCompatGraphMLIOHandler extends GraphMLIOHandler {
40    public void setIgnoreGraphicsEnabled(boolean b) {
41    }
42  
43    public boolean isIgnoreGraphicsEnabled() {
44      return true;
45    }
46  
47    /**
48     * Creates a new instance of the IOHandler.
49     */
50    public DotnetCompatGraphMLIOHandler() {
51      super.setIgnoreGraphicsEnabled(true);
52      super.setWriteEmbeddedResources(false);
53      super.addNamespace(GraphMLConstants.YWORKS_EXT_NS_URI, "y");
54      super.addSchemaLocation(GraphMLConstants.GRAPHML_BASE_NS_URI,
55          "http://www.yworks.com/xml/schema/graphml/1.0/ygraphml.xsd");
56      addInputHandler(new ReadNodeLayoutHandler());
57      addInputHandler(new ReadEdgeLayoutHandler());
58      addInputHandler(new ReadPortLayoutHandler());
59  
60      addOutputHandler(new WriteNodeLayoutHandler(), GraphMLConstants.SCOPE_NODE);
61      addOutputHandler(new WriteEdgeLayoutHandler(), GraphMLConstants.SCOPE_EDGE);
62      addOutputHandler(new WritePortLayoutHandler(), GraphMLConstants.SCOPE_PORT);
63    }
64  
65  
66    protected YGraphElementFactory createGraphElementFactory(Graph2D graph) {
67      return new DotnetGraphElementFactory(graph);
68    }
69  
70    protected GraphElementProvider createGraphElementProvider(Graph2D graph) {
71      return new DotnetGraphElementProvider(graph);
72    }
73  }
74