Source Code Cross Referenced for EditorWindowOperator.java in  » IDE-Netbeans » jellytools » org » netbeans » jellytools » 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 » jellytools » org.netbeans.jellytools 
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:        package org.netbeans.jellytools;
042:
043:        import java.awt.Container;
044:        import java.util.Iterator;
045:        import org.netbeans.core.windows.ModeImpl;
046:        import org.netbeans.core.windows.WindowManagerImpl;
047:        import org.netbeans.jemmy.JemmyException;
048:        import org.netbeans.jemmy.QueueTool;
049:        import org.netbeans.jemmy.operators.ContainerOperator;
050:        import org.netbeans.jemmy.operators.JButtonOperator;
051:        import org.netbeans.jemmy.operators.JTableOperator;
052:        import org.openide.windows.TopComponent;
053:
054:        /**
055:         * Handle documents area of NetBeans IDE. It holds editor top components
056:         * which can be tested by {@link EditorOperator}. This operator only enables
057:         * to switch between editors and to manipulate control buttons.
058:         * <p>
059:         * Usage:<br>
060:         * <pre>
061:         EditorWindowOperator ewo = new EditorWindowOperator();
062:         String filename = "MyClass";
063:         EditorOperator eo1 = ewo.selectPage(filename);
064:         // gets currently selected editor
065:         EditorOperator eo2 = ewo.getEditor();
066:         // switches to requested editor and gets EditorOperator instance
067:         EditorOperator eo3 = ewo.getEditor(filename);
068:         // manipulate control buttons
069:         ewo.moveTabsLeft();
070:         ewo.moveTabsRight();
071:         ewo.jumpLeft();
072:         // selects document from the list
073:         ewo.selectDocument(filename);
074:         * </pre>
075:         * @author Jiri.Skrivanek@sun.com
076:         */
077:        public class EditorWindowOperator {
078:
079:            /** Components operators. */
080:            private static JButtonOperator _btLeft;
081:            private static JButtonOperator _btRight;
082:            private static JButtonOperator _btDown;
083:
084:            /** Creates new instance of EditorWindowOperator.
085:             * @deprecated Use static methods instead.
086:             */
087:            public EditorWindowOperator() {
088:                // useless now because all methods are static
089:            }
090:
091:            /** Returns operator of left arrow button in top right corner intended to 
092:             * move tabs to be visible left ones.
093:             * @return JButtonOperator instance
094:             */
095:            public static JButtonOperator btLeft() {
096:                if (_btLeft == null) {
097:                    _btLeft = new JButtonOperator(new ContainerOperator(
098:                            getEditor().findTabDisplayer()), 0);
099:                }
100:                return _btLeft;
101:            }
102:
103:            /** Returns operator of right arrow button in top right corner intended to 
104:             * move tabs to be visible right ones.
105:             * @return JButtonOperator instance
106:             */
107:            public static JButtonOperator btRight() {
108:                if (_btRight == null) {
109:                    _btRight = new JButtonOperator(new ContainerOperator(
110:                            getEditor().findTabDisplayer()), 1);
111:                }
112:                return _btRight;
113:            }
114:
115:            /** Returns operator of down arrow button in top right corner intended to 
116:             * show list of opened documents and selects a document in the list.
117:             * @return JButtonOperator instance
118:             */
119:            public static JButtonOperator btDown() {
120:                if (_btDown == null) {
121:                    _btDown = new JButtonOperator(new ContainerOperator(
122:                            getEditor().findTabDisplayer()), 2);
123:                }
124:                return _btDown;
125:            }
126:
127:            /** Close all opened documents and discard all changes.
128:             * It works also if no file is modified, so it is a safe way how to close
129:             * documents and no block further execution.
130:             */
131:            public static void closeDiscard() {
132:                Iterator iter = findEditorMode().getOpenedTopComponents()
133:                        .iterator();
134:                while (iter.hasNext()) {
135:                    EditorOperator.close((TopComponent) iter.next(), false);
136:                }
137:            }
138:
139:            /** Selects page by its label. If only one file is open in Editor, it does
140:             * nothing.
141:             * @param label label of page to switch to
142:             * @return instance of selected EditorOperator
143:             */
144:            public static EditorOperator selectPage(String label) {
145:                return new EditorOperator(label);
146:            }
147:
148:            /** Selects page by its index. If only one file is open in Editor, it does
149:             * nothing.
150:             * @param index index of page to be selected
151:             * @return instance of selected EditorOperator
152:             * @see EditorOperator
153:             */
154:            public static EditorOperator selectPage(int index) {
155:                try {
156:                    // finds and selects index-th editor
157:                    new TopComponentOperator((TopComponent) getEditor()
158:                            .findTabbedAdapter().getTopComponentAt(index));
159:                } catch (IndexOutOfBoundsException e) {
160:                    throw new JemmyException("Index " + index
161:                            + " out of bounds.", e); //NOI18N
162:                }
163:                return getEditor();
164:            }
165:
166:            /** Returns EditorOperator instance of currently selected document.
167:             * @return EditorOperator instance of the selected document
168:             * @see EditorOperator
169:             */
170:            public static EditorOperator getEditor() {
171:                final ModeImpl mode = findEditorMode();
172:                // run in dispatch thread
173:                String name = (String) new QueueTool()
174:                        .invokeSmoothly(new QueueTool.QueueAction(
175:                                "getSelectedTopComponent().getName()") { // NOI18N
176:                            public Object launch() {
177:                                return mode.getSelectedTopComponent().getName();
178:                            }
179:                        });
180:                return new EditorOperator(name);
181:            }
182:
183:            /** Selects page with given label and returns EditorOperator instance of
184:             * that page.
185:             * @param label label of page to be selected
186:             * @return EditorOperator instance of requested page
187:             * @see EditorOperator
188:             */
189:            public static EditorOperator getEditor(String label) {
190:                return selectPage(label);
191:            }
192:
193:            /** Selects page with given index and returns EditorOperator instance of
194:             * that page.
195:             * @param index index of page to be selected
196:             * @return EditorOperator instance of requested page
197:             * @see EditorOperator
198:             */
199:            public static EditorOperator getEditor(int index) {
200:                return selectPage(index);
201:            }
202:
203:            /********************** Control buttons ********************************/
204:
205:            /** If the leftmost visible tab is partially hidden, it clicks on it. 
206:             * Otherwise it does nothing.
207:             * @return true if tabs were moved, false otherwise
208:             */
209:            public boolean jumpLeft() {
210:                if (btLeft().isEnabled()) {
211:                    Container cont = getEditor().findTabDisplayer();
212:                    // click left corner
213:                    new ContainerOperator(cont).clickMouse(cont.getX() + 1,
214:                            cont.getY() + cont.getHeight() / 2, 1);
215:                    return true;
216:                }
217:                return false;
218:            }
219:
220:            /** Pushes rigth arrow control button in top right corner intended to 
221:             * move tabs to be visible right ones. If the button is not enabled, 
222:             * it does nothing.
223:             */
224:            public static void moveTabsRight() {
225:                btRight().push();
226:            }
227:
228:            /** Pushes left arrow control button in top right corner intended to 
229:             * move tabs to be visible left ones. If the button is not enabled, 
230:             * it does nothing.
231:             */
232:            public static void moveTabsLeft() {
233:                btLeft().push();
234:            }
235:
236:            /** Pushes down arrow control button in top right corner intended to 
237:             * show list of opened documents and selects index-th documents in the list.
238:             */
239:            public static void selectDocument(int index) {
240:                btDown().push();
241:                JTableOperator tableOper = new JTableOperator(
242:                        MainWindowOperator.getDefault());
243:                tableOper.selectCell(index, 0);
244:            }
245:
246:            /** Pushes down arrow control button in top right corner intended to 
247:             * show list of opened documents and selects document with given name
248:             * in the list.
249:             */
250:            public static void selectDocument(String name) {
251:                btDown().push();
252:                JTableOperator tableOper = new JTableOperator(
253:                        MainWindowOperator.getDefault());
254:                int row = tableOper.findCellRow(name);
255:                if (row > -1) {
256:                    tableOper.selectCell(row, 0);
257:                } else {
258:                    throw new JemmyException("Cannot select document \"" + name
259:                            + "\".");
260:                }
261:            }
262:
263:            /** Performs verification by accessing all sub-components */
264:            public static void verify() {
265:                getEditor().verify();
266:            }
267:
268:            /** Finds editor mode within IDE window system.
269:             * @return editor mode instance
270:             */
271:            private static ModeImpl findEditorMode() {
272:                // run in dispatch thread
273:                return (ModeImpl) new QueueTool()
274:                        .invokeSmoothly(new QueueTool.QueueAction("findMode") { // NOI18N
275:                            public Object launch() {
276:                                return WindowManagerImpl.getInstance()
277:                                        .findMode("editor"); //NOI18N
278:                            }
279:                        });
280:            }
281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.