Path: blob/master/src/java.desktop/macosx/classes/com/apple/eawt/FullScreenHandler.java
41153 views
/*1* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.apple.eawt;2627import com.apple.eawt.event.FullScreenEvent;28import java.awt.*;29import java.util.*;30import java.util.List;3132import javax.swing.RootPaneContainer;3334import sun.awt.SunToolkit;3536import java.lang.annotation.Native;3738final class FullScreenHandler {39private static final String CLIENT_PROPERTY = "com.apple.eawt.event.internalFullScreenHandler";4041@Native static final int FULLSCREEN_WILL_ENTER = 1;42@Native static final int FULLSCREEN_DID_ENTER = 2;43@Native static final int FULLSCREEN_WILL_EXIT = 3;44@Native static final int FULLSCREEN_DID_EXIT = 4;4546// installs a private instance of the handler, if necessary47static void addFullScreenListenerTo(final RootPaneContainer window, final FullScreenListener listener) {48final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);49if (value instanceof FullScreenHandler) {50((FullScreenHandler)value).addListener(listener);51return;52}5354if (value != null) return; // some other garbage is in our client property5556final FullScreenHandler newHandler = new FullScreenHandler();57newHandler.addListener(listener);58window.getRootPane().putClientProperty(CLIENT_PROPERTY, newHandler);59}6061// asks the installed FullScreenHandler to remove it's listener (does not uninstall the FullScreenHandler)62static void removeFullScreenListenerFrom(final RootPaneContainer window, final FullScreenListener listener) {63final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);64if (!(value instanceof FullScreenHandler)) return;65((FullScreenHandler)value).removeListener(listener);66}6768static FullScreenHandler getHandlerFor(final RootPaneContainer window) {69final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);70if (value instanceof FullScreenHandler) return (FullScreenHandler)value;71return null;72}7374// called from native75static void handleFullScreenEventFromNative(final Window window, final int type) {76if (!(window instanceof RootPaneContainer)) return; // handles null7778SunToolkit.executeOnEventHandlerThread(window, new Runnable() {79public void run() {80final FullScreenHandler handler = getHandlerFor((RootPaneContainer)window);81if (handler != null) handler.notifyListener(new FullScreenEvent(window), type);82}83});84}858687final List<FullScreenListener> listeners = new LinkedList<FullScreenListener>();8889FullScreenHandler() { }9091void addListener(final FullScreenListener listener) {92listeners.add(listener);93}9495void removeListener(final FullScreenListener listener) {96listeners.remove(listener);97}9899void notifyListener(final FullScreenEvent e, final int op) {100for (final FullScreenListener listener : listeners) {101switch (op) {102case FULLSCREEN_WILL_ENTER:103listener.windowEnteringFullScreen(e);104return;105case FULLSCREEN_DID_ENTER:106listener.windowEnteredFullScreen(e);107return;108case FULLSCREEN_WILL_EXIT:109listener.windowExitingFullScreen(e);110return;111case FULLSCREEN_DID_EXIT:112listener.windowExitedFullScreen(e);113return;114}115}116}117}118119120