Java Code Examples for java.awt.event.MouseEvent#getID()

The following examples show how to use java.awt.event.MouseEvent#getID() . 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: EditableLabel.java    From jace with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    if (isEditing) {
        return;
    }
    activateEdit();
    // This next bit will generate a second mouse event and pass it on to the edit component so that 
    // the edit cursor appears under the mouse pointer, not a the start of the component.
    final MouseEvent e2 = new MouseEvent(editComponent, e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            editComponent.dispatchEvent(e2);
        }
    });
}
 
Example 2
Source File: SeaGlassCheckBoxMenuItemUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
public void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement path[], MenuSelectionManager manager) {
    Point p = e.getPoint();
    if (p.x >= 0 && p.x < item.getWidth() && p.y >= 0 && p.y < item.getHeight()) {
        if (e.getID() == MouseEvent.MOUSE_RELEASED) {
            manager.clearSelectedPath();
            item.doClick(0);
        } else {
            manager.setSelectedPath(path);
        }
    } else if (item.getModel().isArmed()) {
        int c = path.length - 1;
        MenuElement newPath[] = new MenuElement[c];
        for (int i = 0; i < c; i++) {
            newPath[i] = path[i];
        }
        manager.setSelectedPath(newPath);
    }
}
 
Example 3
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override protected void processMouseEvent(MouseEvent e, JLayer<? extends JScrollPane> l) {
  int id = e.getID();
  Component c = e.getComponent();
  if (c instanceof JScrollBar) {
    if (id == MouseEvent.MOUSE_ENTERED) {
      c.setPreferredSize(new Dimension(TranslucentScrollBarUI.MAX_WIDTH, 0));
    } else if (id == MouseEvent.MOUSE_EXITED) {
      timer.removeActionListener(listener);
      listener = ev -> {
        c.setPreferredSize(new Dimension(TranslucentScrollBarUI.MIN_WIDTH, 0));
        l.getView().revalidate();
        l.getView().repaint();
      };
      timer.addActionListener(listener);
      timer.setRepeats(false);
      timer.start();
    }
    l.getView().repaint();
  }
}
 
Example 4
Source File: TranslateMouseListener.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private MouseEvent translateEvent(MouseEvent e)
{
	Dimension stretchedDimensions = client.getStretchedDimensions();
	Dimension realDimensions = client.getRealDimensions();

	int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
	int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

	MouseEvent mouseEvent = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(),
		newX, newY, e.getClickCount(), e.isPopupTrigger(), e.getButton());
	if (e.isConsumed())
	{
		mouseEvent.consume();
	}
	return mouseEvent;
}
 
Example 5
Source File: XComponentPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void handleJavaMouseEvent(MouseEvent e) {
        switch (e.getID()) {
          case MouseEvent.MOUSE_PRESSED:
              if (target == e.getSource() &&
                  !target.isFocusOwner() &&
                  XKeyboardFocusManagerPeer.shouldFocusOnClick(target))
              {
                  XWindowPeer parentXWindow = getParentTopLevel();
                  Window parentWindow = ((Window)parentXWindow.getTarget());
                  // Simple windows are non-focusable in X terms but focusable in Java terms.
                  // As X-non-focusable they don't receive any focus events - we should generate them
                  // by ourselfves.
//                   if (parentXWindow.isFocusableWindow() /*&& parentXWindow.isSimpleWindow()*/ &&
//                       !(getCurrentNativeFocusedWindow() == parentWindow))
//                   {
//                       setCurrentNativeFocusedWindow(parentWindow);
//                       WindowEvent wfg = new WindowEvent(parentWindow, WindowEvent.WINDOW_GAINED_FOCUS);
//                       parentWindow.dispatchEvent(wfg);
//                   }
                  XKeyboardFocusManagerPeer.requestFocusFor(target, FocusEvent.Cause.MOUSE_EVENT);
              }
              break;
        }
    }
 
Example 6
Source File: DesktopFloatingDecorator.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected final void processMouseEvent(final MouseEvent e) {
  super.processMouseEvent(e);
  switch (e.getID()) {
    case MouseEvent.MOUSE_PRESSED: {
      myLastPoint = e.getPoint();
      SwingUtilities.convertPointToScreen(myLastPoint, this);
      setMotionMask(e.getPoint());
      myDragging = true;
      break;
    }
    case MouseEvent.MOUSE_RELEASED: {
      DesktopFloatingDecorator.this.validate();
      DesktopFloatingDecorator.this.repaint();
      myDragging = false;
      break;
    }
    case MouseEvent.MOUSE_ENTERED: {
      if (!myDragging) {
        setMotionMask(e.getPoint());
      }
    }
  }
}
 
Example 7
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override protected void processMouseEvent(MouseEvent e) {
  if (e.getID() == MouseEvent.MOUSE_ENTERED || e.getID() == MouseEvent.MOUSE_EXITED) {
    super.processMouseEvent(e);
  } else {
    if (getCellBounds(0, getModel().getSize() - 1).contains(e.getPoint())) {
      super.processMouseEvent(convertMouseEvent(e));
    } else {
      e.consume();
      requestFocusInWindow();
    }
  }
}
 
