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.sg.prism.NGGroup;
  32 import com.sun.javafx.sg.prism.NGNode;
  33 import javafx.geometry.Point2D;
  34 import javafx.geometry.Point3D;
  35 import javafx.scene.Node;
  36 
  37 /**
  38  * Subclass of javafx.scene.Node used for input testing.
  39  */
  40 public class TestNode extends Node {
  41     static {
  42          // This is used by classes in different packages to get access to
  43          // private and package private methods.
  44         TestNodeHelper.setTestNodeAccessor(new TestNodeHelper.TestNodeAccessor() {
  45             @Override
  46             public NGNode doCreatePeer(Node node) {
  47                 return ((TestNode) node).doCreatePeer();
  48             }
  49 
  50             @Override
  51             public BaseBounds doComputeGeomBounds(Node node,
  52                     BaseBounds bounds, BaseTransform tx) {
  53                 return ((TestNode) node).doComputeGeomBounds(bounds, tx);
  54             }
  55 
  56             @Override
  57             public boolean doComputeContains(Node node, double localX, double localY) {
  58                 return ((TestNode) node).doComputeContains(localX, localY);
  59             }
  60         });
  61     }
  62 
  63     private float offsetInScene;
  64 
  65     {
  66         // To initialize the class helper at the begining each constructor of this class
  67         TestNodeHelper.initHelper(this);
  68     }
  69     public TestNode() {
  70     }
  71 
  72     public TestNode(float offsetInScene) {
  73         this.offsetInScene = offsetInScene;
  74     }
  75 
  76     @Override
  77     public Point2D sceneToLocal(double x, double y) {
  78         return new Point2D(x - offsetInScene, y - offsetInScene);
  79     }
  80 
  81     @Override
  82     public Point2D localToScene(double x, double y) {
  83         return new Point2D(x + offsetInScene, y + offsetInScene);
  84     }
  85 
  86     @Override
  87     public Point3D sceneToLocal(double x, double y, double z) {
  88         return new Point3D(x - offsetInScene, y - offsetInScene, z);
  89     }
  90 
  91     @Override
  92     public Point3D localToScene(double x, double y, double z) {
  93         return new Point3D(x + offsetInScene, y + offsetInScene, z);
  94     }
  95 
  96     /*
  97      * Note: This method MUST only be called via its accessor method.
  98      */
  99     private boolean doComputeContains(double f, double f1) {
 100         return false;
 101     }
 102 
 103     /*
 104      * Note: This method MUST only be called via its accessor method.
 105      */
 106     private BaseBounds doComputeGeomBounds(BaseBounds bd, BaseTransform bt) {
 107         return null;
 108     }
 109 
 110     private NGNode doCreatePeer() {
 111         return new NGGroup();
 112     }
 113 }