1 package net.suberic.pooka.gui; 2 3 import javax.swing.*; 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 FolderMenu extends net.suberic.util.gui.ConfigurableMenu { 13 14 Vector folderList; 15 FolderPanel fPanel; 16 17 19 22 public FolderMenu() { 23 } 24 25 28 public void configureComponent(String key, VariableBundle vars) { 29 try { 30 setText(vars.getProperty(key + ".Label")); 31 } catch (MissingResourceException mre) { 32 } 33 34 this.setActionCommand(vars.getProperty(key + ".Action", "message-move")); 35 36 fPanel = Pooka.getMainPanel().getFolderPanel(); 37 38 MailTreeNode root = (MailTreeNode)fPanel.getFolderTree().getModel().getRoot(); 39 buildMenu(root, this); 40 } 41 42 45 protected void buildMenu(MailTreeNode mtn, JMenu currentMenu) 46 { 47 Enumeration children = mtn.children(); 48 while(children.hasMoreElements()) 49 { 50 MailTreeNode curNode = (MailTreeNode)children.nextElement(); 51 if(curNode.isLeaf()) 52 { 53 JMenuItem mi = new FolderMenuItem(curNode.toString(), ((FolderNode)curNode).getFolderInfo()); 54 mi.setActionCommand(getActionCommand()); 55 currentMenu.add(mi); 56 } 57 else { 59 JMenu newMenu = new JMenu(curNode.toString()); 60 currentMenu.add(newMenu); 61 buildMenu(curNode, newMenu); 62 } 63 } 64 } 65 66 67 71 protected void setActiveSubMenuItems(JMenu curMenu) { 72 73 for (int j = 0; j < curMenu.getItemCount(); j++) { 74 if(curMenu.getItem(j) instanceof FolderMenuItem) 75 { 76 JMenuItem mi = curMenu.getItem(j); 77 java.awt.event.ActionListener [] oldActionListeners = mi.getActionListeners(); 78 for (int i = 0; i < oldActionListeners.length; i++) { 79 mi.removeActionListener(oldActionListeners[i]); 80 } 81 82 Action a = getAction(getActionCommand()); 83 if (a != null) { 84 Action newAction = a; 85 if (a instanceof net.suberic.util.DynamicAbstractAction) { 86 try { 87 newAction = (Action)((net.suberic.util.DynamicAbstractAction)a).cloneDynamicAction(); 88 } catch (CloneNotSupportedException cnse) { 89 91 System.out.println("cnse hit."); 92 } 93 } else { 94 System.out.println("action is not a DynamicAbstractAction."); 95 } 96 newAction.putValue("target", ((FolderMenuItem)mi).getFolderInfo()); 97 102 mi.addActionListener(newAction); 103 104 106 mi.setEnabled(true); 107 } else { 108 mi.setEnabled(false); 109 } 110 } 111 else 112 setActiveSubMenuItems((JMenu)curMenu.getItem(j)); 113 } 114 } 115 116 public void setActiveMenuItems() 117 { 118 setActiveSubMenuItems(this); 119 } 120 121 124 class FolderMenuItem extends JMenuItem 125 { 126 public FolderMenuItem(String text, FolderInfo fi) 127 { 128 super(text); 129 folderInfo = fi; 130 } 131 132 public FolderInfo getFolderInfo() { return folderInfo; } 133 134 private FolderInfo folderInfo; 135 } 136 } 137 138 139 | Popular Tags |