1 19 20 21 package com.sshtools.ui.awt; 22 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.util.Enumeration ; 26 import java.util.Vector ; 27 28 public class ActionMenu { 29 30 public final static Action SEPARATOR = new AbstractAction("separator") { public void actionPerformed(ActionEvent e) { 32 } 33 }; 34 35 private int weight; 36 private int mnemonic; 37 private String name; 38 private String displayName; 39 private Vector children; 40 private Vector listeners; 41 private String toolTip; 42 43 private ActionMenu() { 44 } 46 47 public ActionMenu(String name, String displayName, int mnemonic, int weight, String toolTip) { 48 this.name = name; 49 this.displayName = displayName; 50 this.mnemonic = mnemonic; 51 this.weight = weight; 52 this.toolTip = toolTip; 53 children = new Vector (); 54 } 55 56 public String getToolTip() { 57 return toolTip; 58 } 59 60 public void setToolTip() { 61 this.toolTip = toolTip; 62 } 63 64 public int compareTo(Object o) { 65 double oweight = ((ActionMenu) o).weight; 66 return (weight < oweight ? -1 : (weight == oweight ? 0 : 1)); 67 } 68 69 72 73 public String getDisplayName() { 74 return displayName; 75 } 76 77 81 82 public void setDisplayName(String displayName) { 83 this.displayName = displayName; 84 } 85 86 89 90 public int getMnemonic() { 91 return mnemonic; 92 } 93 94 98 99 public void setMnemonic(int mnemonic) { 100 this.mnemonic = mnemonic; 101 } 102 103 106 107 public String getName() { 108 return name; 109 } 110 111 115 116 public void setName(String name) { 117 this.name = name; 118 } 119 120 123 124 public int getWeight() { 125 return weight; 126 } 127 128 132 133 public void setWeight(int weight) { 134 this.weight = weight; 135 } 136 137 140 public void addSeparator() { 141 children.addElement(SEPARATOR); 142 } 143 144 147 public void add(Action item) { 148 children.addElement(item); 149 } 150 151 154 public Enumeration children() { 155 return children.elements(); 156 } 157 158 161 public int getChildCount() { 162 return children.size(); 163 } 164 165 public void addActionListener(ActionListener l) { 166 if (listeners == null) { 167 listeners = new Vector (); 168 } 169 listeners.addElement(l); 170 } 171 172 public void removeActionListener(ActionListener l) { 173 if (listeners != null) { 174 listeners.removeElement(l); 175 } 176 } 177 178 public boolean action() { 179 ActionEvent evt = null; 180 for (int i = listeners == null ? -1 : listeners.size() - 1; i >= 0; i--) { 181 if (evt == null) { 182 evt = new ActionEvent (this, 1001, getName()); 183 } 184 ((ActionListener ) listeners.elementAt(i)).actionPerformed(evt); 185 } 186 return false; 187 } 188 189 193 public Action getChild(int clicked) { 194 return (Action)children.elementAt(clicked); 195 } 196 197 200 public void removeAllChildren() { 201 children.removeAllElements(); 202 } 203 204 } | Popular Tags |