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 static AccessControlContext getAccessControlContext(Window window) { 60 return windowAccessor.getAccessControlContext(window); 61 } 62 63 public static void setWindowAccessor(final WindowAccessor newAccessor) { 64 if (windowAccessor != null) { 65 throw new IllegalStateException(); 66 } 67 68 windowAccessor = newAccessor; 69 } 70 71 public static WindowAccessor getWindowAccessor() { 72 return windowAccessor; 73 } 74 75 public interface WindowAccessor { 76 void notifyLocationChanged(Window window, double x, double y); 77 78 void notifySizeChanged(Window window, double width, double height); 79 80 void notifyScreenChanged(Window window, Object from, Object to); 81 82 float getUIScale(Window window); 83 float getRenderScale(Window window); 84 85 ReadOnlyObjectProperty<Screen> screenProperty(Window window); 86 87 AccessControlContext getAccessControlContext(Window window); 88 } 89 90 private static void forceInit(final Class<?> classToInit) { 91 try { 92 Class.forName(classToInit.getName(), true, 93 classToInit.getClassLoader()); 94 } catch (final ClassNotFoundException e) { 95 throw new AssertionError(e); // Can't happen 96 } 97 } 98 }