001: /*
002: * $Id: JGraphpadApplet.java,v 1.7 2006/03/15 07:23:29 gaudenz Exp $
003: * Copyright (c) 2001-2005, Gaudenz Alder
004: *
005: * All rights reserved.
006: *
007: * See LICENSE file for license details. If you are unable to locate
008: * this file please contact info (at) jgraph (dot) com.
009: */
010: package com.jgraph;
011:
012: import java.applet.Applet;
013: import java.awt.BorderLayout;
014: import java.awt.event.ActionEvent;
015: import java.awt.event.ActionListener;
016: import java.util.Hashtable;
017: import java.util.Map;
018:
019: import javax.swing.JButton;
020: import javax.swing.JTextPane;
021: import javax.swing.text.rtf.RTFEditorKit;
022:
023: import com.jgraph.pad.dialog.JGraphpadDialogs;
024: import com.jgraph.pad.graph.JGraphpadEdgeRenderer;
025: import com.jgraph.pad.graph.JGraphpadEdgeView;
026: import com.jgraph.pad.graph.JGraphpadRichTextEditor;
027: import com.jgraph.pad.graph.JGraphpadRichTextValue;
028: import com.jgraph.pad.graph.JGraphpadVertexRenderer;
029: import com.jgraph.pad.graph.JGraphpadVertexView;
030: import com.jgraph.pad.util.JGraphpadFocusManager;
031:
032: /**
033: * Displays a button to launch a new JGraphpad application.
034: */
035: public class JGraphpadApplet extends Applet {
036:
037: /**
038: * Contains the arguments found in the init method.
039: */
040: protected Map arguments;
041:
042: /**
043: * Constructs a new JGraphpad applet.
044: */
045: public JGraphpadApplet() {
046: appletStaticFixes();
047: setLayout(new BorderLayout());
048:
049: // Adds the start button to the applet
050: // and trigger class init
051: JButton startButton = new JButton(JGraphpad.APPTITLE);
052:
053: // Starts a new application when the start button
054: // is clicked. This overrides the exit method
055: // of JGraphpad, not JGraphEditor.
056: startButton.addActionListener(new ActionListener() {
057: public void actionPerformed(ActionEvent e) {
058: try {
059: // Overrides the exit method to not
060: // call System.exit, but stop the
061: // applet instead.
062: new JGraphpad() {
063: protected void exit(int code) {
064: // empty
065: }
066: }.createApplication(null, arguments);
067:
068: } catch (Exception e1) {
069: JGraphpadDialogs.getSharedInstance().errorDialog(
070: JGraphpadApplet.this , e1.getMessage());
071: e1.printStackTrace();
072: }
073: }
074: });
075: add(startButton, BorderLayout.CENTER);
076: }
077:
078: /**
079: * Fetches the parameters from the applet tag.
080: */
081: public void init() {
082: setLayout(new BorderLayout());
083:
084: // Constructs the arguments from the applet
085: // parameters. This requires the arguments
086: // to be known by name, however, since most
087: // applet pages are static this should be OK.
088: // Override the hook to add more arguments.
089: arguments = processArguments();
090: }
091:
092: /**
093: * Hook for subclassers to add more arguments from the applet page. It is
094: * allowed to return null, eg:
095: *
096: * <PRE>
097: *
098: * String param = getParameter("myParameter"); if (param != null)
099: * arguments.put("myParameter", param);
100: *
101: * </PRE>
102: */
103: protected Map processArguments() {
104: return new Hashtable();
105: }
106:
107: /**
108: * Workaround for the statics not reloaded in applet problem.
109: *
110: */
111: public void appletStaticFixes() {
112: // These cases fall foul of an applet re-load. The browser plugin
113: // doesn't reload classes in this case which means statics are not
114: // re-initialized.
115: JGraphpadFocusManager.currentGraphFocusManager = new JGraphpadFocusManager();
116: JGraphpadRichTextValue.editorKit = new RTFEditorKit();
117: JGraphpadVertexRenderer.textPane = new JTextPane();
118: JGraphpadVertexView.editor = new JGraphpadRichTextEditor();
119: JGraphpadVertexView.renderer = new JGraphpadVertexRenderer();
120: JGraphpadEdgeView.editor = new JGraphpadRichTextEditor();
121: JGraphpadEdgeView.renderer = new JGraphpadEdgeRenderer();
122: }
123:
124: }
|