1 /* 2 * Copyright (c) 2013, 2015, 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.stage; 27 28 import javafx.beans.property.ReadOnlyObjectProperty; 29 import javafx.stage.Screen; 30 import javafx.stage.Window; 31 32 import java.security.AccessControlContext; 33 34 /** 35 * Used to access internal window methods. 36 */ 37 public final class WindowHelper { 38 private static WindowAccessor windowAccessor; 39 40 static { 41 forceInit(Window.class); 42 } 43 44 private WindowHelper() { 45 } 46 47 public static void notifyLocationChanged(final Window window, 48 final double x, 49 final double y) { 50 windowAccessor.notifyLocationChanged(window, x, y); 51 } 52 53 public static void notifySizeChanged(final Window window, 54 final double width, 55 final double height) { 56 windowAccessor.notifySizeChanged(window, width, height); 57 } 58 59 public static void notifyScaleChanged(final Window window, 60 final double newOutputScaleX, 61 final double newOutputScaleY) { 62 windowAccessor.notifyScaleChanged(window, newOutputScaleX, newOutputScaleY); 63 } 64 65 static AccessControlContext getAccessControlContext(Window window) { 66 return windowAccessor.getAccessControlContext(window); 67 } 68 69 public static void setWindowAccessor(final WindowAccessor newAccessor) { 70 if (windowAccessor != null) { 71 throw new IllegalStateException(); 72 } 73 74 windowAccessor = newAccessor; 75 } 76 77 public static WindowAccessor getWindowAccessor() { 78 return windowAccessor; 79 } 80 81 public interface WindowAccessor { 82 void notifyLocationChanged(Window window, double x, double y); 83 84 void notifySizeChanged(Window window, double width, double height); 85 86 void notifyScreenChanged(Window window, Object from, Object to); 87 88 void notifyScaleChanged(Window window, double newOutputScaleX, double newOutputScaleY); 89 90 ReadOnlyObjectProperty<Screen> screenProperty(Window window); 91 92 AccessControlContext getAccessControlContext(Window window); 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 }