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

The following examples show how to use java.awt.event.MouseEvent#MOUSE_RELEASED . 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
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
public void menuDragMouseDragged(final MenuDragMouseEvent e) {
    if (menuItem.isEnabled() == false) return;

    final MenuSelectionManager manager = e.getMenuSelectionManager();
    final MenuElement path[] = e.getPath();

    // In Aqua, we always respect the menu's delay, if one is set.
    // Doesn't matter how the menu is clicked on or otherwise moused over.
    final Point p = e.getPoint();
    if (p.x >= 0 && p.x < menuItem.getWidth() && p.y >= 0 && p.y < menuItem.getHeight()) {
        final JMenu menu = (JMenu)menuItem;
        final MenuElement selectedPath[] = manager.getSelectedPath();
        if (!(selectedPath.length > 0 && selectedPath[selectedPath.length - 1] == menu.getPopupMenu())) {
            if (menu.getDelay() == 0) {
                appendPath(path, menu.getPopupMenu());
            } else {
                manager.setSelectedPath(path);
                setupPostTimer(menu);
            }
        }
    } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {
        final Component comp = manager.componentForPoint(e.getComponent(), e.getPoint());
        if (comp == null) manager.clearSelectedPath();
    }
}
 
Example 3
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);
            item.setArmed(false);
        } else
            manager.setSelectedPath(path);
    } else if (item.getModel().isArmed()) {
        MenuElement newPath[] = new MenuElement[path.length - 1];
        int i, c;
        for (i = 0, c = path.length - 1; i < c; i++)
            newPath[i] = path[i];
        manager.setSelectedPath(newPath);
    }
}
 
Example 4
Source Project: netbeans   File: NbiTreeTable.java    License: Apache License 2.0 6 votes vote down vote up
protected void processMouseEvent(MouseEvent event) {
    int column = columnAtPoint(event.getPoint());
    int row = rowAtPoint(event.getPoint());
    
    if ((event.getID() == MouseEvent.MOUSE_RELEASED) && mousePressedEventConsumed) {
        mousePressedEventConsumed = false;
        event.consume();
        return;
    }
    
    if (mouseEventHitTreeHandle(event)) {
        mousePressedEventConsumed = true;
        event.consume();
        sendTreeHandleEvents(event);
        return;
    }
    
    mousePressedEventConsumed = false;
    super.processMouseEvent(event);
}
 
Example 5
Source Project: consulo   File: BaseButtonBehavior.java    License: Apache License 2.0 6 votes vote down vote up
public void mouseReleased(MouseEvent e) {
  try {
    if (passIfNeeded(e, !myWasPressedOnFocusTransfer)) return;

    setPressedByMouse(false);

    if (myActionTrigger == MouseEvent.MOUSE_RELEASED) {
      execute(e);
    } else {
      repaintComponent();
    }
  }
  finally {
    myWasPressedOnFocusTransfer = false;
  }
}
 
Example 6
Source Project: jdk8u60   File: AquaMenuUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void menuDragMouseDragged(final MenuDragMouseEvent e) {
    if (menuItem.isEnabled() == false) return;

    final MenuSelectionManager manager = e.getMenuSelectionManager();
    final MenuElement path[] = e.getPath();

    // In Aqua, we always respect the menu's delay, if one is set.
    // Doesn't matter how the menu is clicked on or otherwise moused over.
    final Point p = e.getPoint();
    if (p.x >= 0 && p.x < menuItem.getWidth() && p.y >= 0 && p.y < menuItem.getHeight()) {
        final JMenu menu = (JMenu)menuItem;
        final MenuElement selectedPath[] = manager.getSelectedPath();
        if (!(selectedPath.length > 0 && selectedPath[selectedPath.length - 1] == menu.getPopupMenu())) {
            if (menu.getDelay() == 0) {
                appendPath(path, menu.getPopupMenu());
            } else {
                manager.setSelectedPath(path);
                setupPostTimer(menu);
            }
        }
    } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {
        final Component comp = manager.componentForPoint(e.getComponent(), e.getPoint());
        if (comp == null) manager.clearSelectedPath();
    }
}
 
