1 19 package org.netbeans.test.editor.app.core; 20 21 import java.util.ArrayList ; 22 import java.util.Arrays ; 23 import javax.swing.Action ; 24 import javax.swing.text.Keymap ; 25 import org.netbeans.test.editor.app.Main; 26 import org.netbeans.test.editor.app.gui.*; 27 import org.netbeans.test.editor.app.core.TestAction; 28 import org.netbeans.test.editor.app.core.properties.ArrayProperty; 29 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException; 30 import org.netbeans.test.editor.app.core.properties.Properties; 31 import org.netbeans.test.editor.app.core.properties.StringProperty; 32 import org.netbeans.test.editor.app.gui.actions.TestDeleteAction; 33 import org.netbeans.test.editor.app.gui.tree.ActionsCache; 34 import org.netbeans.test.editor.app.util.ParsingUtils; 35 import org.w3c.dom.Element ; 36 41 public class TestLogAction extends TestAction { 42 43 public static final String COMMAND="Command"; 44 private String command; 45 46 public TestLogAction(int num) { 47 this(TestStringAction.STRINGED_NAME,Integer.toString(num)); 48 } 49 50 51 public TestLogAction(String name,String command) { 52 super(name); 53 setCommand(command); 54 } 55 56 public TestLogAction(Element node) { 57 super(node); 58 setCommand(ParsingUtils.fromSafeString(node.getAttribute(COMMAND))); } 60 61 public Element toXML(Element node) { 62 node = super.toXML(node); 63 node.setAttribute(COMMAND, ParsingUtils.toSafeString(getCommand())); 64 return node; 65 } 66 67 public void fromXML(Element node) throws BadPropertyNameException { 68 super.fromXML(node); 69 setCommand(ParsingUtils.fromSafeString(node.getAttribute(COMMAND))); 70 } 71 72 public Properties getProperties() { 73 Properties ret=new Properties(); 74 ret.put(NAME,new ArrayProperty(name,getKeyMaps())); 75 ret.put(COMMAND, new StringProperty(command)); 76 return ret; 77 } 78 79 public Object getProperty(String name) throws BadPropertyNameException { 80 if (name.compareTo(COMMAND) == 0) { 81 return new StringProperty(command); 82 } else if (name.compareTo(NAME) == 0) { 83 return new ArrayProperty(name,getKeyMaps()); 84 } else { 85 return super.getProperty(name); 86 } 87 } 88 89 public void setProperty(String name, Object value) throws BadPropertyNameException { 90 if (name.compareTo(COMMAND) == 0) { 91 setCommand(((StringProperty)(value)).getProperty()); 92 } else if (name.compareTo(NAME) == 0) { 93 setName(((ArrayProperty)value).getProperty()); 94 } else { 95 super.setProperty(name, value); 96 } 97 } 98 99 public void setCommand(String value) { 100 String oldValue = command; 101 command = value; 102 firePropertyChange(COMMAND, oldValue, command); 103 } 104 105 public String getCommand() { 106 return command; 107 } 108 109 public void perform() { 110 isPerforming=true; 111 getLogger().performAction(this); 112 isPerforming=false; 113 } 114 115 public void stop() { 116 } 117 118 public String [] getKeyMaps() { 119 ArrayList ret=new ArrayList (); 120 Keymap map=Main.frame.getEditor().getKeymap(); 121 String name,t; 122 Action [] acs=map.getBoundActions(); 123 boolean found; 124 for (int i=0;i < acs.length;i++) { 125 name=(String )(acs[i].getValue(Action.NAME)); 126 if (name != null) { 127 found=false; 128 for (int j=0;j < ret.size();j++) { 129 t=(String )(ret.get(j)); 130 if (t.compareTo(name) == 0) { 131 found=true; 132 break; 133 } 134 } 135 if (!found) { 136 ret.add(name); 137 } 138 } 139 } 140 ret.add(TestStringAction.STRINGED_NAME); 141 String [] rets=(String [])(ret.toArray(new String [] {})); 142 Arrays.sort(rets); 143 144 return rets; 145 } 146 } 147 148 | Popular Tags |