| CustomNodeRealizerSerializerDemo.java |
1 /****************************************************************************
2 * This demo file is part of yFiles for Java 2.14.
3 * Copyright (c) 2000-2017 by yWorks GmbH, Vor dem Kreuzberg 28,
4 * 72070 Tuebingen, Germany. All rights reserved.
5 *
6 * yFiles demo files exhibit yFiles for Java functionalities. Any redistribution
7 * of demo files in source code or binary form, with or without
8 * modification, is not permitted.
9 *
10 * Owners of a valid software license for a yFiles for Java version that this
11 * demo is shipped with are allowed to use the demo source code as basis
12 * for their own yFiles for Java powered applications. Use of such programs is
13 * governed by the rights and conditions as set out in the yFiles for Java
14 * license agreement.
15 *
16 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL yWorks BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 ***************************************************************************/
28 package demo.io.graphml;
29
30 import y.io.GraphMLIOHandler;
31 import y.view.PolyLineEdgeRealizer;
32 import y.view.Arrow;
33
34 import java.awt.EventQueue;
35 import java.util.Locale;
36
37 /**
38 * A simple customization of {@link demo.io.graphml.GraphMLDemo} that uses objects of type
39 * {@link demo.io.graphml.CustomNodeRealizer} as the graph's default node realizer.
40 * To enable encoding and parsing of this node realizer type a specific serializer
41 * implementation is registered with GraphMLIOHandler.
42 *
43 * @see <a href="http://docs.yworks.com/yfiles/doc/api/index.html#/dguide/graphml#graphml_custom_realizer_serializer" target="_blank">Section Support for Custom Realizer</a> in the yFiles for Java Developer's Guide
44 */
45 public class CustomNodeRealizerSerializerDemo extends GraphMLDemo {
46 /**
47 * Creates a new instance of CustomNodeRealizerSerializerDemo.
48 */
49 public CustomNodeRealizerSerializerDemo() {
50 // Use another default node realizer (the one used in the example graph).
51 view.getGraph2D().setDefaultNodeRealizer(new CustomNodeRealizer());
52
53 // Use a default edge realizer as in the example graph.
54 PolyLineEdgeRealizer edgeRealizer = new PolyLineEdgeRealizer();
55 edgeRealizer.setTargetArrow(Arrow.NONE);
56 view.getGraph2D().setDefaultEdgeRealizer(edgeRealizer);
57 }
58
59
60 protected void loadInitialGraph() {
61 // Load example graph.
62 loadGraph("resources/custom/custom-noderealizer-serializer.graphml");
63 }
64
65 protected String[] getExampleResources() {
66 return null;
67 }
68
69 protected GraphMLIOHandler createGraphMLIOHandler() {
70 GraphMLIOHandler ioHandler = new GraphMLIOHandler();
71 // Register the node realizer's specific serializer that knows how to encode
72 // valid XML markup and also how to parse the encoded data.
73 ioHandler.addNodeRealizerSerializer(new CustomNodeRealizerSerializer());
74 return ioHandler;
75 }
76
77 /**
78 * Launches this demo.
79 */
80 public static void main(String[] args) {
81 EventQueue.invokeLater(new Runnable() {
82 public void run() {
83 Locale.setDefault(Locale.ENGLISH);
84 initLnF();
85 new CustomNodeRealizerSerializerDemo().start();
86 }
87 });
88 }
89 }
90