1 7 8 package org.jdesktop.swing.actions; 9 10 import java.awt.event.ActionEvent ; 11 import java.awt.event.ItemEvent ; 12 13 import javax.swing.Action ; 14 import javax.swing.Icon ; 15 16 28 public class TargetableAction extends AbstractActionExt { 29 30 private TargetManager targetManager; 31 32 public TargetableAction() { 33 this("action"); 34 } 35 36 public TargetableAction(String name) { 37 super(name); 38 } 39 40 44 public TargetableAction(String name, String command) { 45 super(name, command); 46 } 47 48 53 public TargetableAction(String name, String command, Icon icon) { 54 super(name, command, icon); 55 } 56 57 public TargetableAction(String name, Icon icon) { 58 super(name, icon); 59 } 60 61 67 public void setTargetManager(TargetManager tm) { 68 this.targetManager = tm; 69 } 70 71 78 public TargetManager getTargetManager() { 79 if (targetManager == null) { 80 targetManager = TargetManager.getInstance(); 81 } 82 return targetManager; 83 } 84 85 87 94 public void actionPerformed(ActionEvent evt) { 95 if (!isStateAction()) { 96 getTargetManager().doCommand(getActionCommand(), evt); 98 } 99 } 100 101 108 public void itemStateChanged(ItemEvent evt) { 109 boolean newValue; 111 boolean oldValue = isSelected(); 112 113 if (evt.getStateChange() == ItemEvent.SELECTED) { 114 newValue = true; 115 } else { 116 newValue = false; 117 } 118 119 if (oldValue != newValue) { 120 setSelected(newValue); 121 122 getTargetManager().doCommand(getActionCommand(), evt); 123 } 124 } 125 126 public String toString() { 127 return super.toString(); 128 } 129 } 130 | Popular Tags |