1 /*
   2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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 
  26 package test.javafx.scene.input;
  27 
  28 import test.com.sun.javafx.scene.input.TestNodeHelper;
  29 import com.sun.javafx.geom.BaseBounds;
  30 import com.sun.javafx.geom.transform.BaseTransform;
  31 import com.sun.javafx.jmx.MXNodeAlgorithm;
  32 import com.sun.javafx.jmx.MXNodeAlgorithmContext;
  33 import com.sun.javafx.sg.prism.NGGroup;
  34 import com.sun.javafx.sg.prism.NGNode;
  35 import javafx.geometry.Point2D;
  36 import javafx.geometry.Point3D;
  37 import javafx.scene.Node;
  38 
  39 /**
  40  * Subclass of javafx.scene.Node used for input testing.
  41  */
  42 public class TestNode extends Node {
  43     static {
  44          // This is used by classes in different packages to get access to
  45          // private and package private methods.
  46         TestNodeHelper.setTestNodeAccessor(new TestNodeHelper.TestNodeAccessor() {
  47             @Override
  48             public NGNode doCreatePeer(Node node) {
  49                 return ((TestNode) node).doCreatePeer();
  50             }
  51 
  52             @Override
  53             public BaseBounds doComputeGeomBounds(Node node,
  54             BaseBounds bounds, BaseTransform tx) {
  55                 return ((TestNode) node).doComputeGeomBounds(bounds, tx);
  56             }
  57 
  58             @Override
  59             public boolean doComputeContains(Node node, double localX, double localY) {
  60                 return ((TestNode) node).doComputeContains(localX, localY);
  61             }
  62 
  63             @Override
  64             public Object doProcessMXNode(Node node, MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx) {
  65                 return ((TestNode) node).doProcessMXNode(alg, ctx);
  66             }
  67         });
  68     }
  69 
  70     private float offsetInScene;
  71 
  72     {
  73         // To initialize the class helper at the begining each constructor of this class
  74         TestNodeHelper.initHelper(this);
  75     }
  76     public TestNode() {
  77     }
  78 
  79     public TestNode(float offsetInScene) {
  80         this.offsetInScene = offsetInScene;
  81     }
  82 
  83     @Override
  84     public Point2D sceneToLocal(double x, double y) {
  85         return new Point2D(x - offsetInScene, y - offsetInScene);
  86     }
  87 
  88     @Override
  89     public Point2D localToScene(double x, double y) {
  90         return new Point2D(x + offsetInScene, y + offsetInScene);
  91     }
  92 
  93     @Override
  94     public Point3D sceneToLocal(double x, double y, double z) {
  95         return new Point3D(x - offsetInScene, y - offsetInScene, z);
  96     }
  97 
  98     @Override
  99     public Point3D localToScene(double x, double y, double z) {
 100         return new Point3D(x + offsetInScene, y + offsetInScene, z);
 101     }
 102 
 103     /*
 104      * Note: This method MUST only be called via its accessor method.
 105      */
 106     private boolean doComputeContains(double f, double f1) {
 107         return false;
 108     }
 109 
 110     /*
 111      * Note: This method MUST only be called via its accessor method.
 112      */
 113     private BaseBounds doComputeGeomBounds(BaseBounds bd, BaseTransform bt) {
 114         return null;
 115     }
 116 
 117     private NGNode doCreatePeer() {
 118         return new NGGroup();
 119     }
 120 
 121     /*
 122      * Note: This method MUST only be called via its accessor method.
 123      */
 124     private Object doProcessMXNode(MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx) {
 125         return null;
 126     }
 127 }