Example 7
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 8
public MouseNavigationBehavior() {
    WakeupOnAWTEvent mouseMoveCondition = new WakeupOnAWTEvent(MouseEvent.MOUSE_MOVED);
    WakeupOnAWTEvent mouseClickCondition = new WakeupOnAWTEvent(MouseEvent.MOUSE_CLICKED);
    WakeupOnAWTEvent mouseWheel = new WakeupOnAWTEvent(MouseEvent.MOUSE_WHEEL);
    WakeupOnAWTEvent mouseDrag = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
    WakeupOnAWTEvent mouseReleased = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);
    wakeupCondition = new WakeupOr(new WakeupCriterion[]{mouseMoveCondition, mouseClickCondition, mouseWheel, mouseDrag, mouseReleased});
}
 
Example 9
@Override
public void showOrHideTouchKeyboard(Component comp, AWTEvent e) {
    if (!(comp instanceof TextComponent) &&
        !(comp instanceof JTextComponent)) {
        return;
    }

    if ((e instanceof MouseEvent) && isComponentValidForTouchKeyboard(comp)) {
        MouseEvent me = (MouseEvent) e;
        if (me.getID() == MouseEvent.MOUSE_PRESSED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                compOnTouchDownEvent = new WeakReference<>(comp);
            } else {
                compOnMousePressedEvent = new WeakReference<>(comp);
            }
        } else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                if (compOnTouchDownEvent.get() == comp) {
                    showTouchKeyboard(true);
                }
                compOnTouchDownEvent = NULL_COMPONENT_WR;
            } else {
                if (compOnMousePressedEvent.get() == comp) {
                    showTouchKeyboard(false);
                }
                compOnMousePressedEvent = NULL_COMPONENT_WR;
            }
        }
    } else if (e instanceof FocusEvent) {
        FocusEvent fe = (FocusEvent) e;
        if (fe.getID() == FocusEvent.FOCUS_LOST) {
            // Hide the touch keyboard, if not a text component gains focus.
            if (!isComponentValidForTouchKeyboard(fe.getOppositeComponent())) {
                hideTouchKeyboard();
            }
        }
    }
}
 
Example 10
Source Project: hottub   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 11
Source Project: raccoon4   File: QrPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void processMouseEvent(MouseEvent e) {
	if (e.getID() == MouseEvent.MOUSE_RELEASED) {
		if (toggle) {
			menu.setVisible(false);
		}
		else {
			menu.show(e.getComponent(), e.getX(), e.getY());
		}
		toggle = !toggle;
	}
}
 
Example 12
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 13
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 showHelp() {
  if (!helpWindowAllowed() || bg[0] == null)
    return;

  HelpActivityComponent hac = null;
  if (showSolution) {
    hac = new HelpActivityComponent(this) {
      ActiveBoxBag abb = null;
      String currentResponse = "";
      int cellsPlaced = bg[0].countCellsWithIdAss(-1);

      public void render(Graphics2D g2, Rectangle dirtyRegion) {
        if (abb != null)
          abb.update(g2, dirtyRegion, this);
      }

      @Override
      public void init() {
        currentResponse = textField.getText();
        abb = (ActiveBoxBag) bg[0].clone();
        abb.setContainer(this);
        Dimension size = abb.getBounds().getSize();
        abb.setBounds(DEFAULT_MARGIN, DEFAULT_MARGIN, size.width, size.height);
        size.width += 2 * DEFAULT_MARGIN;
        size.height += 2 * DEFAULT_MARGIN;
        setPreferredSize(size);
        setMaximumSize(size);
        setMinimumSize(size);
        Point p = (Point) getClientProperty(HelpActivityComponent.PREFERRED_LOCATION);
        if (p != null)
          p.translate((int) bg[0].x - DEFAULT_MARGIN, (int) bg[0].y - DEFAULT_MARGIN);
      }

      @Override
      public void end() {
        super.end();
        textField.setText(currentResponse);
      }

      @Override
      public void processMouse(MouseEvent e) {
        ActiveBox bx;
        if (abb != null)
          switch (e.getID()) {
          case MouseEvent.MOUSE_PRESSED:
            bx = abb.findActiveBox(e.getPoint());
            if (bx != null) {
              boolean m = bx.playMedia(ps);
              String s = abc[1].getActiveBoxContent(bx.idOrder).text;
              if (s != null)
                textField.setText(s.replace('|', ' '));
              ps.reportNewAction(getActivity(), ACTION_HELP, bx.getDescription(), null, false, cellsPlaced);
              if (!m)
                playEvent(EventSounds.CLICK);
            }
            break;
          case MouseEvent.MOUSE_RELEASED:
            unmarkBox();
            textField.setText("");
            break;
          }
      }
    };
    hac.init();
  }
  if (ps.showHelp(hac, helpMsg))
    ps.reportNewAction(getActivity(), ACTION_HELP, null, null, false, bg[0].countCellsWithIdAss(-1));

  if (hac != null)
    hac.end();
}
 
