< prev index next >

modules/javafx.swt/src/main/java/javafx/embed/swt/SWTEvents.java

Print this page
rev 10032 : 8143596: Ensure FXCanvas properly forwards SWT gesture events to its embedded scene.
Summary: Ensured SWT magnify, rotate, pan, and swipe events are properly forwarded to the embedded scene.
Reviewed-by: XXXX


   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 javafx.embed.swt;
  27 
  28 import org.eclipse.swt.SWT;
  29 import org.eclipse.swt.events.MouseEvent;
  30 
  31 import java.lang.reflect.Method;
  32 
  33 //import com.sun.glass.events.KeyEvent;
  34 import com.sun.javafx.embed.AbstractEvents;
  35 import org.eclipse.swt.widgets.Event;
  36 
  37 import java.lang.reflect.InvocationTargetException;
  38 
  39 /**
  40  * An utility class to translate event types between embedded
  41  * application and SWT.
  42  *
  43  */
  44 class SWTEvents {
  45 
  46 /*
  47     static int mouseIDToEmbedMouseType(int id) {
  48         switch (id) {
  49             case MouseEvent.MOUSE_PRESSED:


  56                 return AbstractEvents.MOUSEEVENT_MOVED;
  57             case MouseEvent.MOUSE_DRAGGED:
  58                 return AbstractEvents.MOUSEEVENT_DRAGGED;
  59             case MouseEvent.MOUSE_ENTERED:
  60                 return AbstractEvents.MOUSEEVENT_ENTERED;
  61             case MouseEvent.MOUSE_EXITED:
  62                 return AbstractEvents.MOUSEEVENT_EXITED;
  63         }
  64         return 0;
  65     }
  66 */
  67     static int mouseButtonToEmbedMouseButton(int button, int extModifiers) {
  68         switch (button) {
  69             case 1: return AbstractEvents.MOUSEEVENT_PRIMARY_BUTTON;
  70             case 2: return AbstractEvents.MOUSEEVENT_MIDDLE_BUTTON;
  71             case 3: return AbstractEvents.MOUSEEVENT_SECONDARY_BUTTON;
  72         }
  73         return AbstractEvents.MOUSEEVENT_NONE_BUTTON;
  74     }
  75 
  76     static int getWheelRotation(Event e) {
  77         int divisor = 1;
  78         if ("win32".equals(SWT.getPlatform())) {
  79             int [] linesToScroll = new int [1];
  80             //OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, linesToScroll, 0);
  81             try {
  82                 Class clazz = Class.forName("org.eclipse.swt.internal.win32.OS");
  83                 Method method = clazz.getDeclaredMethod("SystemParametersInfo", new Class []{int.class, int.class, int [].class, int.class});
  84                 method.invoke(clazz, 104 /*SPI_GETWHEELSCROLLLINES*/, 0, linesToScroll, 0);
  85             } catch (IllegalAccessException iae) {
  86             } catch (InvocationTargetException ite) {
  87             } catch (NoSuchMethodException nme) {
  88             } catch (ClassNotFoundException cfe) {
  89                 //Fail silently
  90             }
  91             if (linesToScroll [0] != -1 /*OS.WHEEL_PAGESCROLL*/) {
  92                 divisor = linesToScroll [0];
  93             }
  94         } else {
  95             if ("gtk".equals(SWT.getPlatform())) {
  96                 divisor = 3;
  97             }


  98         }
  99         return -e.count / Math.max(1, divisor);
 100     }
 101 
 102     static int keyIDToEmbedKeyType(int id) {
 103         switch (id) {
 104             case SWT.KeyDown:
 105                 return AbstractEvents.KEYEVENT_PRESSED;
 106             case SWT.KeyUp:
 107                 return AbstractEvents.KEYEVENT_RELEASED;
 108 //            case KeyEvent.KEY_TYPED:
 109 //                return AbstractEvents.KEYEVENT_TYPED;
 110         }
 111         return 0;
 112     }
 113 
 114     static final int [] [] KeyTable = {
 115 
 116         {0x0 /*KeyEvent.VK_UNDEFINED*/,     SWT.NULL},
 117 
 118         // SWT only
 119         {'\n' /*KeyEvent.VK_?????*/,         SWT.CR},




   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 javafx.embed.swt;
  27 
  28 import org.eclipse.swt.SWT;
  29 //import org.eclipse.swt.events.MouseEvent;
  30 
  31 import java.lang.reflect.Method;
  32 
  33 //import com.sun.glass.events.KeyEvent;
  34 import com.sun.javafx.embed.AbstractEvents;
  35 import org.eclipse.swt.widgets.Event;
  36 
  37 import java.lang.reflect.InvocationTargetException;
  38 
  39 /**
  40  * An utility class to translate event types between embedded
  41  * application and SWT.
  42  *
  43  */
  44 class SWTEvents {
  45 
  46 /*
  47     static int mouseIDToEmbedMouseType(int id) {
  48         switch (id) {
  49             case MouseEvent.MOUSE_PRESSED:


  56                 return AbstractEvents.MOUSEEVENT_MOVED;
  57             case MouseEvent.MOUSE_DRAGGED:
  58                 return AbstractEvents.MOUSEEVENT_DRAGGED;
  59             case MouseEvent.MOUSE_ENTERED:
  60                 return AbstractEvents.MOUSEEVENT_ENTERED;
  61             case MouseEvent.MOUSE_EXITED:
  62                 return AbstractEvents.MOUSEEVENT_EXITED;
  63         }
  64         return 0;
  65     }
  66 */
  67     static int mouseButtonToEmbedMouseButton(int button, int extModifiers) {
  68         switch (button) {
  69             case 1: return AbstractEvents.MOUSEEVENT_PRIMARY_BUTTON;
  70             case 2: return AbstractEvents.MOUSEEVENT_MIDDLE_BUTTON;
  71             case 3: return AbstractEvents.MOUSEEVENT_SECONDARY_BUTTON;
  72         }
  73         return AbstractEvents.MOUSEEVENT_NONE_BUTTON;
  74     }
  75 
  76     static double getWheelRotation(Event e) {
  77         int divisor = 1;
  78         if ("win32".equals(SWT.getPlatform()) && e.type == SWT.MouseVerticalWheel) {
  79             int [] linesToScroll = new int [1];
  80             //OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, linesToScroll, 0);
  81             try {
  82                 Class clazz = Class.forName("org.eclipse.swt.internal.win32.OS");
  83                 Method method = clazz.getDeclaredMethod("SystemParametersInfo", new Class []{int.class, int.class, int [].class, int.class});
  84                 method.invoke(clazz, 104 /*SPI_GETWHEELSCROLLLINES*/, 0, linesToScroll, 0);
  85             } catch (IllegalAccessException iae) {
  86             } catch (InvocationTargetException ite) {
  87             } catch (NoSuchMethodException nme) {
  88             } catch (ClassNotFoundException cfe) {
  89                 //Fail silently
  90             }
  91             if (linesToScroll [0] != -1 /*OS.WHEEL_PAGESCROLL*/) {
  92                 divisor = linesToScroll [0];
  93             }
  94         } else if ("gtk".equals(SWT.getPlatform())) {

  95             divisor = 3;
  96         }
  97         else if ("cocoa".equals(SWT.getPlatform())) {
  98             divisor = Math.abs(e.count);
  99         }
 100         return e.count / (double) Math.max(1, divisor);
 101     }
 102 
 103     static int keyIDToEmbedKeyType(int id) {
 104         switch (id) {
 105             case SWT.KeyDown:
 106                 return AbstractEvents.KEYEVENT_PRESSED;
 107             case SWT.KeyUp:
 108                 return AbstractEvents.KEYEVENT_RELEASED;
 109 //            case KeyEvent.KEY_TYPED:
 110 //                return AbstractEvents.KEYEVENT_TYPED;
 111         }
 112         return 0;
 113     }
 114 
 115     static final int [] [] KeyTable = {
 116 
 117         {0x0 /*KeyEvent.VK_UNDEFINED*/,     SWT.NULL},
 118 
 119         // SWT only
 120         {'\n' /*KeyEvent.VK_?????*/,         SWT.CR},


< prev index next >