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

The following examples show how to use java.awt.event.MouseEvent#getID() . 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
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 2
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 3
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 4
@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 5
Source Project: java-swing-tips   File: MainPanel.java    License: 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 6
Source Project: jace   File: EditableLabel.java    License: 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 7
@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 8
Source Project: java-swing-tips   File: MainPanel.java    License: 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 9
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 10
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 11
@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
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 Project: consulo   File: DnDAwareTree.java    License: 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);
}
 
Example 14
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 15
Source Project: desktop   File: Main.java    License: The Unlicense 4 votes vote down vote up
private void jMenu4MouseClicked(MouseEvent evt) {                                    
    evt.getID();
    String URL = "https://evilinsult.com/";
    webPages(URL);
}
 
Example 16
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 17
Source Project: netbeans   File: ProfilerTable.java    License: 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
protected void processMouseEvent(MouseEvent e) {
    if (!isSelected() || MouseEvent.MOUSE_EXITED == e.getID()) super.processMouseEvent(e);
}
 
Example 19
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 20
@Override
protected void processMouseEvent(MouseEvent e, JLayer l) {
  if (e.getID() == MouseEvent.MOUSE_ENTERED) mActive = true;
  if (e.getID() == MouseEvent.MOUSE_EXITED) mActive = false;
}