0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/Aimport java.awt.Toolkit;
0N/Aimport java.awt.Component;
0N/A
0N/Aimport java.awt.Point;
0N/Aimport java.awt.dnd.DnDConstants;
0N/Aimport java.awt.dnd.DragSource;
0N/Aimport java.awt.dnd.MouseDragGestureRecognizer;
0N/Aimport java.awt.dnd.DragGestureListener;
0N/A
0N/Aimport java.awt.event.InputEvent;
0N/Aimport java.awt.event.MouseEvent;
0N/Aimport java.awt.event.MouseListener;
0N/Aimport java.awt.event.MouseMotionListener;
0N/A
0N/Aimport java.lang.reflect.*;
0N/A
0N/Aimport sun.awt.dnd.SunDragSourceContextPeer;
0N/A
0N/A/**
0N/A * <p>
0N/A * This subclass of MouseDragGestureRecognizer defines a DragGestureRecognizer
0N/A * for Mouse based gestures on OSF/Motif.
0N/A * </p>
0N/A *
0N/A * @author Laurence P. G. Cable
0N/A *
0N/A * @see java.awt.dnd.DragGestureListener
0N/A * @see java.awt.dnd.DragGestureEvent
0N/A * @see java.awt.dnd.DragSource
0N/A */
0N/A
0N/Aclass XMouseDragGestureRecognizer extends MouseDragGestureRecognizer {
0N/A
0N/A private static final long serialVersionUID = -841711780352520383L;
0N/A
0N/A /*
0N/A * constant for number of pixels hysterisis before drag is determined
0N/A * to have started
0N/A */
0N/A
0N/A protected static int motionThreshold;
0N/A
0N/A
0N/A protected static final int ButtonMask = InputEvent.BUTTON1_DOWN_MASK |
0N/A InputEvent.BUTTON2_DOWN_MASK |
0N/A InputEvent.BUTTON3_DOWN_MASK;
0N/A
0N/A /**
0N/A * construct a new XMouseDragGestureRecognizer
0N/A *
0N/A * @param ds The DragSource for the Component c
0N/A * @param c The Component to observe
0N/A * @param act The actions permitted for this Drag
0N/A * @param dgl The DragGestureRecognizer to notify when a gesture is detected
0N/A *
0N/A */
0N/A
0N/A protected XMouseDragGestureRecognizer(DragSource ds, Component c, int act, DragGestureListener dgl) {
0N/A super(ds, c, act, dgl);
0N/A }
0N/A
0N/A /**
0N/A * construct a new XMouseDragGestureRecognizer
0N/A *
0N/A * @param ds The DragSource for the Component c
0N/A * @param c The Component to observe
0N/A * @param act The actions permitted for this Drag
0N/A */
0N/A
0N/A protected XMouseDragGestureRecognizer(DragSource ds, Component c, int act) {
0N/A this(ds, c, act, null);
0N/A }
0N/A
0N/A /**
0N/A * construct a new XMouseDragGestureRecognizer
0N/A *
0N/A * @param ds The DragSource for the Component c
0N/A * @param c The Component to observe
0N/A */
0N/A
0N/A protected XMouseDragGestureRecognizer(DragSource ds, Component c) {
0N/A this(ds, c, DnDConstants.ACTION_NONE);
0N/A }
0N/A
0N/A /**
0N/A * construct a new XMouseDragGestureRecognizer
0N/A *
0N/A * @param ds The DragSource for the Component c
0N/A */
0N/A
0N/A protected XMouseDragGestureRecognizer(DragSource ds) {
0N/A this(ds, null);
0N/A }
0N/A
0N/A /**
0N/A * determine the drop action from the event
0N/A */
0N/A
0N/A protected int mapDragOperationFromModifiers(MouseEvent e) {
0N/A int mods = e.getModifiersEx();
0N/A int btns = mods & ButtonMask;
0N/A
0N/A // Do not allow right mouse button drag since Motif DnD does not
0N/A // terminate drag operation on right mouse button release.
0N/A if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
0N/A btns == InputEvent.BUTTON2_DOWN_MASK)) {
0N/A return DnDConstants.ACTION_NONE;
0N/A }
0N/A
0N/A return
0N/A SunDragSourceContextPeer.convertModifiersToDropAction(mods,
0N/A getSourceActions());
0N/A }
0N/A
0N/A /**
0N/A * Invoked when the mouse has been clicked on a component.
0N/A */
0N/A
0N/A public void mouseClicked(MouseEvent e) {
0N/A // do nothing
0N/A }
0N/A
0N/A /**
0N/A * Invoked when a mouse button has been pressed on a component.
0N/A */
0N/A
0N/A public void mousePressed(MouseEvent e) {
0N/A events.clear();
0N/A
0N/A if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
0N/A try {
0N/A motionThreshold = DragSource.getDragThreshold();
0N/A } catch (Exception exc) {
0N/A motionThreshold = 5;
0N/A }
0N/A appendEvent(e);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Invoked when a mouse button has been released on a component.
0N/A */
0N/A
0N/A public void mouseReleased(MouseEvent e) {
0N/A events.clear();
0N/A }
0N/A
0N/A /**
0N/A * Invoked when the mouse enters a component.
0N/A */
0N/A
0N/A public void mouseEntered(MouseEvent e) {
0N/A events.clear();
0N/A }
0N/A
0N/A /**
0N/A * Invoked when the mouse exits a component.
0N/A */
0N/A
0N/A public void mouseExited(MouseEvent e) {
0N/A if (!events.isEmpty()) { // gesture pending
0N/A int dragAction = mapDragOperationFromModifiers(e);
0N/A
0N/A if (dragAction == DnDConstants.ACTION_NONE) {
0N/A events.clear();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Invoked when a mouse button is pressed on a component.
0N/A */
0N/A
0N/A public void mouseDragged(MouseEvent e) {
0N/A if (!events.isEmpty()) { // gesture pending
0N/A int dop = mapDragOperationFromModifiers(e);
0N/A
0N/A
0N/A if (dop == DnDConstants.ACTION_NONE) {
0N/A return;
0N/A }
0N/A
0N/A MouseEvent trigger = (MouseEvent)events.get(0);
0N/A
0N/A Point origin = trigger.getPoint();
0N/A Point current = e.getPoint();
0N/A
0N/A int dx = Math.abs(origin.x - current.x);
0N/A int dy = Math.abs(origin.y - current.y);
0N/A
0N/A if (dx > motionThreshold || dy > motionThreshold) {
0N/A fireDragGestureRecognized(dop, ((MouseEvent)getTriggerEvent()).getPoint());
0N/A } else
0N/A appendEvent(e);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Invoked when the mouse button has been moved on a component
0N/A * (with no buttons no down).
0N/A */
0N/A
0N/A public void mouseMoved(MouseEvent e) {
0N/A // do nothing
0N/A }
0N/A}