functional/ControlsTests/src/javafx/scene/control/test/utils/ColorHelper.java

Print this page




  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javafx.scene.control.test.utils;
  26 
  27 import javafx.application.Application;
  28 import javafx.event.ActionEvent;
  29 import javafx.event.EventHandler;
  30 import javafx.scene.Scene;
  31 import javafx.scene.control.Button;
  32 import javafx.scene.control.TextArea;
  33 import javafx.scene.control.TextAreaBuilder;
  34 import javafx.scene.control.TextField;
  35 import javafx.scene.control.TextFieldBuilder;
  36 import javafx.scene.layout.VBox;
  37 import javafx.scene.paint.Color;
  38 import javafx.stage.Stage;
  39 import javafx.stage.StageStyle;
  40 import org.jemmy.action.GetAction;
  41 import org.jemmy.fx.Root;
  42 
  43 /**
  44  * @author Alexander Kirov
  45  *
  46  * This helper helps to determine, what say awt and glass robots about color at
  47  * some coordinate. Enter coordinates. X and Y of stage will be set at that
  48  * position, and you can see the result of robot calls.
  49  */
  50 public class ColorHelper extends Application {
  51 
  52     public static void main(String[] args) {
  53         launch(args);
  54     }
  55 
  56     @Override
  57     public void start(final Stage stage) throws Exception {
  58         final TextField xField = TextFieldBuilder.create().promptText("x").build();
  59         final TextField yField = TextFieldBuilder.create().promptText("y").build();
  60 
  61         final TextArea awtField = TextAreaBuilder.create().promptText("awt").build();
  62         final TextArea glassField = TextAreaBuilder.create().promptText("glass").build();




  63 
  64         Button act = new Button("Get colors");
  65         act.setOnAction(new EventHandler<ActionEvent>() {
  66             public void handle(ActionEvent t) {
  67                 try {
  68                     int x = Integer.parseInt(xField.getText());
  69                     int y = Integer.parseInt(yField.getText());
  70 
  71                     stage.setX(x + 1);
  72                     stage.setY(y + 1);
  73 
  74                     java.awt.Robot robotAwt = new java.awt.Robot();
  75                     com.sun.glass.ui.Robot robotGlass = new GetAction<com.sun.glass.ui.Robot>() {
  76                         @Override
  77                         public void run(Object... os) throws Exception {
  78                             setResult(com.sun.glass.ui.Application.GetApplication().createRobot());
  79                         }
  80                     }.dispatch(Root.ROOT.getEnvironment());
  81 
  82                     java.awt.Color glassColor = new java.awt.Color(robotGlass.getPixelColor((int) Math.round(x), (int) Math.round(y)));




  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javafx.scene.control.test.utils;
  26 
  27 import javafx.application.Application;
  28 import javafx.event.ActionEvent;
  29 import javafx.event.EventHandler;
  30 import javafx.scene.Scene;
  31 import javafx.scene.control.Button;
  32 import javafx.scene.control.TextArea;

  33 import javafx.scene.control.TextField;

  34 import javafx.scene.layout.VBox;
  35 import javafx.scene.paint.Color;
  36 import javafx.stage.Stage;
  37 import javafx.stage.StageStyle;
  38 import org.jemmy.action.GetAction;
  39 import org.jemmy.fx.Root;
  40 
  41 /**
  42  * @author Alexander Kirov
  43  *
  44  * This helper helps to determine, what say awt and glass robots about color at
  45  * some coordinate. Enter coordinates. X and Y of stage will be set at that
  46  * position, and you can see the result of robot calls.
  47  */
  48 public class ColorHelper extends Application {
  49 
  50     public static void main(String[] args) {
  51         launch(args);
  52     }
  53 
  54     @Override
  55     public void start(final Stage stage) throws Exception {
  56         final TextField xField = new TextField();

  57         xField.setPromptText("x");

  58         final TextField yField = new TextField();

  59         yField.setPromptText("y");

  60 

  61         final TextArea awtField = new TextArea();

  62         awtField.setPromptText("awt");

  63         final TextArea glassField = new TextArea();

  64         glassField.setPromptText("glass");

  65 
  66         Button act = new Button("Get colors");
  67         act.setOnAction(new EventHandler<ActionEvent>() {
  68             public void handle(ActionEvent t) {
  69                 try {
  70                     int x = Integer.parseInt(xField.getText());
  71                     int y = Integer.parseInt(yField.getText());
  72 
  73                     stage.setX(x + 1);
  74                     stage.setY(y + 1);
  75 
  76                     java.awt.Robot robotAwt = new java.awt.Robot();
  77                     com.sun.glass.ui.Robot robotGlass = new GetAction<com.sun.glass.ui.Robot>() {
  78                         @Override
  79                         public void run(Object... os) throws Exception {
  80                             setResult(com.sun.glass.ui.Application.GetApplication().createRobot());
  81                         }
  82                     }.dispatch(Root.ROOT.getEnvironment());
  83 
  84                     java.awt.Color glassColor = new java.awt.Color(robotGlass.getPixelColor((int) Math.round(x), (int) Math.round(y)));