001: /*
002: * Copyright (c) 2000 - 2001, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: */
022:
023: package org.skunk.dav.client.gui;
024:
025: import java.awt.Cursor;
026: import java.awt.event.WindowAdapter;
027: import java.awt.event.WindowEvent;
028: import java.beans.PropertyVetoException;
029: import java.io.File;
030: import java.io.IOException;
031: import java.util.ArrayList;
032: import java.util.Iterator;
033: import java.util.ListIterator;
034: import javax.swing.JComponent;
035: import javax.swing.JFrame;
036: import javax.swing.JScrollPane;
037: import javax.swing.JTabbedPane;
038: import javax.swing.SwingConstants;
039: import org.skunk.config.Configurator;
040: import org.skunk.config.LocalConfigStore;
041: import org.skunk.dav.client.gui.editor.EditEvent;
042: import org.skunk.dav.client.gui.editor.EditListener;
043: import org.skunk.trace.Debug;
044:
045: public class ExplorerApp implements AppContext {
046: public static final String DAV_DIR = ".skunkdav";
047: public static final String CONFIG_DATA = "config.dat";
048:
049: private Configurator configurator;
050: private static AppContext appContext;
051:
052: private ArrayList viewList;
053: private View currentView;
054:
055: /**
056: * @return a singleton AppContext application object
057: */
058: public static AppContext getAppContext() {
059: return appContext;
060: }
061:
062: /**
063: * convenience method for obtaining the view object that contains a given buffer
064: * Note that it would be insane to call this right now were I not planning to
065: * allow the creation of multiple views.
066: */
067: public static View getViewForBuffer(Buffer buffer) {
068: JComponent jc = buffer.getComponent();
069: for (Iterator it = getAppContext().views(); it.hasNext();) {
070: View v = (View) it.next();
071: for (Iterator it2 = v.getDockedBuffers(); it2.hasNext();) {
072: Buffer b = (Buffer) it2.next();
073: if (b.equals(buffer))
074: return v;
075: }
076: }
077: return null;
078: }
079:
080: /**
081: * return the explorer in the same view as the given buffer
082: */
083: public static Explorer getExplorerForBuffer(Buffer buffer) {
084: if (buffer instanceof Explorer)
085: return (Explorer) buffer;
086: View v = getViewForBuffer(buffer);
087: if (v == null)
088: return null;
089: for (Iterator it = v.getDockedBuffers(); it.hasNext();) {
090: Object o = it.next();
091: if (o instanceof Explorer)
092: return (Explorer) o;
093: }
094: return null;
095: }
096:
097: private ExplorerApp() {
098: StateMonitor.registerProperty(this , "busy",
099: StateProperties.BUSY, null, null);
100: initPrefs();
101: initViews();
102: }
103:
104: private void initPrefs() {
105: File appdir = new File(System.getProperty("user.home"), DAV_DIR);
106: try {
107: makePrefDir(appdir);
108: } catch (Exception e) {
109: Debug.trace(this , Debug.DP2, e);
110: }
111: String path = new File(appdir, CONFIG_DATA).getPath();
112: configurator = new Configurator(new LocalConfigStore(path));
113: //I'll remove this static method later. I must ensure that the explorer component can be used outside
114: //of the app.
115: Configurator.setConfigurator(configurator);
116: }
117:
118: private void initViews() {
119: viewList = new ArrayList();
120: currentView = new ExplorerView(this );
121: addView(currentView);
122:
123: }
124:
125: public void setBusy(boolean busy) {
126: currentView.getComponent().setCursor(
127: (busy) ? Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)
128: : Cursor.getDefaultCursor());
129: }
130:
131: /**
132: * adds a view
133: */
134: public void addView(View view) {
135: viewList.add(view);
136: }
137:
138: /**
139: * removes a view
140: * Precondition: appContext contains this view
141: */
142: public void removeView(View view) {
143: viewList.remove(view);
144: }
145:
146: /**
147: * @return an iterator of all Views in the AppContext
148: */
149: public Iterator views() {
150: return viewList.listIterator();
151: }
152:
153: /**
154: * @return the number of current views
155: */
156: public int getViewCount() {
157: return viewList.size();
158: }
159:
160: /**
161: * @return the view at the given index
162: */
163: public View getView(int index) {
164: return (View) viewList.get(index);
165: }
166:
167: /**
168: * @return the currently active (focussed) view
169: */
170: public View getCurrentView() {
171: //TO BE DONE --add a mechanism to track the current view
172: return currentView;
173: }
174:
175: public static void main(String[] args) {
176: if (System.getProperty("LandF") == null)
177: LookAndFeel.setLookAndFeel();
178: appContext = new ExplorerApp();
179: // N.B. -- the SPI version is no more; now folded into the main app.
180: // However, this is where plugins should be loaded -- TO BE DONE.
181: // //this is a hack for the SPI version of this app.
182: // //it saves me the trouble of writing a subclass of ExplorerApp to do this,
183: // //and using a separate jar manifest for spi.
184: // try
185: // {
186: // Class.forName("org.skunk.spi.SpiInitializer");
187: // }
188: // catch (ClassNotFoundException conifer)
189: // {
190: // //OK, this should happen
191: // }
192: }
193:
194: private static void makePrefDir(File appdir) throws IOException,
195: SecurityException {
196:
197: if (appdir.exists()) {
198: if (appdir.isDirectory())
199: return;
200: else
201: throw new IOException(
202: "unable to create directory: name taken by file");
203: } else {
204: boolean succeeded = appdir.mkdir();
205: if (!succeeded)
206: throw new IOException("unable to create directory");
207: }
208: }
209:
210: /**
211: * @return the dock mode (interface style)
212: */
213: public DockMode getDockMode() {
214: //for now, hard-code this
215: return DockMode.TABBED_PANE_MODE;
216: }
217:
218: /**
219: * @return the configurator object for the application
220: */
221: public Configurator getConfigurator() {
222: return configurator;
223: }
224:
225: /**
226: * @return whether or not the application is trusted to access the filesystem,
227: * open sockets to multiple hosts, etc.
228: */
229: public boolean isTrusted() {
230: return true;
231: }
232: }
233:
234: /* $Log: ExplorerApp.java,v $
235: /* Revision 1.20 2001/07/22 07:04:24 smulloni
236: /* changed the handling of release number.
237: /*
238: /* Revision 1.19 2001/07/11 02:15:01 smulloni
239: /* the previous spi build targets have been folded into the main build;
240: /* also added a javadoc target.
241: /*
242: /* Revision 1.18 2001/01/30 23:03:19 smulloni
243: /* beginning of integration of syntax highlighting into SimpleTextEditor.
244: /*
245: /* Revision 1.17 2000/12/21 18:53:13 smulloni
246: /* cosmetic improvements.
247: /*
248: /* Revision 1.16 2000/12/19 22:36:05 smulloni
249: /* adjustments to preamble.
250: /*
251: /* Revision 1.15 2000/12/05 03:47:43 smulloni
252: /* added preamble
253: /*
254: /* Revision 1.14 2000/12/04 23:51:16 smulloni
255: /* added ImageViewer; fixed word in SimpleTextEditor
256: /*
257: /* Revision 1.13 2000/12/01 16:25:52 smullyan
258: /* improvements to look and feel; fixed NPE in DAVFile; new actions for text
259: /* editor
260: /*
261: /* Revision 1.12 2000/11/28 00:01:38 smullyan
262: /* added a status bar/minibuffer, with a location field showing the current line and
263: /* column number (for the SimpleTextEditor and kin only).
264: /*
265: /* Revision 1.11 2000/11/22 00:11:26 smullyan
266: /* editor now locks and unlocks, more or less appropriately.
267: /*
268: /* Revision 1.10 2000/11/20 23:30:20 smullyan
269: /* more editor integration work.
270: /*
271: /* Revision 1.9 2000/11/17 20:25:05 smullyan
272: /* new SaveAction; a StateMonitor being added to handle application state.
273: /*
274: /* Revision 1.8 2000/11/16 20:45:17 smullyan
275: /* the start of editor integration.
276: /*
277: /* Revision 1.7 2000/11/15 20:17:03 smullyan
278: /* added a Buffer interface, which is a wrapper around a displayable component.
279: /*
280: /* Revision 1.6 2000/11/15 19:45:36 smullyan
281: /* beginning of revamp of application to include multiple buffers.
282: /*
283: /* Revision 1.5 2000/11/09 23:34:57 smullyan
284: /* log added to every Java file, with the help of python. Lock stealing
285: /* implemented, and treatment of locks made more robust.
286: /* */
|