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-2007 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 gui.action;
043:
044: import org.netbeans.performance.test.guitracker.ActionTracker;
045: import org.netbeans.performance.test.guitracker.LoggingRepaintManager.RegionFilter;
046:
047: import org.netbeans.modules.editor.java.JavaKit;
048: import org.netbeans.modules.editor.options.BaseOptions;
049: import org.netbeans.modules.java.editor.options.JavaOptions;
050:
051: import org.netbeans.jellytools.EditorOperator;
052: import org.netbeans.jellytools.EditorWindowOperator;
053: import org.netbeans.jellytools.nodes.Node;
054: import org.netbeans.jellytools.actions.OpenAction;
055: import org.netbeans.jellytools.modules.editor.CompletionJListOperator;
056: import org.netbeans.jellytools.nodes.SourcePackagesNode;
057:
058: import org.netbeans.jemmy.operators.ComponentOperator;
059:
060: /**
061: * Test of java completion in opened source editor.
062: *
063: * @author anebuzelsky@netbeans.org, mmirilovic@netbeans.org
064: */
065: public class JavaCompletionInEditor extends
066: org.netbeans.performance.test.utilities.PerformanceTestCase {
067:
068: private static final int lineNumber = 39;
069: private static final String ccText = " System";
070:
071: private EditorOperator editorOperator;
072: private int completionAutoPopupDelay, caretBlinkRate;
073: private boolean javaDocAutoPopup;
074:
075: /** Creates a new instance of JavaCompletionInEditor */
076: public JavaCompletionInEditor(String testName) {
077: super (testName);
078: expectedTime = WINDOW_OPEN;
079: }
080:
081: /** Creates a new instance of JavaCompletionInEditor */
082: public JavaCompletionInEditor(String testName,
083: String performanceDataName) {
084: super (testName, performanceDataName);
085: expectedTime = WINDOW_OPEN;
086: }
087:
088: public void initialize() {
089: // prepare editor/completion for measuring
090: setCompletionForMeasuringOn();
091:
092: // open a java file in the editor
093: new OpenAction().performAPI(new Node(new SourcePackagesNode(
094: "PerformanceTestData"),
095: "org.netbeans.test.performance|Main.java"));
096: editorOperator = EditorWindowOperator.getEditor("Main.java");
097:
098: // scroll to the place where we start
099: editorOperator.setCaretPositionToLine(lineNumber);
100:
101: // insert the initial text
102: editorOperator.insert(ccText);
103:
104: // track component show (no paints from Code Completion)
105: MY_END_EVENT = ActionTracker.TRACK_COMPONENT_SHOW;
106: }
107:
108: public void prepare() {
109: // scroll to the place where we start
110: EditorWindowOperator.getEditor("Main.java");
111: editorOperator.setCaretPositionToEndOfLine(lineNumber);
112:
113: // wait
114: waitNoEvent(1000);
115: }
116:
117: public ComponentOperator open() {
118: // invoke the completion dialog
119: editorOperator.typeKey('.');
120:
121: // wait for the completion window
122: return new CompletionJListOperator();
123: }
124:
125: public void close() {
126: super .close();
127: editorOperator.setCaretPositionRelative(-1);
128: editorOperator.delete(1);
129: }
130:
131: public void shutdown() {
132: // set default values after measuring
133: setCompletionForMeasuringOff();
134:
135: editorOperator.closeDiscard();
136: super .shutdown();
137: }
138:
139: private void setCompletionForMeasuringOn() {
140: // measure only paint events from QuietEditorPane
141: repaintManager().addRegionFilter(COMPLETION_FILTER);
142:
143: // set large font size for Editor
144: BaseOptions options = BaseOptions.getOptions(JavaKit.class);
145: if (options instanceof JavaOptions) {
146: completionAutoPopupDelay = ((JavaOptions) options)
147: .getCompletionAutoPopupDelay();
148: ((JavaOptions) options).setCompletionAutoPopupDelay(0);
149: javaDocAutoPopup = ((JavaOptions) options)
150: .getJavaDocAutoPopup();
151: ((JavaOptions) options).setJavaDocAutoPopup(false);
152: }
153:
154: caretBlinkRate = options.getCaretBlinkRate();
155: //disable caret blinkering
156: options.setCaretBlinkRate(0);
157:
158: // turn off the error hightlighting feature
159: /* TODO doesn't work after retouche integration
160: parsingErrors = JavaSettings.getDefault().getParsingErrors();
161: JavaSettings.getDefault().setParsingErrors(0);
162: */
163: }
164:
165: private void setCompletionForMeasuringOff() {
166: // reset filter
167: repaintManager().resetRegionFilters();
168:
169: // set back the original font size for Editor
170: Class kitClass = JavaKit.class;
171: BaseOptions options = BaseOptions.getOptions(kitClass);
172: if (options instanceof JavaOptions) {
173: ((JavaOptions) options)
174: .setCompletionAutoPopupDelay(completionAutoPopupDelay);
175: ((JavaOptions) options)
176: .setJavaDocAutoPopup(javaDocAutoPopup);
177: }
178:
179: // set back the original blink rate
180: options.setCaretBlinkRate(caretBlinkRate);
181:
182: /* doesn't work after retouche integration
183: JavaSettings.getDefault().setParsingErrors(parsingErrors);
184: */
185: }
186:
187: private static final RegionFilter COMPLETION_FILTER = new RegionFilter() {
188:
189: public boolean accept(javax.swing.JComponent c) {
190: return c
191: .getClass()
192: .getName()
193: .equals(
194: "org.netbeans.modules.editor.completion.CompletionScrollPane")
195: || c.getClass().getName().equals(
196: "org.openide.text.QuietEditorPane");
197: }
198:
199: public String getFilterName() {
200: return "Accept paints from org.netbeans.modules.editor.completion.CompletionScrollPane || org.openide.text.QuietEditorPane";
201: }
202: };
203:
204: public static void main(java.lang.String[] args) {
205: repeat = 3;
206: junit.textui.TestRunner.run(new JavaCompletionInEditor(
207: "measureTime"));
208: }
209:
210: }
|