Java Code Examples for java.awt.event.MouseEvent#NOBUTTON

The following examples show how to use java.awt.event.MouseEvent#NOBUTTON . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
Example 2
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
Example 3
Source Project: SIMVA-SoS   File: SWTUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates an AWT <code>MouseEvent</code> from a swt event.
 * This method helps passing SWT mouse event to awt components.
 * @param event The swt event.
 * @return A AWT mouse event based on the given SWT event.
 */
public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) {
    int button = MouseEvent.NOBUTTON;
    switch (event.button) {
    case 1: button = MouseEvent.BUTTON1; break;
    case 2: button = MouseEvent.BUTTON2; break;
    case 3: button = MouseEvent.BUTTON3; break;
    }
    int modifiers = 0;
    if ((event.stateMask & SWT.CTRL) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((event.stateMask & SWT.SHIFT) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((event.stateMask & SWT.ALT) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(),
            event.time, modifiers, event.x, event.y, 1, false, button);
    return awtMouseEvent;
}
 
Example 4
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
Example 5
Source Project: jdk8u60   File: bug7170657.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
Example 6
Source Project: astor   File: SWTUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an AWT <code>MouseEvent</code> from a swt event.
 * This method helps passing SWT mouse event to awt components.
 * @param event The swt event.
 * @return A AWT mouse event based on the given SWT event.
 */
public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) {
    int button = MouseEvent.NOBUTTON;
    switch (event.button) {
    case 1: button = MouseEvent.BUTTON1; break;
    case 2: button = MouseEvent.BUTTON2; break;
    case 3: button = MouseEvent.BUTTON3; break;
    }
    int modifiers = 0;
    if ((event.stateMask & SWT.CTRL) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((event.stateMask & SWT.SHIFT) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((event.stateMask & SWT.ALT) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(),
            event.time, modifiers, event.x, event.y, 1, false, button);
    return awtMouseEvent;
}
 
Example 7
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
Example 8
/**
 * Handles mouse events.
 */
void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
                      int clickCount, int x, int y, int absoluteX,
                      int absoluteY) {
    final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
    if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
            || buttonNumber > tk.getNumberOfButtons() - 1) {
        return;
    }

    int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
                                       NSEvent.nsToJavaEventType(eventType);

    int jbuttonNumber = MouseEvent.NOBUTTON;
    int jclickCount = 0;

    if (jeventType != MouseEvent.MOUSE_MOVED &&
        jeventType != MouseEvent.MOUSE_ENTERED &&
        jeventType != MouseEvent.MOUSE_EXITED)
    {
        jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
        jclickCount = clickCount;
    }

    int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                    modifierFlags);
    boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);

    eventNotifier.notifyMouseEvent(jeventType, System.currentTimeMillis(), jbuttonNumber,
            x, y, absoluteX, absoluteY, jmodifiers, jclickCount,
            jpopupTrigger, null);
}
 
Example 9
/**
 * Handles mouse events.
 */
void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
                      int clickCount, int x, int y, int absoluteX,
                      int absoluteY) {
    final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
    if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
            || buttonNumber > tk.getNumberOfButtons() - 1) {
        return;
    }

    int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
                                       NSEvent.nsToJavaEventType(eventType);

    int jbuttonNumber = MouseEvent.NOBUTTON;
    int jclickCount = 0;

    if (jeventType != MouseEvent.MOUSE_MOVED &&
        jeventType != MouseEvent.MOUSE_ENTERED &&
        jeventType != MouseEvent.MOUSE_EXITED)
    {
        jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
        jclickCount = clickCount;
    }

    int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                    modifierFlags);
    boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);

    eventNotifier.notifyMouseEvent(jeventType, System.currentTimeMillis(), jbuttonNumber,
            x, y, absoluteX, absoluteY, jmodifiers, jclickCount,
            jpopupTrigger, null);
}
 
Example 10
public SunDropTargetEvent(Component source, int id, int x, int y,
                          SunDropTargetContextPeer.EventDispatcher d) {
    super(source, id, System.currentTimeMillis(), 0, x, y, 0, 0, 0,
          false,  MouseEvent.NOBUTTON);
    dispatcher = d;
    dispatcher.registerEvent(this);
}
 
Example 11
public SunDropTargetEvent(Component source, int id, int x, int y,
                          SunDropTargetContextPeer.EventDispatcher d) {
    super(source, id, System.currentTimeMillis(), 0, x, y, 0, 0, 0,
          false,  MouseEvent.NOBUTTON);
    dispatcher = d;
    dispatcher.registerEvent(this);
}
 
Example 12
public SunDropTargetEvent(Component source, int id, int x, int y,
                          SunDropTargetContextPeer.EventDispatcher d) {
    super(source, id, System.currentTimeMillis(), 0, x, y, 0, 0, 0,
          false,  MouseEvent.NOBUTTON);
    dispatcher = d;
    dispatcher.registerEvent(this);
}
 
Example 13
/**
 * Handles mouse events.
 */
