| SimpleSVGNodeRealizerDemo.java |
1 /****************************************************************************
2 **
3 ** This file is part of the yFiles extension package ySVG-2.1.
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-2007 by yWorks GmbH, Vor dem Kreuzberg 28,
11 ** 72070 Tuebingen, Germany. All rights reserved.
12 **
13 ***************************************************************************/
14
15 package demo.yext.svg;
16
17 import java.io.File;
18 import java.net.URL;
19
20 import y.view.Arrow;
21 import yext.svg.view.SVGNodeRealizer;
22
23 /**
24 * Demonstrates the usage of a SVGNodeRealizer which displays a node
25 * as a scalable vector graphic.
26 * <p>
27 * The SVG file describing the graphics of the node to be displayed
28 * can be given on the commandline. See the resource folder for
29 * examples of svg files.
30 */
31 public class SimpleSVGNodeRealizerDemo extends SVGExportDemo
32 {
33 /**
34 * Instantiates SVGNodeDemo with a given URL that has
35 * to refer to a resource in SVG format
36 */
37 public SimpleSVGNodeRealizerDemo(URL svgURL)
38 {
39 SVGNodeRealizer nr = new SVGNodeRealizer(svgURL);
40 view.getGraph2D().setDefaultNodeRealizer(nr);
41
42 view.getGraph2D().getDefaultEdgeRealizer().setArrow(Arrow.WHITE_DELTA);
43 }
44
45 /**
46 * Launches this demo.
47 */
48 public static void main(String[] args)
49 {
50 initLnF();
51
52 SimpleSVGNodeRealizerDemo demo;
53 if(args.length > 0)
54 {
55 demo = new SimpleSVGNodeRealizerDemo(getURL(args[0]));
56 }
57 else
58 {
59 demo = new SimpleSVGNodeRealizerDemo(getURL("resource/svg/logo.svg"));
60 }
61 demo.start();
62 }
63
64 static URL getURL(String res)
65 {
66 try
67 {
68 URL url = SimpleSVGNodeRealizerDemo.class.getResource(res);
69 if(url == null)
70 {
71 url = new File(res).toURL();
72 }
73 return url;
74 }
75 catch(Exception ex)
76 {
77 System.err.println("Can't find SVG resource " + res);
78 ex.printStackTrace(System.err);
79 return null;
80 }
81 }
82 }
83