Source Code Cross Referenced for StartupManager.java in  » Mail-Clients » pooka » net » suberic » pooka » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Mail Clients » pooka » net.suberic.pooka 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.suberic.pooka;
002:
003:        import net.suberic.pooka.gui.*;
004:        import net.suberic.util.VariableBundle;
005:        import net.suberic.pooka.resource.*;
006:        import net.suberic.pooka.messaging.*;
007:
008:        import java.awt.*;
009:        import javax.swing.*;
010:        import javax.help.*;
011:        import java.util.logging.*;
012:
013:        /**
014:         * This manages all startup options for Pooka.
015:         */
016:        public class StartupManager {
017:
018:            // the PookaManager that we're using to startup.  for convenience.
019:            PookaManager mPookaManager = null;
020:
021:            JFrame mFrame = null;
022:
023:            // settings
024:            public boolean mOpenFolders = true;
025:            public boolean mUseHttp = false;
026:            public boolean mUseLocalFiles = true;
027:            public boolean mFullStartup = true;
028:            String mToAddress = null;
029:            String mFromProfile = null;
030:
031:            /**
032:             * Creates a new StartupManager.
033:             */
034:            public StartupManager(PookaManager pPookaManager) {
035:                mPookaManager = pPookaManager;
036:            }
037:
038:            /**
039:             * Runs Pooka.
040:             */
041:            public void runPooka(String argv[]) {
042:                mStartTime = System.currentTimeMillis();
043:
044:                Pooka.loadInitialResources();
045:
046:                updateTime("intial resources parsed.");
047:
048:                parseArgs(argv);
049:
050:                updateTime("args parsed.");
051:
052:                Pooka.loadResources(mUseLocalFiles, mUseHttp);
053:
054:                mPookaManager.setLogManager(new PookaLogManager());
055:
056:                updateTime("resources loaded.");
057:
058:                if (!checkJavaVersion()) {
059:                    versionError();
060:                    System.exit(-1);
061:                }
062:
063:                // check to see if there's already a Pooka instance running.
064:                if (!checkRunningInstance()) {
065:                    if (mFullStartup) {
066:                        startupPooka();
067:                    } else {
068:                        startupMinimal();
069:                    }
070:                }
071:            }
072:
073:            /**
074:             * Does a full startup of Pooka.
075:             */
076:            public void startupPooka() {
077:                net.suberic.pooka.gui.PookaStartup startup = new net.suberic.pooka.gui.PookaStartup();
078:                startup.show();
079:
080:                updateTime("startup invoked.");
081:
082:                loadManagers(startup);
083:
084:                startupMainPookaWindow(startup);
085:            }
086:
087:            /**
088:             * Starts up the main Pooka window.
089:             */
090:            public void startupMainPookaWindow(
091:                    net.suberic.pooka.gui.PookaStartup pStartup) {
092:
093:                final net.suberic.pooka.gui.PookaStartup startup = pStartup;
094:                mFrame = new JFrame("Pooka");
095:                final JFrame finalFrame = mFrame;
096:
097:                mPookaManager
098:                        .setFolderTracker(new net.suberic.pooka.thread.FolderTracker());
099:                mPookaManager.getFolderTracker().start();
100:                updateTime("started folderTracker");
101:
102:                mPookaManager
103:                        .setSearchThread(new net.suberic.util.thread.ActionThread(
104:                                Pooka.getProperty("thread.searchThread",
105:                                        "Search Thread ")));
106:                mPookaManager.getSearchThread().start();
107:                updateTime("started search thread");
108:
109:                if (Pooka.getUIFactory() == null) {
110:                    if (Pooka.getProperty("Pooka.guiType", "Desktop")
111:                            .equalsIgnoreCase("Preview"))
112:                        mPookaManager
113:                                .setUIFactory(new PookaPreviewPaneUIFactory());
114:                    else
115:                        mPookaManager
116:                                .setUIFactory(new PookaDesktopPaneUIFactory());
117:                } else if (Pooka.getUIFactory() instanceof  net.suberic.pooka.gui.PookaMinimalUIFactory) {
118:                    if (Pooka.getProperty("Pooka.guiType", "Desktop")
119:                            .equalsIgnoreCase("Preview"))
120:                        mPookaManager
121:                                .setUIFactory(new PookaPreviewPaneUIFactory(
122:                                        Pooka.getUIFactory()));
123:                    else
124:                        mPookaManager
125:                                .setUIFactory(new PookaDesktopPaneUIFactory(
126:                                        Pooka.getUIFactory()));
127:                }
128:
129:                if (startup != null)
130:                    startup.setStatus("Pooka.startup.configuringWindow");
131:
132:                // do all of this on the awt event thread.
133:                Runnable createPookaUI = new Runnable() {
134:                    public void run() {
135:                        finalFrame.setBackground(Color.lightGray);
136:                        finalFrame.getContentPane().setLayout(
137:                                new BorderLayout());
138:                        MainPanel panel = new MainPanel(finalFrame);
139:                        mPookaManager.setMainPanel(panel);
140:                        finalFrame.getContentPane().add("Center", panel);
141:
142:                        updateTime("created main panel");
143:                        if (startup != null)
144:                            startup.setStatus("Pooka.startup.starting");
145:
146:                        panel.configureMainPanel();
147:
148:                        updateTime("configured main panel");
149:
150:                        finalFrame.getContentPane().add("North",
151:                                panel.getMainToolbar());
152:                        finalFrame.setJMenuBar(panel.getMainMenu());
153:                        finalFrame.getContentPane().add("South",
154:                                panel.getInfoPanel());
155:                        finalFrame.pack();
156:                        finalFrame.setSize(Integer.parseInt(Pooka.getProperty(
157:                                "Pooka.hsize", "800")), Integer.parseInt(Pooka
158:                                .getProperty("Pooka.vsize", "600")));
159:
160:                        int x = Integer.parseInt(Pooka.getProperty(
161:                                "Pooka.lastX", "10"));
162:                        int y = Integer.parseInt(Pooka.getProperty(
163:                                "Pooka.lastY", "10"));
164:
165:                        finalFrame.setLocation(x, y);
166:                        updateTime("configured frame");
167:                        if (startup != null)
168:                            startup.hide();
169:                        finalFrame.show();
170:                        updateTime("showed frame");
171:
172:                        mPookaManager.getUIFactory().setShowing(true);
173:
174:                        if (Pooka.getProperty("Store", "").equals("")) {
175:                            if (panel.getContentPanel() instanceof  MessagePanel) {
176:                                SwingUtilities.invokeLater(new Runnable() {
177:                                    public void run() {
178:                                        NewAccountPooka nap = new NewAccountPooka(
179:                                                (MessagePanel) Pooka
180:                                                        .getMainPanel()
181:                                                        .getContentPanel());
182:                                        nap.start();
183:                                    }
184:                                });
185:                            }
186:                        } else if (mOpenFolders
187:                                && Pooka.getProperty(
188:                                        "Pooka.openSavedFoldersOnStartup",
189:                                        "false").equalsIgnoreCase("true")) {
190:                            panel
191:                                    .getContentPanel()
192:                                    .openSavedFolders(
193:                                            mPookaManager
194:                                                    .getResources()
195:                                                    .getPropertyAsVector(
196:                                                            "Pooka.openFolderList",
197:                                                            ""));
198:                        }
199:                        panel.refreshActiveMenus();
200:                    }
201:                };
202:
203:                try {
204:                    javax.swing.SwingUtilities.invokeAndWait(createPookaUI);
205:                } catch (Exception e) {
206:                    System.err.println("caught exception creating ui:  " + e);
207:                    e.printStackTrace();
208:                }
209:            }
210:
211:            /**
212:             * Stops the main Pooka window.
213:             */
214:            public void stopMainPookaWindow(Object pSource) {
215:
216:                checkUnsentMessages();
217:
218:                //checkUncachedMessages();
219:
220:                net.suberic.pooka.thread.FolderTracker ft = mPookaManager
221:                        .getFolderTracker();
222:                if (ft != null)
223:                    ft.setStopped(true);
224:
225:                mPookaManager.setFolderTracker(null);
226:
227:                net.suberic.util.thread.ActionThread searchThread = mPookaManager
228:                        .getSearchThread();
229:                if (searchThread != null)
230:                    mPookaManager.getSearchThread().setStop(true);
231:
232:                closeAllStores(pSource);
233:
234:                Pooka.getResources().saveProperties();
235:
236:                try {
237:                    SwingUtilities.invokeAndWait(new Runnable() {
238:                        public void run() {
239:                            Pooka.getMainPanel().getParentFrame().setVisible(
240:                                    false);
241:                            Pooka.getMainPanel().getParentFrame().dispose();
242:                        }
243:                    });
244:                } catch (Exception e) {
245:                }
246:
247:            }
248:
249:            /**
250:             * Checks for any unsent messages.
251:             */
252:            void checkUnsentMessages() {
253:                java.util.List allServers = mPookaManager
254:                        .getOutgoingMailManager().getOutgoingMailServerList();
255:                // first stop all the servers.
256:                java.util.Iterator iter = allServers.iterator();
257:                while (iter.hasNext()) {
258:                    OutgoingMailServer oms = (OutgoingMailServer) iter.next();
259:                    oms.stopServer();
260:                }
261:
262:                int counter = 0;
263:                iter = allServers.iterator();
264:                String waitingMessage = Pooka
265:                        .getProperty("info.exit.waiting.send",
266:                                "Waiting {0,number} seconds to send unsent messages...");
267:
268:                while (iter.hasNext()) {
269:                    OutgoingMailServer oms = (OutgoingMailServer) iter.next();
270:                    /*
271:                    while (oms.isSending() && counter < 5) {
272:                    Object[] args = new Object[] { new Integer(5 - counter) };
273:                    Pooka.getUIFactory().showStatusMessage(java.text.MessageFormat.format(waitingMessage, args));
274:                    // wait for 5 seconds for all threads to exit.
275:                    try {
276:                    Thread.currentThread().sleep(1000);
277:                    } catch (Exception e) { }
278:                    counter++;
279:                    }
280:                     */
281:                    while (oms.isSending()) {
282:                        Pooka
283:                                .getUIFactory()
284:                                .showStatusMessage(
285:                                        Pooka
286:                                                .getProperty(
287:                                                        "info.exit.waiting.send.noCounter",
288:                                                        "Waiting to finish sending unsent messages..."));
289:                        try {
290:                            Thread.currentThread().sleep(1000);
291:                        } catch (Exception e) {
292:                        }
293:                    }
294:                }
295:
296:            }
297:
298:            /**
299:             * Closes all stores.
300:             */
301:            void closeAllStores(Object pSource) {
302:                mPookaManager.getStoreManager().cleanup();
303:                java.util.Vector v = mPookaManager.getStoreManager()
304:                        .getStoreList();
305:                final java.util.HashMap doneMap = new java.util.HashMap();
306:
307:                for (int i = 0; i < v.size(); i++) {
308:                    // FIXME:  we should check to see if there are any messages
309:                    // to be deleted, and ask the user if they want to expunge the
310:                    // deleted messages.
311:                    final StoreInfo currentStore = (StoreInfo) v.elementAt(i);
312:                    net.suberic.util.thread.ActionThread storeThread = currentStore
313:                            .getStoreThread();
314:                    if (storeThread != null) {
315:                        doneMap.put(currentStore, new Boolean(false));
316:                        storeThread.addToQueue(
317:                                new net.suberic.util.thread.ActionWrapper(
318:                                        new javax.swing.AbstractAction() {
319:
320:                                            public void actionPerformed(
321:                                                    java.awt.event.ActionEvent actionEvent) {
322:                                                try {
323:                                                    if (currentStore
324:                                                            .isConnected()) {
325:                                                        currentStore
326:                                                                .closeAllFolders(
327:                                                                        false,
328:                                                                        true);
329:                                                        currentStore
330:                                                                .disconnectStore();
331:                                                    } else {
332:                                                        doneMap.put(
333:                                                                currentStore,
334:                                                                new Boolean(
335:                                                                        true));
336:                                                    }
337:                                                } catch (Exception e) {
338:                                                    // ignore.  just say done and exit.
339:                                                } finally {
340:                                                    currentStore
341:                                                            .stopStoreThread();
342:                                                    currentStore.cleanup();
343:                                                    doneMap.put(currentStore,
344:                                                            new Boolean(true));
345:                                                }
346:                                            }
347:                                        }, storeThread),
348:                                new java.awt.event.ActionEvent(pSource, 1,
349:                                        "store-close"),
350:                                net.suberic.util.thread.ActionThread.PRIORITY_HIGH);
351:                    }
352:                }
353:                long sleepTime = 30000;
354:                try {
355:                    sleepTime = Long.parseLong(Pooka.getProperty(
356:                            "Pooka.exitTimeout", "30000"));
357:                } catch (Exception e) {
358:                }
359:                long currentTime = System.currentTimeMillis();
360:                boolean done = false;
361:
362:                String closingMessage = Pooka.getProperty("info.exit.closing",
363:                        "Closing Store {0}");
364:                String waitingMessage = Pooka.getProperty("info.exit.waiting",
365:                        "Closing Store {0}... Waiting {1,number} seconds.");
366:                String waitingMultipleMessage = Pooka
367:                        .getProperty("info.exit.waiting.multiple",
368:                                "Waiting {0,number} seconds for {1,number} Stores to close.");
369:
370:                while (!done
371:                        && System.currentTimeMillis() - currentTime < sleepTime) {
372:                    String waitingStoreName = null;
373:                    int waitingStoreCount = 0;
374:                    try {
375:                        Thread.currentThread().sleep(1000);
376:                    } catch (InterruptedException ie) {
377:                    }
378:                    done = true;
379:                    for (int i = 0; i < v.size(); i++) {
380:                        Object key = v.get(i);
381:                        Boolean value = (Boolean) doneMap.get(key);
382:                        if (value != null && !value.booleanValue()) {
383:                            done = false;
384:                            waitingStoreCount++;
385:                            if (waitingStoreName == null)
386:                                waitingStoreName = ((StoreInfo) key)
387:                                        .getStoreID();
388:                        }
389:                    }
390:
391:                    if (!done) {
392:                        int secondsWaiting = (int) (sleepTime - (System
393:                                .currentTimeMillis() - currentTime)) / 1000;
394:                        String message = closingMessage;
395:                        Object[] args;
396:                        if (secondsWaiting > 20) {
397:                            args = new Object[] { waitingStoreName };
398:                            message = closingMessage;
399:                        } else if (waitingStoreCount == 1) {
400:                            args = new Object[] { waitingStoreName,
401:                                    new Integer(secondsWaiting) };
402:                            message = waitingMessage;
403:                        } else {
404:                            args = new Object[] { new Integer(secondsWaiting),
405:                                    new Integer(waitingStoreCount) };
406:                            message = waitingMultipleMessage;
407:                        }
408:                        Pooka.getUIFactory().showStatusMessage(
409:                                java.text.MessageFormat.format(message, args));
410:                    }
411:                }
412:
413:            }
414:
415:            /**
416:             * Moves Pooka over to a Minimal startup.
417:             */
418:            public void stopPookaToTray(Object pSource) {
419:                final Object fSource = pSource;
420:                Runnable runMe = new Runnable() {
421:                    public void run() {
422:                        stopMainPookaWindow(fSource);
423:                        mFrame = null;
424:                        if (mPookaManager.getMainPanel() != null) {
425:                            KeyboardFocusManager
426:                                    .getCurrentKeyboardFocusManager()
427:                                    .removePropertyChangeListener(
428:                                            mPookaManager.getMainPanel()
429:                                                    .getFocusManager());
430:                            mPookaManager.getMainPanel().getInfoPanel()
431:                                    .stopThread();
432:                        }
433:                        mPookaManager.setMainPanel(null);
434:                        mPookaManager.getUIFactory().setShowing(false);
435:                        /*
436:                        mPookaManager.setStoreManager(new StoreManager());
437:                        updateTime("created store manager.");
438:                        
439:                        mPookaManager.getStoreManager().loadAllSentFolders();
440:                        mPookaManager.getOutgoingMailManager().loadOutboxFolders();
441:                        updateTime("loaded sent/outbox");
442:                         */
443:                        mPookaManager.setStoreManager(null);
444:                        mPookaManager.getUserProfileManager().shutdownManager();
445:                        mPookaManager.setUserProfileManager(null);
446:                        mPookaManager.getOutgoingMailManager().stopServers();
447:
448:                        /*
449:                        java.util.Map allListeners = mPookaManager.getResources().getAllListeners();
450:                        java.util.Iterator keys = allListeners.keySet().iterator();
451:                        while (keys.hasNext()) {
452:                          Object o = keys.next();
453:                          Object value = allListeners.get(o);
454:                          if (value instanceof java.util.List) {
455:                            java.util.Iterator values = ((java.util.List) value).iterator();
456:                            while (values.hasNext()) {
457:                        System.err.println("key " + o + ", value " + values.next());
458:                            }
459:                          } else {
460:                            System.err.println("key " + o + ", value " + allListeners.get(o));
461:                          }
462:                        }
463:                         */
464:
465:                        PookaUIFactory newFactory = new PookaMinimalUIFactory(
466:                                Pooka.getUIFactory());
467:
468:                        mFullStartup = false;
469:
470:                        loadManagers(null);
471:                        mPookaManager.setUIFactory(newFactory);
472:                        if (mPookaManager.getResources().getProperty(
473:                                "Pooka.exitToIcon.notify", "true")
474:                                .equalsIgnoreCase("true")) {
475:                            MessageNotificationManager mnm = newFactory
476:                                    .getMessageNotificationManager();
477:                            if (mnm != null)
478:                                mnm
479:                                        .displayMessage(
480:                                                mPookaManager
481:                                                        .getResources()
482:                                                        .getProperty(
483:                                                                "info.exitToIcon.title",
484:                                                                "System Tray Notification"),
485:                                                mPookaManager
486:                                                        .getResources()
487:                                                        .getProperty(
488:                                                                "info.exitToIcon",
489:                                                                "Pooka has disconnected from you mail servers, but is still running in the System Tray.  To exit Pooka completely, use File->Exit from the toolbar or right-click on the Tray Icon and choose Exit."),
490:                                                MessageNotificationManager.INFO_MESSAGE_TYPE);
491:
492:                        }
493:
494:                    }
495:                };
496:                if (Pooka.getMainPanel() != null)
497:                    Pooka.getMainPanel().setCursor(
498:                            java.awt.Cursor
499:                                    .getPredefinedCursor(Cursor.WAIT_CURSOR));
500:
501:                Thread stopWindowThread = new Thread(runMe);
502:                stopWindowThread.start();
503:            }
504:
505:            /**
506:             * Does a minimal startup of Pooka.
507:             */
508:            public void startupMinimal() {
509:                updateTime("startup invoked.");
510:
511:                loadManagers(null);
512:
513:                mPookaManager.setUIFactory(new PookaMinimalUIFactory());
514:
515:                if (mToAddress != null) {
516:                    if (!sendMessageTo(mToAddress, mFromProfile))
517:                        System.err.println("send failed.");
518:                }
519:            }
520:
521:            /**
522:             * Checks to see if there's already a running instance of Pooka that
523:             * we can use.
524:             */
525:            boolean checkRunningInstance() {
526:                // first see if there's already a pooka instance running.
527:                net.suberic.pooka.messaging.PookaMessageSender sender = new net.suberic.pooka.messaging.PookaMessageSender();
528:                try {
529:                    sender.openConnection();
530:                    // check to make sure that we're connected to a correct version of Pooka.
531:                    if (sender.checkVersion()) {
532:                        // ok, there is one.  try either sending a message or starting
533:                        // up Pooka, whichever we're trying to do.
534:                        if (mFullStartup) {
535:                            sender.sendStartPookaMessage();
536:                            sender.closeConnection();
537:                            System.out
538:                                    .println("contacted already running instance of Pooka.");
539:                            return true;
540:                        } else {
541:                            return sendMessageTo(mToAddress, mFromProfile);
542:                        }
543:                    }
544:                } catch (Exception e) {
545:
546:                }
547:
548:                return false;
549:            }
550:
551:            /**
552:             * This loads all of the background managers that Pooka uses.
553:             */
554:            public void loadManagers(net.suberic.pooka.gui.PookaStartup startup) {
555:                if (startup != null)
556:                    startup.setStatus("Pooka.startup.ssl");
557:                updateTime("loading ssl");
558:                StoreManager.setupSSL();
559:                updateTime("ssl loaded.");
560:
561:                try {
562:                    UIManager.setLookAndFeel(Pooka.getProperty(
563:                            "Pooka.looknfeel", UIManager
564:                                    .getCrossPlatformLookAndFeelClassName()));
565:                } catch (Exception e) {
566:                    System.out.println("Cannot set look and feel...");
567:                }
568:                updateTime("set looknfeel");
569:
570:                if (startup != null)
571:                    startup.setStatus("Pooka.startup.addressBook");
572:                mPookaManager.setAddressBookManager(new AddressBookManager());
573:                updateTime("loaded address book");
574:
575:                mPookaManager
576:                        .setConnectionManager(new NetworkConnectionManager());
577:                updateTime("loaded connections");
578:
579:                mPookaManager
580:                        .setOutgoingMailManager(new OutgoingMailServerManager());
581:                updateTime("loaded mailservers");
582:
583:                mPookaManager.setDateFormatter(new DateFormatter());
584:
585:                if (startup != null)
586:                    startup.setStatus("Pooka.startup.profiles");
587:                UserProfileManager profileManager = new UserProfileManager(
588:                        mPookaManager.getResources());
589:                mPookaManager.setUserProfileManager(profileManager);
590:                updateTime("created profiles");
591:
592:                String mailcapSource = null;
593:                if (System.getProperty("file.separator").equals("\\")) {
594:                    mailcapSource = System.getProperty("user.home")
595:                            + "\\pooka_mailcap.txt";
596:                } else {
597:                    mailcapSource = System.getProperty("user.home")
598:                            + System.getProperty("file.separator")
599:                            + ".pooka_mailcap";
600:                }
601:                try {
602:                    mPookaManager.setMailcap(Pooka.getResourceManager()
603:                            .createMailcap(mailcapSource));
604:                } catch (java.io.IOException ioe) {
605:                    System.err.println("exception loading mailcap:  " + ioe);
606:                }
607:
608:                updateTime("created mailcaps");
609:
610:                javax.activation.CommandMap.setDefaultCommandMap(mPookaManager
611:                        .getMailcap());
612:                javax.activation.FileTypeMap
613:                        .setDefaultFileTypeMap(mPookaManager.getMimeTypesMap());
614:                updateTime("set command/file maps");
615:
616:                if (startup != null)
617:                    startup.setStatus("Pooka.startup.crypto");
618:                mPookaManager.setCryptoManager(new PookaEncryptionManager(
619:                        mPookaManager.getResources(), "EncryptionManager"));
620:                updateTime("loaded encryption manager");
621:
622:                mPookaManager.setSearchManager(new SearchTermManager("Search"));
623:                updateTime("created search manager");
624:
625:                if (mFullStartup) {
626:                    if (Pooka.getProperty("Pooka.guiType", "Desktop")
627:                            .equalsIgnoreCase("Preview"))
628:                        mPookaManager
629:                                .setUIFactory(new PookaPreviewPaneUIFactory());
630:                    else
631:                        mPookaManager
632:                                .setUIFactory(new PookaDesktopPaneUIFactory());
633:
634:                    updateTime("created ui factory");
635:                }
636:
637:                mPookaManager.getResources().addValueChangeListener(
638:                        new net.suberic.util.ValueChangeListener() {
639:                            public void valueChanged(String changedValue) {
640:                                if (Pooka.getProperty("Pooka.guiType",
641:                                        "Desktop").equalsIgnoreCase("Preview")) {
642:                                    MessagePanel mp = (MessagePanel) Pooka
643:                                            .getMainPanel().getContentPanel();
644:                                    mPookaManager
645:                                            .setUIFactory(new PookaPreviewPaneUIFactory(
646:                                                    Pooka.getUIFactory()));
647:                                    ContentPanel cp = ((PookaPreviewPaneUIFactory) mPookaManager
648:                                            .getUIFactory())
649:                                            .createContentPanel(mp);
650:                                    Pooka.getMainPanel().setContentPanel(cp);
651:                                } else {
652:                                    PreviewContentPanel pcp = (PreviewContentPanel) Pooka
653:                                            .getMainPanel().getContentPanel();
654:                                    mPookaManager
655:                                            .setUIFactory(new PookaDesktopPaneUIFactory(
656:                                                    Pooka.getUIFactory()));
657:                                    ContentPanel mp = ((PookaDesktopPaneUIFactory) mPookaManager
658:                                            .getUIFactory())
659:                                            .createContentPanel(pcp);
660:                                    Pooka.getMainPanel().setContentPanel(mp);
661:                                }
662:                            }
663:                        }, "Pooka.guiType");
664:
665:                mPookaManager.getResources().addValueChangeListener(
666:                        new net.suberic.util.ValueChangeListener() {
667:                            public void valueChanged(String changedValue) {
668:                                try {
669:                                    UIManager
670:                                            .setLookAndFeel(Pooka
671:                                                    .getProperty(
672:                                                            "Pooka.looknfeel",
673:                                                            UIManager
674:                                                                    .getCrossPlatformLookAndFeelClassName()));
675:                                    javax.swing.SwingUtilities
676:                                            .updateComponentTreeUI(javax.swing.SwingUtilities
677:                                                    .windowForComponent(Pooka
678:                                                            .getMainPanel()));
679:                                } catch (Exception e) {
680:                                    System.out
681:                                            .println("Cannot set look and feel...");
682:                                }
683:                            }
684:                        }, "Pooka.looknfeel");
685:
686:                updateTime("created resource listeners");
687:                // set up help
688:                if (startup != null)
689:                    startup.setStatus("Pooka.startup.help");
690:                try {
691:                    ClassLoader cl = new Pooka().getClass().getClassLoader();
692:                    java.net.URL hsURL = HelpSet.findHelpSet(cl,
693:                            "net/suberic/pooka/doc/en/help/Master.hs");
694:                    HelpSet hs = new HelpSet(cl, hsURL);
695:                    mPookaManager.setHelpBroker(hs.createHelpBroker());
696:                } catch (Exception ee) {
697:                    System.out
698:                            .println("HelpSet net/suberic/pooka/doc/en/help/merge/Master.hs not found:  "
699:                                    + ee);
700:                    ee.printStackTrace();
701:                }
702:                updateTime("loaded help");
703:
704:                // create the MessageListener.
705:                if (mPookaManager.getMessageListener() == null) {
706:                    PookaMessageListener pmlistener = new PookaMessageListener();
707:                    mPookaManager.setMessageListener(pmlistener);
708:                }
709:
710:                /*
711:                mFrame = new JFrame("Pooka");
712:                updateTime("created frame");
713:                 */
714:
715:                mPookaManager
716:                        .setDefaultAuthenticator(new SimpleAuthenticator());
717:                java.util.Properties sysProps = System.getProperties();
718:                sysProps.setProperty("mail.mbox.mailspool", mPookaManager
719:                        .getResources().getProperty("Pooka.spoolDir",
720:                                "/var/spool/mail"));
721:                mPookaManager.setDefaultSession(javax.mail.Session
722:                        .getDefaultInstance(sysProps, mPookaManager
723:                                .getDefaultAuthenticator()));
724:                if (Pooka.getProperty("Pooka.sessionDebug", "false")
725:                        .equalsIgnoreCase("true"))
726:                    mPookaManager.getDefaultSession().setDebug(true);
727:
728:                updateTime("created session.");
729:                if (startup != null)
730:                    startup.setStatus("Pooka.startup.mailboxInfo");
731:                mPookaManager.setStoreManager(new StoreManager());
732:                updateTime("created store manager.");
733:
734:                mPookaManager.getStoreManager().loadAllSentFolders();
735:                mPookaManager.getOutgoingMailManager().loadOutboxFolders();
736:                updateTime("loaded sent/outbox");
737:
738:            }
739:
740:            /**
741:             * This parses any command line arguments, and makes the appropriate
742:             * changes.
743:             */
744:            public void parseArgs(String[] argv) {
745:                if (argv == null || argv.length < 1)
746:                    return;
747:
748:                String mailAddress = null;
749:                String selectedProfile = null;
750:
751:                for (int i = 0; i < argv.length; i++) {
752:                    if (argv[i] != null) {
753:                        if (argv[i].equals("-nf")
754:                                || argv[i].equals("--noOpenSavedFolders")) {
755:                            mOpenFolders = false;
756:                        } else if (argv[i].equals("-rc")
757:                                || argv[i].equals("--rcfile")) {
758:                            String filename = argv[++i];
759:                            if (filename == null) {
760:                                System.err
761:                                        .println("error:  no startup file specified.");
762:                                printUsage();
763:                                System.exit(-1);
764:                            }
765:
766:                            mPookaManager.setLocalrc(filename);
767:                        } else if (argv[i].equals("--http")) {
768:                            mUseHttp = true;
769:                            mUseLocalFiles = false;
770:                        } else if (argv[i].equals("-open")) {
771:                            if (argv.length < i + 2) {
772:                                System.err
773:                                        .println("error:  no address specified.");
774:                                printUsage();
775:                                System.exit(-1);
776:                            }
777:                            mToAddress = argv[++i];
778:                            mFullStartup = false;
779:                        } else if (argv[i].equals("--minimal")) {
780:                            mFullStartup = false;
781:                        } else if (argv[i].equals("--from")) {
782:                            mFromProfile = argv[++i];
783:                            if (mFromProfile == null) {
784:                                System.err
785:                                        .println("error:  no from profile specified.");
786:                                printUsage();
787:                                System.exit(-1);
788:                            }
789:                            mFullStartup = false;
790:                        } else if (argv[i].equals("--help")) {
791:                            printUsage();
792:                            System.exit(0);
793:                        } else {
794:                            // if invalid arguments are specified
795:                            printUsage();
796:                            System.exit(0);
797:                        }
798:                    }
799:                }
800:            }
801:
802:            /**
803:             * Prints the usage information.
804:             */
805:            public void printUsage() {
806:                System.out
807:                        .println(Pooka
808:                                .getProperty(
809:                                        "info.startup.help",
810:                                        "\nUsage:  net.suberic.pooka.Pooka [OPTIONS]\n\n  -nf, --noOpenSavedFolders    don't open saved folders on startup.\n  -rc, --rcfile FILE           use the given file as the pooka startup file.\n  --http                       runs with a configuration file loaded via http\n  -open ADDRESS                sends a new message to ADDRESS.\n       [--from USER]           [from user USER].\n  --minimal                    startup to system tray only.\n  --help                       shows these options.\n"));
811:            }
812:
813:            /**
814:             * Checks to make sure that the Java version is valid.
815:             */
816:            public boolean checkJavaVersion() {
817:                // Pooka 1.1 only runs on JDK 1.4 or higher.
818:                String javaVersion = System.getProperty("java.version");
819:                if (javaVersion.compareTo("1.4") >= 0) {
820:                    return true;
821:                } else {
822:                    return false;
823:                }
824:            }
825:
826:            /**
827:             * Called if an incorrect version of Java is being used.
828:             */
829:            private void versionError() {
830:                Runnable runMe = new Runnable() {
831:                    public void run() {
832:                        String errorString = Pooka
833:                                .getProperty(
834:                                        "error.incorrectJavaVersion",
835:                                        "Error running Pooka.  This version (1.0 beta) \nof Pooka requires a 1.2 or 1.3 JDK.  \n\nFor JDK 1.4, please use a release of Pooka 1.1.\n\nPooka can be downloaded from\nhttp://pooka.sourceforge.net/\n\nYour JDK version:  ");
836:                        javax.swing.JOptionPane.showMessageDialog(null,
837:                                errorString
838:                                        + System.getProperty("java.version"));
839:                    }
840:                };
841:
842:                if (SwingUtilities.isEventDispatchThread())
843:                    runMe.run();
844:                else {
845:                    try {
846:                        SwingUtilities.invokeAndWait(runMe);
847:                    } catch (Exception ie) {
848:                    }
849:                }
850:            }
851:
852:            /**
853:             * Sends a message to the given mail address on startup.
854:             */
855:            public boolean sendMessageTo(String pAddress, String pProfile) {
856:                // first see if there's already a pooka instance running.
857:                net.suberic.pooka.messaging.PookaMessageSender sender = new net.suberic.pooka.messaging.PookaMessageSender();
858:                try {
859:                    sender.openConnection();
860:                    // check to make sure that we're connected to a correct version of Pooka.
861:                    if (sender.checkVersion()) {
862:                        sender.openNewEmail(pAddress, pProfile);
863:                    } else
864:                        return false;
865:                } catch (Exception e) {
866:                    return false;
867:                } finally {
868:                    if (sender.isConnected())
869:                        sender.closeConnection();
870:                }
871:
872:                mToAddress = null;
873:                mFromProfile = null;
874:
875:                return true;
876:            }
877:
878:            private long mStartTime = 0;
879:            private long mLastUpdate = 0;
880:
881:            /**
882:             * debug.
883:             */
884:            public void updateTime(String message) {
885:                if (mPookaManager.getResources() != null && Pooka.isDebug()) {
886:                    long current = System.currentTimeMillis();
887:                    System.err.println(message + ", time "
888:                            + (current - mLastUpdate) + ", total "
889:                            + (current - mStartTime));
890:                    mLastUpdate = current;
891:                }
892:            }
893:
894:            /**
895:             * Gets the logger for this class.
896:             */
897:            public Logger getLogger() {
898:                return Logger.getLogger("Pooka.debug.startupManager");
899:            }
900:
901:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.