1 19 package org.netbeans.test.editor.app.core; 20 21 import java.util.ArrayList ; 22 import java.util.Vector ; 23 import org.netbeans.test.editor.app.gui.*; 24 import org.netbeans.test.editor.app.core.TestAction; 25 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException; 26 import org.netbeans.test.editor.app.core.properties.Properties; 27 import org.netbeans.test.editor.app.core.properties.StringProperty; 28 import org.netbeans.test.editor.app.gui.actions.TestDeleteAction; 29 import org.netbeans.test.editor.app.gui.tree.ActionsCache; 30 import org.netbeans.test.editor.app.util.ParsingUtils; 31 import org.w3c.dom.Element ; 32 37 public class TestStringAction extends TestAction { 38 39 public static final String STRINGED_NAME="default-typed"; 40 public static final String STRING="String"; 41 private String string; 42 43 public TestStringAction(int num) { 44 this("string"+Integer.toString(num),""); 45 } 46 47 public TestStringAction(int num, String string) { 48 this("string"+Integer.toString(num),string); 49 } 50 51 52 public TestStringAction(String name, String string) { 53 super(name); 54 setString(string); 55 } 56 57 public TestStringAction(Element node) { 58 super(node); 59 setString(ParsingUtils.fromSafeString(node.getAttribute(STRING))); 60 } 61 62 public Element toXML(Element node) { 63 node = super.toXML(node); 64 node.setAttribute(STRING, ParsingUtils.toSafeString(getString())); 65 return node; 66 } 67 68 public void fromXML(Element node) throws BadPropertyNameException { 69 super.fromXML(node); 70 setString(ParsingUtils.fromSafeString(node.getAttribute(STRING))); 71 } 72 73 public Properties getProperties() { 74 Properties ret=super.getProperties(); 75 ret.put(STRING, new StringProperty(string)); 76 return ret; 77 } 78 79 public Object getProperty(String name) throws BadPropertyNameException { 80 if (name.compareTo(STRING) == 0) { 81 return new StringProperty(string); 82 } else { 83 return super.getProperty(name); 84 } 85 } 86 87 public void setProperty(String name, Object value) throws BadPropertyNameException { 88 if (name.compareTo(STRING) == 0) { 89 setString(((StringProperty)value).getProperty()); 90 } else { 91 super.setProperty(name, value); 92 } 93 } 94 95 public void setString(String value) { 96 String oldValue = string; 97 string = value; 98 firePropertyChange(STRING, oldValue, string); 99 } 100 101 public String getString() { 102 return string; 103 } 104 105 public static TestAction[] generate(Vector acts) { ArrayList ret=new ArrayList (); 107 TestAction ta; 108 TestStringAction tsa; 109 StringBuffer sb=null; 110 String com; 111 boolean logging=false; 112 113 for (int i=0;i < acts.size();i++) { 114 ta=(TestAction)(acts.get(i)); 115 if (ta instanceof TestLogAction && ta.getName().compareTo(STRINGED_NAME) == 0) { 116 com=((TestLogAction)ta).getCommand(); 117 if (!(com.compareTo("\0A") == 0 || com.compareTo("\0C") == 0)) { if (!logging) { 119 sb=new StringBuffer (com); 120 logging=true; 121 } else { 122 sb.append(com); 123 } 124 } 125 } else { 126 if (logging) { 127 logging=false; 128 if (sb.length() > 0) 129 ret.add(new TestStringAction(getNameCounter(),sb.toString())); 130 } 131 ret.add(ta); 132 } 133 } 134 if (logging) { 135 ret.add(new TestStringAction(getNameCounter(),sb.toString())); 136 } 137 return (TestAction[])(ret.toArray(new TestAction[] {})); 138 } 139 140 public void perform() { 141 isPerforming=true; 142 getLogger().performAction(this); 143 isPerforming=false; 144 } 145 146 public void stop() { 147 getLogger().stopPerforming(); 148 } 149 } 150 | Popular Tags |