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

The following examples show how to use java.awt.event.MouseEvent#MOUSE_DRAGGED . 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: XToolkit.java    From hottub 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 2
Source File: XToolkit.java    From jdk8u-dev-jdk 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: XToolkit.java    From jdk8u-jdk 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 4
Source File: Splitter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void processMouseMotionEvent(MouseEvent e) {
  super.processMouseMotionEvent(e);
  if (!myResizeEnabled) return;
  if (MouseEvent.MOUSE_DRAGGED == e.getID()) {
    myPoint = SwingUtilities.convertPoint(this, e.getPoint(), Splitter.this);
    float proportion;
    if (isVertical()) {
      if (getHeight() > 0) {
        proportion = MathUtil.clamp(MathUtil.clamp((float)myPoint.y / (float)Splitter.this.getHeight(), getMinProportion(true), 1 - getMinProportion(false)), .0f, 1.0f);
        setProportion(proportion);
      }
    }
    else {
      if (getWidth() > 0) {
        proportion = MathUtil.clamp(MathUtil.clamp((float)myPoint.x / (float)Splitter.this.getWidth(), getMinProportion(true), 1 - getMinProportion(false)), .0f, 1.0f);
        setProportion(proportion);
      }
    }
  }
}
 
Example 5
Source File: XToolkit.java    From dragonwell8_jdk 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: OnePixelDivider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void processMouseMotionEvent(MouseEvent e) {
  super.processMouseMotionEvent(e);
  if (!myResizeEnabled) return;
  if (MouseEvent.MOUSE_DRAGGED == e.getID() && myDragging) {
    myPoint = SwingUtilities.convertPoint(this, e.getPoint(), mySplitter.asComponent());
    float proportion;
    final float firstMinProportion = mySplitter.getMinProportion(true);
    final float secondMinProportion = mySplitter.getMinProportion(false);
    if (isVertical()) {
      if (getHeight() > 0) {
        proportion = Math.min(1.0f, Math
                .max(.0f, Math.min(Math.max(firstMinProportion, (float)myPoint.y / (float)mySplitter.asComponent().getHeight()), 1 - secondMinProportion)));
        mySplitter.setProportion(proportion);
      }
    }
    else {
      if (getWidth() > 0) {
        proportion = Math.min(1.0f, Math.max(.0f, Math.min(
                Math.max(firstMinProportion, (float)myPoint.x / (float)mySplitter.asComponent().getWidth()), 1 - secondMinProportion)));
        mySplitter.setProportion(proportion);
      }
    }
    e.consume();
  }
}
 
Example 7
Source File: XToolkit.java    From TencentKona-8 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 8
Source File: bug7146377.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static String eventToString(MouseEvent e) {
    StringBuilder result = new StringBuilder();

    switch (e.getID()) {
        case MouseEvent.MOUSE_PRESSED:
            result.append("MOUSE_PRESSED");
            break;
        case MouseEvent.MOUSE_RELEASED:
            result.append("MOUSE_RELEASED");
            break;
        case MouseEvent.MOUSE_CLICKED:
            result.append("MOUSE_CLICKED");
            break;
        case MouseEvent.MOUSE_ENTERED:
            result.append("MOUSE_ENTERED");
            break;
        case MouseEvent.MOUSE_EXITED:
            result.append("MOUSE_EXITED");
            break;
        case MouseEvent.MOUSE_MOVED:
            result.append("MOUSE_MOVED");
            break;
        case MouseEvent.MOUSE_DRAGGED:
            result.append("MOUSE_DRAGGED");
            break;
        case MouseEvent.MOUSE_WHEEL:
            result.append("MOUSE_WHEEL");
            break;
        default:
            result.append("unknown type");
    }

    result.append(", modifiers = " + MouseEvent.getMouseModifiersText(e.getModifiers()));
    result.append(", modifiersEx = " + MouseEvent.getMouseModifiersText(e.getModifiersEx()));
    result.append(", button = " + e.getButton());

    return result.toString();
}
 