Example 15
private boolean isForwardEvent(MouseEvent e) {
    int eventID = e.getID();
    return eventID == MouseEvent.MOUSE_PRESSED ||
           eventID == MouseEvent.MOUSE_RELEASED ||
           eventID == MouseEvent.MOUSE_WHEEL;
}
 
Example 16
Source Project: marathonv5   File: NativeEventsTest.java    License: Apache License 2.0 4 votes vote down vote up
public void releaseGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_RELEASED;
    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);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    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();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    AssertJUnit.assertEquals(expected, t.getText());

    tclear();
    new Actions(driver).moveToElement(b).click().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
Example 17
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 18
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 19
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
@Override
public void showHelp() {

  if (!helpWindowAllowed() || bg[0] == null)
    return;

  HelpActivityComponent hac = null;
  if (showSolution) {
    hac = new HelpActivityComponent(this) {
      ActiveBoxBag abb = null;
      int cellsPlaced = bg[1].countCellsWithIdAss(-1);

      public void render(Graphics2D g2, Rectangle dirtyRegion) {
        if (abb != null)
          abb.update(g2, dirtyRegion, this);
      }

      @Override
      public void init() {
        abb = (ActiveBoxBag) bg[0].clone();
        abb.setContainer(this);
        Dimension size = abb.getBounds().getSize();
        abb.setBounds(DEFAULT_MARGIN, DEFAULT_MARGIN, size.width, size.height);
        size.width += 2 * DEFAULT_MARGIN;
        size.height += 2 * DEFAULT_MARGIN;
        setPreferredSize(size);
        setMaximumSize(size);
        setMinimumSize(size);
        Point p = (Point) getClientProperty(HelpActivityComponent.PREFERRED_LOCATION);
        if (p != null)
          p.translate((int) bg[0].x - DEFAULT_MARGIN, (int) bg[0].y - DEFAULT_MARGIN);
      }

      @Override
      public void processMouse(MouseEvent e) {
        ActiveBox bx;
        boolean m;
        if (abb != null)
          switch (e.getID()) {
          case MouseEvent.MOUSE_PRESSED:
            bx = abb.findActiveBox(e.getPoint());
            if (bx != null) {
              m = bx.playMedia(ps);
              if (!m)
                playEvent(EventSounds.CLICK);
              if (bx.idAss >= 0) {
                ActiveBox bxSolution = bg[1].getActiveBox(useIdAss ? bx.idAss : bx.idOrder);
                markBox(bxSolution, false);
                if (bxSolution != null)
                  ps.reportNewAction(getActivity(), ACTION_HELP, bx.getDescription(), bxSolution.getDescription(),
                      false, cellsPlaced);
              }
            }
            break;
          case MouseEvent.MOUSE_RELEASED:
            unmarkBox();
            break;
          }
      }
    };
    hac.init();
  }
  if (ps.showHelp(hac, helpMsg))
    ps.reportNewAction(getActivity(), ACTION_HELP, null, null, false, bg[1].countCellsWithIdAss(-1));

  if (hac != null)
    hac.end();
}