void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
                      int clickCount, int x, int y, int absoluteX,
                      int absoluteY) {
    final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
    if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
            || buttonNumber > tk.getNumberOfButtons() - 1) {
        return;
    }

    int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
                                       NSEvent.nsToJavaEventType(eventType);

    int jbuttonNumber = MouseEvent.NOBUTTON;
    int jclickCount = 0;

    if (jeventType != MouseEvent.MOUSE_MOVED &&
        jeventType != MouseEvent.MOUSE_ENTERED &&
        jeventType != MouseEvent.MOUSE_EXITED)
    {
        jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
        jclickCount = clickCount;
    }

    int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                    modifierFlags);
    boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);

    eventNotifier.notifyMouseEvent(jeventType, System.currentTimeMillis(), jbuttonNumber,
            x, y, absoluteX, absoluteY, jmodifiers, jclickCount,
            jpopupTrigger, null);
}
 
Example 14
/**
 * Handles mouse events.
 */
void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
                      int clickCount, int x, int y, int absoluteX,
                      int absoluteY) {
    final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
    if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
            || buttonNumber > tk.getNumberOfButtons() - 1) {
        return;
    }

    int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
                                       NSEvent.nsToJavaEventType(eventType);

    int jbuttonNumber = MouseEvent.NOBUTTON;
    int jclickCount = 0;

    if (jeventType != MouseEvent.MOUSE_MOVED &&
        jeventType != MouseEvent.MOUSE_ENTERED &&
        jeventType != MouseEvent.MOUSE_EXITED)
    {
        jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
        jclickCount = clickCount;
    }

    int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                    modifierFlags);
    boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);

    eventNotifier.notifyMouseEvent(jeventType, System.currentTimeMillis(), jbuttonNumber,
            x, y, absoluteX, absoluteY, jmodifiers, jclickCount,
            jpopupTrigger, null);
}
 
Example 15
public SunDropTargetEvent(Component source, int id, int x, int y,
                          SunDropTargetContextPeer.EventDispatcher d) {
    super(source, id, System.currentTimeMillis(), 0, x, y, 0, 0, 0,
          false,  MouseEvent.NOBUTTON);
    dispatcher = d;
    dispatcher.registerEvent(this);
}
 
Example 16
/**
 * Handles mouse events.
 */
void handleMouseEvent(int eventType, int modifierFlags, int buttonNumber,
                      int clickCount, int x, int y, int absX, int absY) {
    final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
    if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
            || buttonNumber > tk.getNumberOfButtons() - 1) {
        return;
    }

    int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
                                       NSEvent.nsToJavaEventType(eventType);

    int jbuttonNumber = MouseEvent.NOBUTTON;
    int jclickCount = 0;

    if (jeventType != MouseEvent.MOUSE_MOVED &&
        jeventType != MouseEvent.MOUSE_ENTERED &&
        jeventType != MouseEvent.MOUSE_EXITED)
    {
        jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
        jclickCount = clickCount;
    }

    int jmodifiers = NSEvent.nsToJavaModifiers(modifierFlags);
    boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);

    eventNotifier.notifyMouseEvent(jeventType, System.currentTimeMillis(), jbuttonNumber,
            x, y, absX, absY, jmodifiers, jclickCount,
            jpopupTrigger, null);
}
 
Example 17
/**
 * Handles mouse events.
 */
void handleMouseEvent(PlatformWindow platformWindow, int eventType, int modifierFlags, int buttonNumber,
                      int clickCount, int x, int y, int absoluteX,
                      int absoluteY) {
    final SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
    if ((buttonNumber > 2 && !tk.areExtraMouseButtonsEnabled())
            || buttonNumber > tk.getNumberOfButtons() - 1) {
        return;
    }

    int jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
                                       NSEvent.nsToJavaEventType(eventType);

    boolean dragged = jeventType == MouseEvent.MOUSE_DRAGGED;
    if (dragged  // ignore dragged event that does not change any location
            && lastDraggedAbsoluteX == absoluteX && lastDraggedRelativeX == x
            && lastDraggedAbsoluteY == absoluteY && lastDraggedRelativeY == y) return;

    if (dragged || jeventType == MouseEvent.MOUSE_PRESSED) {
        lastDraggedAbsoluteX = absoluteX;
        lastDraggedAbsoluteY = absoluteY;
        lastDraggedRelativeX = x;
        lastDraggedRelativeY = y;
    }

    int jbuttonNumber = MouseEvent.NOBUTTON;
    int jclickCount = 0;

    if (jeventType != MouseEvent.MOUSE_MOVED &&
        jeventType != MouseEvent.MOUSE_ENTERED &&
        jeventType != MouseEvent.MOUSE_EXITED)
    {
        jbuttonNumber = NSEvent.nsToJavaButton(buttonNumber);
        jclickCount = clickCount;
    }

    int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                    modifierFlags);
    boolean jpopupTrigger = NSEvent.isPopupTrigger(jmodifiers);

    eventNotifier.notifyMouseEvent(platformWindow, jeventType, System.currentTimeMillis(), jbuttonNumber,
            x, y, absoluteX, absoluteY, jmodifiers, jclickCount,
            jpopupTrigger, null);
}
 
