01: package net.suberic.pooka.gui;
02:
03: import javax.swing.*;
04: import java.util.*;
05: import net.suberic.pooka.Pooka;
06: import net.suberic.pooka.FolderInfo;
07: import net.suberic.util.*;
08:
09: /**
10: * A Menu that shows the list of all new messages available.
11: */
12: public class RecentMessageMenu extends
13: net.suberic.util.gui.ConfigurableMenu {
14:
15: /**
16: * This creates a new RecentMessageMenu.
17: */
18: public RecentMessageMenu() {
19: }
20:
21: /**
22: * Overrides ConfigurableMenu.configureComponent().
23: */
24: public void configureComponent(String key, VariableBundle vars) {
25: try {
26: setText(vars.getProperty(key + ".Label"));
27: } catch (MissingResourceException mre) {
28: }
29:
30: this .setActionCommand(vars.getProperty(key + ".Action",
31: "message-open"));
32:
33: /*
34: MessageNotificationManager mnm = Pooka.getMainPanel().getMessageNotificationManager();
35: Map newMessageMap = mnm.getNewMessageMap();
36: Iterator folders = newMessageMap.keySet().iterator();
37: while (folders.hasNext()) {
38: String current = (String) folders.next();
39: buildFolderMenu(current, (List)newMessageMap.get(current));
40: }
41: */
42:
43: }
44:
45: /**
46: * This builds the menu for each folder/message group.
47: */
48: protected void buildFolderMenu(String pFolderName, List pMessageList) {
49: MessageNotificationManager mnm = Pooka.getUIFactory()
50: .getMessageNotificationManager();
51: JMenu newMenu = new JMenu(pFolderName);
52: for (int i = 0; i < pMessageList.size(); i++) {
53: JMenuItem mi = new JMenuItem();
54: net.suberic.pooka.MessageInfo messageInfo = (net.suberic.pooka.MessageInfo) pMessageList
55: .get(i);
56: mi.setAction(mnm.new OpenMessageAction(messageInfo));
57: try {
58: mi.setLabel(messageInfo.getMessageProperty("From")
59: + ": "
60: + messageInfo.getMessageProperty("Subject"));
61: } catch (Exception e) {
62: mi.setLabel("new message");
63: }
64: newMenu.add(mi);
65:
66: }
67: this .add(newMenu);
68: }
69:
70: void reset() {
71: removeAll();
72: MessageNotificationManager mnm = Pooka.getUIFactory()
73: .getMessageNotificationManager();
74: if (mnm != null) {
75: Map newMessageMap = mnm.getNewMessageMap();
76: Iterator folders = newMessageMap.keySet().iterator();
77: while (folders.hasNext()) {
78: String current = (String) folders.next();
79: buildFolderMenu(current, (List) newMessageMap
80: .get(current));
81: }
82: }
83:
84: }
85:
86: public void addNotify() {
87: reset();
88:
89: super.addNotify();
90: }
91:
92: }
|