src/macosx/classes/com/apple/eawt/event/GestureHandler.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 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.apple.eawt.event;
  27 
  28 import java.awt.*;
  29 import java.util.*;
  30 import java.util.List;
  31 
  32 import javax.swing.*;
  33 
  34 import javax.tools.annotation.GenerateNativeHeader;
  35 
  36 /* No native methods here, but the constants are needed in the supporting JNI code */
  37 @GenerateNativeHeader
  38 final class GestureHandler {
  39     private static final String CLIENT_PROPERTY = "com.apple.eawt.event.internalGestureHandler";
  40 
  41     // native constants for the supported types of high-level gestures
  42     static final int PHASE = 1;
  43     static final int ROTATE = 2;
  44     static final int MAGNIFY = 3;
  45     static final int SWIPE = 4;
  46 
  47     // installs a private instance of GestureHandler, if necessary
  48     static void addGestureListenerTo(final JComponent component, final GestureListener listener) {
  49         final Object value = component.getClientProperty(CLIENT_PROPERTY);
  50         if (value instanceof GestureHandler) {
  51             ((GestureHandler)value).addListener(listener);
  52             return;
  53         }
  54 
  55         if (value != null) return; // some other garbage is in our client property
  56 
  57         final GestureHandler newHandler = new GestureHandler();
  58         newHandler.addListener(listener);
  59         component.putClientProperty(CLIENT_PROPERTY, newHandler);
  60     }
  61 
  62     // asks the installed GestureHandler to remove it's listener (does not uninstall the GestureHandler)
  63     static void removeGestureListenerFrom(final JComponent component, final GestureListener listener) {
  64         final Object value = component.getClientProperty(CLIENT_PROPERTY);
  65         if (!(value instanceof GestureHandler)) return;


   1 /*
   2  * Copyright (c) 2011, 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.apple.eawt.event;
  27 
  28 import java.awt.*;
  29 import java.util.*;
  30 import java.util.List;
  31 
  32 import javax.swing.*;
  33 
  34 import java.lang.annotation.Native;
  35 


  36 final class GestureHandler {
  37     private static final String CLIENT_PROPERTY = "com.apple.eawt.event.internalGestureHandler";
  38 
  39     // native constants for the supported types of high-level gestures
  40     @Native static final int PHASE = 1;
  41     @Native static final int ROTATE = 2;
  42     @Native static final int MAGNIFY = 3;
  43     @Native static final int SWIPE = 4;
  44 
  45     // installs a private instance of GestureHandler, if necessary
  46     static void addGestureListenerTo(final JComponent component, final GestureListener listener) {
  47         final Object value = component.getClientProperty(CLIENT_PROPERTY);
  48         if (value instanceof GestureHandler) {
  49             ((GestureHandler)value).addListener(listener);
  50             return;
  51         }
  52 
  53         if (value != null) return; // some other garbage is in our client property
  54 
  55         final GestureHandler newHandler = new GestureHandler();
  56         newHandler.addListener(listener);
  57         component.putClientProperty(CLIENT_PROPERTY, newHandler);
  58     }
  59 
  60     // asks the installed GestureHandler to remove it's listener (does not uninstall the GestureHandler)
  61     static void removeGestureListenerFrom(final JComponent component, final GestureListener listener) {
  62         final Object value = component.getClientProperty(CLIENT_PROPERTY);
  63         if (!(value instanceof GestureHandler)) return;