001: /*
002: * $Id: JGraphEditor.java,v 1.1.1.1 2005/08/04 11:21:58 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.io.File;
013: import java.net.MalformedURLException;
014: import java.net.URL;
015:
016: import com.jgraph.editor.JGraphEditorFactory;
017: import com.jgraph.editor.JGraphEditorKit;
018: import com.jgraph.editor.JGraphEditorModel;
019: import com.jgraph.editor.JGraphEditorSettings;
020:
021: /**
022: * Defines the structure of an JGraph editor.
023: */
024: public class JGraphEditor {
025:
026: /**
027: * Global static product identifier.
028: */
029: public static final String VERSION = "JGraphEditor (v6.0.4.0)";
030:
031: /**
032: * Holds the settings.
033: */
034: protected JGraphEditorSettings settings;
035:
036: /**
037: * Holds the document model.
038: */
039: protected JGraphEditorModel model;
040:
041: /**
042: * Holds the editor kit.
043: */
044: protected JGraphEditorKit kit;
045:
046: /**
047: * Holds the UI factory.
048: */
049: protected JGraphEditorFactory factory;
050:
051: /**
052: * Constructs an empty editor.
053: */
054: public JGraphEditor() {
055: this (null);
056: }
057:
058: /**
059: * Constructs a new editor for the specified settings and model.
060: *
061: * @param settings
062: * The settings to use for the editor.
063: */
064: public JGraphEditor(JGraphEditorSettings settings) {
065: this (settings, null, null, null);
066: }
067:
068: /**
069: * Constructs a new editor for the specified settings and model.
070: *
071: * @param settings
072: * The settings to use for the editor.
073: * @param model
074: * The model to use as the document model.
075: * @param kit
076: * The kit to be used to store the actions and tools.
077: * @param factory
078: * The factory to be used to creat the user interface.
079: */
080: public JGraphEditor(JGraphEditorSettings settings,
081: JGraphEditorModel model, JGraphEditorKit kit,
082: JGraphEditorFactory factory) {
083: this .settings = settings;
084: this .model = model;
085: this .kit = kit;
086: this .factory = factory;
087: }
088:
089: /**
090: * Implements an application exit. This implementation invokes
091: * {@link JGraphEditorSettings#shutdown()}. Subclassers should call the
092: * superclass method as the first step. Note: This method is never called
093: * from within the framework.
094: */
095: public void exit(int code) {
096: getSettings().shutdown();
097: }
098:
099: /**
100: * @return Returns the settings.
101: */
102: public JGraphEditorSettings getSettings() {
103: return settings;
104: }
105:
106: /**
107: * @param settings
108: * The settings to set.
109: */
110: public void setSettings(JGraphEditorSettings settings) {
111: this .settings = settings;
112: }
113:
114: /**
115: * @return Returns the factory.
116: */
117: public JGraphEditorFactory getFactory() {
118: return factory;
119: }
120:
121: /**
122: * @param factory
123: * The factory to set.
124: */
125: public void setFactory(JGraphEditorFactory factory) {
126: this .factory = factory;
127: }
128:
129: /**
130: * @return Returns the kit.
131: */
132: public JGraphEditorKit getKit() {
133: return kit;
134: }
135:
136: /**
137: * @param kit
138: * The kit to set.
139: */
140: public void setKit(JGraphEditorKit kit) {
141: this .kit = kit;
142: }
143:
144: /**
145: * @return Returns the model.
146: */
147: public JGraphEditorModel getModel() {
148: return model;
149: }
150:
151: /**
152: * @param model
153: * The model to set.
154: */
155: public void setModel(JGraphEditorModel model) {
156: this .model = model;
157: }
158:
159: /**
160: * Returns true if the specified value is a URL, that is, if it starts with
161: * one of http://, mailto:, ftp://, file:, https://, webdav:// or
162: * webdavs://.
163: *
164: * @param value
165: * The value that represents a potential URL.
166: * @return Returns true if <code>value</code> is a URL.
167: */
168: public static boolean isURL(Object value) {
169: return (value != null && (value.toString()
170: .startsWith("http://")
171: || value.toString().startsWith("mailto:")
172: || value.toString().startsWith("ftp://")
173: || value.toString().startsWith("file:")
174: || value.toString().startsWith("https://")
175: || value.toString().startsWith("webdav://") || value
176: .toString().startsWith("webdavs://")));
177: }
178:
179: /**
180: * Returns a URL representation for the specified file or an empty string if
181: * there was an exception. This method silently ignores exceptions.
182: *
183: * @param file
184: * The file to return the URL for.
185: * @return Returns the URL representation of <code>file</code> or an empty
186: * string.
187: */
188: public static String toURL(File file) {
189: String result = "";
190: try {
191: result = file.toURL().toString();
192: } catch (MalformedURLException e) {
193: // ignore
194: }
195: return result;
196: }
197:
198: /**
199: * Returns a URL representation for the specified string or null if there
200: * was an exception. This method silently ignores exceptions.
201: *
202: * @param s
203: * The string to return the URL for.
204: * @return Returns the URL representation of <code>string</code> or null.
205: */
206: public static URL toURL(String s) {
207: try {
208: return new URL(String.valueOf(s));
209: } catch (MalformedURLException e) {
210: // ignore
211: }
212: return null;
213: }
214:
215: public static void main(String[] args) {
216: System.out.println(VERSION);
217: }
218:
219: }
|