1 package org.columba.core.gui.menu; 19 20 import java.awt.Component ; 21 import java.util.Enumeration ; 22 import java.util.Vector ; 23 24 import javax.swing.Action ; 25 import javax.swing.JMenuItem ; 26 27 32 public class MenuElement implements IMenuElement { 33 34 private int type; 35 36 private Action action; 37 38 private String placeholderId; 39 40 private String menuId; 41 42 private String menuLabel; 43 44 private IMenuElement parent; 45 46 private JMenuItem menuItem; 47 48 private Component component; 49 50 private Vector children = new Vector (); 51 52 public MenuElement(int type) { 53 this.type = type; 54 } 55 56 public boolean isSeparator() { 57 return type == TYPE_SEPARATOR ? true : false; 58 } 59 60 public boolean isAction() { 61 return type == TYPE_ACTION ? true : false; 62 } 63 64 public boolean isPlaceholder() { 65 return type == TYPE_PLACEHOLDER ? true : false; 66 } 67 68 public boolean isMenu() { 69 return type == TYPE_MENU ? true : false; 70 } 71 72 public boolean isComponent() { 73 return type == TYPE_MENUITEM ? true : false; 74 } 75 76 79 public Action getAction() { 80 return action; 81 } 82 83 86 public String getPlaceholderId() { 87 return placeholderId; 88 } 89 90 public IMenuElement getParent() { 91 return parent; 92 } 93 94 public Enumeration getChildren() { 95 return children.elements(); 96 } 97 98 public void add(IMenuElement child) { 99 child.setParent(this); 100 children.add(child); 101 } 102 103 public void setParent(IMenuElement parent) { 104 this.parent = parent; 105 } 106 107 public void remove(IMenuElement child) { 108 children.remove(child); 109 } 110 111 public void remove(int index) { 112 children.remove(index); 113 } 114 115 118 public String getMenuId() { 119 return menuId; 120 } 121 122 126 public void setMenuId(String menuId) { 127 this.menuId = menuId; 128 } 129 130 134 public void setAction(Action action) { 135 this.action = action; 136 } 137 138 142 public void setPlaceholderId(String placeholderId) { 143 this.placeholderId = placeholderId; 144 } 145 146 149 public String getMenuLabel() { 150 return menuLabel; 151 } 152 153 157 public void setMenuLabel(String menuLabel) { 158 this.menuLabel = menuLabel; 159 } 160 161 public int indexOf(IMenuElement child) { 162 return children.indexOf(child); 163 } 164 165 public void insert(IMenuElement child, int position) { 166 child.setParent(this); 167 168 children.insertElementAt(child, position); 169 } 170 171 public String toString() { 172 StringBuffer buf = new StringBuffer (); 173 if (menuId != null) 174 buf.append(menuId); 175 if (placeholderId != null) 176 buf.append(placeholderId); 177 if (action != null) 178 buf.append(action.toString()); 179 180 buf.append(" type="+type); 181 182 return buf.toString(); 183 } 184 185 public JMenuItem getMenuItem() { 186 return menuItem; 187 } 188 189 193 public void setMenuItem(JMenuItem menuItem) { 194 this.menuItem = menuItem; 195 } 196 197 public Component getComponent() { 198 return component; 199 } 200 201 204 public void setComponent(Component component) { 205 this.component = component; 206 } 207 208 } 209 | Popular Tags |