src/macosx/classes/com/apple/eawt/FullScreenHandler.java

Print this page




  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.apple.eawt;
  27 
  28 import java.awt.*;
  29 import java.util.*;
  30 import java.util.List;
  31 
  32 import javax.swing.RootPaneContainer;
  33 
  34 import com.apple.eawt.AppEvent.FullScreenEvent;

  35 
  36 import java.lang.annotation.Native;
  37 
  38 final class FullScreenHandler {
  39     private static final String CLIENT_PROPERTY = "com.apple.eawt.event.internalFullScreenHandler";
  40 
  41     @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;
  45 
  46     // installs a private instance of the handler, if necessary
  47     static void addFullScreenListenerTo(final RootPaneContainer window, final FullScreenListener listener) {
  48         final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);
  49         if (value instanceof FullScreenHandler) {
  50             ((FullScreenHandler)value).addListener(listener);
  51             return;
  52         }
  53 
  54         if (value != null) return; // some other garbage is in our client property


  58         window.getRootPane().putClientProperty(CLIENT_PROPERTY, newHandler);
  59     }
  60 
  61     // asks the installed FullScreenHandler to remove it's listener (does not uninstall the FullScreenHandler)
  62     static void removeFullScreenListenerFrom(final RootPaneContainer window, final FullScreenListener listener) {
  63         final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);
  64         if (!(value instanceof FullScreenHandler)) return;
  65         ((FullScreenHandler)value).removeListener(listener);
  66     }
  67 
  68     static FullScreenHandler getHandlerFor(final RootPaneContainer window) {
  69         final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);
  70         if (value instanceof FullScreenHandler) return (FullScreenHandler)value;
  71         return null;
  72     }
  73 
  74     // called from native
  75     static void handleFullScreenEventFromNative(final Window window, final int type) {
  76         if (!(window instanceof RootPaneContainer)) return; // handles null
  77 
  78         EventQueue.invokeLater(new Runnable() {
  79             public void run() {
  80                 final FullScreenHandler handler = getHandlerFor((RootPaneContainer)window);
  81                 if (handler != null) handler.notifyListener(new FullScreenEvent(window), type);
  82             }
  83         });
  84     }
  85 
  86 
  87     final List<FullScreenListener> listeners = new LinkedList<FullScreenListener>();
  88 
  89     FullScreenHandler() { }
  90 
  91     void addListener(final FullScreenListener listener) {
  92         listeners.add(listener);
  93     }
  94 
  95     void removeListener(final FullScreenListener listener) {
  96         listeners.remove(listener);
  97     }
  98 


  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.apple.eawt;
  27 
  28 import java.awt.*;
  29 import java.util.*;
  30 import java.util.List;
  31 
  32 import javax.swing.RootPaneContainer;
  33 
  34 import com.apple.eawt.AppEvent.FullScreenEvent;
  35 import sun.awt.SunToolkit;
  36 
  37 import java.lang.annotation.Native;
  38 
  39 final class FullScreenHandler {
  40     private static final String CLIENT_PROPERTY = "com.apple.eawt.event.internalFullScreenHandler";
  41 
  42     @Native static final int FULLSCREEN_WILL_ENTER = 1;
  43     @Native static final int FULLSCREEN_DID_ENTER = 2;
  44     @Native static final int FULLSCREEN_WILL_EXIT = 3;
  45     @Native static final int FULLSCREEN_DID_EXIT = 4;
  46 
  47     // installs a private instance of the handler, if necessary
  48     static void addFullScreenListenerTo(final RootPaneContainer window, final FullScreenListener listener) {
  49         final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);
  50         if (value instanceof FullScreenHandler) {
  51             ((FullScreenHandler)value).addListener(listener);
  52             return;
  53         }
  54 
  55         if (value != null) return; // some other garbage is in our client property


  59         window.getRootPane().putClientProperty(CLIENT_PROPERTY, newHandler);
  60     }
  61 
  62     // asks the installed FullScreenHandler to remove it's listener (does not uninstall the FullScreenHandler)
  63     static void removeFullScreenListenerFrom(final RootPaneContainer window, final FullScreenListener listener) {
  64         final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);
  65         if (!(value instanceof FullScreenHandler)) return;
  66         ((FullScreenHandler)value).removeListener(listener);
  67     }
  68 
  69     static FullScreenHandler getHandlerFor(final RootPaneContainer window) {
  70         final Object value = window.getRootPane().getClientProperty(CLIENT_PROPERTY);
  71         if (value instanceof FullScreenHandler) return (FullScreenHandler)value;
  72         return null;
  73     }
  74 
  75     // called from native
  76     static void handleFullScreenEventFromNative(final Window window, final int type) {
  77         if (!(window instanceof RootPaneContainer)) return; // handles null
  78 
  79         SunToolkit.executeOnEventHandlerThread(window, new Runnable() {
  80             public void run() {
  81                 final FullScreenHandler handler = getHandlerFor((RootPaneContainer)window);
  82                 if (handler != null) handler.notifyListener(new FullScreenEvent(window), type);
  83             }
  84         });
  85     }
  86 
  87 
  88     final List<FullScreenListener> listeners = new LinkedList<FullScreenListener>();
  89 
  90     FullScreenHandler() { }
  91 
  92     void addListener(final FullScreenListener listener) {
  93         listeners.add(listener);
  94     }
  95 
  96     void removeListener(final FullScreenListener listener) {
  97         listeners.remove(listener);
  98     }
  99