Source Code Cross Referenced for JavaEditActionsTest.java in  » IDE-Netbeans » java » java_editor_actions » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » java » java_editor_actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package java_editor_actions;
043:
044:        import java.awt.datatransfer.Transferable;
045:        import java.awt.event.KeyEvent;
046:        import java.io.File;
047:        import java.io.FileOutputStream;
048:        import java.io.IOException;
049:        import java.io.OutputStream;
050:        import java.io.PrintStream;
051:        import java.util.Hashtable;
052:        import javax.swing.text.BadLocationException;
053:        import javax.swing.text.Document;
054:        import javax.swing.text.JTextComponent;
055:        import org.netbeans.jellytools.EditorOperator;
056:        import org.netbeans.jemmy.operators.JEditorPaneOperator;
057:        import editor_actions.EditorActionsTest;
058:        import junit.textui.TestRunner;
059:        import org.netbeans.jemmy.EventTool;
060:
061:        /**
062:         * Basic Edit Actions Test class.
063:         * The base edit actions can be found at:
064:         * http://editor.netbeans.org/doc/UserView/apdx_a_eshortcuts.html
065:         *
066:         * Test covers following actions:
067:         *
068:         *
069:         * @author Martin Roskanin, Jiri Prox
070:         */
071:        public class JavaEditActionsTest extends JavaEditorActionsTest {
072:
073:            /** Creates a new instance of Main */
074:            public JavaEditActionsTest(String testMethodName) {
075:                super (testMethodName);
076:            }
077:
078:            public void testEditActions() {
079:                resetCounter();
080:                openDefaultProject();
081:                openDefaultSampleFile();
082:                try {
083:
084:                    EditorOperator editor = getDefaultSampleEditorOperator();
085:                    editor.requestFocus();
086:                    JEditorPaneOperator txtOper = editor.txtEditorPane();
087:
088:                    // 00 ---------------------- test insert action -----------------
089:                    // 1. move to adequate place
090:                    editor.setCaretPosition(5, 17);
091:                    // 2. set insert Mode ON
092:                    txtOper.pushKey(KeyEvent.VK_INSERT);
093:                    // 3. type d
094:                    txtOper.typeKey('d');
095:                    // 4. set insert Mode OFF
096:                    txtOper.pushKey(KeyEvent.VK_INSERT);
097:                    // 5. type x
098:                    txtOper.typeKey('x');
099:                    // previous word ins|ert, with caret at | should be modified to
100:                    // insdxrt
101:                    // Compare document content to golden file
102:                    compareToGoldenFile(txtOper.getDocument());
103:                    //------------------------------------------------------------
104:                    // 01 -------- test delete word action. Caret in the middle of the word ---
105:                    // remove-word action has been removed. Changing test to delete selected word
106:                    editor.setCaretPosition(17, 20);
107:                    txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK
108:                            | KeyEvent.SHIFT_DOWN_MASK);
109:                    txtOper.pushKey(KeyEvent.VK_DELETE);
110:                    compareToGoldenFile(txtOper.getDocument());
111:
112:                    // 02 -------- test delete previous word action. Caret after the word ------
113:                    //  delete word - Caret after the word was removed
114:                    txtOper.pushKey(KeyEvent.VK_BACK_SPACE,
115:                            KeyEvent.CTRL_DOWN_MASK);
116:                    compareToGoldenFile(txtOper.getDocument());
117:
118:                    // 03 --------- test remove the current line --------------------
119:                    txtOper.pushKey(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK);
120:                    compareToGoldenFile(txtOper.getDocument());
121:
122:                    // 04 -- test Select the word the insertion point is on or
123:                    // -- deselect any selected text (Alt + j)
124:                    // -- after that test CUT action ---------------
125:                    editor.setCaretPosition(9, 24);
126:                    txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK
127:                            | KeyEvent.SHIFT_DOWN_MASK);
128:                    cutCopyViaStrokes(txtOper, KeyEvent.VK_X,
129:                            KeyEvent.CTRL_DOWN_MASK);
130:                    compareToGoldenFile(txtOper.getDocument());
131:
132:                    // 05 -- test PASTE ------
133:                    editor.setCaretPosition(11, 17);
134:                    txtOper.pushKey(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK);
135:                    compareToGoldenFile(txtOper.getDocument());
136:
137:                    // 06 -- test UNDO/REDO ----
138:                    int oldDocLenhth = txtOper.getDocument().getLength();
139:                    txtOper.pushKey(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK);
140:                    waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_UNDO_REDO,
141:                            getFileLengthChangeResolver(txtOper, oldDocLenhth),
142:                            Boolean.FALSE);
143:                    oldDocLenhth = txtOper.getDocument().getLength();
144:                    txtOper.pushKey(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK);
145:                    waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_UNDO_REDO,
146:                            getFileLengthChangeResolver(txtOper, oldDocLenhth),
147:                            Boolean.FALSE);
148:                    oldDocLenhth = txtOper.getDocument().getLength();
149:                    txtOper.pushKey(KeyEvent.VK_Y, KeyEvent.CTRL_DOWN_MASK);
150:                    waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_UNDO_REDO,
151:                            getFileLengthChangeResolver(txtOper, oldDocLenhth),
152:                            Boolean.FALSE);
153:                    compareToGoldenFile(txtOper.getDocument());
154:
155:                    // 07 -- test CTRL+backspace -- delete previous word
156:                    txtOper.pushKey(KeyEvent.VK_BACK_SPACE,
157:                            KeyEvent.CTRL_DOWN_MASK);
158:                    txtOper.pushKey(KeyEvent.VK_BACK_SPACE,
159:                            KeyEvent.CTRL_DOWN_MASK);
160:                    txtOper.pushKey(KeyEvent.VK_BACK_SPACE,
161:                            KeyEvent.CTRL_DOWN_MASK);
162:                    compareToGoldenFile(txtOper.getDocument());
163:
164:                    // 08 -- test CTRL+u -- delete the indentation level
165:                    txtOper.pushKey(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK);
166:                    compareToGoldenFile(txtOper.getDocument());
167:
168:                    // 09 -- test CTRL+u -- delete the line break
169:                    txtOper.pushKey(KeyEvent.VK_BACK_SPACE);
170:                    txtOper.pushKey(KeyEvent.VK_BACK_SPACE);
171:                    txtOper.typeKey(' ');
172:                    compareToGoldenFile(txtOper.getDocument());
173:
174:                    // 10 -- test delete action
175:                    txtOper.pushKey(KeyEvent.VK_BACK_SPACE);
176:                    compareToGoldenFile(txtOper.getDocument());
177:
178:                    // 11 -- test delete selected block and selecting to end of the line
179:                    txtOper.pushKey(KeyEvent.VK_END, KeyEvent.SHIFT_DOWN_MASK);
180:                    txtOper.pushKey(KeyEvent.VK_DELETE);
181:                    compareToGoldenFile(txtOper.getDocument());
182:
183:                    // 12 -- test COPY action ---
184:                    editor.setCaretPosition(9, 15);
185:                    txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK
186:                            | KeyEvent.ALT_DOWN_MASK);
187:                    cutCopyViaStrokes(txtOper, KeyEvent.VK_C,
188:                            KeyEvent.CTRL_DOWN_MASK);
189:                    editor.setCaretPosition(10, 17);
190:                    txtOper.pushKey(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK);
191:                    compareToGoldenFile(txtOper.getDocument());
192:
193:                    // -- test Select All ---
194:                    txtOper.pushKey(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK);
195:                    if (txtOper.getSelectionStart() != 0
196:                            || txtOper.getSelectionEnd() != txtOper
197:                                    .getDocument().getLength()) {
198:                        fail("Select all action fails. [start/end of selection] [docLength]: ["
199:                                + txtOper.getSelectionStart()
200:                                + "/"
201:                                + txtOper.getSelectionEnd()
202:                                + "] ["
203:                                + txtOper.getDocument().getLength() + "]");
204:                    }
205:
206:                    // 13 -- test Shift+delete (CUT) and shift+insert (PASTE)---
207:                    editor.setCaretPosition(5, 17);
208:                    txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK
209:                            | KeyEvent.SHIFT_DOWN_MASK);
210:                    cutCopyViaStrokes(txtOper, KeyEvent.VK_DELETE,
211:                            KeyEvent.SHIFT_DOWN_MASK);
212:                    editor.setCaretPosition(13, 8);
213:                    txtOper.pushKey(KeyEvent.VK_INSERT,
214:                            KeyEvent.SHIFT_DOWN_MASK);
215:                    compareToGoldenFile(txtOper.getDocument());
216:
217:                    // 14 -- test ctrl+insert (COPY)---
218:                    editor.setCaretPosition(10, 20);
219:                    txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK
220:                            | KeyEvent.SHIFT_DOWN_MASK);
221:                    cutCopyViaStrokes(txtOper, KeyEvent.VK_INSERT,
222:                            KeyEvent.CTRL_DOWN_MASK);
223:                    editor.setCaretPosition(13, 15);
224:                    txtOper.pushKey(KeyEvent.VK_INSERT,
225:                            KeyEvent.SHIFT_DOWN_MASK);
226:                    compareToGoldenFile(txtOper.getDocument());
227:
228:                    // 15 -- test CTRL+K ----
229:                    editor.setCaretPosition(6, 21);
230:                    txtOper.pushKey(KeyEvent.VK_K, KeyEvent.CTRL_DOWN_MASK);
231:                    compareToGoldenFile(txtOper.getDocument());
232:
233:                    // 16 -- test CTRL+SHITF+K ----
234:                    editor.setCaretPosition(10, 20);
235:                    //type space to change String to Str ing
236:                    txtOper.typeKey(' ');
237:                    editor.setCaretPosition(10, 23);
238:                    txtOper.pushKey(KeyEvent.VK_K, KeyEvent.CTRL_DOWN_MASK
239:                            | KeyEvent.SHIFT_DOWN_MASK);
240:                    compareToGoldenFile(txtOper.getDocument());
241:
242:                    /// 17 -- test expanding abbreviation
243:                    editor.setCaretPosition(19, 12);
244:                    txtOper.typeKey('s');
245:                    txtOper.typeKey('t');
246:                    txtOper.pressKey(KeyEvent.VK_TAB);
247:                    compareToGoldenFile(txtOper.getDocument());
248:
249:                    // 18 -- test Insert space without expanding abbreviation (SPACE)
250:                    editor.setCaretPosition(20, 9);
251:                    txtOper.typeKey('s');
252:                    txtOper.typeKey('t');
253:                    txtOper.typeKey(' ');
254:                    compareToGoldenFile(txtOper.getDocument());
255:
256:                    /* __________________ Capitlization ___________________ */
257:
258:                    // 19 -- w/o selection upper case ------
259:                    editor.setCaretPosition(13, 18);
260:                    txtOper.pushKey(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK);
261:                    txtOper.pushKey(KeyEvent.VK_U);
262:                    compareToGoldenFile(txtOper.getDocument());
263:
264:                    // 20 -- selection upper case ------
265:                    txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK
266:                            | KeyEvent.SHIFT_DOWN_MASK);
267:                    txtOper.pushKey(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK);
268:                    txtOper.pushKey(KeyEvent.VK_U);
269:                    compareToGoldenFile(txtOper.getDocument());
270:
271:                    // 21 -- w/o selection lower case ------
272:                    editor.setCaretPosition(13, 18);
273:                    txtOper.pushKey(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK);
274:                    txtOper.pushKey(KeyEvent.VK_L);
275:                    compareToGoldenFile(txtOper.getDocument());
276:
277:                    // 22 -- selection lower case ------
278:                    txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK
279:                            | KeyEvent.SHIFT_DOWN_MASK);
280:                    txtOper.pushKey(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK);
281:                    txtOper.pushKey(KeyEvent.VK_L);
282:                    compareToGoldenFile(txtOper.getDocument());
283:
284:                    // 23 -- w/o selection reverse case ------
285:                    editor.setCaretPosition(13, 18);
286:                    txtOper.pushKey(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK);
287:                    txtOper.pushKey(KeyEvent.VK_S);
288:                    compareToGoldenFile(txtOper.getDocument());
289:
290:                    // 24 -- selection reverse case ------
291:                    txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK
292:                            | KeyEvent.SHIFT_DOWN_MASK);
293:                    txtOper.pushKey(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK);
294:                    txtOper.pushKey(KeyEvent.VK_S);
295:                    compareToGoldenFile(txtOper.getDocument());
296:
297:                    /* __________________ Several Indentation Actions ___________________ */
298:
299:                    // 25 -- Shift left  ------
300:                    editor.setCaretPosition(10, 9);
301:                    txtOper.pushKey(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK);
302:                    compareToGoldenFile(txtOper.getDocument());
303:
304:                    // 26 -- insert tab  ------
305:                    txtOper.pushKey(KeyEvent.VK_TAB);
306:                    compareToGoldenFile(txtOper.getDocument());
307:
308:                    // 27 -- Shift selection left  ------
309:                    editor.setCaretPosition(9, 1);
310:                    //select method
311:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
312:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
313:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
314:                    // shift left
315:                    txtOper.pushKey(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK);
316:                    compareToGoldenFile(txtOper.getDocument());
317:
318:                    // 28 -- Shift  selection right  ------
319:                    txtOper.pushKey(KeyEvent.VK_TAB);
320:                    compareToGoldenFile(txtOper.getDocument());
321:
322:                    // 29 -- Shift selection left (Alt+Shift+left) ------
323:                    editor.setCaretPosition(9, 1);
324:                    //select method
325:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
326:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
327:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
328:                    // shift left
329:                    txtOper.pushKey(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK
330:                            | KeyEvent.SHIFT_DOWN_MASK);
331:                    compareToGoldenFile(txtOper.getDocument());
332:
333:                    // 30 -- Shift  selection right (Alt+Shift+Right) ------
334:                    txtOper.pushKey(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK
335:                            | KeyEvent.SHIFT_DOWN_MASK);
336:                    compareToGoldenFile(txtOper.getDocument());
337:
338:                    //31 -- reformat the selection + testing BACK_SPACE----
339:                    //delete syntax error - otherwise reformat will not work
340:                    editor.setCaretPosition(20, 1);
341:                    txtOper.pushKey(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK);
342:                    //make a mess
343:                    editor.setCaretPosition(6, 5);
344:                    txtOper.typeKey(' ');
345:                    editor.setCaretPosition(9, 5);
346:                    txtOper.pushKey(KeyEvent.VK_BACK_SPACE);
347:                    editor.setCaretPosition(9, 1);
348:                    //select method
349:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
350:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
351:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
352:                    txtOper.pushKey(KeyEvent.VK_F, KeyEvent.SHIFT_DOWN_MASK
353:                            | KeyEvent.ALT_DOWN_MASK);
354:                    compareToGoldenFile(txtOper.getDocument());
355:
356:                    //32 -- reformat the entire file ----
357:                    // deselect
358:                    txtOper.setSelectionStart(1);
359:                    txtOper.setSelectionEnd(1);
360:                    // invoke formatter
361:                    txtOper.pushKey(KeyEvent.VK_F, KeyEvent.SHIFT_DOWN_MASK
362:                            | KeyEvent.ALT_DOWN_MASK);
363:                    compareToGoldenFile(txtOper.getDocument());
364:
365:                    /* __________________ Extension Actions ___________________ */
366:                    //
367:                    //            //33 -- Prefix the identifier with get ------
368:                    //            editor.setCaretPosition(19,32);
369:                    //            txtOper.pushKey(KeyEvent.VK_ENTER);
370:                    //            new EventTool().waitNoEvent(2000);
371:                    //            txtOper.pushKey(KeyEvent.VK_S);
372:                    //            new EventTool().waitNoEvent(2000);
373:                    //            txtOper.pushKey(KeyEvent.VK_T);
374:                    //            new EventTool().waitNoEvent(2000);
375:                    //            editor.setCaretPosition(20, 10);
376:                    //            new EventTool().waitNoEvent(2000);
377:                    //            txtOper.pushKey(KeyEvent.VK_U, KeyEvent.ALT_DOWN_MASK);
378:                    //            txtOper.pushKey(KeyEvent.VK_G);
379:                    //            compareToGoldenFile(txtOper.getDocument());
380:                    //
381:                    //            //34 -- Prefix the identifier with set ------
382:                    //            txtOper.pushKey(KeyEvent.VK_U, KeyEvent.ALT_DOWN_MASK);
383:                    //            txtOper.pushKey(KeyEvent.VK_S);
384:                    //            compareToGoldenFile(txtOper.getDocument());
385:                    //
386:                    //            //35 -- Prefix the identifier with is ------
387:                    //            txtOper.pushKey(KeyEvent.VK_U, KeyEvent.ALT_DOWN_MASK);
388:                    //            txtOper.pushKey(KeyEvent.VK_I);
389:                    //            compareToGoldenFile(txtOper.getDocument());
390:                    //
391:                    //            //36 -- Comment out the current line ------
392:                    //            txtOper.pushKey(KeyEvent.VK_T, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
393:                    //            compareToGoldenFile(txtOper.getDocument());
394:                    //
395:                    //            //37 -- Remove comment from the current line ------
396:                    //            txtOper.pushKey(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
397:                    //            compareToGoldenFile(txtOper.getDocument());
398:                    //
399:                    //            //38 -- Comment out the selected lines of code. ------
400:                    //            editor.setCaretPosition(19, 1);
401:                    //            //select method
402:                    //            txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
403:                    //            txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
404:                    //            txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
405:                    //            txtOper.pushKey(KeyEvent.VK_T, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
406:                    //            compareToGoldenFile(txtOper.getDocument());
407:                    //
408:                    //            //39 -- Remove comment from the selected lines. ------
409:                    //            txtOper.pushKey(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
410:                    //            compareToGoldenFile(txtOper.getDocument());
411:                    //
412:                    //            // 40 -- Paste Formatted action ----------
413:                    //            //make a mess
414:                    //            editor.setCaretPosition(6, 1);
415:                    //            txtOper.typeKey(' ');
416:                    //            editor.setCaretPosition(7, 1);
417:                    //            txtOper.pushKey(KeyEvent.VK_DELETE);
418:                    //            editor.setCaretPosition(6, 1);
419:                    //            //select method
420:                    //            txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
421:                    //            txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
422:                    //            //copy
423:                    //            cutCopyViaStrokes(txtOper, KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK);
424:                    //            editor.setCaretPosition(12, 1);
425:                    //            //paste formatted
426:                    //            txtOper.pushKey(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
427:                    //            compareToGoldenFile(txtOper.getDocument());
428:                    //
429:                    //            // 41 -- Split a line  (CTRL-ENTER)---
430:                    //            editor.setCaretPosition(15, 21);
431:                    //            txtOper.pushKey(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK);
432:                    //            txtOper.typeKey('x');
433:                    //            compareToGoldenFile(txtOper.getDocument());
434:                    //
435:                    //            // 42 -- Start a new line (SHIFT-ENTER) ---
436:                    //            editor.setCaretPosition(15, 15);
437:                    //            txtOper.pushKey(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK);
438:                    //            txtOper.typeKey('x');
439:                    //            compareToGoldenFile(txtOper.getDocument());
440:                    //
441:                    //            //------------- newly added action --------------
442:                    //
443:                    //            //43  -- remove previous word, caret at the middle of the word
444:                    //            editor.setCaretPosition(23, 15);
445:                    //            txtOper.pushKey(KeyEvent.VK_BACK_SPACE, KeyEvent.CTRL_DOWN_MASK);
446:                    //            compareToGoldenFile(txtOper.getDocument());
447:                    //
448:                    //            //44  -- remove next word, caret at the middle of the word
449:                    //            editor.setCaretPosition(23, 7);
450:                    //            txtOper.pushKey(KeyEvent.VK_DELETE, KeyEvent.CTRL_DOWN_MASK);
451:                    //            compareToGoldenFile(txtOper.getDocument());
452:                    //
453:                    //            //45  -- remove previous word, caret after the word
454:                    //            editor.setCaretPosition(5, 14);
455:                    //            txtOper.pushKey(KeyEvent.VK_BACK_SPACE, KeyEvent.CTRL_DOWN_MASK);
456:                    //            compareToGoldenFile(txtOper.getDocument());
457:                    //
458:                    //            //46  -- remove next word, caret before the word
459:                    //            editor.setCaretPosition(5, 10);
460:                    //            txtOper.pushKey(KeyEvent.VK_DELETE, KeyEvent.CTRL_DOWN_MASK);
461:                    //            compareToGoldenFile(txtOper.getDocument());
462:                    //
463:                    //            //47  -- remove previous word, caret at the middle of the first word in document
464:                    //            // #51866
465:                    //            editor.setCaretPosition(1, 5);
466:                    //            txtOper.pushKey(KeyEvent.VK_BACK_SPACE, KeyEvent.CTRL_DOWN_MASK);
467:                    //            compareToGoldenFile(txtOper.getDocument());
468:                    //
469:                    //            //48  -- remove next word, caret at the middle of the last word in document
470:                    //            // #51866
471:                    //            editor.setCaretPosition(3, 4);
472:                    //            txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK);
473:                    //            cutCopyViaStrokes(txtOper, KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK);
474:                    //            txtOper.pushKey(KeyEvent.VK_END, KeyEvent.CTRL_DOWN_MASK);
475:                    //            txtOper.pushKey(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK);
476:                    //            txtOper.pushKey(KeyEvent.VK_LEFT, 0);
477:                    //            txtOper.pushKey(KeyEvent.VK_LEFT, 0);
478:                    //            txtOper.pushKey(KeyEvent.VK_LEFT, 0);
479:                    //            txtOper.pushKey(KeyEvent.VK_DELETE, KeyEvent.CTRL_DOWN_MASK);
480:                    //            compareToGoldenFile(txtOper.getDocument());
481:                } finally {
482:                    closeFileWithDiscard();
483:                }
484:            }
485:
486:            public void testLineTools() {
487:                resetCounter();
488:                openDefaultProject();
489:                openDefaultSampleFile();
490:                try {
491:
492:                    EditorOperator editor = getDefaultSampleEditorOperator();
493:                    editor.requestFocus();
494:                    JEditorPaneOperator txtOper = editor.txtEditorPane();
495:                    editor.setCaretPosition(7, 25);
496:                    // 00
497:                    txtOper.pushKey(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK
498:                            | KeyEvent.SHIFT_DOWN_MASK);
499:                    compareToGoldenFile(txtOper.getDocument());
500:                    //01
501:                    txtOper.pushKey(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK
502:                            | KeyEvent.SHIFT_DOWN_MASK);
503:                    compareToGoldenFile(txtOper.getDocument());
504:                    //02
505:                    txtOper.pushKey(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK
506:                            | KeyEvent.SHIFT_DOWN_MASK);
507:                    compareToGoldenFile(txtOper.getDocument());
508:                    //03
509:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK
510:                            | KeyEvent.SHIFT_DOWN_MASK);
511:                    compareToGoldenFile(txtOper.getDocument());
512:
513:                    //04 - the same with block
514:                    editor.setCaretPosition(7, 25);
515:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
516:
517:                    txtOper.pushKey(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK
518:                            | KeyEvent.SHIFT_DOWN_MASK);
519:                    compareToGoldenFile(txtOper.getDocument());
520:                    //05
521:                    txtOper.pushKey(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK
522:                            | KeyEvent.SHIFT_DOWN_MASK);
523:                    compareToGoldenFile(txtOper.getDocument());
524:                    //06
525:                    txtOper.pushKey(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK
526:                            | KeyEvent.SHIFT_DOWN_MASK);
527:                    compareToGoldenFile(txtOper.getDocument());
528:                    //07
529:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK
530:                            | KeyEvent.SHIFT_DOWN_MASK);
531:                    compareToGoldenFile(txtOper.getDocument());
532:
533:                    //copy lines
534:                    editor.setCaretPosition(7, 25);
535:
536:                    //08
537:                    txtOper.pushKey(KeyEvent.VK_UP, KeyEvent.CTRL_DOWN_MASK
538:                            | KeyEvent.SHIFT_DOWN_MASK);
539:                    compareToGoldenFile(txtOper.getDocument());
540:
541:                    //09
542:                    txtOper.pushKey(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK);
543:                    editor.setCaretPosition(7, 25);
544:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.CTRL_DOWN_MASK
545:                            | KeyEvent.SHIFT_DOWN_MASK);
546:                    compareToGoldenFile(txtOper.getDocument());
547:
548:                    //10
549:                    txtOper.pushKey(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK);
550:                    editor.setCaretPosition(7, 25);
551:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
552:                    txtOper.pushKey(KeyEvent.VK_UP, KeyEvent.CTRL_DOWN_MASK
553:                            | KeyEvent.SHIFT_DOWN_MASK);
554:                    compareToGoldenFile(txtOper.getDocument());
555:
556:                    //11
557:                    txtOper.pushKey(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK);
558:                    editor.setCaretPosition(7, 25);
559:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
560:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.CTRL_DOWN_MASK
561:                            | KeyEvent.SHIFT_DOWN_MASK);
562:                    compareToGoldenFile(txtOper.getDocument());
563:
564:                } finally {
565:                    closeFileWithDiscard();
566:                }
567:            }
568:
569:            public void testSyntaxSelection() {
570:                resetCounter();
571:                openDefaultProject();
572:                openDefaultSampleFile();
573:                int[] begins = { 584, 573, 569, 552, 530, 471, 453, 441, 404,
574:                        383, 349, 310, 176 };
575:                int[] ends = { 590, 591, 593, 594, 612, 612, 626, 626, 637,
576:                        637, 643, 645, 645 };
577:                try {
578:                    EditorOperator editor = getDefaultSampleEditorOperator();
579:                    editor.requestFocus();
580:                    JEditorPaneOperator txtOper = editor.txtEditorPane();
581:                    editor.setCaretPosition(27, 56);
582:                    int x = 0;
583:                    while (x < begins.length) {
584:                        txtOper.pushKey(KeyEvent.VK_PERIOD,
585:                                KeyEvent.ALT_DOWN_MASK
586:                                        | KeyEvent.SHIFT_DOWN_MASK);
587:                        int start = txtOper.getSelectionStart();
588:                        int end = txtOper.getSelectionEnd();
589:                        if (start != begins[x] || end != ends[x])
590:                            fail("Wrong selection expected <" + begins[x] + ","
591:                                    + ends[x] + "> but got <" + start + ","
592:                                    + end + ">");
593:                        x++;
594:                    }
595:                    x--;
596:                    while (x > 0) {
597:                        x--;
598:                        txtOper.pushKey(KeyEvent.VK_COMMA,
599:                                KeyEvent.ALT_DOWN_MASK
600:                                        | KeyEvent.SHIFT_DOWN_MASK);
601:                        int start = txtOper.getSelectionStart();
602:                        int end = txtOper.getSelectionEnd();
603:                        if (start != begins[x] || end != ends[x])
604:                            fail("Wrong selection expected <" + begins[x] + ","
605:                                    + ends[x] + "> but got <" + start + ","
606:                                    + end + ">");
607:                    }
608:                } finally {
609:                    closeFileWithDiscard();
610:                }
611:            }
612:
613:            public void testCommentUncomment() {
614:                resetCounter();
615:                openDefaultProject();
616:                openDefaultSampleFile();
617:                try {
618:                    EditorOperator editor = getDefaultSampleEditorOperator();
619:                    editor.requestFocus();
620:                    JEditorPaneOperator txtOper = editor.txtEditorPane();
621:                    //00
622:                    editor.setCaretPosition(6, 1);
623:                    txtOper.pushKey(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK);
624:                    compareToGoldenFile(txtOper.getDocument());
625:
626:                    //01            
627:                    txtOper.pushKey(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK);
628:                    compareToGoldenFile(txtOper.getDocument());
629:
630:                    //02
631:                    editor.setCaretPosition(10, 1);
632:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
633:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
634:                    txtOper.pushKey(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK);
635:                    compareToGoldenFile(txtOper.getDocument());
636:
637:                    //03
638:                    txtOper.pushKey(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK);
639:                    compareToGoldenFile(txtOper.getDocument());
640:
641:                    //04
642:                    editor.setCaretPosition(15, 1);
643:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
644:                    txtOper.pushKey(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK);
645:                    txtOper.pushKey(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK);
646:                    compareToGoldenFile(txtOper.getDocument());
647:
648:                    //05
649:                    txtOper.pushKey(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK);
650:                    compareToGoldenFile(txtOper.getDocument());
651:
652:                    //06
653:                    editor.setCaretPosition(20, 1);
654:                    txtOper.pushKey(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK);
655:                    compareToGoldenFile(txtOper.getDocument());
656:
657:                    //07
658:                    txtOper.pushKey(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK);
659:                    compareToGoldenFile(txtOper.getDocument());
660:
661:                    //08
662:                    editor.setCaretPosition(21, 1);
663:                    txtOper.pushKey(KeyEvent.VK_SLASH, KeyEvent.CTRL_DOWN_MASK);
664:                    compareToGoldenFile(txtOper.getDocument());
665:
666:                    //09
667:                    editor.setCaretPosition(21, 1);
668:                    txtOper.pushKey(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK);
669:                    compareToGoldenFile(txtOper.getDocument());
670:
671:                } finally {
672:                    closeFileWithDiscard();
673:                }
674:            }
675:
676:            public static void main(String[] args) {
677:                TestRunner.run(JavaEditActionsTest.class);
678:            }
679:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.