alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package gui.action;

import java.awt.event.KeyEvent;
import java.awt.Component;
import java.awt.Point;
import javax.swing.text.Caret;

import org.netbeans.editor.BaseCaret;
//import org.netbeans.modules.java.settings.JavaSettings;
import org.netbeans.modules.editor.java.JavaKit;
import org.netbeans.modules.editor.options.BaseOptions;
import org.netbeans.modules.editor.options.JavaOptions;

import org.netbeans.jellytools.MainWindowOperator;
import org.netbeans.jellytools.EditorOperator;
import org.netbeans.jellytools.EditorWindowOperator;
import org.netbeans.jellytools.ProjectsTabOperator;
import org.netbeans.jellytools.nodes.Node;
import org.netbeans.jellytools.actions.ActionNoBlock;
import org.netbeans.jellytools.actions.Action.Shortcut;
import org.netbeans.jellytools.actions.OpenAction;

import org.netbeans.jemmy.operators.ComponentOperator;
import org.netbeans.jemmy.ComponentChooser;
import org.netbeans.modules.web.core.syntax.JSPKit;
import org.netbeans.modules.web.core.syntax.JSPOptions;

/**
 * Test of typing in opened source editor.
 *
 * @author  anebuzelsky@netbeans.org
 */
public class TypingInJspEditor extends testUtilities.PerformanceTestCase {
    
    private String file;
    private int line;
    
    /** Creates a new instance of TypingInEditor */
    public TypingInJspEditor(String file, int line, String testName) {
        super(testName);
        expectedTime = UI_RESPONSE;
        this.file = file;
        this.line = line;
        /*
        expectedTime = 10;
        WAIT_AFTER_OPEN = 0;
        WAIT_AFTER_PREPARE = 0;
        WAIT_AFTER_CLOSE = 0;
        repeat = 100;
        */
    }
    
    /** Creates a new instance of TypingInEditor */
    public TypingInJspEditor(String file, int line, String testName, String performanceDataName) {
        super(testName, performanceDataName);
        expectedTime = UI_RESPONSE;
        this.file = file;
        this.line = line;
        /*
        expectedTime = 10;
        repeat = 100;
        WAIT_AFTER_OPEN = 0;
        WAIT_AFTER_PREPARE = 0;
        WAIT_AFTER_CLOSE = 0;
        */
    }
    
    private EditorOperator editorOperator;
    private int fontSize;
    private int parsingErrors;
    
    protected void turnOff() {
        // set large font size
        
        Class kitClass = JSPKit.class;
        BaseOptions options = BaseOptions.getOptions (kitClass);
        if (options instanceof JSPOptions) {
            fontSize = ((JSPOptions)options).getFontSize();
            ((JSPOptions)options).setFontSize(20);
        }
        // turn off the error hightlighting feature
        //parsingErrors = JavaSettings.getDefault().getParsingErrors();
        //JavaSettings.getDefault().setParsingErrors(0);        
    }
    
    protected void turnBack() {
        // set back the original font size
        Class kitClass = JSPKit.class;
        BaseOptions options = BaseOptions.getOptions (kitClass);
        if (options instanceof JSPOptions) {
            ((JSPOptions)options).setFontSize(fontSize);
        }
        // set the modified properties back to default
        //JavaSettings.getDefault().setParsingErrors(parsingErrors);        
    }
    
    protected void initialize() {
        /*
        javax.swing.text.Caret thecaret = editorOperator.txtEditorPane().getCaret();
        if (thecaret instanceof BaseCaret)
        {
            BaseCaret thebasecaret = (BaseCaret) thecaret;
            setAreaToFilter (thebasecaret.x-20, thebasecaret.y-20, thebasecaret.width+40, thebasecaret.height+40);
        }
        */
        setPaintFilteringForEditor();
        setJSPEditorCaretFilteringOn();

        // open a java file in the editor
        new OpenAction().performAPI(new Node(new ProjectsTabOperator().getProjectRootNode("TestWebProject"),"Web Pages|"+file));
        editorOperator = new EditorWindowOperator().getEditor(file);

        //wait painting pf folds in the editor
        waitNoEvent(5000);

        // go to the right place
        editorOperator.setCaretPositionToLine(line);
        // make the file modified
        //new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_ENTER)).perform(editorOperator);
        
        turnOff();
    }
    
    public void prepare() {
        // do nothing
   }
    
    public ComponentOperator open(){
        new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_A)).perform(editorOperator);
        return null;
    }
    
    public void close() {
        // do nothing
    }
    
    protected void shutdown() {
        turnBack();
        editorOperator.closeDiscard();
        super.shutdown();
    }

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.