KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jellytools > modules > editor > KeyBindings


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
20 /*
21  * KeyBindings.java
22  *
23  * Created on 10/17/02 12:54 PM
24  */

25 package org.netbeans.jellytools.modules.editor;
26
27 import java.io.File JavaDoc;
28 import java.io.FileWriter JavaDoc;
29 import java.io.PrintWriter JavaDoc;
30 import org.netbeans.jellytools.properties.Property;
31 import org.netbeans.jemmy.operators.*;
32 import java.util.*;
33
34 import javax.swing.ListModel JavaDoc;
35 import org.netbeans.jellytools.OptionsOperator;
36 import org.netbeans.jellytools.properties.PropertySheetOperator;
37 import org.netbeans.jemmy.EventTool;
38
39 /** Class implementing all necessary methods for handling "Key Bindings" NbDialog.
40  *
41  * @author eh103527
42  * @version 1.0
43  */

44 public class KeyBindings extends JDialogOperator {
45     
46     /** Creates new KeyBindings that can handle it.
47      */

48     public KeyBindings() {
49         super(java.util.ResourceBundle.getBundle("org.netbeans.modules.editor.options.Bundle").getString("PROP_KeyBindings"));
50     }
51     
52     private JRadioButtonOperator _rbSortByName;
53     private JRadioButtonOperator _rbSortByAction;
54     private JListOperator _lstActions;
55     private JButtonOperator _btMetalScrollButton;
56     private JButtonOperator _btMetalScrollButton2;
57     private JLabelOperator _lblKeybindings;
58     private JListOperator _lstKeybindings;
59     private JButtonOperator _btAdd;
60     private JButtonOperator _btRemove;
61     private JButtonOperator _btOK;
62     private JButtonOperator _btCancel;
63     private JButtonOperator _btHelp;
64     
65     
66     //******************************
67
// Subcomponents definition part
68
//******************************
69

70     /** Tries to find " Sort by Name" JRadioButton in this dialog.
71      * @return JRadioButtonOperator
72      */

73     public JRadioButtonOperator rbSortByName() {
74         if (_rbSortByName==null) {
75             _rbSortByName = new JRadioButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.modules.editor.options.Bundle").getString("KBEP_name_sort_button"));
76         }
77         return _rbSortByName;
78     }
79     
80     /** Tries to find " Sort by Action" JRadioButton in this dialog.
81      * @return JRadioButtonOperator
82      */

83     public JRadioButtonOperator rbSortByAction() {
84         if (_rbSortByAction==null) {
85             _rbSortByAction = new JRadioButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.modules.editor.options.Bundle").getString("KBEP_action_sort_button"));
86         }
87         return _rbSortByAction;
88     }
89     
90     /** Tries to find null JList in this dialog.
91      * @return JListOperator
92      */

93     public JListOperator lstActions() {
94         if (_lstActions==null) {
95             _lstActions = new JListOperator(this);
96         }
97         return _lstActions;
98     }
99     
100     /** Tries to find "" MetalScrollButton in this dialog.
101      * @return JButtonOperator
102      */

103     public JButtonOperator btMetalScrollButton() {
104         if (_btMetalScrollButton==null) {
105             _btMetalScrollButton = new JButtonOperator(this, "");
106         }
107         return _btMetalScrollButton;
108     }
109     
110     /** Tries to find "" MetalScrollButton in this dialog.
111      * @return JButtonOperator
112      */

113     public JButtonOperator btMetalScrollButton2() {
114         if (_btMetalScrollButton2==null) {
115             _btMetalScrollButton2 = new JButtonOperator(this, "", 1);
116         }
117         return _btMetalScrollButton2;
118     }
119     
120     /** Tries to find "Keybindings:" JLabel in this dialog.
121      * @return JLabelOperator
122      */

123     public JLabelOperator lblKeybindings() {
124         if (_lblKeybindings==null) {
125             _lblKeybindings = new JLabelOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.modules.editor.options.Bundle").getString("KBEP_Sequences"));
126         }
127         return _lblKeybindings;
128     }
129     
130     /** Tries to find null JList in this dialog.
131      * @return JListOperator
132      */

133     public JListOperator lstKeybindings() {
134         if (_lstKeybindings==null) {
135             _lstKeybindings = new JListOperator(this, 1);
136         }
137         return _lstKeybindings;
138     }
139     
140     /** Tries to find "Add..." JButton in this dialog.
141      * @return JButtonOperator
142      */

143     public JButtonOperator btAdd() {
144         if (_btAdd==null) {
145             _btAdd = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.modules.editor.options.Bundle").getString("KBEP_Add"));
146         }
147         return _btAdd;
148     }
149     
150     /** Tries to find "Remove" JButton in this dialog.
151      * @return JButtonOperator
152      */

153     public JButtonOperator btRemove() {
154         if (_btRemove==null) {
155             _btRemove = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.modules.editor.options.Bundle").getString("KBEP_Remove"));
156         }
157         return _btRemove;
158     }
159     
160     /** Tries to find "OK" JButton in this dialog.
161      * @return JButtonOperator
162      */

163     public JButtonOperator btOK() {
164         if (_btOK==null) {
165             _btOK = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.modules.editor.options.Bundle").getString("KBEP_OK_LABEL"));
166         }
167         return _btOK;
168     }
169     
170     /** Tries to find "Cancel" JButton in this dialog.
171      * @return JButtonOperator
172      */

173     public JButtonOperator btCancel() {
174         if (_btCancel==null) {
175             _btCancel = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.core.awt.Bundle").getString("CancelButton"));
176         }
177         return _btCancel;
178     }
179     
180     /** Tries to find "Help" JButton in this dialog.
181      * @return JButtonOperator
182      */

183     public JButtonOperator btHelp() {
184         if (_btHelp==null) {
185             _btHelp = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.openide.explorer.propertysheet.Bundle").getString("CTL_Help"));
186         }
187         return _btHelp;
188     }
189     
190     
191     //****************************************
192
// Low-level functionality definition part
193
//****************************************
194

195     /** clicks on " Sort by Name" JRadioButton
196      */

197     public void sortByName() {
198         rbSortByName().push();
199     }
200     
201     /** clicks on " Sort by Action" JRadioButton
202      */

203     public void sortByAction() {
204         rbSortByAction().push();
205     }
206     
207     /** clicks on "" MetalScrollButton
208      */

209     public void metalScrollButton() {
210         btMetalScrollButton().push();
211     }
212     
213     /** clicks on "" MetalScrollButton
214      */

215     public void metalScrollButton2() {
216         btMetalScrollButton2().push();
217     }
218     
219     /** clicks on "Add..." JButton
220      */

221     public void add() {
222         btAdd().push();
223     }
224     
225     /** clicks on "Remove" JButton
226      */

227     public void remove() {
228         btRemove().push();
229     }
230     
231     /** clicks on "OK" JButton
232      */

233     public void oK() {
234         btOK().push();
235     }
236     
237     /** clicks on "Cancel" JButton
238      */

239     public void cancel() {
240         btCancel().push();
241     }
242     
243     /** clicks on "Help" JButton
244      */

245     public void help() {
246         btHelp().push();
247     }
248     
249     
250     //*****************************************
251
// High-level functionality definition part
252
//*****************************************
253

254     /** Performs verification of KeyBindings by accessing all its components.
255      */

256     public void verify() {
257         rbSortByName();
258         rbSortByAction();
259         lstActions();
260         btMetalScrollButton();
261         btMetalScrollButton2();
262         lblKeybindings();
263         lstKeybindings();
264         btAdd();
265         btRemove();
266         btOK();
267         btCancel();
268         btHelp();
269     }
270     
271     public List listActions() {
272         ListModel JavaDoc model = lstActions().getModel();
273         List ret=new Vector();
274         for (int i=0;i < model.getSize();i++) {
275             ret.add(model.getElementAt(i));
276         }
277         return ret;
278     }
279     
280     public List listKeyBindings(String JavaDoc actionName) {
281         JListOperator jlist=lstActions();
282         jlist.selectItem(actionName);
283         ListModel JavaDoc model = lstKeybindings().getModel();
284         List ret=new Vector();
285         for (int i=0;i < model.getSize();i++) {
286             ret.add(model.getElementAt(i));
287         }
288         return ret;
289     }
290     
291     /**
292      * @param editorName
293      * @return
294      */

295     public static KeyBindings invoke(String JavaDoc editorName) {
296         OptionsOperator options = OptionsOperator.invoke();
297         options.switchToClassicView();
298         options.selectOption(ResourceBundle.getBundle("org/netbeans/core/Bundle").getString("UI/Services/Editing")+"|"+ResourceBundle.getBundle("org/netbeans/modules/editor/options/Bundle").getString("OPTIONS_all")+"|" + editorName);
299         //new EventTool().waitNoEvent(500);
300
try {
301             Thread.sleep(1000);
302         } catch (Exception JavaDoc ex) {
303         }
304         PropertySheetOperator pso = new PropertySheetOperator(options);
305         Property p=new Property(pso, ResourceBundle.getBundle("org/netbeans/modules/editor/options/Bundle").getString("PROP_KeyBindings"));
306         p.openEditor();
307         KeyBindings ret=new KeyBindings();
308         options.close();
309         return ret;
310     }
311     
312     public static List listActions(String JavaDoc editorName) {
313         KeyBindings instance = invoke(editorName);
314         List result = instance.listActions();
315         instance.oK();
316         return result;
317     }
318     
319     public static Hashtable listAllKeyBindings(String JavaDoc editorName) {
320         KeyBindings instance = invoke(editorName);
321         List result = instance.listActions();
322         Hashtable ret=new Hashtable();
323         for (int i=0;i < result.size();i++) {
324             ret.put(result.get(i).toString(),instance.listKeyBindings(result.get(i).toString()));
325         }
326         instance.oK();
327         return ret;
328     }
329     
330     /** Performs simple test of KeyBindings
331      * @param args the command line arguments
332      */

333     public static void main(String JavaDoc args[]) {
334         //repeating test
335
String JavaDoc[] names=new String JavaDoc[] {"Plain Editor","HTML Editor","Java Editor"};
336         List list;
337         for (int j=0;j < 20;j++) {
338             
339             for (int i=0;i < names.length;i++) {
340                 list = KeyBindings.listActions(names[i]);
341                 System.out.println("step "+j+" output size="+list.size());
342             }
343         }
344         /*
345         String name="Java Editor";
346         Hashtable table;
347         table = KeyBindings.listAllKeyBindings(name);
348         Object[] keys=table.keySet().toArray();
349         Arrays.sort(keys);
350         List list;
351         try {
352             File out=new File("/tmp/"+name+" actions.lst");
353             PrintWriter pw=new PrintWriter(new FileWriter(out));
354             for (int i=0;i < keys.length;i++) {
355                 pw.print(keys[i]+": ");
356                 list=(List)table.get(keys[i]);
357                 for (int j=0;j < list.size();j++) {
358                     pw.print(list.get(j)+" ");
359                 }
360                 pw.println();
361             }
362             pw.close();
363         } catch (Exception ex) {
364             ex.printStackTrace();
365         }*/

366     }
367 }
368
369
Popular Tags