1 /*
   2  * Copyright (c) 2013, 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 com.sun.javafx.scene;
  27 
  28 import com.sun.javafx.geom.BaseBounds;
  29 import com.sun.javafx.geom.PickRay;
  30 import com.sun.javafx.geom.transform.BaseTransform;
  31 import com.sun.javafx.scene.input.PickResultChooser;
  32 import com.sun.javafx.sg.prism.NGNode;
  33 import com.sun.javafx.util.Utils;
  34 import javafx.scene.Camera;
  35 import javafx.scene.Node;
  36 import javafx.scene.SubScene;
  37 
  38 /**
  39  * Used to access internal methods of SubScene.
  40  */
  41 public class SubSceneHelper extends NodeHelper {
  42 
  43     private static final SubSceneHelper theInstance;
  44     private static SubSceneAccessor subSceneAccessor;
  45 
  46     static {
  47         theInstance = new SubSceneHelper();
  48         Utils.forceInit(SubScene.class);
  49     }
  50 
  51     private static SubSceneHelper getInstance() {
  52         return theInstance;
  53     }
  54 
  55     public static void initHelper(SubScene subScene) {
  56         setHelper(subScene, getInstance());
  57     }
  58 
  59     public static void superProcessCSS(Node node) {
  60         ((SubSceneHelper) getHelper(node)).superProcessCSSImpl(node);
  61     }
  62 
  63     @Override
  64     protected NGNode createPeerImpl(Node node) {
  65         return subSceneAccessor.doCreatePeer(node);
  66     }
  67 
  68     @Override
  69     protected void updatePeerImpl(Node node) {
  70         super.updatePeerImpl(node);
  71         subSceneAccessor.doUpdatePeer(node);
  72     }
  73 
  74     @Override
  75     protected BaseBounds computeGeomBoundsImpl(Node node, BaseBounds bounds,
  76             BaseTransform tx) {
  77         return subSceneAccessor.doComputeGeomBounds(node, bounds, tx);
  78     }
  79 
  80     @Override
  81     protected boolean computeContainsImpl(Node node, double localX, double localY) {
  82         return subSceneAccessor.doComputeContains(node, localX, localY);
  83     }
  84 
  85     void superProcessCSSImpl(Node node) {
  86         super.processCSSImpl(node);
  87     }
  88 
  89     protected void processCSSImpl(Node node) {
  90         subSceneAccessor.doProcessCSS(node);
  91     }
  92 
  93     @Override
  94     protected void pickNodeLocalImpl(Node node, PickRay localPickRay,
  95             PickResultChooser result) {
  96         subSceneAccessor.doPickNodeLocal(node, localPickRay, result);
  97     }
  98 
  99     public static boolean isDepthBuffer(SubScene subScene) {
 100         return subSceneAccessor.isDepthBuffer(subScene);
 101     }
 102 
 103     public static Camera getEffectiveCamera(SubScene subScene) {
 104         return subSceneAccessor.getEffectiveCamera(subScene);
 105     }
 106 
 107     public static void setSubSceneAccessor(final SubSceneAccessor newAccessor) {
 108         if (subSceneAccessor != null) {
 109             throw new IllegalStateException();
 110         }
 111 
 112         subSceneAccessor = newAccessor;
 113     }
 114 
 115     public interface SubSceneAccessor {
 116         NGNode doCreatePeer(Node node);
 117         void doUpdatePeer(Node node);
 118         BaseBounds doComputeGeomBounds(Node node, BaseBounds bounds, BaseTransform tx);
 119         boolean doComputeContains(Node node, double localX, double localY);
 120         void doProcessCSS(Node node);
 121         void doPickNodeLocal(Node node, PickRay localPickRay,
 122                 PickResultChooser result);
 123         boolean isDepthBuffer(SubScene subScene);
 124         Camera getEffectiveCamera(SubScene subScene);
 125     }
 126 
 127 }