1 7 8 46 package org.jdesktop.swing.actions; 47 48 import java.awt.event.ActionEvent ; 49 import java.awt.event.ItemEvent ; 50 51 import java.util.ArrayList ; 52 import java.util.Iterator ; 53 import java.util.List ; 54 55 import javax.swing.Action ; 56 import javax.swing.Icon ; 57 58 import org.jdesktop.swing.Application; 59 60 73 public class CompositeAction extends AbstractActionExt { 74 75 78 private static final String LIST_IDS = "action-list-ids"; 79 80 public CompositeAction() { 81 this("CompositeAction"); 82 } 83 84 public CompositeAction(String name) { 85 super(name); 86 } 87 88 92 public CompositeAction(String name, String command) { 93 super(name, command); 94 } 95 96 public CompositeAction(String name, Icon icon) { 97 super(name, icon); 98 } 99 100 105 public CompositeAction(String name, String command, Icon icon) { 106 super(name, command, icon); 107 } 108 109 113 public void addAction(String id) { 114 List list = (List )getValue(LIST_IDS); 115 if (list == null) { 116 list = new ArrayList (); 117 putValue(LIST_IDS, list); 118 } 119 list.add(id); 120 } 121 122 127 public List getActionIDs() { 128 return (List )getValue(LIST_IDS); 129 } 130 131 135 public void actionPerformed(ActionEvent evt) { 136 ActionManager manager = Application.getInstance().getActionManager(); 137 138 Iterator iter = getActionIDs().iterator(); 139 while (iter.hasNext()) { 140 String id = (String )iter.next(); 141 Action action = manager.getAction(id); 142 if (action != null) { 143 action.actionPerformed(evt); 144 } 145 } 146 } 147 148 151 public void itemStateChanged(ItemEvent evt) { 152 ActionManager manager = Application.getInstance().getActionManager(); 153 154 Iterator iter = getActionIDs().iterator(); 155 while (iter.hasNext()) { 156 String id = (String )iter.next(); 157 Action action = manager.getAction(id); 158 if (action != null && action instanceof AbstractActionExt) { 159 ((AbstractActionExt)action).itemStateChanged(evt); 160 } 161 } 162 } 163 } 164 | Popular Tags |