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 12 public class RecentMessageMenu extends net.suberic.util.gui.ConfigurableAwtMenu { 13 14 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 28 public void configureComponent(String 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 45 46 } 47 48 51 protected void buildFolderMenu(String pFolderName, java.util.List 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 oma = mnm.new OpenMessageAction(messageInfo); 58 mi.setActionCommand((String ) 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 e) { 64 mi.setLabel("new message"); 65 } 66 newMenu.add(mi); 67 68 } 69 this.add(newMenu); 70 } 71 72 void reset() { 73 Runnable runMe = new Runnable () { 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 current = (String ) folders.next(); 82 buildFolderMenu(current, (java.util.List )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 |