KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > Pooka


1 package net.suberic.pooka;
2 import net.suberic.pooka.gui.*;
3 import net.suberic.util.VariableBundle;
4 import net.suberic.pooka.resource.*;
5
6 import java.awt.*;
7 import javax.swing.*;
8 import javax.help.*;
9 import java.util.logging.*;
10
11 public class Pooka {
12
13   /** The configuration for this instance of Pooka. */
14   public static PookaManager sManager;
15
16   /**
17    * Runs Pooka. Takes the following arguments:
18    *
19    * -nf
20    * --noOpenSavedFolders don't open saved folders on startup.
21    *
22    * -rc [FILE]
23    * --rcfile [FILE] use the given file as the pooka startup file.
24    *
25    * --http [URL] runs with a configuration file loaded via http
26    *
27    * --help shows these options.
28    */

29   static public void main(String JavaDoc argv[]) {
30     sManager = new PookaManager();
31     sStartupManager = new StartupManager(sManager);
32     sStartupManager.runPooka(argv);
33   }
34   public static StartupManager sStartupManager = null;
35
36   /**
37    * Loads the initial resources for Pooka. These are used during startup.
38    */

39   public static void loadInitialResources() {
40     try {
41       ClassLoader JavaDoc cl = new Pooka().getClass().getClassLoader();
42       java.net.URL JavaDoc url;
43       if (cl == null) {
44   url = ClassLoader.getSystemResource("net/suberic/pooka/Pookarc");
45       } else {
46   url = cl.getResource("net/suberic/pooka/Pookarc");
47       }
48
49       if (url == null) {
50   //sigh
51
url = new Pooka().getClass().getResource("/net/suberic/pooka/Pookarc");
52       }
53
54       java.io.InputStream JavaDoc is = url.openStream();
55       VariableBundle resources = new net.suberic.util.VariableBundle(is, "net.suberic.pooka.Pooka");
56       sManager.setResources(resources);
57     } catch (Exception JavaDoc e) {
58       System.err.println("caught exception loading system resources: " + e);
59       e.printStackTrace();
60       System.exit(-1);
61     }
62   }
63
64
65   /**
66    * Loads all the resources for Pooka.
67    */

68   public static void loadResources(boolean pUseLocalFiles, boolean pUseHttp) {
69     if (sManager == null || sManager.getResources() == null) {
70       System.err.println("Error starting up Pooka: No system resource files found.");
71       System.exit(-1);
72     }
73
74     try {
75       net.suberic.util.VariableBundle pookaDefaultBundle = sManager.getResources();
76       ResourceManager resourceManager = null;
77
78       if (! pUseLocalFiles || pookaDefaultBundle.getProperty("Pooka.useLocalFiles", "true").equalsIgnoreCase("false")) {
79   resourceManager = new DisklessResourceManager();
80       } else {
81   resourceManager = new FileResourceManager();
82       }
83
84       sManager.setResourceManager(resourceManager);
85
86       // if localrc hasn't been set, use the user's home directory.
87
if (sManager.getLocalrc() == null) {
88   String JavaDoc localrc = new String JavaDoc (System.getProperty("user.home") + System.getProperty("file.separator") + ".pookarc");
89   sManager.setLocalrc(localrc);
90       }
91       sManager.setResources(sManager.getResourceManager().createVariableBundle(sManager.getLocalrc(), pookaDefaultBundle));
92     } catch (Exception JavaDoc e) {
93       System.err.println("caught exception: " + e);
94       e.printStackTrace();
95     }
96
97     if (pUseHttp || sManager.getResources().getProperty("Pooka.httpConfig", "false").equalsIgnoreCase("true")) {
98       net.suberic.pooka.gui.LoadHttpConfigPooka configPooka = new net.suberic.pooka.gui.LoadHttpConfigPooka();
99       configPooka.start();
100     }
101   }
102
103   /**
104    * Exits Pooka. Attempts to close all stores first.
105    */

106   public static void exitPooka(int exitValue, Object JavaDoc pSource) {
107     final int fExitValue = exitValue;
108     final Object JavaDoc fSource = pSource;
109     Runnable JavaDoc runMe = new Runnable JavaDoc() {
110   public void run() {
111     sStartupManager.stopMainPookaWindow(fSource);
112     System.exit(fExitValue);
113   }
114       };
115
116     if (Pooka.getMainPanel() != null)
117       Pooka.getMainPanel().setCursor(java.awt.Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
118
119     Thread JavaDoc shutdownThread = new Thread JavaDoc(runMe);
120     shutdownThread.start();
121   }
122
123   /**
124    * Convenience method for getting Pooka configuration properties. Calls
125    * getResources().getProperty(propName, defVal).
126    */

127   static public String JavaDoc getProperty(String JavaDoc propName, String JavaDoc defVal) {
128     return (getResources().getProperty(propName, defVal));
129   }
130
131   /**
132    * Convenience method for getting Pooka configuration properties. Calls
133    * getResources().getProperty(propName).
134    */

135   static public String JavaDoc getProperty(String JavaDoc propName) {
136     return (getResources().getProperty(propName));
137   }
138
139   /**
140    * Convenience method for setting Pooka configuration properties. Calls
141    * getResources().setProperty(propName, propValue).
142    */

143   static public void setProperty(String JavaDoc propName, String JavaDoc propValue) {
144     getResources().setProperty(propName, propValue);
145   }
146
147   /**
148    * Returns the VariableBundle which provides all of the Pooka resources.
149    */

150   static public net.suberic.util.VariableBundle getResources() {
151     return sManager.getResources();
152   }
153   /**
154    * Sets the VariableBundle which provides all of the Pooka resources.
155    */

156   static public void setResources(net.suberic.util.VariableBundle pResources) {
157     sManager.setResources(pResources);
158   }
159
160
161   /**
162    * Returns whether or not debug is enabled for this Pooka instance.
163    *
164    */

165   static public boolean isDebug() {
166     if (getResources().getProperty("Pooka.debug", "true").equals("true"))
167       return true;
168     else if (Logger.getLogger("Pooka.debug").isLoggable(Level.FINE))
169       return true;
170     else
171       return false;
172   }
173
174   /**
175    * Returns the DateFormatter used by Pooka.
176    */

177   static public DateFormatter getDateFormatter() {
178     return sManager.getDateFormatter();
179   }
180
181   /**
182    * Returns the mailcap command map. This is what is used to determine
183    * which external programs are used to handle files of various MIME
184    * types.
185    */

186   static public javax.activation.CommandMap JavaDoc getMailcap() {
187     return sManager.getMailcap();
188   }
189
190   /**
191    * Returns the Mime Types map. This is used to map file extensions to
192    * MIME types.
193    */

194   static public javax.activation.MimetypesFileTypeMap JavaDoc getMimeTypesMap() {
195     return sManager.getMimeTypesMap();
196   }
197
198   /**
199    * Gets the default mail Session for Pooka.
200    */

201   static public javax.mail.Session JavaDoc getDefaultSession() {
202     return sManager.getDefaultSession();
203   }
204
205   /**
206    * Gets the default authenticator for Pooka.
207    */

208   static public javax.mail.Authenticator JavaDoc getDefaultAuthenticator() { return sManager.getDefaultAuthenticator(); }
209
210
211   /**
212    * Gets the Folder Tracker thread. This is the thread that monitors the
213    * individual folders and checks to make sure that they stay connected,
214    * checks for new email, etc.
215    */

216   static public net.suberic.pooka.thread.FolderTracker getFolderTracker() {
217     return sManager.getFolderTracker();
218   }
219
220   /**
221    * Gets the Pooka Main Panel. This is the root of the entire Pooka UI.
222    */

223   static public MainPanel getMainPanel() {
224     return sManager.getMainPanel();
225   }
226
227   /**
228    * The Store Manager. This tracks all of the Mail Stores that Pooka knows
229    * about.
230    */

231   static public StoreManager getStoreManager() {
232     return sManager.getStoreManager();
233   }
234
235   /**
236    * The Search Manager. This manages the Search Terms that Pooka knows
237    * about, and also can be used to construct Search queries from sets
238    * of properties.
239    */

240   static public SearchTermManager getSearchManager() {
241     return sManager.getSearchManager();
242   }
243
244   /**
245    * The UIFactory for Pooka. This is used to create just about all of the
246    * graphical UI components for Pooka. Usually this is either an instance
247    * of PookaDesktopPaneUIFactory or PookaPreviewPaneUIFactory, for the
248    * Desktop and Preview UI styles, respectively.
249    */

250   static public PookaUIFactory getUIFactory() {
251     return sManager.getUIFactory();
252   }
253
254   /**
255    * The Search Thread. This is the thread that folder searches are done
256    * on.
257    */

258   static public net.suberic.util.thread.ActionThread getSearchThread() {
259     return sManager.getSearchThread();
260   }
261
262   /**
263    * The Address Book Manager keeps track of all of the configured Address
264    * Books.
265    */

266   static public AddressBookManager getAddressBookManager() {
267     return sManager.getAddressBookManager();
268   }
269
270   /**
271    * The ConnectionManager tracks the configured Network Connections.
272    */

273   static public NetworkConnectionManager getConnectionManager() {
274     return sManager.getConnectionManager();
275   }
276
277   /**
278    * The OutgoingMailManager tracks the various SMTP server that Pooka can
279    * use to send mail.
280    */

281   static public OutgoingMailServerManager getOutgoingMailManager() {
282     return sManager.getOutgoingMailManager();
283   }
284
285   /**
286    * The EncryptionManager, not surprisingly, manages Pooka's encryption
287    * facilities.
288    */

289   public static PookaEncryptionManager getCryptoManager() {
290     return sManager.getCryptoManager();
291   }
292
293   /**
294    * The HelpBroker is used to bring up the Pooka help system.
295    */

296   static public HelpBroker getHelpBroker() {
297     return sManager.getHelpBroker();
298   }
299
300   /**
301    * The ResourceManager controls access to resource files.
302    */

303   static public ResourceManager getResourceManager() {
304     return sManager.getResourceManager();
305   }
306
307   /**
308    * The SSL Trust Manager.
309    */

310   static public net.suberic.pooka.ssl.PookaTrustManager getTrustManager() {
311     return sManager.getTrustManager();
312   }
313
314   /**
315    * The SSL Trust Manager.
316    */

317   static public void setTrustManager(net.suberic.pooka.ssl.PookaTrustManager pTrustManager) {
318     sManager.setTrustManager(pTrustManager);
319   }
320
321   /**
322    * The Log Manager.
323    */

324   static public PookaLogManager getLogManager() {
325     return sManager.getLogManager();
326   }
327
328   /**
329    * The Pooka configuration manager itself.
330    */

331   static public PookaManager getPookaManager() {
332     return sManager;
333   }
334
335 }
336
337
338
Popular Tags