package org.netbeans.jellytools.examples; import java.awt.event.KeyEvent; import java.io.File; import org.netbeans.jellytools.EditorOperator; import org.netbeans.jellytools.EditorWindowOperator; import org.netbeans.jellytools.JellyTestCase; import org.netbeans.jellytools.nodes.JavaNode; import org.netbeans.jellytools.nodes.FilesystemNode; import org.netbeans.jemmy.operators.JEditorPaneOperator; import org.netbeans.junit.NbTestSuite; //types main method into java file //requires that /sampledir/HelloWorld exists. public class TestEditor extends JellyTestCase { public TestEditor(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public static junit.framework.Test suite() { return new NbTestSuite(TestEditor.class); } public void testEditor() { //create a node for the sampledir directory FilesystemNode tmpNode = new FilesystemNode( System.getProperty("netbeans.user") + File.separator + "sampledir"); //create a node for the source JavaNode clNode = new JavaNode(tmpNode, "HelloWorld"); //open class for editing clNode.open(); //find editor window EditorWindowOperator editorWindow = new EditorWindowOperator("HelloWorld"); //find editor EditorOperator editor = editorWindow.selectPage("HelloWorld"); //get reference to editing component JEditorPaneOperator txtOper = editor.txtEditorPane(); //put caret at the beginning of "public class HelloWorld" line txtOper.setCaretPosition( txtOper.getPositionByText("public class HelloWorld")); //move caret 1 line down editor.setCaretPositionToLine(editor.getLineNumber() + 1); //push Enter txtOper.pushKey(KeyEvent.VK_ENTER); //push up arrow editor.pushUpArrowKey(); //pust Tab editor.pushTabKey(); //type first line txtOper.typeText("public static void main(String[] argv) {\n"); //type second line txtOper.typeText("System.out.println(\"Hello, world!\");\n"); //type third line // closing brace is generated automatically // txtOper.typeText("}\n"); } }