changeset 29:fe969660ac2e

Text sample SampleList
author Alexandre (Shura) Iline <alexandre.iline@sun.com>
date Fri, 15 Jun 2012 19:15:36 +0400
parents e424915d876f
children e37f6f5cb0cd
files tools/Jemmy/JemmyFX/samples/org/jemmy/samples/index.html tools/Jemmy/JemmyFX/samples/org/jemmy/samples/lookup/LookupApp.java tools/Jemmy/JemmyFX/samples/org/jemmy/samples/text/TextApp.java tools/Jemmy/JemmyFX/samples/org/jemmy/samples/text/TextSample.java
diffstat 4 files changed, 216 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/index.html	Fri Jun 15 19:15:36 2012 +0400
@@ -0,0 +1,27 @@
+<!--
+To change this template, choose Tools | Templates
+and open the template in the editor.
+-->
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>JemmyFX samples</title>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    </head>
+    <body>
+        <h2>Recommended order of samples</h2>
+        <table>
+            <tr><td><a href="lookup/LookupSample.java">lookup/LookupSample.java</a></td></tr>
+            <tr><td><a href="lookup/CompoundLookupSample.java">lookup/CompoundLookupSample.java</a></td></tr>
+            <tr><td><a href="lookup/CoorinateLookupSample.java">lookup/CoorinateLookupSample.java</a></td></tr>
+            <tr><td><a href="environment/EnvironmentSample.java">environment/EnvironmentSample.java</a></td></tr>
+            <tr><td><a href="environment/TimeoutsSample.java">environment/TimeoutsSample.java</a></td></tr>
+            <tr><td><a href="input/MouseClickSample.java">input/MouseClickSample.java</a></td></tr>
+            <tr><td><a href="input/KeyboardSample.java">input/KeyboardSample.java</a></td></tr>
+            <tr><td><a href="input/MouseMoveSample.java">input/MouseMoveSample.java</a></td></tr>
+            <tr><td><a href="input/MouseDNDSample.java">input/MouseDNDSample.java</a></td></tr>
+            <tr><td><a href="buttons/ButtonsSample.java">buttons/ButtonsSample.java</a></td></tr>
+            <tr><td><a href="text/TextSample.java">text/TextSample.java</a></td></tr>
+        </table>
+    </body>
+</html>
--- a/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/lookup/LookupApp.java	Thu Jun 14 23:58:26 2012 +0400
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/lookup/LookupApp.java	Fri Jun 15 19:15:36 2012 +0400
@@ -35,7 +35,7 @@
 import javafx.stage.Stage;
 
 /**
- * This small FX app is used in lookup JemmyFX demos. It displays a few labels
+ * This small FX app is used in lookup JemmyFX samples. It displays a few labels
  * with different text and, should the mouse be place over a label, displays the 
  * label's text at the bottom of the stage.
  * @author shura
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/text/TextApp.java	Fri Jun 15 19:15:36 2012 +0400
@@ -0,0 +1,55 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.jemmy.samples.text;
+
+import javafx.application.Application;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
+import javafx.scene.control.TextArea;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.VBox;
+import javafx.stage.Stage;
+
+/**
+ *
+ * @author shura
+ */
+public class TextApp extends Application {
+
+    TextField singleLine;
+    TextArea multiLine;
+        
+    @Override
+    public void start(Stage stage) throws Exception {
+        singleLine = new TextField();
+        singleLine.setId("single");
+        multiLine = new TextArea();
+        reset();
+        Button reset = new Button("Reset");
+        reset.setOnAction(new EventHandler<ActionEvent>() {
+
+            public void handle(ActionEvent t) {
+                reset();
+            }
+        });
+        VBox content = new VBox();
+        content.getChildren().addAll(singleLine, multiLine);
+        content.getChildren().add(reset);
+        stage.setScene(new Scene(content));
+        stage.show();
+    }
+    
+    private void reset() {
+        singleLine.setText("single line text");
+        multiLine.setText("multi\nline\ntext\n");
+    }
+    
+    public static void main(String[] args) {
+        launch();
+    }
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/text/TextSample.java	Fri Jun 15 19:15:36 2012 +0400
@@ -0,0 +1,133 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.jemmy.samples.text;
+
+import javafx.scene.control.TextArea;
+import javafx.scene.control.TextField;
+import org.jemmy.fx.AppExecutor;
+import org.jemmy.fx.SceneDock;
+import org.jemmy.fx.control.LabeledDock;
+import org.jemmy.fx.control.TextInputControlDock;
+import org.jemmy.resources.StringComparePolicy;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * How to access text controls with Jemmy
+ * 
+ * @author shura
+ */
+public class TextSample {
+
+    static SceneDock scene;
+    @BeforeClass
+    public static void launch() {
+        AppExecutor.executeNoBlock(TextApp.class);
+        scene = new SceneDock();
+    }
+    
+    @Before
+    public void reset() {
+        new LabeledDock(scene.asParent(), "Reset", StringComparePolicy.EXACT).mouse().click();
+    }
+    
+    /**
+     * How to find a text control.
+     */
+    @Test
+    public void lookup() {
+        //naturally, you could find it by it's text
+        TextInputControlDock multiLine = new TextInputControlDock(scene.asParent(), 
+                "multi", StringComparePolicy.SUBSTRING);
+        assertTrue(multiLine.wrap().getControl() instanceof TextArea);
+        
+        //text, however, could be unknown or even empty, so, you would want to consider
+        //one of the generic lookup approaches.
+        //such as by id
+        TextInputControlDock singleLine = new TextInputControlDock(scene.asParent(), 
+                "single");
+        assertTrue(singleLine.wrap().getControl() instanceof TextField);
+    }
+
+    /**
+     * How to navigate in a text control.
+     */
+    @Test
+    public void navigate() {
+        TextInputControlDock multiLine = new TextInputControlDock(scene.asParent(), 
+                "multi", StringComparePolicy.SUBSTRING);
+        
+        //of course you could move cursor to a position
+        multiLine.asSelectionText().caret().to(4);
+
+        //or to a portion of text
+        multiLine.asSelectionText().to("line");
+        
+        //or to an end of a portion of text
+        multiLine.asSelectionText().to("text", false);
+        
+        //or to an end of an index'th occurance os a portion of text
+        multiLine.asSelectionText().to("t", false, 1);
+        
+        //where a portion of text is really a regex
+        multiLine.asSelectionText().to("[ue].t");
+    }
+
+    /**
+     * How to select text in a text control.
+     */
+    @Test
+    public void select() {
+        TextInputControlDock multiLine = new TextInputControlDock(scene.asParent(), 
+                "multi", StringComparePolicy.SUBSTRING);
+        
+        //of course you could select a portion of text by position
+        multiLine.asSelectionText().caret().to(6);
+        multiLine.asSelectionText().caret().selectTo(10);
+        
+        //or by text
+        multiLine.asSelectionText().select("multi\n");
+
+        //which could be a regex
+        multiLine.asSelectionText().select("[ue].t", 1);
+    }
+
+    /**
+     * How to clear text in a text control.
+     */
+    @Test
+    public void clear() {
+        TextInputControlDock multiLine = new TextInputControlDock(scene.asParent(), 
+                "multi", StringComparePolicy.SUBSTRING);
+        
+        //just clear
+        multiLine.asSelectionText().clear();
+    }
+
+
+    /**
+     * How to type text in a text control.
+     */
+    @Test
+    public void type() {
+        TextInputControlDock singleLine = new TextInputControlDock(scene.asParent(), 
+                "single", StringComparePolicy.SUBSTRING);
+        TextInputControlDock multiLine = new TextInputControlDock(scene.asParent(), 
+                "multi", StringComparePolicy.SUBSTRING);
+        
+        //typing starts right where cursor it
+        multiLine.asSelectionText().to("text\n", false);
+        
+        multiLine.asSelectionText().type("and we are adding another line\n");
+                
+        //so, if you are going to replace the whole text, clear old text first
+        singleLine.clear();
+        singleLine.type("still a single line");
+    }
+
+}