1 /* 2 * Copyright (c) 2010, 2013, 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 @Override 79 public void closing() { 80 Event.fireEvent(window, 81 new WindowEvent(window, 82 WindowEvent.WINDOW_CLOSE_REQUEST)); 83 } 84 85 @Override 86 public void closed() { 87 if (window.isShowing()) { 88 // This is a notification to an owned window, which is being 89 // closed as a result of closing its owner. The owned window 90 // can be a modal dialog, so we call hide() to exit its nested 91 // event loop and unblock other windows. 92 window.hide(); 93 } 94 } 95 96 @Override public void focusUngrab() { 97 Event.fireEvent(window, new FocusUngrabEvent()); 98 } 99 100 /** 101 * Initialize accessibility 102 */ 103 @Override 104 public void initAccessibleTKStageListener() { 105 // Overridden in subclasses 106 } 107 }