1 7 package javax.swing.text; 8 9 import java.awt.event.ActionEvent ; 10 import java.awt.KeyboardFocusManager ; 11 import java.awt.Component ; 12 import java.util.Hashtable ; 13 import java.util.Enumeration ; 14 import javax.swing.Action ; 15 import javax.swing.AbstractAction ; 16 import javax.swing.KeyStroke ; 17 18 44 public abstract class TextAction extends AbstractAction { 45 46 51 public TextAction(String name) { 52 super(name); 53 } 54 55 64 protected final JTextComponent getTextComponent(ActionEvent e) { 65 if (e != null) { 66 Object o = e.getSource(); 67 if (o instanceof JTextComponent ) { 68 return (JTextComponent ) o; 69 } 70 } 71 return getFocusedComponent(); 72 } 73 74 88 public static final Action [] augmentList(Action [] list1, Action [] list2) { 89 Hashtable h = new Hashtable (); 90 for (int i = 0; i < list1.length; i++) { 91 Action a = list1[i]; 92 String value = (String )a.getValue(Action.NAME); 93 h.put((value!=null ? value:""), a); 94 } 95 for (int i = 0; i < list2.length; i++) { 96 Action a = list2[i]; 97 String value = (String )a.getValue(Action.NAME); 98 h.put((value!=null ? value:""), a); 99 } 100 Action [] actions = new Action [h.size()]; 101 int index = 0; 102 for (Enumeration e = h.elements() ; e.hasMoreElements() ;) { 103 actions[index++] = (Action ) e.nextElement(); 104 } 105 return actions; 106 } 107 108 117 protected final JTextComponent getFocusedComponent() { 118 return JTextComponent.getFocusedComponent(); 119 } 120 } 121 | Popular Tags |