| AppletDemo.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.view.applet;
29
30 import javax.swing.JApplet;
31
32 import java.io.IOException;
33 import java.net.MalformedURLException;
34 import java.net.URL;
35 import java.net.URLConnection;
36
37 /**
38 * This class represents a simple graph editor applet. The applet can be used inside a web browser with
39 * a Java 2 plugin (version >= 1.4) installed.
40 * <p>
41 * This applet supports the applet parameter "graphsource" which allows to specify the graph that is initially
42 * displayed by the applet. The graph needs to be in GraphML format. URLs are specified relative to
43 * the document base of the applet.
44 * </p>
45 * <p>
46 * To compile and deploy the applet it is best to use the Ant build script "build.xml" located in this directory.
47 * It compiles the application classes, jars them as "application.jar" in this directory and also copies "y.jar" into this directory.
48 * Once these Jar files are in place, the applet can be launched by opening the included HTML page
49 * "applet.html" with your browser.
50 * </p>
51 * <p>
52 * This applet demo has been successfully tested with Internet Explorer 9, 7 and 6, Firefox 7 and 3.5, Chrome 15 and 3,
53 * and Safari 5 and 4.
54 * </p>
55 */
56 public class AppletDemo extends JApplet {
57
58 DemoEditor demoEditor;
59
60 /**
61 * Mandatory default constructor for an applet.
62 */
63 public AppletDemo() {
64 }
65
66 /**
67 * Applet initialization. Create the application GUI.
68 */
69 public void init() {
70 super.init();
71 demoEditor = new DemoEditor();
72 getRootPane().setContentPane(demoEditor);
73 getRootPane().setJMenuBar(demoEditor.createMenuBar());
74 }
75
76 /**
77 * Start the applet. Try to load the graph given by applet parameter "graphsource".
78 */
79 public void start() {
80 super.start();
81
82 String graphSource = getParameter("graphsource");
83
84 if (graphSource != null) {
85 try {
86 URL graphURL = new URL(getDocumentBase(), graphSource);
87 try {
88 URLConnection urlConnection = graphURL.openConnection();
89 urlConnection.connect();
90 } catch (IOException ioex) {
91 //try classpath if resource node located at document base
92 graphURL = DemoEditor.getResource(getClass(), graphSource);
93 }
94 if (graphURL != null) {
95 demoEditor.loadAndDisplayGraph(graphURL);
96 }
97 } catch (MalformedURLException muex) {
98 muex.printStackTrace();
99 }
100 }
101 }
102
103 /**
104 * Returns applet parameter information.
105 */
106 public String[][] getParameterInfo() {
107 return new String[][]{
108 // Parameter Name Kind of Value Description
109 {"graphsource", "URL", "an URL pointing to a diagram in GraphML format"}
110 };
111 }
112 }
113