Path: blob/master/src/java.desktop/macosx/classes/com/apple/eawt/FullScreenUtilities.java
41153 views
/*1* Copyright (c) 2011, 2017, 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 java.awt.Component;28import java.awt.Window;2930import javax.swing.RootPaneContainer;3132import com.apple.eawt.event.GestureUtilities;33import sun.lwawt.macosx.CPlatformWindow;3435/**36* Utility class perform animated full screen actions to top-level {@link Window}s.37*38* This class manages the relationship between {@link Window}s and the {@link FullScreenListener}s39* attached to them. It adds additional functionality to AWT Windows, without adding new API to the40* {@link java.awt.Window} class.41*42* Full screen operations can only be performed on top-level {@link Window}s that are also {@link RootPaneContainer}s.43*44* @see FullScreenAdapter45* @see GestureUtilities46*47* @since Java for Mac OS X 10.7 Update 148*/49public final class FullScreenUtilities {50FullScreenUtilities() {51// package private52}5354/**55* Marks a {@link Window} as able to animate into or out of full screen mode.56*57* Only top-level {@link Window}s which are {@link RootPaneContainer}s are able to be animated into and out of full screen mode.58* The {@link Window} must be marked as full screen-able before the native peer is created with {@link Component#addNotify()}.59*60* @param window61* @param canFullScreen62* @throws IllegalArgumentException if window is not a {@link RootPaneContainer}63*/64public static void setWindowCanFullScreen(final Window window, final boolean canFullScreen) {65if (!(window instanceof RootPaneContainer)) throw new IllegalArgumentException("Can't mark a non-RootPaneContainer as full screen-able");66final RootPaneContainer rpc = (RootPaneContainer)window;67rpc.getRootPane().putClientProperty(CPlatformWindow.WINDOW_FULLSCREENABLE, Boolean.valueOf(canFullScreen));68}6970/**71* Attaches a {@link FullScreenListener} to the specified top-level {@link Window}.72* @param window to attach the {@link FullScreenListener} to73* @param listener to be notified when a full screen event occurs74* @throws IllegalArgumentException if window is not a {@link RootPaneContainer}75*/76public static void addFullScreenListenerTo(final Window window, final FullScreenListener listener) {77if (!(window instanceof RootPaneContainer)) throw new IllegalArgumentException("Can't attach FullScreenListener to a non-RootPaneContainer");78if (listener == null) throw new NullPointerException();79FullScreenHandler.addFullScreenListenerTo((RootPaneContainer)window, listener);80}8182/**83* Removes a {@link FullScreenListener} from the specified top-level {@link Window}.84* @param window to remove the {@link FullScreenListener} from85* @param listener to be removed86* @throws IllegalArgumentException if window is not a {@link RootPaneContainer}87*/88public static void removeFullScreenListenerFrom(final Window window, final FullScreenListener listener) {89if (!(window instanceof RootPaneContainer)) throw new IllegalArgumentException("Can't remove FullScreenListener from non-RootPaneContainer");90if (listener == null) throw new NullPointerException();91FullScreenHandler.removeFullScreenListenerFrom((RootPaneContainer)window, listener);92}93}949596