1 /*
   2  * Copyright (c) 2013, 2018, 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.glass.ui.Accessible;
  29 import com.sun.javafx.tk.TKPulseListener;
  30 import com.sun.javafx.tk.TKScene;
  31 import com.sun.javafx.util.Utils;
  32 import javafx.scene.Camera;
  33 import javafx.scene.Node;
  34 import javafx.scene.Parent;
  35 import javafx.scene.Scene;
  36 import javafx.scene.input.KeyEvent;
  37 import javafx.scene.input.MouseEvent;
  38 import javafx.stage.Window;
  39 
  40 /**
  41  * Used to access internal scene methods.
  42  */
  43 public final class SceneHelper {
  44     private static SceneAccessor sceneAccessor;
  45 
  46     static {
  47         Utils.forceInit(Scene.class);
  48     }
  49 
  50     private SceneHelper() {
  51     }
  52 
  53     public static void enableInputMethodEvents(Scene scene, boolean enable) {
  54         sceneAccessor.enableInputMethodEvents(scene, enable);
  55     }
  56 
  57     public static void processKeyEvent(Scene scene, KeyEvent e) {
  58         sceneAccessor.processKeyEvent(scene, e);
  59     }
  60 
  61     public static void processMouseEvent(Scene scene, MouseEvent e) {
  62         sceneAccessor.processMouseEvent(scene, e);
  63     }
  64 
  65     public static void preferredSize(Scene scene) {
  66         sceneAccessor.preferredSize(scene);
  67     }
  68 
  69     public static void disposePeer(Scene scene) {
  70         sceneAccessor.disposePeer(scene);
  71     }
  72 
  73     public static void initPeer(Scene scene) {
  74         sceneAccessor.initPeer(scene);
  75     }
  76 
  77     public static void setWindow(Scene scene, Window window) {
  78         sceneAccessor.setWindow(scene, window);
  79     }
  80 
  81     public static TKScene getPeer(Scene scene) {
  82         return sceneAccessor.getPeer(scene);
  83     }
  84 
  85     public static void setAllowPGAccess(boolean flag) {
  86         sceneAccessor.setAllowPGAccess(flag);
  87     }
  88 
  89     public static void parentEffectiveOrientationInvalidated(
  90             final Scene scene) {
  91         sceneAccessor.parentEffectiveOrientationInvalidated(scene);
  92     }
  93 
  94     public static Camera getEffectiveCamera(final Scene scene) {
  95         return sceneAccessor.getEffectiveCamera(scene);
  96     }
  97 
  98     public static Scene createPopupScene(final Parent root) {
  99         return sceneAccessor.createPopupScene(root);
 100     }
 101 
 102     public static Accessible getAccessible(Scene scene) {
 103         return sceneAccessor.getAccessible(scene);
 104     }
 105 
 106     public static void setSceneAccessor(final SceneAccessor newAccessor) {
 107         if (sceneAccessor != null) {
 108             throw new IllegalStateException();
 109         }
 110 
 111         sceneAccessor = newAccessor;
 112     }
 113 
 114     public static SceneAccessor getSceneAccessor() {
 115         if (sceneAccessor == null) throw new IllegalStateException();
 116         return sceneAccessor;
 117     }
 118 
 119     public interface SceneAccessor {
 120         void enableInputMethodEvents(Scene scene, boolean enable);
 121 
 122         void processKeyEvent(Scene scene, KeyEvent e);
 123 
 124         void processMouseEvent(Scene scene, MouseEvent e);
 125 
 126         void preferredSize(Scene scene);
 127 
 128         void disposePeer(Scene scene);
 129 
 130         void initPeer(Scene scene);
 131 
 132         void setWindow(Scene scene, Window window);
 133 
 134         TKScene getPeer(Scene scene);
 135 
 136         void setAllowPGAccess(boolean flag);
 137 
 138         void parentEffectiveOrientationInvalidated(Scene scene);
 139 
 140         Camera getEffectiveCamera(Scene scene);
 141 
 142         Scene createPopupScene(Parent root);
 143 
 144         void setTransientFocusContainer(Scene scene, Node node);
 145 
 146         Accessible getAccessible(Scene scene);
 147     }
 148 
 149 }