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

The following examples show how to use java.awt.event.MouseEvent#BUTTON2 . 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
Source Project: javase   File: Interactive_v2.java    License: 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 2
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
/**
 * 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 Project: jdk8u60   File: XToolkit.java    License: 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 5
Source Project: javase   File: Interactive.java    License: 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 6
Source Project: java-swing-tips   File: MainPanel.java    License: 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 7
/**
 * 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 8
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 9
/**
 * 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;
}
 
Example 10
Source Project: netbeans   File: Utils.java    License: 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 11
/**
 * {@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 12
@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 13
Source Project: netbeans   File: VMDNodeWidget.java    License: 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 14
@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 15
@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
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 17
@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 Project: marathonv5   File: EventQueueDevice.java    License: 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 19
Source Project: workcraft   File: DockableWindow.java    License: 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 20
Source Project: mochadoom   File: event_t.java    License: 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;
}