KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.java.editor.options.JavaOptions;
22 import org.netbeans.test.editor.app.gui.*;
23 import javax.swing.text.EditorKit JavaDoc;
24 import javax.swing.JEditorPane JavaDoc;
25 import org.netbeans.modules.editor.java.JavaKit;
26 import org.netbeans.modules.editor.html.HTMLKit;
27 import org.netbeans.modules.editor.plain.PlainKit;
28 //import org.netbeans.modules.web.core.syntax.JSPKit;
29
import javax.swing.text.PlainDocument JavaDoc;
30 //import org.netbeans.modules.web.core.jsploader.JspLoader;
31
import org.openide.text.IndentEngine;
32 import org.openide.options.SystemOption;
33 import org.netbeans.modules.editor.options.BaseOptions;
34 import java.util.Enumeration JavaDoc;
35 import org.netbeans.test.editor.app.util.Scheduler;
36 import javax.swing.SwingUtilities JavaDoc;
37 import org.netbeans.test.editor.app.Main;
38 import org.netbeans.test.editor.app.core.TestSetAction;
39 import org.netbeans.test.editor.app.core.properties.ArrayProperty;
40 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException;
41 import org.netbeans.test.editor.app.core.properties.Properties;
42 import org.netbeans.test.editor.app.gui.actions.TestDeleteAction;
43 import org.netbeans.test.editor.app.gui.tree.ActionsCache;
44 import org.w3c.dom.Element JavaDoc;
45 /**
46  *
47  * @author ehucka
48  * @version
49  */

50 public class TestSetKitAction extends TestSetAction {
51     
52     private String JavaDoc kit;
53     
54     public static final String JavaDoc KIT="Kit";
55     
56     public static String JavaDoc[] editorKitsNames={"PlainKit","JavaKit","HTMLKit"};
57     public static String JavaDoc[] kitsTypes={PlainKit.PLAIN_MIME_TYPE,
58     JavaKit.JAVA_MIME_TYPE,HTMLKit.HTML_MIME_TYPE};
59     
60     
61     /** Creates new TestSetAction */
62     public TestSetKitAction(int num) {
63         this("set"+Integer.toString(num));
64     }
65     
66     public TestSetKitAction(String JavaDoc name) {
67         super(name);
68         kit=editorKitsNames[0];
69     }
70     
71     public TestSetKitAction(Element JavaDoc node) {
72         super(node);
73         kit = node.getAttribute(KIT);
74     }
75     
76     public Element JavaDoc toXML(Element JavaDoc node) {
77         node = super.toXML(node);
78         
79         node.setAttribute(KIT, kit);
80         return node;
81     }
82     
83     public void fromXML(Element JavaDoc node) throws BadPropertyNameException {
84         super.fromXML(node);
85         kit = node.getAttribute(KIT);
86     }
87     
88     public Properties getProperties() {
89         Properties ret=super.getProperties();
90         ret.put(KIT, new ArrayProperty(kit, editorKitsNames));
91         return ret;
92     }
93     
94     public Object JavaDoc getProperty(String JavaDoc name) throws BadPropertyNameException {
95         if (name.compareTo(KIT) == 0) {
96             return new ArrayProperty(kit, editorKitsNames);
97         } else {
98             return super.getProperty(name);
99         }
100     }
101     
102     public void setProperty(String JavaDoc name, Object JavaDoc value) throws BadPropertyNameException {
103         if (name.compareTo(KIT) == 0) {
104             setKit(((ArrayProperty)value).getProperty());
105         } else {
106             super.setProperty(name, value);
107         }
108     }
109     
110     public void setKit(String JavaDoc value) {
111         String JavaDoc oldValue = kit;
112         kit = value;
113         firePropertyChange(KIT, oldValue, kit);
114     }
115     
116     public String JavaDoc getKit() {
117         return kit;
118     }
119     
120     public int getKitI() {
121         for (int i=0;i < editorKitsNames.length;i++) {
122             if (kit.compareTo(editorKitsNames[i]) == 0) {
123                 return i;
124             }
125         }
126         return 0;
127     }
128     
129     public String JavaDoc[] getKits() {
130         return editorKitsNames;
131     }
132     
133     public void perform() {
134         super.perform();
135         try {
136         SwingUtilities.invokeAndWait(new Runnable JavaDoc() {
137             public void run() {
138                 Main.frame.getEditor().setEditorKit(getKitI());
139             }
140         });
141         } catch (Exception JavaDoc e) {
142             e.printStackTrace(System.err);
143         }
144     }
145     
146     public void stop() {
147     }
148 }
149
Popular Tags