Example 18
/**
 * Constructs a MenuDragMouseEvent object.
 * <p>Even if inconsistent values for relative and absolute coordinates are
 * passed to the constructor, the MenuDragMouseEvent instance is still
 * created.
 * @param source        the Component that originated the event
 *                      (typically <code>this</code>)
 * @param id            an int specifying the type of event, as defined
 *                      in {@link java.awt.event.MouseEvent}
 * @param when          a long identifying the time the event occurred
 * @param modifiers     an int specifying any modifier keys held down,
 *                      as specified in {@link java.awt.event.InputEvent}
 * @param x             an int specifying the horizontal position at which
 *                      the event occurred, in pixels
 * @param y             an int specifying the vertical position at which
 *                      the event occurred, in pixels
 * @param xAbs          an int specifying the horizontal absolute position at which
 *                      the event occurred, in pixels
 * @param yAbs          an int specifying the vertical absolute position at which
 *                      the event occurred, in pixels
 * @param clickCount    an int specifying the number of mouse-clicks
 * @param popupTrigger  a boolean -- true if the event {should?/did?}
 *                      trigger a popup
 * @param p             an array of MenuElement objects specifying a path
 *                        to a menu item affected by the drag
 * @param m             a MenuSelectionManager object that handles selections
 * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
 * @since 1.6
 */
public MenuDragMouseEvent(Component source, int id, long when,
                          int modifiers, int x, int y, int xAbs,
                          int yAbs, int clickCount,
                          boolean popupTrigger, MenuElement p[],
                          MenuSelectionManager m) {
    super(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount,
          popupTrigger, MouseEvent.NOBUTTON);
    path = p;
    manager = m;
}
 
Example 19
/**
 * Constructs a MenuDragMouseEvent object.
 * <p>Even if inconsistent values for relative and absolute coordinates are
 * passed to the constructor, the MenuDragMouseEvent instance is still
 * created.
 * @param source        the Component that originated the event
 *                      (typically <code>this</code>)
 * @param id            an int specifying the type of event, as defined
 *                      in {@link java.awt.event.MouseEvent}
 * @param when          a long identifying the time the event occurred
 * @param modifiers     an int specifying any modifier keys held down,
 *                      as specified in {@link java.awt.event.InputEvent}
 * @param x             an int specifying the horizontal position at which
 *                      the event occurred, in pixels
 * @param y             an int specifying the vertical position at which
 *                      the event occurred, in pixels
 * @param xAbs          an int specifying the horizontal absolute position at which
 *                      the event occurred, in pixels
 * @param yAbs          an int specifying the vertical absolute position at which
 *                      the event occurred, in pixels
 * @param clickCount    an int specifying the number of mouse-clicks
 * @param popupTrigger  a boolean -- true if the event {should?/did?}
 *                      trigger a popup
 * @param p             an array of MenuElement objects specifying a path
 *                        to a menu item affected by the drag
 * @param m             a MenuSelectionManager object that handles selections
 * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
 * @since 1.6
 */
public MenuDragMouseEvent(Component source, int id, long when,
                          int modifiers, int x, int y, int xAbs,
                          int yAbs, int clickCount,
                          boolean popupTrigger, MenuElement p[],
                          MenuSelectionManager m) {
    super(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount,
          popupTrigger, MouseEvent.NOBUTTON);
    path = p;
    manager = m;
}
 
Example 20
/**
 * Constructs a MenuDragMouseEvent object.
 * <p>Even if inconsistent values for relative and absolute coordinates are
 * passed to the constructor, the MenuDragMouseEvent instance is still
 * created.
 * @param source        the Component that originated the event
 *                      (typically <code>this</code>)
 * @param id            an int specifying the type of event, as defined
 *                      in {@link java.awt.event.MouseEvent}
 * @param when          a long identifying the time the event occurred
 * @param modifiers     an int specifying any modifier keys held down,
 *                      as specified in {@link java.awt.event.InputEvent}
 * @param x             an int specifying the horizontal position at which
 *                      the event occurred, in pixels
 * @param y             an int specifying the vertical position at which
 *                      the event occurred, in pixels
 * @param xAbs          an int specifying the horizontal absolute position at which
 *                      the event occurred, in pixels
 * @param yAbs          an int specifying the vertical absolute position at which
 *                      the event occurred, in pixels
 * @param clickCount    an int specifying the number of mouse-clicks
 * @param popupTrigger  a boolean -- true if the event {should?/did?}
 *                      trigger a popup
 * @param p             an array of MenuElement objects specifying a path
 *                        to a menu item affected by the drag
 * @param m             a MenuSelectionManager object that handles selections
 * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
 * @since 1.6
 */
public MenuDragMouseEvent(Component source, int id, long when,
                          int modifiers, int x, int y, int xAbs,
                          int yAbs, int clickCount,
                          boolean popupTrigger, MenuElement p[],
                          MenuSelectionManager m) {
    super(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount,
          popupTrigger, MouseEvent.NOBUTTON);
    path = p;
    manager = m;
}