1 /* 2 * Copyright (c) 2010, 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.stage; 27 28 import javafx.event.Event; 29 import javafx.stage.Window; 30 31 import com.sun.javafx.tk.FocusCause; 32 import com.sun.javafx.tk.TKStageListener; 33 import javafx.stage.WindowEvent; 34 35 /** 36 * Listener for the Stage Peer to pass updates and events back to the stage. 37 * 38 */ 39 public class WindowPeerListener implements TKStageListener { 40 41 private final Window window; 42 43 public WindowPeerListener(Window window) { 44 this.window = window; 45 } 46 47 @Override 48 public void changedLocation(float x, float y) { 49 WindowHelper.notifyLocationChanged(window, x, y); 50 } 51 52 @Override 53 public void changedSize(float width, float height) { 54 WindowHelper.notifySizeChanged(window, width, height); 55 } 56 57 public void changedFocused(boolean focused, FocusCause cause) { 58 // Also overridden in subclasses 59 window.setFocused(focused); 60 } 61 62 public void changedIconified(boolean iconified) { 63 // Overridden in subclasses 64 } 65 66 public void changedMaximized(boolean maximized) { 67 // Overridden in subclasses 68 } 69 70 public void changedResizable(boolean resizable) { 71 // Overridden in subclasses 72 } 73 74 public void changedFullscreen(boolean fs) { 75 // Overridden in subclasses 76 } 77 78 public void changedAlwaysOnTop(boolean aot) { 79 // Overridden in subclasses 80 } 81 82 @Override 83 public void closing() { 84 Event.fireEvent(window, 85 new WindowEvent(window, 86 WindowEvent.WINDOW_CLOSE_REQUEST)); 87 } 88 89 @Override 90 public void closed() { 91 if (window.isShowing()) { 92 // This is a notification to an owned window, which is being 93 // closed as a result of closing its owner. The owned window 94 // can be a modal dialog, so we call hide() to exit its nested 95 // event loop and unblock other windows. 96 window.hide(); 97 } 98 } 99 100 @Override public void focusUngrab() { 101 Event.fireEvent(window, new FocusUngrabEvent()); 102 } 103 104 /** 105 * Initialize accessibility 106 */ 107 @Override 108 public void initAccessibleTKStageListener() { 109 // Overridden in subclasses 110 } 111 }