1 /*
   2  * Copyright (c) 2013, 2014, 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 javafx.scene.Camera;
  30 import javafx.scene.Node;
  31 import javafx.scene.Parent;
  32 import javafx.scene.Scene;
  33 
  34 /**
  35  * Used to access internal scene methods.
  36  */
  37 public final class SceneHelper {
  38     private static SceneAccessor sceneAccessor;
  39 
  40     static {
  41         forceInit(Scene.class);
  42     }
  43 
  44     private SceneHelper() {
  45     }
  46 
  47     public static void setPaused(final boolean paused) {
  48         sceneAccessor.setPaused(paused);
  49     }
  50 
  51     public static void parentEffectiveOrientationInvalidated(
  52             final Scene scene) {
  53         sceneAccessor.parentEffectiveOrientationInvalidated(scene);
  54     }
  55 
  56     public static Camera getEffectiveCamera(final Scene scene) {
  57         return sceneAccessor.getEffectiveCamera(scene);
  58     }
  59 
  60     public static Scene createPopupScene(final Parent root) {
  61         return sceneAccessor.createPopupScene(root);
  62     }
  63 
  64     public static Accessible getAccessible(Scene scene) {
  65         return sceneAccessor.getAccessible(scene);
  66     }
  67 
  68     public static void setSceneAccessor(final SceneAccessor newAccessor) {
  69         if (sceneAccessor != null) {
  70             throw new IllegalStateException();
  71         }
  72 
  73         sceneAccessor = newAccessor;
  74     }
  75 
  76     public static SceneAccessor getSceneAccessor() {
  77         if (sceneAccessor == null) throw new IllegalStateException();
  78         return sceneAccessor;
  79     }
  80 
  81     public interface SceneAccessor {
  82         void setPaused(boolean paused);
  83 
  84         void parentEffectiveOrientationInvalidated(Scene scene);
  85 
  86         Camera getEffectiveCamera(Scene scene);
  87 
  88         Scene createPopupScene(Parent root);
  89 
  90         void setTransientFocusContainer(Scene scene, Node node);
  91 
  92         Accessible getAccessible(Scene scene);
  93     }
  94 
  95     private static void forceInit(final Class<?> classToInit) {
  96         try {
  97             Class.forName(classToInit.getName(), true,
  98                           classToInit.getClassLoader());
  99         } catch (final ClassNotFoundException e) {
 100             throw new AssertionError(e);  // Can't happen
 101         }
 102     }
 103 }