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.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 TKPulseListener getScenePulseListener(Scene scene) {
  82         return sceneAccessor.getScenePulseListener(scene);
  83     }
  84 
  85     public static TKScene getPeer(Scene scene) {
  86         return sceneAccessor.getPeer(scene);
  87     }
  88 
  89     public static void setAllowPGAccess(boolean flag) {
  90         sceneAccessor.setAllowPGAccess(flag);
  91     }
  92 
  93     public static void setPaused(final boolean paused) {
  94         sceneAccessor.setPaused(paused);
  95     }
  96 
  97     public static void parentEffectiveOrientationInvalidated(
  98             final Scene scene) {
  99         sceneAccessor.parentEffectiveOrientationInvalidated(scene);
 100     }
 101 
 102     public static Camera getEffectiveCamera(final Scene scene) {
 103         return sceneAccessor.getEffectiveCamera(scene);
 104     }
 105 
 106     public static Scene createPopupScene(final Parent root) {
 107         return sceneAccessor.createPopupScene(root);
 108     }
 109 
 110     public static Accessible getAccessible(Scene scene) {
 111         return sceneAccessor.getAccessible(scene);
 112     }
 113 
 114     public static void setSceneAccessor(final SceneAccessor newAccessor) {
 115         if (sceneAccessor != null) {
 116             throw new IllegalStateException();
 117         }
 118 
 119         sceneAccessor = newAccessor;
 120     }
 121 
 122     public static SceneAccessor getSceneAccessor() {
 123         if (sceneAccessor == null) throw new IllegalStateException();
 124         return sceneAccessor;
 125     }
 126 
 127     public interface SceneAccessor {
 128         void enableInputMethodEvents(Scene scene, boolean enable);
 129 
 130         void processKeyEvent(Scene scene, KeyEvent e);
 131 
 132         void processMouseEvent(Scene scene, MouseEvent e);
 133 
 134         void preferredSize(Scene scene);
 135 
 136         void disposePeer(Scene scene);
 137 
 138         void initPeer(Scene scene);
 139 
 140         void setWindow(Scene scene, Window window);
 141 
 142         TKPulseListener getScenePulseListener(Scene scene);
 143 
 144         TKScene getPeer(Scene scene);
 145 
 146         void setAllowPGAccess(boolean flag);
 147 
 148         void setPaused(boolean paused);
 149 
 150         void parentEffectiveOrientationInvalidated(Scene scene);
 151 
 152         Camera getEffectiveCamera(Scene scene);
 153 
 154         Scene createPopupScene(Parent root);
 155 
 156         void setTransientFocusContainer(Scene scene, Node node);
 157 
 158         Accessible getAccessible(Scene scene);
 159     }
 160 
 161 }