Example 8
Source File: bug7146377.java    From jdk8u-dev-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 9
Source File: WComponentPeer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void handleJavaMouseEvent(MouseEvent e) {
    switch (e.getID()) {
      case MouseEvent.MOUSE_PRESSED:
          // Note that Swing requests focus in its own mouse event handler.
          if (target == e.getSource() &&
              !((Component)target).isFocusOwner() &&
              WKeyboardFocusManagerPeer.shouldFocusOnClick((Component)target))
          {
              WKeyboardFocusManagerPeer.requestFocusFor((Component)target,
                                                        CausedFocusEvent.Cause.MOUSE_EVENT);
          }
          break;
    }
}
 
Example 10
Source File: XTextFieldPeer.java    From openjdk-jdk8u 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 11
Source File: XTextFieldPeer.java    From jdk8u-jdk 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 openjdk-jdk8u-backup 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: XButtonPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void handleJavaMouseEvent(MouseEvent e) {
    super.handleJavaMouseEvent(e);
    int id = e.getID();
    switch (id) {
      case MouseEvent.MOUSE_PRESSED:
          if (XToolkit.isLeftMouseButton(e) ) {
              Button b = (Button) e.getSource();

              if(b.contains(e.getX(), e.getY())) {
                  if (!isEnabled()) {
                      // Disabled buttons ignore all input...
                      return;
                  }
                  pressed = true;
                  armed = true;
                  repaint();
              }
          }

          break;

      case MouseEvent.MOUSE_RELEASED:
          if (XToolkit.isLeftMouseButton(e)) {
              if (armed)
              {
                  action(e.getWhen(),e.getModifiers());
              }
              pressed = false;
              armed = false;
              repaint();
          }

          break;

      case  MouseEvent.MOUSE_ENTERED:
          if (pressed)
              armed = true;
          break;
      case MouseEvent.MOUSE_EXITED:
          armed = false;
          break;
    }
}
 
Example 14
Source File: SpotlightLayerUI.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void processMouseEvent(MouseEvent e, JLayer l) {
  if (e.getID() == MouseEvent.MOUSE_ENTERED) mActive = true;
  if (e.getID() == MouseEvent.MOUSE_EXITED) mActive = false;
}
 
Example 15
Source File: JavaWindowsView.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private void handleMiddleClick(MouseEvent e) {
    HeapViewerNodeAction.Actions nodeActions = HeapViewerNodeAction.Actions.forNode(windowNode, actionProviders, context, actions);
    ActionEvent ae = new ActionEvent(e.getSource(), e.getID(), "middle button", e.getWhen(), e.getModifiers()); // NOI18N
    nodeActions.performMiddleButtonAction(ae);
}
 
Example 16
Source File: SamplerViewSupport.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
protected void processMouseEvent(MouseEvent e) {
    if (!isSelected() || MouseEvent.MOUSE_EXITED == e.getID()) super.processMouseEvent(e);
}
 
Example 17
Source File: ProfilerTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected static MouseEvent clearClicks(MouseEvent e) {
    // Clear unwanted doubleclicks
    return new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(),
                          e.getModifiers(), e.getX(), e.getY(),
                          1, e.isPopupTrigger(), e.getButton());
}
 
Example 18
Source File: Main.java    From desktop with The Unlicense 4 votes vote down vote up
private void jMenu4MouseClicked(MouseEvent evt) {                                    
    evt.getID();
    String URL = "https://evilinsult.com/";
    webPages(URL);
}
 
Example 19
Source File: XButtonPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
void handleJavaMouseEvent(MouseEvent e) {
    super.handleJavaMouseEvent(e);
    int id = e.getID();
    switch (id) {
      case MouseEvent.MOUSE_PRESSED:
          if (XToolkit.isLeftMouseButton(e) ) {
              Button b = (Button) e.getSource();

              if(b.contains(e.getX(), e.getY())) {
                  if (!isEnabled()) {
                      // Disabled buttons ignore all input...
                      return;
                  }
                  pressed = true;
                  armed = true;
                  repaint();
              }
          }

          break;

      case MouseEvent.MOUSE_RELEASED:
          if (XToolkit.isLeftMouseButton(e)) {
              if (armed)
              {
                  action(e.getWhen(),e.getModifiers());
              }
              pressed = false;
              armed = false;
              repaint();
          }

          break;

      case  MouseEvent.MOUSE_ENTERED:
          if (pressed)
              armed = true;
          break;
      case MouseEvent.MOUSE_EXITED:
          armed = false;
          break;
    }
}
 
Example 20
Source File: DnDAwareTree.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void processMouseMotionEvent(MouseEvent e) {
  if (SystemInfo.isMac && JBSwingUtilities.isRightMouseButton(e) && e.getID() == MouseEvent.MOUSE_DRAGGED) return;
  super.processMouseMotionEvent(e);
}