1   package demo.yext.graphml;
2   
3   import org.graphdrawing.graphml.reader.dom.DOMGraphMLParseContext;
4   import org.graphdrawing.graphml.reader.dom.DOMInputHandler;
5   import org.graphdrawing.graphml.reader.dom.Precedence;
6   import org.w3c.dom.NamedNodeMap;
7   import org.w3c.dom.Node;
8   import y.util.D;
9   import yext.graphml.graph2D.GraphMLIOHandler;
10  
11  import javax.swing.JMenu;
12  
13  /**
14   * A simple customization of {@link GraphMLDemo} that uses objects of type 
15   * {@link CustomNodeRealizer} as the graph's default node realizer. 
16   * To enable encoding and parsing of this node realizer type a specific serializer 
17   * implementation is registered with GraphMLIOHandler. 
18   */
19  public class CustomNodeRealizerSerializerDemo extends GraphMLDemo {
20    /**
21     * Creates a new instance of CustomNodeRealizerSerializerDemo.
22     */
23    public CustomNodeRealizerSerializerDemo() {
24      // Use another default node realizer. 
25      view.getGraph2D().setDefaultNodeRealizer(new CustomNodeRealizer());
26    }
27  
28    protected JMenu createSampleGraphMenu() {
29      return createSampleGraphMenu(new String[]{"resources/custom/custom-noderealizer-serializer.graphml"});
30    }
31  
32    protected GraphMLIOHandler createGraphMLIOHandler() {
33      GraphMLIOHandler ioHandler = new GraphMLIOHandler();
34      // Register the node realizer's specific serializer that knows how to encode 
35      // valid XML markup and also how to parse the encoded data.
36      ioHandler.getRealizerSerializerManager().addNodeRealizerSerializer(new CustomNodeRealizerSerializer());
37      ioHandler.addNamespace("demo.yext.graphml.CustomNodeRealizerSerializer", "custom");
38  
39      return ioHandler;
40    }
41  
42    /**
43     * Launches this demo. 
44     */
45    public static void main(String[] args) {
46      initLnF();
47      final CustomNodeRealizerSerializerDemo demo = new CustomNodeRealizerSerializerDemo();
48      demo.start();
49    }
50  }
51