1 /*
   2  * Copyright (c) 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.scene.traversal.ParentTraversalEngine;
  33 import com.sun.javafx.sg.prism.NGNode;
  34 import com.sun.javafx.util.Utils;
  35 import java.util.List;
  36 import javafx.scene.Node;
  37 import javafx.scene.Parent;
  38 
  39 /*
  40  * Used to access internal methods of Parent.
  41  * Note: ParentHelper needs to be a concrete class even though Parent is an
  42  * abstract class since user is allowed to subclass Parent.
  43  */
  44 public class ParentHelper extends NodeHelper {
  45 
  46     private static final ParentHelper theInstance;
  47     private static ParentAccessor parentAccessor;
  48 
  49     static {
  50         theInstance = new ParentHelper();
  51         Utils.forceInit(Parent.class);
  52     }
  53 
  54     private static ParentHelper getInstance() {
  55         return theInstance;
  56     }
  57 
  58     public static void initHelper(Parent parent) {
  59         setHelper(parent, getInstance());
  60     }
  61 
  62     public static void superProcessCSS(Node node) {
  63         ((ParentHelper) getHelper(node)).superProcessCSSImpl(node);
  64     }
  65 
  66     public static List<String> getAllParentStylesheets(Parent parent) {
  67         return ((ParentHelper) getHelper(parent)).getAllParentStylesheetsImpl(parent);
  68     }
  69 
  70     @Override
  71     protected NGNode createPeerImpl(Node node) {
  72         return parentAccessor.doCreatePeer(node);
  73     }
  74 
  75     @Override
  76     protected void updatePeerImpl(Node node) {
  77         super.updatePeerImpl(node);
  78         parentAccessor.doUpdatePeer(node);
  79     }
  80 
  81     @Override
  82     protected BaseBounds computeGeomBoundsImpl(Node node, BaseBounds bounds,
  83             BaseTransform tx) {
  84         return parentAccessor.doComputeGeomBounds(node, bounds, tx);
  85     }
  86 
  87     @Override
  88     protected boolean computeContainsImpl(Node node, double localX, double localY) {
  89         return parentAccessor.doComputeContains(node, localX, localY);
  90     }
  91 
  92     void superProcessCSSImpl(Node node) {
  93         super.processCSSImpl(node);
  94     }
  95 
  96     @Override
  97     protected void processCSSImpl(Node node) {
  98         parentAccessor.doProcessCSS(node);
  99     }
 100 
 101     protected List<String> getAllParentStylesheetsImpl(Parent parent) {
 102         return parentAccessor.doGetAllParentStylesheets(parent);
 103     }
 104 
 105     @Override
 106     protected void pickNodeLocalImpl(Node node, PickRay localPickRay,
 107             PickResultChooser result) {
 108         parentAccessor.doPickNodeLocal(node, localPickRay, result);
 109     }
 110 
 111     public static boolean pickChildrenNode(Parent parent, PickRay pickRay,
 112             PickResultChooser result) {
 113         return parentAccessor.pickChildrenNode(parent, pickRay, result);
 114     }
 115 
 116     public static void setTraversalEngine(Parent parent, ParentTraversalEngine value) {
 117         parentAccessor.setTraversalEngine(parent, value);
 118     }
 119 
 120     public static ParentTraversalEngine getTraversalEngine(Parent parent) {
 121         return parentAccessor.getTraversalEngine(parent);
 122     }
 123 
 124     public static void setParentAccessor(final ParentAccessor newAccessor) {
 125         if (parentAccessor != null) {
 126             throw new IllegalStateException();
 127         }
 128 
 129         parentAccessor = newAccessor;
 130     }
 131 
 132     public interface ParentAccessor {
 133         NGNode doCreatePeer(Node node);
 134         void doUpdatePeer(Node node);
 135         boolean doComputeContains(Node node, double localX, double localY);
 136         BaseBounds doComputeGeomBounds(Node node, BaseBounds bounds, BaseTransform tx);
 137         void doProcessCSS(Node node);
 138         void doPickNodeLocal(Node node, PickRay localPickRay, PickResultChooser result);
 139         boolean pickChildrenNode(Parent parent, PickRay pickRay, PickResultChooser result);
 140         void setTraversalEngine(Parent parent, ParentTraversalEngine value);
 141         ParentTraversalEngine getTraversalEngine(Parent parent);
 142         List<String> doGetAllParentStylesheets(Parent parent);
 143     }
 144 
 145 }