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

The following examples show how to use java.awt.event.MouseEvent#MOUSE_DRAGGED . 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: hottub   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 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
Source Project: jdk8u-jdk   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 4
Source Project: consulo   File: Splitter.java    License: 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
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
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 7
Source Project: consulo   File: OnePixelDivider.java    License: 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 8
Source Project: java-swing-tips   File: MainPanel.java    License: 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 9
Source Project: darklaf   File: DarkTreeCellEditor.java    License: 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 10
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
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 12
Source Project: consulo   File: IdeGlassPaneImpl.java    License: 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 13
Source Project: jdk8u_jdk   File: XToolkit.java    License: 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 14
@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 15
Source Project: jdk8u-jdk   File: XToolkit.java    License: 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 Project: hottub   File: bug7146377.java    License: 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 17
Source Project: jclic   File: DoublePuzzle.java    License: 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;
    }
}
 
Example 18
Source Project: consulo   File: IdeTooltipManager.java    License: 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 19
Source Project: marathonv5   File: NativeEventsTest.java    License: 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 20
/**
 * 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;
}