KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > app > core > TestStringAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.test.editor.app.core;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Vector JavaDoc;
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 JavaDoc;
32 /**
33  *
34  * @author ehucka
35  * @version
36  */

37 public class TestStringAction extends TestAction {
38     
39     public static final String JavaDoc STRINGED_NAME="default-typed";
40     public static final String JavaDoc STRING="String";
41     private String JavaDoc string;
42     
43     public TestStringAction(int num) {
44         this("string"+Integer.toString(num),"");
45     }
46     
47     public TestStringAction(int num, String JavaDoc string) {
48         this("string"+Integer.toString(num),string);
49     }
50     
51     /** Creates new TestLogAction */
52     public TestStringAction(String JavaDoc name, String JavaDoc string) {
53         super(name);
54         setString(string);
55     }
56     
57     public TestStringAction(Element JavaDoc node) {
58         super(node);
59         setString(ParsingUtils.fromSafeString(node.getAttribute(STRING)));
60     }
61     
62     public Element JavaDoc toXML(Element JavaDoc node) {
63         node = super.toXML(node);
64         node.setAttribute(STRING, ParsingUtils.toSafeString(getString()));
65         return node;
66     }
67     
68     public void fromXML(Element JavaDoc 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 JavaDoc getProperty(String JavaDoc 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 JavaDoc name, Object JavaDoc 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 JavaDoc value) {
96         String JavaDoc oldValue = string;
97         string = value;
98         firePropertyChange(STRING, oldValue, string);
99     }
100     
101     public String JavaDoc getString() {
102         return string;
103     }
104     
105     public static TestAction[] generate(Vector JavaDoc acts) { //only "default-typed" will be "stringed" together
106
ArrayList JavaDoc ret=new ArrayList JavaDoc();
107         TestAction ta;
108         TestStringAction tsa;
109         StringBuffer JavaDoc sb=null;
110         String JavaDoc 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)) { //break lines aren't text
118
if (!logging) {
119                         sb=new StringBuffer JavaDoc(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