IDEA-154765 Handler for a force click in Magic Trackpad 2 on Mac
diff --git a/src/macosx/classes/com/apple/eawt/event/GestureHandler.java b/src/macosx/classes/com/apple/eawt/event/GestureHandler.java
index 4514da9..e3813cf 100644
--- a/src/macosx/classes/com/apple/eawt/event/GestureHandler.java
+++ b/src/macosx/classes/com/apple/eawt/event/GestureHandler.java
@@ -43,6 +43,7 @@
@Native static final int ROTATE = 2;
@Native static final int MAGNIFY = 3;
@Native static final int SWIPE = 4;
+ @Native static final int PRESSURE = 5;
// installs a private instance of GestureHandler, if necessary
static void addGestureListenerTo(final JComponent component, final GestureListener listener) {
@@ -97,6 +98,9 @@
case SWIPE:
firstNotifier.recursivelyHandleSwipe(a, b, new SwipeEvent());
return;
+ case PRESSURE:
+ firstNotifier.recursivelyHandlePressure(new PressureEvent(a,b));
+ return;
}
}
});
@@ -107,6 +111,7 @@
final List<RotationListener> rotaters = new LinkedList<RotationListener>();
final List<MagnificationListener> magnifiers = new LinkedList<MagnificationListener>();
final List<SwipeListener> swipers = new LinkedList<SwipeListener>();
+ final List<PressureListener> pressures = new LinkedList<PressureListener>();
GestureHandler() { }
@@ -115,6 +120,7 @@
if (listener instanceof RotationListener) rotaters.add((RotationListener)listener);
if (listener instanceof MagnificationListener) magnifiers.add((MagnificationListener)listener);
if (listener instanceof SwipeListener) swipers.add((SwipeListener)listener);
+ if (listener instanceof PressureListener) pressures.add((PressureListener)listener);
}
void removeListener(final GestureListener listener) {
@@ -169,6 +175,16 @@
if (next != null) next.recursivelyHandleMagnify(e);
}
+ void recursivelyHandlePressure(final PressureEvent e) {
+ for (final PressureListener listener : handler.pressures) {
+ listener.pressure(e);
+ if (e.isConsumed()) return;
+ }
+
+ final PerComponentNotifier next = getNextNotifierForComponent(component.getParent());
+ if (next != null) next.recursivelyHandlePressure(e);
+ }
+
void recursivelyHandleSwipe(final double x, final double y, final SwipeEvent e) {
for (final SwipeListener listener : handler.swipers) {
if (x < 0) listener.swipedLeft(e);
diff --git a/src/macosx/classes/com/apple/eawt/event/PressureEvent.java b/src/macosx/classes/com/apple/eawt/event/PressureEvent.java
new file mode 100644
index 0000000..f3140cc
--- /dev/null
+++ b/src/macosx/classes/com/apple/eawt/event/PressureEvent.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Event indicating a swipe was performed by the user.
+ *
+ * @see PressureListener
+ *
+ * @since Java for Mac OS X 10.10 Update 3, JDK 8
+ */
+public class PressureEvent extends GestureEvent {
+
+ public double getPressure() {
+ return pressure;
+ }
+
+ public double getStage() {
+ return stage;
+ }
+
+ private double pressure;
+ private double stage;
+
+ PressureEvent(double pressure, double stage) {
+ this.pressure = pressure;
+ this.stage = stage;
+ }
+}
diff --git a/src/macosx/classes/com/apple/eawt/event/PressureListener.java b/src/macosx/classes/com/apple/eawt/event/PressureListener.java
new file mode 100644
index 0000000..de6a646
--- /dev/null
+++ b/src/macosx/classes/com/apple/eawt/event/PressureListener.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.apple.eawt.event;
+
+/**
+ * Listener interface for receiving pressure events.
+ *
+ * @see PressureEvent
+ * @see GestureUtilities
+ *
+ * @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
+ */
+public interface PressureListener extends GestureListener {
+ public void pressure(final PressureEvent e);
+}
diff --git a/src/macosx/native/sun/awt/AWTWindow.m b/src/macosx/native/sun/awt/AWTWindow.m
index e5b6a69..c205831 100644
--- a/src/macosx/native/sun/awt/AWTWindow.m
+++ b/src/macosx/native/sun/awt/AWTWindow.m
@@ -165,6 +165,18 @@
b:[event deltaY]];
}
+- (void)pressureChangeWithEvent:(NSEvent *)event {
+
+ float pressure = event.pressure;
+
+ [self postGesture:event
+ as:com_apple_eawt_event_GestureHandler_PRESSURE
+ a:pressure
+ b:(([event respondsToSelector:@selector(stage)]) ? ((NSInteger)[event stage]) : -1)
+ ];
+
+}
+
@end
@implementation AWTWindow_Panel
AWT_NS_WINDOW_IMPLEMENTATION