001: package net.suberic.pooka.gui;
002:
003: import net.suberic.pooka.Pooka;
004: import net.suberic.pooka.StoreInfo;
005: import java.util.*;
006: import java.awt.*;
007: import java.awt.event.*;
008: import java.io.*;
009: import java.beans.*;
010: import javax.swing.*;
011: import javax.swing.text.*;
012: import javax.swing.border.*;
013: import javax.mail.Session;
014: import javax.mail.MessagingException;
015: import javax.mail.event.MessageCountEvent;
016: import javax.help.*;
017: import java.util.logging.Logger;
018:
019: import net.suberic.pooka.MailQueue;
020: import net.suberic.pooka.UserProfile;
021: import net.suberic.util.gui.*;
022:
023: import org.jdesktop.jdic.tray.TrayIcon;
024: import org.jdesktop.jdic.tray.SystemTray;
025:
026: /**
027: * The main panel for PookaMail
028: *
029: * @author Allen Petersen
030: * @version $Id: MainPanel.java,v 1.19 2006/02/27 18:25:47 akp Exp $
031: */
032:
033: public class MainPanel extends JSplitPane implements
034: net.suberic.pooka.UserProfileContainer, ActionContainer {
035: private ConfigurableMenuBar mainMenu;
036: private ConfigurableToolbar mainToolbar;
037: private FolderPanel folderPanel;
038: private ContentPanel contentPanel;
039: private InfoPanel infoPanel;
040: private Session session;
041: private MailQueue mailQueue;
042: private UserProfile currentUser = null;
043: private ConfigurableKeyBinding keyBindings;
044:
045: protected PookaFocusManager focusManager;
046:
047: // status
048: private static int CONTENT_LAST = 0;
049: private static int FOLDER_LAST = 5;
050:
051: public MainPanel(JFrame frame) {
052: super (JSplitPane.HORIZONTAL_SPLIT);
053:
054: session = Pooka.getDefaultSession();
055:
056: mailQueue = new MailQueue(Pooka.getDefaultSession());
057:
058: }
059:
060: /**
061: * This actually sets up the main panel.
062: */
063: public void configureMainPanel() {
064: // set supported actions
065: // this.setLayout(new BorderLayout());
066: // create the menu bar.
067:
068: contentPanel = Pooka.getUIFactory().createContentPanel();
069: folderPanel = new FolderPanel(this );
070: infoPanel = new InfoPanel();
071: infoPanel.setMessage("Pooka");
072:
073: this .setLeftComponent(folderPanel);
074: this .setRightComponent(contentPanel.getUIComponent());
075: this
076: .setDividerLocation(folderPanel.getPreferredSize().width + 1);
077:
078: mainMenu = new ConfigurableMenuBar("MenuBar", Pooka
079: .getResources());
080: mainToolbar = new ConfigurableToolbar("MainToolbar", Pooka
081: .getResources());
082:
083: keyBindings = new ConfigurableKeyBinding(this ,
084: "MainPanel.keyBindings", Pooka.getResources());
085: //keyBindings.setCondition(JComponent.WHEN_IN_FOCUSED_WINDOW);
086: keyBindings
087: .setCondition(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
088:
089: Pooka.getHelpBroker().enableHelpKey(this , "pooka.intro",
090: Pooka.getHelpBroker().getHelpSet());
091:
092: getParentFrame().addWindowListener(new WindowAdapter() {
093: public void windowClosing(WindowEvent e) {
094: exitPooka(true);
095: }
096: });
097:
098: focusManager = new PookaFocusManager();
099:
100: this .addFocusListener(new FocusAdapter() {
101: public void focusGained(FocusEvent e) {
102: // we never want focus.
103: focusManager.passFocus();
104: }
105: });
106:
107: // set the initial currentUser
108: refreshCurrentUser();
109:
110: // set up the MessageNotificationManager.
111: if (Pooka.getUIFactory().getMessageNotificationManager() != null) {
112: Pooka.getUIFactory().getMessageNotificationManager()
113: .setMainPanel(this );
114: }
115: // select the content panel.
116: contentPanel.getUIComponent().requestFocusInWindow();
117:
118: }
119:
120: /**
121: * This gets all the actions associated with this panel. Useful for
122: * populating the MenuBar and Toolbar.
123: *
124: * The method actually returns the Panel's defaultActions plus the
125: * actions of the folderPanel and/or contentPanel, depending on which
126: * one currently has the focus.
127: */
128: public Action[] getActions() {
129: Action[] actions = getDefaultActions();
130: Component focusedComponent = KeyboardFocusManager
131: .getCurrentKeyboardFocusManager().getFocusOwner();
132:
133: boolean foundParent = false;
134:
135: if (focusedComponent != null) {
136: if (contentPanel != null) {
137: if (SwingUtilities.isDescendingFrom(focusedComponent,
138: contentPanel.getUIComponent())) {
139: foundParent = true;
140: focusManager.setLastStatus(CONTENT_LAST);
141: if (contentPanel.getActions() != null) {
142: actions = TextAction.augmentList(contentPanel
143: .getActions(), actions);
144: }
145: }
146: }
147:
148: if (!foundParent && folderPanel != null) {
149: if (SwingUtilities.isDescendingFrom(focusedComponent,
150: folderPanel)) {
151: foundParent = true;
152: focusManager.setLastStatus(FOLDER_LAST);
153: if (folderPanel.getActions() != null) {
154: actions = TextAction.augmentList(folderPanel
155: .getActions(), actions);
156: }
157: }
158: }
159: }
160:
161: if (!foundParent) {
162: // if no parent is found, get the actions from the last selected
163: // item.
164: int lastStatus = focusManager.getLastStatus();
165: if (lastStatus == CONTENT_LAST && contentPanel != null) {
166: if (contentPanel.getActions() != null) {
167: actions = TextAction.augmentList(contentPanel
168: .getActions(), actions);
169: }
170: } else if (lastStatus == FOLDER_LAST && folderPanel != null) {
171: if (folderPanel.getActions() != null) {
172: actions = TextAction.augmentList(folderPanel
173: .getActions(), actions);
174: }
175:
176: }
177: }
178: return actions;
179: }
180:
181: /**
182: * Called by ExtendedDesktopManager every time the focus on the windows
183: * changes. Resets the Actions associated with the menu items and toolbar
184: * to the ones in the active window.
185: *
186: * Also called when the selected message in a FolderWindow is changed.
187: */
188:
189: public void refreshActiveMenus() {
190: Action[] currentActions = getActions();
191: mainMenu.setActive(currentActions);
192: mainToolbar.setActive(currentActions);
193: contentPanel.refreshActiveMenus();
194: keyBindings.setActive(currentActions);
195: if (Pooka.getUIFactory().getMessageNotificationManager() != null)
196: Pooka.getUIFactory().getMessageNotificationManager()
197: .clearNewMessageFlag();
198: }
199:
200: /**
201: * refreshCurrentUser() is called to get a new value for the currently
202: * selected item. In MainPanel, all it does is tries to get a
203: * UserProfile from the currently selected object in the ContentPanel.
204: * If there is no object in the ContentPanel which gives a default
205: * UserProfile, it then checks the FolderPanel. If neither of these
206: * returns a UserProfile, then the default UserProfile is returned.
207: */
208: protected void refreshCurrentUser() {
209: UserProfile selectedProfile = getDefaultProfile();
210: if (selectedProfile != null) {
211: currentUser = selectedProfile;
212: } else {
213: currentUser = Pooka.getPookaManager()
214: .getUserProfileManager().getDefaultProfile();
215: }
216: }
217:
218: /**
219: * As defined in net.suberic.pooka.UserProfileContainer.
220: *
221: * Note that this method can return null, and is primarily used to
222: * get the currentUser. If you want to get the current default
223: * profile, use getCurrentUser() instead.
224: */
225: public UserProfile getDefaultProfile() {
226: UserProfile returnValue = null;
227:
228: if (contentPanel != null) {
229: returnValue = contentPanel.getDefaultProfile();
230: }
231:
232: if (returnValue != null)
233: return returnValue;
234:
235: if (folderPanel != null)
236: returnValue = folderPanel.getDefaultProfile();
237:
238: return returnValue;
239:
240: }
241:
242: public UserProfile getCurrentUser() {
243: return currentUser;
244: }
245:
246: /**
247: * This exits Pooka.
248: */
249:
250: public void exitPooka(boolean exitToIcon) {
251: if (!processUnsentMessages())
252: return;
253:
254: if (contentPanel instanceof MessagePanel
255: && ((MessagePanel) contentPanel)
256: .isSavingWindowLocations()) {
257: ((MessagePanel) contentPanel).saveWindowLocations();
258: }
259:
260: Pooka.setProperty("Pooka.hsize", Integer.toString(this
261: .getParentFrame().getWidth()));
262: Pooka.setProperty("Pooka.vsize", Integer.toString(this
263: .getParentFrame().getHeight()));
264: Pooka.setProperty("Pooka.folderPanel.hsize", Integer
265: .toString(folderPanel.getWidth()));
266: Pooka.setProperty("Pooka.folderPanel.vsize", Integer
267: .toString(folderPanel.getHeight()));
268: Pooka.setProperty("Pooka.lastX", Integer.toString(this
269: .getParentFrame().getX()));
270: Pooka.setProperty("Pooka.lastY", Integer.toString(this
271: .getParentFrame().getY()));
272: contentPanel.savePanelSize();
273:
274: if (contentPanel.isSavingOpenFolders()) {
275: contentPanel.saveOpenFolders();
276: }
277:
278: if (exitToIcon
279: && Pooka.getProperty("Pooka.exitToIcon", "false")
280: .equalsIgnoreCase("true")
281: && Pooka.getUIFactory().getMessageNotificationManager()
282: .getTrayIcon() != null) {
283: Pooka.sStartupManager.stopPookaToTray(this );
284: } else {
285: Pooka.exitPooka(0, this );
286: }
287: }
288:
289: /**
290: * Checks to see if there are any unsent messages. If there are,
291: * then find out if we want to save them as drafts, send them, or
292: * forget them.
293: *
294: * Returns true if all of the messages are processed, false if the
295: * user cancels out.
296: */
297: public boolean processUnsentMessages() {
298: Vector unsentMessages = NewMessageProxy.getUnsentProxies();
299: boolean cancel = false;
300: Vector unsentCopy = new Vector(unsentMessages);
301: for (int i = 0; !cancel && i < unsentCopy.size(); i++) {
302: NewMessageProxy current = (NewMessageProxy) unsentCopy
303: .get(i);
304: if (current.promptForClose()) {
305: NewMessageUI nmui = current.getNewMessageUI();
306: // FIXME
307: if (nmui != null) {
308: nmui.openMessageUI();
309: int saveDraft = nmui.promptSaveDraft();
310: switch (saveDraft) {
311: case JOptionPane.YES_OPTION:
312: current.saveDraft();
313: break;
314: case JOptionPane.NO_OPTION:
315: nmui.setModified(false);
316: nmui.closeMessageUI();
317: break;
318: case JOptionPane.CANCEL_OPTION:
319: cancel = true;
320: }
321: }
322: }
323: }
324:
325: return !cancel;
326: }
327:
328: // Accessor methods.
329: // These shouldn't all be public.
330:
331: public ConfigurableMenuBar getMainMenu() {
332: return mainMenu;
333: }
334:
335: public InfoPanel getInfoPanel() {
336: return infoPanel;
337: }
338:
339: public void setMainMenu(ConfigurableMenuBar newMainMenu) {
340: mainMenu = newMainMenu;
341: }
342:
343: public ConfigurableToolbar getMainToolbar() {
344: return mainToolbar;
345: }
346:
347: public ConfigurableKeyBinding getKeyBindings() {
348: return keyBindings;
349: }
350:
351: public void setKeyBindings(ConfigurableKeyBinding newKeyBindings) {
352: keyBindings = newKeyBindings;
353: }
354:
355: public void setMainToolbar(ConfigurableToolbar newMainToolbar) {
356: mainToolbar = newMainToolbar;
357: }
358:
359: public ContentPanel getContentPanel() {
360: return contentPanel;
361: }
362:
363: public void setContentPanel(ContentPanel newCp) {
364: contentPanel = newCp;
365: this .setRightComponent(newCp.getUIComponent());
366: this .repaint();
367: }
368:
369: public FolderPanel getFolderPanel() {
370: return folderPanel;
371: }
372:
373: public Session getSession() {
374: return session;
375: }
376:
377: public MailQueue getMailQueue() {
378: return mailQueue;
379: }
380:
381: public Action[] getDefaultActions() {
382: return defaultActions;
383: }
384:
385: public PookaFocusManager getFocusManager() {
386: return focusManager;
387: }
388:
389: /**
390: * Find the hosting frame, for the file-chooser dialog.
391: */
392: public JFrame getParentFrame() {
393: return (JFrame) getTopLevelAncestor();
394: }
395:
396: //-----------actions----------------
397: // Actions supported by the main Panel itself. These should always
398: // be available, even when no documents are open.
399:
400: private Action[] defaultActions = { new ExitAction(),
401: new EditUserConfigAction(), new EditStoreConfigAction(),
402: new EditPreferencesAction(), new EditAddressBookAction(),
403: new EditOutgoingServerAction(), new EditConnectionAction(),
404: new EditInterfaceAction(), new EditCryptoAction(),
405: new HelpAboutAction(), new HelpLicenseAction(),
406: new HelpAction(), new HelpKeyBindingsAction(),
407: new SelectMessagePanelAction(),
408: new SelectFolderPanelAction(), new NewMessageAction(),
409: new ExportConfigAction() };
410:
411: /*
412: * TODO: This really needs to check and ask if you want to save any
413: * modified documents. Of course, we don't check to see if the docs
414: * are modified yet, so this will do for now.
415: */
416: class ExitAction extends AbstractAction {
417:
418: ExitAction() {
419: super ("file-exit");
420: }
421:
422: public void actionPerformed(ActionEvent e) {
423: exitPooka(false);
424: }
425: }
426:
427: class ActivateWindowAction extends AbstractAction {
428:
429: ActivateWindowAction() {
430: super ("activate-window");
431: }
432:
433: public void actionPerformed(ActionEvent e) {
434: try {
435: ((JInternalFrame) (((MessagePanel) contentPanel)
436: .getComponent(Integer.parseInt(e
437: .getActionCommand()))))
438: .setSelected(true);
439: } catch (java.beans.PropertyVetoException pve) {
440: } catch (NumberFormatException nfe) {
441: }
442: }
443: }
444:
445: class EditUserConfigAction extends AbstractAction {
446:
447: EditUserConfigAction() {
448: super ("cfg-users");
449: }
450:
451: public void actionPerformed(ActionEvent e) {
452: Vector valuesToEdit = new Vector();
453: valuesToEdit.add("UserProfile");
454: valuesToEdit.add("UserProfile.default");
455:
456: Pooka.getUIFactory().showEditorWindow(
457: Pooka.getProperty("title.userConfig",
458: "Edit User Information"), valuesToEdit);
459: }
460: }
461:
462: class EditStoreConfigAction extends AbstractAction {
463:
464: EditStoreConfigAction() {
465: super ("cfg-stores");
466: }
467:
468: public void actionPerformed(ActionEvent e) {
469: Vector valuesToEdit = new Vector();
470: valuesToEdit.add("Store");
471:
472: Pooka.getUIFactory().showEditorWindow(
473: Pooka.getProperty("title.storeConfig",
474: "Edit Mailbox Information"), valuesToEdit);
475: }
476: }
477:
478: class EditPreferencesAction extends AbstractAction {
479:
480: EditPreferencesAction() {
481: super ("cfg-prefs");
482: }
483:
484: public void actionPerformed(ActionEvent e) {
485: Vector valuesToEdit = new Vector();
486: valuesToEdit.add("Preferences");
487: Pooka.getUIFactory().showEditorWindow(
488: Pooka.getProperty("title.preferences",
489: "Edit Preferences"), valuesToEdit);
490: }
491: }
492:
493: class EditAddressBookAction extends AbstractAction {
494:
495: EditAddressBookAction() {
496: super ("cfg-address-book");
497: }
498:
499: public void actionPerformed(ActionEvent e) {
500: //Vector valuesToEdit = Pooka.getResources().getPropertyAsVector("Preferences", "");
501:
502: Vector valuesToEdit = new Vector();
503: valuesToEdit.add("AddressBook");
504: valuesToEdit.add("AddressBook._default");
505: Pooka.getUIFactory().showEditorWindow(
506: Pooka.getProperty("title.addressBook",
507: "Address Book Editor"), valuesToEdit);
508: }
509: }
510:
511: class EditOutgoingServerAction extends AbstractAction {
512:
513: EditOutgoingServerAction() {
514: super ("cfg-outgoing");
515: }
516:
517: public void actionPerformed(ActionEvent e) {
518: Vector valuesToEdit = new Vector();
519: valuesToEdit.add("OutgoingServer");
520: valuesToEdit.add("OutgoingServer._default");
521: Pooka.getUIFactory().showEditorWindow(
522: Pooka.getProperty("title.outgoingServer",
523: "Outgoing Mail Editor"), valuesToEdit);
524: }
525: }
526:
527: class EditConnectionAction extends AbstractAction {
528:
529: EditConnectionAction() {
530: super ("cfg-connection");
531: }
532:
533: public void actionPerformed(ActionEvent e) {
534: Vector valuesToEdit = new Vector();
535: valuesToEdit.add("Connection");
536: valuesToEdit.add("Connection._default");
537: Pooka.getUIFactory().showEditorWindow(
538: Pooka.getProperty("title.connectionEditor",
539: "Connection Editor"), valuesToEdit);
540: }
541: }
542:
543: class EditCryptoAction extends AbstractAction {
544:
545: EditCryptoAction() {
546: super ("cfg-crypto");
547: }
548:
549: public void actionPerformed(ActionEvent e) {
550: Vector valuesToEdit = new Vector();
551: valuesToEdit.add("EncryptionManager");
552: Pooka.getUIFactory().showEditorWindow(
553: Pooka.getProperty("title.cryptoEditor",
554: "Encryption Editor"), valuesToEdit);
555: }
556: }
557:
558: class EditInterfaceAction extends AbstractAction {
559:
560: EditInterfaceAction() {
561: super ("cfg-interface-style");
562: }
563:
564: public void actionPerformed(ActionEvent e) {
565: Vector valuesToEdit = new Vector();
566: valuesToEdit.add("Pooka.theme");
567: valuesToEdit.add("Pooka.theme._default");
568: valuesToEdit.add("Pooka.looknfeel");
569: valuesToEdit.add("IconManager._default");
570: Pooka.getUIFactory().showEditorWindow(
571: Pooka.getProperty("title.interfaceEditor",
572: "User Interface Editor"), valuesToEdit);
573: }
574: }
575:
576: class HelpAboutAction extends AbstractAction {
577:
578: HelpAboutAction() {
579: super ("help-about");
580: }
581:
582: public void actionPerformed(ActionEvent e) {
583: String fileName = "About.html";
584: String dir = "/net/suberic/pooka/doc";
585: contentPanel.showHelpScreen(Pooka.getProperty(
586: "MenuBar.Help.About.Label", "About Pooka"), this
587: .getClass().getResource(
588: dir
589: + "/"
590: + java.util.Locale.getDefault()
591: .getLanguage() + "/"
592: + fileName));
593:
594: }
595: }
596:
597: class HelpLicenseAction extends AbstractAction {
598:
599: HelpLicenseAction() {
600: super ("help-license");
601: }
602:
603: public void actionPerformed(ActionEvent e) {
604: String fileName = "COPYING";
605: String dir = "/net/suberic/pooka";
606: contentPanel.showHelpScreen(Pooka.getProperty(
607: "MenuBar.Help.License.Label", "License"), this
608: .getClass().getResource(dir + "/" + fileName));
609: }
610: }
611:
612: class HelpAction extends AbstractAction {
613:
614: HelpAction() {
615: super ("help");
616: }
617:
618: public void actionPerformed(ActionEvent e) {
619: new CSH.DisplayHelpFromSource(Pooka.getHelpBroker())
620: .actionPerformed(e);
621: }
622: }
623:
624: class HelpKeyBindingsAction extends AbstractAction {
625:
626: HelpKeyBindingsAction() {
627: super ("help-keybindings");
628: }
629:
630: public void actionPerformed(ActionEvent e) {
631: String fileName = "KeyBindings.html";
632: String dir = "/net/suberic/pooka/doc";
633: contentPanel.showHelpScreen(Pooka.getProperty(
634: "MenuBar.Help.KeyBindings.Label",
635: "Pooka KeyBindings"), this .getClass().getResource(
636: dir
637: + "/"
638: + java.util.Locale.getDefault()
639: .getLanguage() + "/" + fileName));
640: }
641: }
642:
643: class SelectMessagePanelAction extends AbstractAction {
644:
645: SelectMessagePanelAction() {
646: super ("select-message-panel");
647: }
648:
649: public void actionPerformed(ActionEvent e) {
650: contentPanel.getUIComponent().requestFocusInWindow();
651: }
652: }
653:
654: class SelectFolderPanelAction extends AbstractAction {
655:
656: SelectFolderPanelAction() {
657: super ("select-folder-panel");
658: }
659:
660: public void actionPerformed(ActionEvent e) {
661: folderPanel.requestFocusInWindow();
662: }
663: }
664:
665: public class NewMessageAction extends AbstractAction {
666: NewMessageAction() {
667: super ("message-new");
668: }
669:
670: public void actionPerformed(ActionEvent e) {
671: try {
672: MessageUI nmu = Pooka
673: .getUIFactory()
674: .createMessageUI(
675: new NewMessageProxy(
676: new net.suberic.pooka.NewMessageInfo(
677: new javax.mail.internet.MimeMessage(
678: getSession()))));
679: nmu.openMessageUI();
680: } catch (MessagingException me) {
681: Pooka
682: .getUIFactory()
683: .showError(
684: Pooka
685: .getProperty(
686: "error.NewMessage.errorLoadingMessage",
687: "Error creating new message: ")
688: + "\n" + me.getMessage(),
689: Pooka
690: .getProperty(
691: "error.NewMessage.errorLoadingMessage.title",
692: "Error creating new message."),
693: me);
694: }
695:
696: }
697:
698: }
699:
700: public class ExportConfigAction extends AbstractAction {
701: ExportConfigAction() {
702: super ("cfg-export");
703: }
704:
705: public void actionPerformed(ActionEvent e) {
706: JFileChooser jfc;
707: String currentDirectoryPath = Pooka.getProperty(
708: "Pooka.tmp.currentDirectory", "");
709: if (currentDirectoryPath == "")
710: jfc = new JFileChooser();
711: else
712: jfc = new JFileChooser(currentDirectoryPath);
713:
714: jfc.setDialogTitle("Choose Export File");
715: jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
716: jfc.setMultiSelectionEnabled(false);
717: int a = jfc.showDialog(MainPanel.this , "Save");
718:
719: Pooka.getResources().setProperty(
720: "Pooka.tmp.currentDirectory",
721: jfc.getCurrentDirectory().getPath(), true);
722:
723: if (a == JFileChooser.APPROVE_OPTION) {
724: File f = jfc.getSelectedFile();
725: try {
726: net.suberic.pooka.resource.DisklessResourceManager
727: .exportResources(f, false);
728: Pooka.getUIFactory().showMessage(
729: "Resources exported successfully",
730: "Export complete");
731: } catch (Exception exc) {
732: Pooka.getUIFactory().showError(
733: "Error exporting resources", exc);
734: }
735:
736: }
737: }
738:
739: }
740:
741: /**
742: * Keeps the menus and configured Actions current by following the
743: * keyboard focus.
744: */
745: public class PookaFocusManager implements PropertyChangeListener {
746:
747: int lastStatus = CONTENT_LAST;
748:
749: /**
750: * Creates a new PookaFocusManager.
751: */
752: public PookaFocusManager() {
753: KeyboardFocusManager kfm = KeyboardFocusManager
754: .getCurrentKeyboardFocusManager();
755: kfm.addPropertyChangeListener("permanentFocusOwner", this );
756: }
757:
758: /**
759: * Called when the focus changes.
760: */
761: public void propertyChange(java.beans.PropertyChangeEvent pce) {
762: // make sure that we're not doing anything stupid like saying that
763: // either the JFrame or nothing has the keyboard focus.
764: Object newValue = pce.getNewValue();
765: Object oldValue = pce.getOldValue();
766: // if seems like it, pass it on to a default.
767: if ((newValue == null && oldValue == null)
768: || newValue instanceof JFrame) {
769: passFocus();
770: } else {
771: // see if the new value is actually part of this frame.
772: if (newValue != null && newValue instanceof Component) {
773: Window parentWindow = SwingUtilities
774: .getWindowAncestor(MainPanel.this );
775: Window componentParentWindow = SwingUtilities
776: .getWindowAncestor((Component) newValue);
777: if (parentWindow == componentParentWindow
778: || componentParentWindow == null) {
779: refreshActiveMenus();
780: refreshCurrentUser();
781: } else {
782:
783: java.util.logging.Logger
784: .getLogger("Pooka.debug.gui.focus")
785: .fine(
786: "component "
787: + newValue
788: + " got focus, but it's not part of the main window. Ignoring.");
789:
790: java.util.logging.Logger.getLogger(
791: "Pooka.debug.gui.focus").fine(
792: "main window = " + parentWindow
793: + "; component's parent = "
794: + componentParentWindow);
795: }
796: }
797: }
798: }
799:
800: /**
801: * Passes the focus to the correct subcomponent.
802: */
803: public void passFocus() {
804: java.util.logging.Logger.getLogger("Pooka.debug.gui.focus")
805: .fine("passing focus to subcomponent.");
806: if (lastStatus == CONTENT_LAST && contentPanel != null) {
807: if (contentPanel instanceof JComponent)
808: ((JComponent) contentPanel).requestFocusInWindow();
809: else
810: contentPanel.getUIComponent()
811: .requestFocusInWindow();
812: } else if (lastStatus == FOLDER_LAST && folderPanel != null) {
813: folderPanel.requestFocusInWindow();
814: }
815: }
816:
817: /**
818: * Returns the last panel that had focus.
819: */
820: public int getLastStatus() {
821: return lastStatus;
822: }
823:
824: /**
825: * Sets the last panel that had focus.
826: */
827: public void setLastStatus(int newStatus) {
828: lastStatus = newStatus;
829: }
830: }
831: }
|