KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.jellytools.modules.editor;
21
22 import javax.swing.ComboBoxModel JavaDoc;
23 import javax.swing.tree.TreePath JavaDoc;
24 import org.netbeans.jellytools.HelpOperator;
25 import org.netbeans.jellytools.OptionsOperator;
26 import org.netbeans.jellytools.nodes.Node;
27 import org.netbeans.jemmy.EventTool;
28 import org.netbeans.jemmy.operators.JButtonOperator;
29 import org.netbeans.jemmy.operators.JComboBoxOperator;
30 import org.netbeans.jemmy.operators.JDialogOperator;
31 import org.netbeans.jemmy.operators.JListOperator;
32 import org.netbeans.jemmy.operators.JTreeOperator;
33
34 /**
35  *
36  * @author Jiri Prox Jiri.Prox@Sun.COM
37  */

38 public class KeyMapOperator extends JDialogOperator{
39     
40     
41     private static final String JavaDoc DUPLICATE_BUTTON = "Duplicate";
42     private static final String JavaDoc RESTORE_BUTTON = "Restore";
43     private static final String JavaDoc DELETE_BUTTON = "Delete";
44     private static final String JavaDoc ADD_BUTTON = "Add ...";
45     private static final String JavaDoc REMOVE_BUTTON = "Remove";
46     
47     private JComboBoxOperator profile;
48     private JButtonOperator duplicate;
49     private JButtonOperator restore;
50     private JButtonOperator delete;
51     private JTreeOperator actions;
52     private JListOperator shortcuts;
53     private JButtonOperator add;
54     private JButtonOperator remove;
55     
56     private static OptionsOperator options;
57     
58     /** Creates a new instance of KeyMapOperator */
59     public KeyMapOperator() {
60         super("Options");
61     }
62     
63     public static KeyMapOperator invoke() {
64         options = OptionsOperator.invoke();
65         options.selectKeymap();
66         new EventTool().waitNoEvent(500);
67         return new KeyMapOperator();
68     }
69     
70     public JComboBoxOperator profile() {
71         if(profile==null) {
72             profile = new JComboBoxOperator(this);
73         }
74         return profile;
75     }
76     
77     public JButtonOperator duplicate() {
78         if(duplicate==null) {
79             duplicate = new JButtonOperator(this, DUPLICATE_BUTTON);
80         }
81         return duplicate;
82     }
83     
84     public JButtonOperator delete() {
85         if(delete==null) {
86             delete = new JButtonOperator(this, DELETE_BUTTON);
87         }
88         return delete;
89     }
90     
91     public JButtonOperator restore() {
92         if(restore==null) {
93             restore = new JButtonOperator(this, RESTORE_BUTTON);
94         }
95         return restore;
96     }
97     
98     public JTreeOperator actions() {
99         if(actions==null) {
100             actions = new JTreeOperator(this);
101         }
102         return actions;
103     }
104     
105     public JListOperator shortcuts() {
106         if(shortcuts==null) {
107             shortcuts = new JListOperator(this);
108         }
109         return shortcuts;
110     }
111     
112     public JButtonOperator add() {
113         if(add==null) {
114             add = new JButtonOperator(this, ADD_BUTTON);
115         }
116         return add;
117     }
118     
119     public JButtonOperator remove() {
120         if(remove==null) {
121             remove = new JButtonOperator(this, REMOVE_BUTTON);
122         }
123         return remove;
124     }
125     
126     public JButtonOperator ok() {
127         return options.btOK();
128     }
129     
130     public JButtonOperator cancel() {
131         return options.btCancel();
132     }
133     
134     public JButtonOperator help() {
135         return options.btHelp();
136     }
137     
138     public void selectAction(String JavaDoc path) {
139         Node n = new Node(actions(), path);
140         n.select();
141     }
142     
143     public void selectProfile(String JavaDoc profile) {
144         JComboBoxOperator combo = profile();
145         if(combo.getSelectedItem().toString().equals(profile)) return; //no need to switch profile
146
ComboBoxModel JavaDoc model = combo.getModel();
147         for (int i = 0; i < model.getSize(); i++) {
148             Object JavaDoc item = model.getElementAt(i);
149             if(item.toString().equals(profile)) {
150                 combo.setSelectedIndex(i);
151                 return;
152             }
153         }
154         throw new IllegalArgumentException JavaDoc("Profile "+profile+" not found");
155     }
156     
157     
158     public void verify() {
159         profile();
160         duplicate();
161         restore();
162         actions();
163         shortcuts();
164         add();
165         remove();
166         ok();
167         cancel();
168         help();
169     }
170     
171     
172     
173     
174     public static void main(String JavaDoc[] args) throws InterruptedException JavaDoc {
175         //KeyMapOperator.invoke().verify();
176
KeyMapOperator.invoke().selectAction("Other|select-line");
177         
178         
179     }
180
181     
182 }
183
Popular Tags