Example 9
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override protected void processMouseMotionEvent(MouseEvent e, JLayer<? extends JScrollPane> l) {
  int id = e.getID();
  Component c = e.getComponent();
  if (c instanceof JTableHeader && id == MouseEvent.MOUSE_DRAGGED && SwingUtilities.isRightMouseButton(e)) {
    e.consume();
  }
}
 
Example 10
Source File: XToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static boolean isLeftMouseButton(MouseEvent me) {
    switch (me.getID()) {
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
          return (me.getButton() == MouseEvent.BUTTON1);
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_DRAGGED:
          return ((me.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0);
    }
    return false;
}
 
Example 11
Source File: XTextFieldPeer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleJavaMouseEvent( MouseEvent mouseEvent ) {
    super.handleJavaMouseEvent(mouseEvent);
    if (xtext != null)  {
        mouseEvent.setSource(xtext);
        int id = mouseEvent.getID();
        if (id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED)
            xtext.processMouseMotionEventImpl(mouseEvent);
        else
            xtext.processMouseEventImpl(mouseEvent);
    }
}
 
Example 12
Source File: XToolkit.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static boolean isLeftMouseButton(MouseEvent me) {
    switch (me.getID()) {
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
          return (me.getButton() == MouseEvent.BUTTON1);
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_DRAGGED:
          return ((me.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0);
    }
    return false;
}
 
Example 13
Source File: IdeGlassPaneImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void fireMouseMotion(MouseMotionListener listener, final MouseEvent event) {
  switch (event.getID()) {
    case MouseEvent.MOUSE_DRAGGED:
      listener.mouseDragged(event);
    case MouseEvent.MOUSE_MOVED:
      listener.mouseMoved(event);
  }
}
 
Example 14
Source File: bug7146377.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String eventToString(MouseEvent e) {
    StringBuilder result = new StringBuilder();

    switch (e.getID()) {
        case MouseEvent.MOUSE_PRESSED:
            result.append("MOUSE_PRESSED");
            break;
        case MouseEvent.MOUSE_RELEASED:
            result.append("MOUSE_RELEASED");
            break;
        case MouseEvent.MOUSE_CLICKED:
            result.append("MOUSE_CLICKED");
            break;
        case MouseEvent.MOUSE_ENTERED:
            result.append("MOUSE_ENTERED");
            break;
        case MouseEvent.MOUSE_EXITED:
            result.append("MOUSE_EXITED");
            break;
        case MouseEvent.MOUSE_MOVED:
            result.append("MOUSE_MOVED");
            break;
        case MouseEvent.MOUSE_DRAGGED:
            result.append("MOUSE_DRAGGED");
            break;
        case MouseEvent.MOUSE_WHEEL:
            result.append("MOUSE_WHEEL");
            break;
        default:
            result.append("unknown type");
    }

    result.append(", modifiers = " + MouseEvent.getMouseModifiersText(e.getModifiers()));
    result.append(", modifiersEx = " + MouseEvent.getMouseModifiersText(e.getModifiersEx()));
    result.append(", button = " + e.getButton());

    return result.toString();
}
 
Example 15
Source File: XToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static boolean isLeftMouseButton(MouseEvent me) {
    switch (me.getID()) {
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
          return (me.getButton() == MouseEvent.BUTTON1);
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_DRAGGED:
          return ((me.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0);
    }
    return false;
}
 
Example 16
Source File: DarkTreeCellEditor.java    From darklaf with MIT License 5 votes vote down vote up
public DarkTreeCellEditor(final JSpinner spinner) {
    super(dummyCheckBox);
    editorComponent = spinner;
    editorComponent.putClientProperty(SpinnerConstants.KEY_IS_TREE_EDITOR, Boolean.TRUE);
    editorComponent.addFocusListener(this);
    setClickCountToStart(2);
    delegate = new EditorDelegate() {
        public Object getCellEditorValue() {
            return spinner.getValue();
        }

        public void setValue(final Object value) {
            try {
                SpinnerModel model = spinner.getModel();
                if (model instanceof SpinnerNumberModel) {
                    spinner.setValue(NumberFormat.getInstance().parse(value.toString()));
                } else if (model instanceof SpinnerDateModel) {
                    spinner.setValue(DateFormat.getInstance().parse(value.toString()));
                } else {
                    spinner.setValue(value);
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        public boolean shouldSelectCell(final EventObject anEvent) {
            if (anEvent instanceof MouseEvent) {
                MouseEvent e = (MouseEvent) anEvent;
                return e.getID() != MouseEvent.MOUSE_DRAGGED;
            }
            return true;
        }
    };
}
 
Example 17
Source File: UIMouse.java    From open-ig with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Create an UIMouse from a Mouse Event.
 * @param e the mouse event
 * @return the UI mouse
 */
public static UIMouse from(MouseEvent e) {
	UIMouse m = new UIMouse();
	m.x = e.getX();
	m.y = e.getY();
	if (SwingUtilities.isLeftMouseButton(e)) {
		m.buttons.add(Button.LEFT);
	}
	if (SwingUtilities.isMiddleMouseButton(e)) {
		m.buttons.add(Button.MIDDLE);
	}
	if (SwingUtilities.isRightMouseButton(e)) {
		m.buttons.add(Button.RIGHT);
	}
	if (e.isShiftDown()) {
		m.modifiers.add(Modifier.SHIFT);
	}
	if (e.isControlDown()) {
		m.modifiers.add(Modifier.CTRL);
	}
	if (e.isAltDown()) {
		m.modifiers.add(Modifier.ALT);
	}
	switch (e.getID()) {
	case MouseEvent.MOUSE_CLICKED:
		m.type = e.getClickCount() == 1 ? Type.CLICK : Type.DOUBLE_CLICK;
		m.z = e.getClickCount();
		break;
	case MouseEvent.MOUSE_PRESSED:
		m.type = Type.DOWN;
		break;
	case MouseEvent.MOUSE_RELEASED:
		m.type = Type.UP;
		break;
	case MouseEvent.MOUSE_MOVED:
		m.type = Type.MOVE;
		break;
	case MouseEvent.MOUSE_DRAGGED:
		m.type = Type.DRAG;
		break;
	case MouseEvent.MOUSE_ENTERED:
		m.type = Type.ENTER;
		break;
	case MouseEvent.MOUSE_EXITED:
		m.type = Type.LEAVE;
		break;
	case MouseEvent.MOUSE_WHEEL:
		m.type = Type.WHEEL;
		m.z = ((MouseWheelEvent)e).getUnitsToScroll();
		break;
	default:
	}
	
	return m;
}
 
Example 18
Source File: NativeEventsTest.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public void draggedGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_DRAGGED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");

    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override
        public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    tclear();
    System.err.println("============================");
    new Actions(driver).clickAndHold(b).moveToElement(b).release().perform();
    System.err.println("============================");
    AssertJUnit.assertEquals(expected, t.getText());
}
 
Example 19
Source File: IdeTooltipManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void eventDispatched(AWTEvent event) {
  if (!myIsEnabled.asBoolean()) return;

  MouseEvent me = (MouseEvent)event;
  myProcessingComponent = me.getComponent();
  try {
    if (me.getID() == MouseEvent.MOUSE_ENTERED) {
      boolean canShow = true;
      if (componentContextHasChanged(myProcessingComponent)) {
        canShow = hideCurrent(me, null, null);
      }
      if (canShow) {
        maybeShowFor(myProcessingComponent, me);
      }
    }
    else if (me.getID() == MouseEvent.MOUSE_EXITED) {
      //We hide tooltip (but not hint!) when it's shown over myComponent and mouse exits this component
      if (myProcessingComponent == myCurrentComponent && myCurrentTooltip != null && !myCurrentTooltip.isHint() && myCurrentTipUi != null) {
        myCurrentTipUi.setAnimationEnabled(false);
        hideCurrent(null, null, null, null, false);
      }
      else if (myProcessingComponent == myCurrentComponent || myProcessingComponent == myQueuedComponent) {
        hideCurrent(me, null, null);
      }
    }
    else if (me.getID() == MouseEvent.MOUSE_MOVED) {
      if (myProcessingComponent == myCurrentComponent || myProcessingComponent == myQueuedComponent) {
        if (myCurrentTipUi != null && myCurrentTipUi.wasFadedIn()) {
          maybeShowFor(myProcessingComponent, me);
        }
        else {
          if (!myCurrentTipIsCentered) {
            myX = me.getX();
            myY = me.getY();
            if (myProcessingComponent instanceof JComponent && !isTooltipDefined((JComponent)myProcessingComponent, me) && (myQueuedTooltip == null || !myQueuedTooltip.isHint())) {
              hideCurrent(me, null, null);//There is no tooltip or hint here, let's proceed it as MOUSE_EXITED
            }
            else {
              maybeShowFor(myProcessingComponent, me);
            }
          }
        }
      }
      else if (myCurrentComponent == null && myQueuedComponent == null) {
        maybeShowFor(myProcessingComponent, me);
      }
    }
    else if (me.getID() == MouseEvent.MOUSE_PRESSED) {
      boolean clickOnTooltip = myCurrentTipUi != null && myCurrentTipUi == JBPopupFactory.getInstance().getParentBalloonFor(myProcessingComponent);
      if (myProcessingComponent == myCurrentComponent || (clickOnTooltip && !myCurrentTipUi.isClickProcessor())) {
        hideCurrent(me, null, null, null, !clickOnTooltip);
      }
    }
    else if (me.getID() == MouseEvent.MOUSE_DRAGGED) {
      hideCurrent(me, null, null);
    }
  }
  finally {
    myProcessingComponent = null;
  }
}
 
Example 20
Source File: DoublePuzzle.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void processMouse(MouseEvent e) {
  ActiveBox bx1, bx2;
  Point p = e.getPoint();

  if (playing)
    switch (e.getID()) {
    case MouseEvent.MOUSE_PRESSED:
      ps.stopMedia(1);
      if (bc.active) {
        if (dragCells)
          bx1 = bc.getBox();
        else
          bx1 = bgA.findActiveBox(bc.origin);
        bc.end();
        bx2 = bgB.findActiveBox(p);
        if (bx1 != null && bx2 != null && bx2.isInactive()) {
          boolean ok = false;
          String src = bx1.getDescription() + " (" + bx1.idOrder + ")";
          String dest = "(" + bx2.idOrder + ")";
          if (bx1.getContent().isEquivalent(abc[0].getActiveBoxContent(bx2.idOrder), true)) {
            ok = true;
            bx1.exchangeContent(bx2);
            bx1.setVisible(false);
            if (useOrder)
              currentItem = bgA.getNextItem(currentItem);
          }
          int cellsAtPlace = bgA.countInactiveCells();
          ps.reportNewAction(DoublePuzzle.this, ACTION_PLACE, src, dest, ok, cellsAtPlace);
          if (ok && cellsAtPlace == bgA.getNumCells())
            finishActivity(true);
          else
            playEvent(ok ? EventSounds.ACTION_OK : EventSounds.ACTION_ERROR);
        }
        repaint();
      } else {
        if ((bx1 = bgA.findActiveBox(p)) != null && !bx1.isInactive()
            && (!useOrder || bx1.idOrder == currentItem)) {
          if (dragCells)
            bc.begin(p, bx1);
          else
            bc.begin(p);
          if (!bx1.playMedia(ps))
            playEvent(EventSounds.CLICK);
        }
      }
      break;

    case MouseEvent.MOUSE_MOVED:
    case MouseEvent.MOUSE_DRAGGED:
      bc.moveTo(p);
      break;
    }
}