| CustomNodeRealizerSerializerDemo.java |
1 /****************************************************************************
2 **
3 ** This file is part of yFiles-2.9.
4 **
5 ** yWorks proprietary/confidential. Use is subject to license terms.
6 **
7 ** Redistribution of this file or of an unauthorized byte-code version
8 ** of this file is strictly forbidden.
9 **
10 ** Copyright (c) 2000-2011 by yWorks GmbH, Vor dem Kreuzberg 28,
11 ** 72070 Tuebingen, Germany. All rights reserved.
12 **
13 ***************************************************************************/
14 package demo.io.graphml;
15
16 import y.io.GraphMLIOHandler;
17 import y.view.PolyLineEdgeRealizer;
18 import y.view.Arrow;
19
20 import java.awt.EventQueue;
21 import java.util.Locale;
22
23 /**
24 * A simple customization of {@link demo.io.graphml.GraphMLDemo} that uses objects of type
25 * {@link demo.io.graphml.CustomNodeRealizer} as the graph's default node realizer.
26 * To enable encoding and parsing of this node realizer type a specific serializer
27 * implementation is registered with GraphMLIOHandler.
28 *
29 * @see <a href="http://docs.yworks.com/yfiles/doc/developers-guide/graphml.html#graphml_custom_realizer_serializer">Section Support for Custom Realizer</a> in the yFiles for Java Developer's Guide
30 */
31 public class CustomNodeRealizerSerializerDemo extends GraphMLDemo {
32 /**
33 * Creates a new instance of CustomNodeRealizerSerializerDemo.
34 */
35 public CustomNodeRealizerSerializerDemo() {
36 // Use another default node realizer (the one used in the example graph).
37 view.getGraph2D().setDefaultNodeRealizer(new CustomNodeRealizer());
38
39 // Use a default edge realizer as in the example graph.
40 PolyLineEdgeRealizer edgeRealizer = new PolyLineEdgeRealizer();
41 edgeRealizer.setTargetArrow(Arrow.NONE);
42 view.getGraph2D().setDefaultEdgeRealizer(edgeRealizer);
43 }
44
45
46 protected void loadInitialGraph() {
47 // Load example graph.
48 loadGraph("resources/custom/custom-noderealizer-serializer.graphml");
49 }
50
51 protected String[] getExampleResources() {
52 return null;
53 }
54
55 protected GraphMLIOHandler createGraphMLIOHandler() {
56 GraphMLIOHandler ioHandler = new GraphMLIOHandler();
57 // Register the node realizer's specific serializer that knows how to encode
58 // valid XML markup and also how to parse the encoded data.
59 ioHandler.addNodeRealizerSerializer(new CustomNodeRealizerSerializer());
60 return ioHandler;
61 }
62
63 /**
64 * Launches this demo.
65 */
66 public static void main(String[] args) {
67 EventQueue.invokeLater(new Runnable() {
68 public void run() {
69 Locale.setDefault(Locale.ENGLISH);
70 initLnF();
71 new CustomNodeRealizerSerializerDemo().start();
72 }
73 });
74 }
75 }
76