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

The following examples show how to use java.awt.event.MouseEvent#BUTTON2 . 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
Source File: SWTUtils.java    From SIMVA-SoS with 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 2
Source File: XToolkit.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static boolean isRightMouseButton(MouseEvent me) {
    int numButtons = ((Integer)getDefaultToolkit().getDesktopProperty("awt.mouse.numButtons")).intValue();
    switch (me.getID()) {
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
          return ((numButtons == 2 && me.getButton() == MouseEvent.BUTTON2) ||
                   (numButtons > 2 && me.getButton() == MouseEvent.BUTTON3));
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_DRAGGED:
          return ((numButtons == 2 && (me.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0) ||
                  (numButtons > 2 && (me.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0));
    }
    return false;
}
 
Example 3
Source File: SWTUtils.java    From ccu-historian with GNU General Public License v3.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
Source File: SWTUtils.java    From ECG-Viewer with 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 5
Source File: XToolkit.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static boolean isRightMouseButton(MouseEvent me) {
    int numButtons = ((Integer)getDefaultToolkit().getDesktopProperty("awt.mouse.numButtons")).intValue();
    switch (me.getID()) {
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
          return ((numButtons == 2 && me.getButton() == MouseEvent.BUTTON2) ||
                   (numButtons > 2 && me.getButton() == MouseEvent.BUTTON3));
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_DRAGGED:
          return ((numButtons == 2 && (me.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0) ||
                  (numButtons > 2 && (me.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0));
    }
    return false;
}
 
Example 6
Source File: Interactive_v2.java    From javase with MIT License 6 votes vote down vote up
public void onMousePressed(MouseEvent e) {
	if (e.getButton() == MouseEvent.BUTTON3) {
		// Button 3: fire power = 3 energy points, bullet color = red
		firePower = 3;
		setBulletColor(Color.RED);
	} else if (e.getButton() == MouseEvent.BUTTON2) {
		// Button 2: fire power = 2 energy points, bullet color = orange
		firePower = 2;
		setBulletColor(Color.ORANGE);
	} else {
		// Button 1 or unknown button:
		// fire power = 1 energy points, bullet color = yellow
		firePower = 1;
		setBulletColor(Color.YELLOW);
	}
}
 
Example 7
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override protected TrackListener createTrackListener() {
  return new TrackListener() {
    @Override public void mousePressed(MouseEvent e) {
      if (SwingUtilities.isLeftMouseButton(e)) {
        super.mousePressed(new MouseEvent(
            e.getComponent(), e.getID(), e.getWhen(),
            InputEvent.BUTTON2_DOWN_MASK ^ InputEvent.BUTTON2_MASK, // e.getModifiers(),
            e.getX(), e.getY(),
            e.getXOnScreen(), e.getYOnScreen(),
            e.getClickCount(),
            e.isPopupTrigger(),
            MouseEvent.BUTTON2));
      } else {
        super.mousePressed(e);
      }
    }
  };
}
 
Example 8
Source File: Interactive.java    From javase with MIT License 6 votes vote down vote up
public void onMousePressed(MouseEvent e) {
	if (e.getButton() == MouseEvent.BUTTON3) {
		// Button 3: fire power = 3 energy points, bullet color = red
		firePower = 3;
		setBulletColor(Color.RED);
	} else if (e.getButton() == MouseEvent.BUTTON2) {
		// Button 2: fire power = 2 energy points, bullet color = orange
		firePower = 2;
		setBulletColor(Color.ORANGE);
	} else {
		// Button 1 or unknown button:
		// fire power = 1 energy points, bullet color = yellow
		firePower = 1;
		setBulletColor(Color.YELLOW);
	}
}
 
Example 9
Source File: ExtendedPanAction.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public State mousePressed(Widget widget, WidgetMouseEvent event) {
    if (event.getButton() == MouseEvent.BUTTON2 || event.getButton() == MouseEvent.BUTTON1 && ((event.getModifiers() & MouseEvent.CTRL_MASK) != 0)) {
        scene = widget.getScene();
        scrollPane = findScrollPane(scene.getView());
        if (scrollPane != null) {
            lastLocation = scene.convertSceneToView(widget.convertLocalToScene(event.getPoint()));
            SwingUtilities.convertPointToScreen(lastLocation, scrollPane.getViewport().getView());
            return State.createLocked(widget, this);
        }
    }
    return State.REJECTED;
}
 
Example 10
Source File: event_t.java    From mochadoom with GNU General Public License v3.0 5 votes vote down vote up
static int mouseBits(int button) {
    switch(button) {
        case MouseEvent.BUTTON1:
            return MOUSE_LEFT;
        case MouseEvent.BUTTON2:
            return MOUSE_RIGHT;
        case MouseEvent.BUTTON3:
            return MOUSE_MID;
    }
    
    return 0;
}
 
Example 11
Source File: DockableWindow.java    From workcraft with MIT License 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON2) {
        MainWindow mainWindow = Framework.getInstance().getMainWindow();
        mainWindow.closeDockableWindow(DockableWindow.this);
    } else {
        for (DockableListener l : new ArrayList<>(dockableListeners)) {
            l.headerClicked(e.getButton());
        }
    }
}
 
Example 12
Source File: EventQueueDevice.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void storeMouseUp(int button) {
    if (button == MouseEvent.BUTTON1) {
        button1Pressed = false;
    }
    if (button == MouseEvent.BUTTON2) {
        button2Pressed = false;
    }
    if (button == MouseEvent.BUTTON3) {
        button3Pressed = false;
    }
}
 
Example 13
Source File: ExtendedPanAction.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public State mousePressed(Widget widget, WidgetMouseEvent event) {
    if (event.getButton() == MouseEvent.BUTTON2 || event.getButton() == MouseEvent.BUTTON1 && ((event.getModifiers() & MouseEvent.CTRL_MASK) != 0)) {
        scene = widget.getScene();
        scrollPane = findScrollPane(scene.getView());
        if (scrollPane != null) {
            lastLocation = scene.convertSceneToView(widget.convertLocalToScene(event.getPoint()));
            SwingUtilities.convertPointToScreen(lastLocation, scrollPane.getViewport().getView());
            return State.createLocked(widget, this);
        }
    }
    return State.REJECTED;
}
 
Example 14
Source File: DisplayablePanel.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public void mousePressed(final MouseEvent me) {
	if (display.isTransforming()) return;
	display.select(d, me.isShiftDown());
	if (me.isPopupTrigger() || (ij.IJ.isMacOSX() && me.isControlDown()) || MouseEvent.BUTTON2 == me.getButton() || 0 != (me.getModifiers() & Event.META_MASK)) {
		display.getPopupMenu().show(DisplayablePanel.this, me.getX(), me.getY());
	}
}
 
Example 15
Source File: ExtendedPanAction.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public State mousePressed(Widget widget, WidgetMouseEvent event) {
    if (event.getButton() == MouseEvent.BUTTON2 || event.getButton() == MouseEvent.BUTTON1 && ((event.getModifiers() & MouseEvent.CTRL_MASK) != 0)) {
        scene = widget.getScene();
        scrollPane = findScrollPane(scene.getView());
        if (scrollPane != null) {
            lastLocation = scene.convertSceneToView(widget.convertLocalToScene(event.getPoint()));
            SwingUtilities.convertPointToScreen(lastLocation, scrollPane.getViewport().getView());
            return State.createLocked(widget, this);
        }
    }
    return State.REJECTED;
}
 
Example 16
Source File: VMDNodeWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public State mousePressed (Widget widget, WidgetMouseEvent event) {
    if (event.getButton () == MouseEvent.BUTTON1 || event.getButton () == MouseEvent.BUTTON2) {
        stateModel.toggleBooleanState ();
        return State.CONSUMED;
    }
    return State.REJECTED;
}
 
Example 17
Source File: ExtendedPanAction.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public State mousePressed(Widget widget, WidgetMouseEvent event) {
    if (event.getButton() == MouseEvent.BUTTON2 || event.getButton() == MouseEvent.BUTTON1 && ((event.getModifiers() & MouseEvent.CTRL_MASK) != 0)) {
        scene = widget.getScene();
        scrollPane = findScrollPane(scene.getView());
        if (scrollPane != null) {
            lastLocation = scene.convertSceneToView(widget.convertLocalToScene(event.getPoint()));
            SwingUtilities.convertPointToScreen(lastLocation, scrollPane.getViewport().getView());
            return State.createLocked(widget, this);
        }
    }
    return State.REJECTED;
}
 
Example 18
Source File: CanvasMouseListener.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void mousePressed(MouseEvent e) {
    if (!e.getComponent().isEnabled()) return;

    if (e.isPopupTrigger()) {
        getGUI().showTilePopup(e.getX(), e.getY());
        return;
    }

    switch (e.getButton()) {
    case MouseEvent.BUTTON1: 
        // If we have GoTo mode enabled then GoTo takes precedence
        if (getGUI().isGotoStarted()) {
            getGUI().performGoto(e.getX(), e.getY());
            break;
        }

        // Drag and selection
        // Enable dragging with button 1
        // @see CanvasMouseMotionListener#mouseDragged
        getGUI().prepareDrag(e.getX(), e.getY());
        break;
    case MouseEvent.BUTTON2: // Immediate goto
        getGUI().performGoto(e.getX(), e.getY());
        break;
    case MouseEvent.BUTTON3: // Immediate tile popup
        getGUI().showTilePopup(e.getX(), e.getY());
        break;
    default:
        break;
    }
}
 
Example 19
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public State mousePressed(Widget widget, WidgetMouseEvent event) {
    if (event.getClickCount() == 1) {
        if (event.getButton() == MouseEvent.BUTTON1 || event.getButton() == MouseEvent.BUTTON2) {
            addNode("node" + nodeCounter++).setPreferredLocation(widget.convertLocalToScene(event.getPoint()));
            return State.CONSUMED;
        }
    }
    return State.REJECTED;
}
 
Example 20
Source File: ChartGesture.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * returns the BUTTON for a MouseEvent.BUTTON
 * 
 * @param mouseeventbutton
 * @return
 */
public static GestureButton getButton(int mouseeventbutton) {
  switch (mouseeventbutton) {
    case MouseEvent.BUTTON1:
      return BUTTON1;
    case MouseEvent.BUTTON2:
      return BUTTON2;
    case MouseEvent.BUTTON3:
      return BUTTON3;
  }
  return null;
}