KickJava   Java API By Example, From Geeks To Geeks.

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


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  * GoToLine.java
22  *
23  * Created on 2/11/03 10:58 AM
24  */

25 package org.netbeans.jellytools.modules.editor;
26
27 import java.awt.Robot JavaDoc;
28 import java.awt.event.InputEvent JavaDoc;
29 import org.netbeans.jemmy.operators.*;
30
31 /** Class implementing all necessary methods for handling "Go to Line" NbDialog.
32  *
33  * @author eh103527
34  * @version 1.0
35  */

36 public class GoToLine extends JDialogOperator {
37
38     /** Creates new GoToLine that can handle it.
39      */

40     public GoToLine() {
41         super(java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("goto-title"));
42     }
43     
44     private JLabelOperator _lblGoToLine;
45     private JComboBoxOperator _cboGoToLine;
46     private JButtonOperator _btGoto;
47     private JButtonOperator _btClose;
48     private JButtonOperator _btHelp;
49     
50     
51     //******************************
52
// Subcomponents definition part
53
//******************************
54

55     /** Tries to find "Go to Line:" JLabel in this dialog.
56      * @return JLabelOperator
57      */

58     public JLabelOperator lblGoToLine() {
59         if (_lblGoToLine==null) {
60             _lblGoToLine = new JLabelOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("goto-line"));
61         }
62         return _lblGoToLine;
63     }
64     
65     /** Tries to find null JComboBox in this dialog.
66      * @return JComboBoxOperator
67      */

68     public JComboBoxOperator cboGoToLine() {
69         if (_cboGoToLine==null) {
70             _cboGoToLine = new JComboBoxOperator(this);
71         }
72         return _cboGoToLine;
73     }
74     
75     /** Tries to find "Goto" JButton in this dialog.
76      * @return JButtonOperator
77      */

78     public JButtonOperator btGoto() {
79         if (_btGoto==null) {
80             _btGoto = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("goto-button-goto"));
81         }
82         return _btGoto;
83     }
84     
85     /** Tries to find "Close" JButton in this dialog.
86      * @return JButtonOperator
87      */

88     public JButtonOperator btClose() {
89         if (_btClose==null) {
90             _btClose = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("goto-button-cancel"));
91         }
92         return _btClose;
93     }
94     
95     /** Tries to find "Help" JButton in this dialog.
96      * @return JButtonOperator
97      */

98     public JButtonOperator btHelp() {
99         if (_btHelp==null) {
100             _btHelp = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.openide.explorer.propertysheet.Bundle").getString("CTL_Help"));
101         }
102         return _btHelp;
103     }
104     
105     
106     //****************************************
107
// Low-level functionality definition part
108
//****************************************
109

110     /** returns selected item for cboGoToLine
111      * @return String item
112      */

113     public String JavaDoc getSelectedGoToLine() {
114         return cboGoToLine().getSelectedItem().toString();
115     }
116     
117     /** selects item for cboGoToLine
118      * @param item String item
119      */

120     public void selectGoToLine(String JavaDoc item) {
121         cboGoToLine().selectItem(item);
122     }
123     
124     /** types text for cboGoToLine
125      * @param text String text
126      */

127     public void typeGoToLine(String JavaDoc text) {
128         cboGoToLine().typeText(text);
129     }
130     
131     /** clicks on "Goto" JButton
132      */

133     public void goTo() {
134         btGoto().push();
135     }
136     
137     /** clicks on "Close" JButton
138      */

139     public void close() {
140         btClose().push();
141     }
142     
143     /** clicks on "Help" JButton
144      */

145     public void help() {
146         btHelp().push();
147     }
148     
149     
150     //*****************************************
151
// High-level functionality definition part
152
//*****************************************
153

154     /** Performs verification of GoToLine by accessing all its components.
155      */

156     public void verify() {
157         lblGoToLine();
158         cboGoToLine();
159         btGoto();
160         btClose();
161         btHelp();
162     }
163     
164     public static void goToLine(int line) {
165         GoToLine op=new GoToLine();
166         op.typeGoToLine(String.valueOf(line));
167         op.goTo();
168         while (op.isVisible()) {
169             op.goTo();
170         }
171     }
172     
173     public static void goToLine(int line,Robot JavaDoc robot) {
174         GoToLine op=new GoToLine();
175         java.awt.Point JavaDoc p;
176         int x,y;
177         
178         String JavaDoc s=String.valueOf(line);
179         int c;
180         robot.waitForIdle();
181         robot.delay(200);
182         for (int i=0;i < s.length();i++) {
183             c=(int)s.charAt(i);
184             robot.keyPress(c);
185             robot.delay(50);
186             robot.keyRelease(c);
187         }
188         p=op.btGoto().getLocationOnScreen();
189         x=p.x+op.btGoto().getWidth()/2;
190         y=p.y+op.btGoto().getHeight()/2;
191         robot.mouseMove(x,y);
192         robot.mousePress(InputEvent.BUTTON1_MASK);
193         robot.delay(50);
194         robot.mouseRelease(InputEvent.BUTTON1_MASK);
195         robot.delay(50);
196         robot.waitForIdle();
197         while (op.isVisible()) {
198             robot.delay(50);
199         }
200     }
201     
202     /** Performs simple test of GoToLine
203      * @param args the command line arguments
204      */

205     public static void main(String JavaDoc args[]) {
206         //new GoToLine().verify();
207
System.out.println("GoToLine verification finished.");
208         char c='0';
209         System.out.println("Char c="+Integer.toHexString((int)c));
210     }
211 }
212
213
Popular Tags