KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > RecentMessageMenu


1 package net.suberic.pooka.gui;
2
3 import java.awt.*;
4 import java.util.*;
5 import net.suberic.pooka.Pooka;
6 import net.suberic.pooka.FolderInfo;
7 import net.suberic.util.*;
8
9 /**
10  * A Menu that shows the list of all new messages available.
11  */

12 public class RecentMessageMenu extends net.suberic.util.gui.ConfigurableAwtMenu {
13
14   /**
15    * This creates a new RecentMessageMenu.
16    */

17   public RecentMessageMenu() {
18     if (Pooka.getUIFactory() != null) {
19       MessageNotificationManager mnm = Pooka.getUIFactory().getMessageNotificationManager();
20       if (mnm != null)
21         mnm.setRecentMessageMenu(this);
22     }
23   }
24
25   /**
26    * Overrides ConfigurableAwtMenu.configureComponent().
27    */

28   public void configureComponent(String JavaDoc key, VariableBundle vars) {
29     try {
30       setLabel(vars.getProperty(key + ".Label"));
31     } catch (MissingResourceException mre) {
32     }
33
34     this.setActionCommand(vars.getProperty(key + ".Action", "message-open"));
35
36     /*
37       MessageNotificationManager mnm = Pooka.getMainPanel().getMessageNotificationManager();
38       Map newMessageMap = mnm.getNewMessageMap();
39       Iterator folders = newMessageMap.keySet().iterator();
40       while (folders.hasNext()) {
41       String current = (String) folders.next();
42       buildFolderMenu(current, (List)newMessageMap.get(current));
43       }
44     */

45
46   }
47
48   /**
49    * This builds the menu for each folder/message group.
50    */

51   protected void buildFolderMenu(String JavaDoc pFolderName, java.util.List JavaDoc pMessageList) {
52     MessageNotificationManager mnm = Pooka.getUIFactory().getMessageNotificationManager();
53     Menu newMenu = new Menu(pFolderName);
54     for(int i = 0 ; i < pMessageList.size(); i++) {
55       MenuItem mi = new MenuItem();
56       net.suberic.pooka.MessageInfo messageInfo = (net.suberic.pooka.MessageInfo) pMessageList.get(i);
57       javax.swing.Action JavaDoc oma = mnm.new OpenMessageAction(messageInfo);
58       mi.setActionCommand((String JavaDoc) oma.getValue(javax.swing.Action.NAME));
59       mi.addActionListener(oma);
60
61       try {
62         mi.setLabel(messageInfo.getMessageProperty("From") + ": " + messageInfo.getMessageProperty("Subject"));
63       } catch (Exception JavaDoc e) {
64         mi.setLabel("new message");
65       }
66       newMenu.add(mi);
67
68     }
69     this.add(newMenu);
70   }
71
72   void reset() {
73     Runnable JavaDoc runMe = new Runnable JavaDoc() {
74         public void run() {
75           removeAll();
76           MessageNotificationManager mnm = Pooka.getUIFactory().getMessageNotificationManager();
77           if (mnm != null) {
78             Map newMessageMap = mnm.getNewMessageMap();
79             Iterator folders = newMessageMap.keySet().iterator();
80             while (folders.hasNext()) {
81               String JavaDoc current = (String JavaDoc) folders.next();
82               buildFolderMenu(current, (java.util.List JavaDoc)newMessageMap.get(current));
83             }
84           }
85         }
86       };
87
88     if (javax.swing.SwingUtilities.isEventDispatchThread()) {
89       runMe.run();
90     } else {
91       javax.swing.SwingUtilities.invokeLater(runMe);
92     }
93
94   }
95 }
96
Popular Tags