001: /*
002: * $Id: JGraphpadDemo.java,v 1.1 2006/01/31 15:33:25 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.awt.Window;
013: import java.io.IOException;
014: import java.net.MalformedURLException;
015: import java.util.Hashtable;
016: import java.util.List;
017: import java.util.Map;
018:
019: import javax.xml.parsers.ParserConfigurationException;
020:
021: import org.xml.sax.SAXException;
022:
023: import com.jgraph.editor.JGraphEditorFile;
024: import com.jgraph.editor.JGraphEditorKit;
025: import com.jgraph.editor.JGraphEditorModel;
026: import com.jgraph.pad.action.JGraphpadFileAction;
027:
028: /**
029: * @author Administrator
030: *
031: */
032: public class JGraphpadDemo extends JGraphpad {
033:
034: /**
035: *
036: */
037: private static final String MESSAGE = "This demo does not allow to open or save files.";
038:
039: /**
040: * Issues a warning message in the online demo.
041: */
042: public Window createApplication(List files, Map args)
043: throws ParserConfigurationException, SAXException,
044: IOException {
045: args.put(ARG_JGOODIESLOOKANDFEEL, "");
046: Window wnd = super .createApplication(null, args);
047: System.err.println(MESSAGE);
048: return wnd;
049: }
050:
051: /**
052: * Creates a model that does not allow to add files.
053: */
054: protected JGraphEditorModel createModel() {
055: JGraphEditorModel model = new JGraphEditorModel() {
056: public Object addFile(String uri) {
057: throw new RuntimeException(MESSAGE);
058: }
059: };
060: configureModel(model);
061: return model;
062: }
063:
064: /**
065: * Replaces some actions with empty implementations.
066: */
067: protected void addActions(JGraphEditor editor, JGraphEditorKit kit) {
068: super .addActions(editor, kit);
069: kit.addBundle(new AllActions(editor));
070: }
071:
072: /**
073: * Replaces file open / save action with different actions.
074: *
075: */
076: public static class JGraphpadDemoFileAction extends
077: JGraphpadFileAction {
078:
079: /**
080: * @param name
081: * @param editor
082: */
083: public JGraphpadDemoFileAction(String name, JGraphEditor editor) {
084: super (name, editor);
085: }
086:
087: /**
088: * Replaces the saveFile action with an error message.
089: */
090: protected void doSaveFile(JGraphEditorFile file,
091: boolean forceFilenameDialog, boolean urlDialog)
092: throws IOException {
093: throw new RuntimeException(MESSAGE);
094: }
095:
096: /**
097: * Replaces the open action with an error message.
098: */
099: public void doSave(String filename, byte[] data)
100: throws Exception {
101: throw new RuntimeException(MESSAGE);
102: }
103:
104: /**
105: * Replaces the saveFile action with an error message.
106: */
107: protected void doOpenFile(String filename)
108: throws MalformedURLException, IOException {
109: throw new RuntimeException(MESSAGE);
110: }
111:
112: }
113:
114: /**
115: * Bundle of all actions in this class.
116: */
117: public static class AllActions extends
118: JGraphpadFileAction.AllActions {
119:
120: /**
121: * Constructs the action bundle for the specified editor.
122: *
123: * @param editor
124: * The enclosing editor for this bundle.
125: */
126: public AllActions(JGraphEditor editor) {
127: super (editor);
128: actionClose = new JGraphpadDemoFileAction(
129: JGraphpadFileAction.NAME_CLOSE, editor);
130: actionCloseAll = new JGraphpadDemoFileAction(
131: JGraphpadFileAction.NAME_CLOSE, editor);
132: actionOpen = new JGraphpadDemoFileAction(
133: JGraphpadFileAction.NAME_OPEN, editor);
134: actionSave = new JGraphpadDemoFileAction(
135: JGraphpadFileAction.NAME_SAVE, editor);
136: actionSaveAs = new JGraphpadDemoFileAction(
137: JGraphpadFileAction.NAME_SAVEAS, editor);
138: actionSaveAll = new JGraphpadDemoFileAction(
139: JGraphpadFileAction.NAME_SAVEALL, editor);
140: }
141:
142: /*
143: * (non-Javadoc)
144: */
145: public void update() {
146: actionOpen.setEnabled(false);
147: actionSave.setEnabled(false);
148: actionSaveAs.setEnabled(false);
149: actionSaveAll.setEnabled(false);
150: actionUploadAs.setEnabled(false);
151: }
152:
153: }
154:
155: //
156: // Main
157: //
158:
159: /**
160: * Constructs and displays a new application window.
161: *
162: * @param args
163: * The command line arguments to pass to the application.
164: */
165: public static void main(String[] args) {
166: try {
167: new JGraphpadDemo()
168: .createApplication(null, new Hashtable());
169: } catch (Exception e) {
170: e.printStackTrace();
171: }
172: }
173: }
|