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