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.stage; 27 28 import com.sun.javafx.tk.TKStage; 29 import com.sun.javafx.util.Utils; 30 import javafx.beans.property.ReadOnlyObjectProperty; 31 import javafx.stage.Screen; 32 import javafx.stage.Window; 33 34 import java.security.AccessControlContext; 35 36 /** 37 * Used to access internal window methods. 38 */ 39 public class WindowHelper { 40 private static final WindowHelper theInstance; 41 private static WindowAccessor windowAccessor; 42 43 static { 44 theInstance = new WindowHelper(); 45 Utils.forceInit(Window.class); 46 } 47 48 protected WindowHelper() { 49 } 50 51 private static WindowHelper getInstance() { 52 return theInstance; 53 } 54 55 public static void initHelper(Window window) { 56 setHelper(window, getInstance()); 57 } 58 59 private static WindowHelper getHelper(Window window) { 60 return windowAccessor.getHelper(window); 61 } 62 63 protected static void setHelper(Window window, WindowHelper windowHelper) { 64 windowAccessor.setHelper(window, windowHelper); 65 } 66 67 /* 68 * Static helper methods for cases where the implementation is done in an 69 * instance method that is overridden by subclasses. 70 * These methods exist in the base class only. 71 */ 72 public static void visibleChanging(Window window, boolean visible) { 73 getHelper(window).visibleChangingImpl(window, visible); 74 } 75 76 public static void visibleChanged(Window window, boolean visible) { 77 getHelper(window).visibleChangedImpl(window, visible); 78 } 79 80 /* 81 * Methods that will be overridden by subclasses 82 */ 83 protected void visibleChangingImpl(Window window, boolean visible) { 84 windowAccessor.doVisibleChanging(window, visible); 85 } 86 87 protected void visibleChangedImpl(Window window, boolean visible) { 88 windowAccessor.doVisibleChanged(window, visible); 89 } 90 91 /* 92 * Methods used by Window (base) class only 93 */ 94 95 public static TKStage getPeer(Window window) { 96 return windowAccessor.getPeer(window); 97 } 98 99 public static void setPeer(Window window, TKStage peer) { 100 windowAccessor.setPeer(window, peer); 101 } 102 103 public static WindowPeerListener getPeerListener(Window window) { 104 return windowAccessor.getPeerListener(window); 105 } 106 107 public static void setPeerListener(Window window, WindowPeerListener peerListener) { 108 windowAccessor.setPeerListener(window, peerListener); 109 } 110 111 public static void setFocused(Window window, boolean value) { 112 windowAccessor.setFocused(window, value); 113 } 114 115 public static void notifyLocationChanged(final Window window, 116 final double x, 117 final double y) { 118 windowAccessor.notifyLocationChanged(window, x, y); 119 } 120 121 public static void notifySizeChanged(final Window window, 122 final double width, 123 final double height) { 124 windowAccessor.notifySizeChanged(window, width, height); 125 } 126 127 public static void notifyScaleChanged(final Window window, 128 final double newOutputScaleX, 129 final double newOutputScaleY) { 130 windowAccessor.notifyScaleChanged(window, newOutputScaleX, newOutputScaleY); 131 } 132 133 static AccessControlContext getAccessControlContext(Window window) { 134 return windowAccessor.getAccessControlContext(window); 135 } 136 137 public static void setWindowAccessor(final WindowAccessor newAccessor) { 138 if (windowAccessor != null) { 139 throw new IllegalStateException(); 140 } 141 142 windowAccessor = newAccessor; 143 } 144 145 public static WindowAccessor getWindowAccessor() { 146 return windowAccessor; 147 } 148 149 public interface WindowAccessor { 150 WindowHelper getHelper(Window window); 151 void setHelper(Window window, WindowHelper windowHelper); 152 void doVisibleChanging(Window window, boolean visible); 153 void doVisibleChanged(Window window, boolean visible); 154 TKStage getPeer(Window window); 155 void setPeer(Window window, TKStage peer); 156 WindowPeerListener getPeerListener(Window window); 157 void setPeerListener(Window window, WindowPeerListener peerListener); 158 void setFocused(Window window, boolean value); 159 void notifyLocationChanged(Window window, double x, double y); 160 161 void notifySizeChanged(Window window, double width, double height); 162 163 void notifyScreenChanged(Window window, Object from, Object to); 164 165 float getPlatformScaleX(Window window); 166 float getPlatformScaleY(Window window); 167 168 void notifyScaleChanged(Window window, double newOutputScaleX, double newOutputScaleY); 169 170 ReadOnlyObjectProperty<Screen> screenProperty(Window window); 171 172 AccessControlContext getAccessControlContext(Window window); 173 } 174 }