KickJava   Java API By Example, From Geeks To Geeks.

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


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.Arrays JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import javax.swing.text.Keymap JavaDoc;
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 JavaDoc;
36 /**
37  *
38  * @author ehucka
39  * @version
40  */

41 public class TestLogAction extends TestAction {
42     
43     public static final String JavaDoc COMMAND="Command";
44     private String JavaDoc command;
45     
46     public TestLogAction(int num) {
47     this(TestStringAction.STRINGED_NAME,Integer.toString(num));
48     }
49     
50     /** Creates new TestLogAction */
51     public TestLogAction(String JavaDoc name,String JavaDoc command) {
52     super(name);
53     setCommand(command);
54     }
55     
56     public TestLogAction(Element JavaDoc node) {
57     super(node);
58     setCommand(ParsingUtils.fromSafeString(node.getAttribute(COMMAND))); //???
59
}
60     
61     public Element JavaDoc toXML(Element JavaDoc node) {
62     node = super.toXML(node);
63     node.setAttribute(COMMAND, ParsingUtils.toSafeString(getCommand()));
64     return node;
65     }
66     
67     public void fromXML(Element JavaDoc 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 JavaDoc getProperty(String JavaDoc 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 JavaDoc name, Object JavaDoc 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 JavaDoc value) {
100     String JavaDoc oldValue = command;
101     command = value;
102     firePropertyChange(COMMAND, oldValue, command);
103     }
104     
105     public String JavaDoc 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 JavaDoc[] getKeyMaps() {
119     ArrayList JavaDoc ret=new ArrayList JavaDoc();
120     Keymap JavaDoc map=Main.frame.getEditor().getKeymap();
121     String JavaDoc name,t;
122     Action JavaDoc[] acs=map.getBoundActions();
123     boolean found;
124     for (int i=0;i < acs.length;i++) {
125         name=(String JavaDoc)(acs[i].getValue(Action.NAME));
126         if (name != null) {
127         found=false;
128         for (int j=0;j < ret.size();j++) {
129             t=(String JavaDoc)(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 JavaDoc[] rets=(String JavaDoc[])(ret.toArray(new String JavaDoc[] {}));
142     Arrays.sort(rets);
143     
144     return rets;
145     }
146 }
147
148
Popular Tags