Java Code Examples for java.awt.event.MouseEvent#MOUSE_PRESSED
The following examples show how to use
java.awt.event.MouseEvent#MOUSE_PRESSED .
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: MouseEventUI.java From darklaf with MIT License | 6 votes |
@SuppressWarnings("DuplicatedCode") private Component getListeningComponent(final MouseEvent event, final Component component) { Component comp; switch (event.getID()) { case MouseEvent.MOUSE_CLICKED : case MouseEvent.MOUSE_ENTERED : case MouseEvent.MOUSE_EXITED : case MouseEvent.MOUSE_PRESSED : case MouseEvent.MOUSE_RELEASED : comp = getMouseListeningComponent(component); break; case MouseEvent.MOUSE_DRAGGED : case MouseEvent.MOUSE_MOVED : comp = getMouseMotionListeningComponent(component); break; case MouseEvent.MOUSE_WHEEL : comp = getMouseWheelListeningComponent(component); break; default : comp = null; } return comp; }
Example 2
Source File: XComponentPeer.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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, CausedFocusEvent.Cause.MOUSE_EVENT); } break; } }
Example 3
Source File: XComponentPeer.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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, CausedFocusEvent.Cause.MOUSE_EVENT); } break; } }
Example 4
Source File: LootProfitAndDropRecorder.java From 07kit with GNU General Public License v3.0 | 6 votes |
@EventHandler public void handleReset(MouseEvent event) { if (resetBounds != null && resetBounds.contains(event.getX() - getPosition().getX(), event.getY() - getPosition().getY())) { if (event.getID() == MouseEvent.MOUSE_PRESSED) { clicking = true; event.consume(); } else if (event.getID() == MouseEvent.MOUSE_CLICKED) { resetKills(); event.consume(); } else { hovered = true; clicking = false; event.consume(); } } else { clicking = false; hovered = false; } }
Example 5
Source File: XToolkit.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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: PanningManager.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
@Override public void eventDispatched(AWTEvent e) { if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; if (!SwingUtilities.isDescendingFrom(me.getComponent(), target)) { return; } if (me.getID() == MouseEvent.MOUSE_RELEASED) { // stop when mouse released mouseOnScreenPoint = null; if (timer.isRunning()) { timer.stop(); } } else if (me.getID() == MouseEvent.MOUSE_DRAGGED && me.getComponent() == target) { mouseOnScreenPoint = me.getLocationOnScreen(); } else if (me.getID() == MouseEvent.MOUSE_PRESSED && me.getComponent() == target) { mouseOnScreenPoint = me.getLocationOnScreen(); timer.start(); } } }
Example 7
Source File: bug7146377.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 8
Source File: bug7146377.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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: WLightweightFramePeer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public void handleEvent(java.awt.AWTEvent e) { if (e.getID() == MouseEvent.MOUSE_PRESSED) { emulateActivation(true); } super.handleEvent(e); }
Example 10
Source File: WLightweightFramePeer.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public void handleEvent(java.awt.AWTEvent e) { if (e.getID() == MouseEvent.MOUSE_PRESSED) { emulateActivation(true); } super.handleEvent(e); }
Example 11
Source File: MegamekButton.java From megamek with GNU General Public License v2.0 | 5 votes |
protected void processMouseEvent(MouseEvent e) { if (e.getID() == MouseEvent.MOUSE_EXITED) { isMousedOver = false; repaint(); } else if (e.getID() == MouseEvent.MOUSE_ENTERED) { isMousedOver = true; } else if (e.getID() == MouseEvent.MOUSE_PRESSED) { isPressed = true; } else if (e.getID() == MouseEvent.MOUSE_RELEASED) { isPressed = false; } super.processMouseEvent(e); }
Example 12
Source File: TreeTable.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean editCellAt(int row, int column, EventObject e) { boolean editResult = super.editCellAt(row, column, e); if (e instanceof MouseEvent && isTreeColumn(column)){ MouseEvent me = (MouseEvent)e; int y = me.getY(); if (getRowHeight() != myTree.getRowHeight()) { // fix y if row heights are not equal // [todo]: review setRowHeight to synchronize heights correctly! final Rectangle tableCellRect = getCellRect(row, column, true); y = Math.min(y - tableCellRect.y, myTree.getRowHeight() - 1) + row * myTree.getRowHeight(); } MouseEvent newEvent = new MouseEvent(myTree, me.getID(), me.getWhen(), me.getModifiers(), me.getX() - getCellRect(0, column, true).x, y, me.getClickCount(), me.isPopupTrigger() ); myTree.dispatchEvent(newEvent); // Some LAFs, for example, Aqua under MAC OS X // expand tree node by MOUSE_RELEASED event. Unfortunately, // it's not possible to find easy way to wedge in table's // event sequense. Therefore we send "synthetic" release event. if (newEvent.getID()==MouseEvent.MOUSE_PRESSED) { MouseEvent newME2 = new MouseEvent( myTree, MouseEvent.MOUSE_RELEASED, me.getWhen(), me.getModifiers(), me.getX() - getCellRect(0, column, true).x, y - getCellRect(0, column, true).y, me.getClickCount(), me.isPopupTrigger() ); myTree.dispatchEvent(newME2); } } return editResult; }
Example 13
Source File: NonEditabilityTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testClickInvokesCustomEditor() throws Exception { if( !ExtTestCase.canSafelyRunFocusTests() ) return; Node n = new ANode(); setCurrentNode (n, sheet); sleep(); requestFocus (sheet.table); sleep(); Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); if (owner == sheet.table) { //sanity check to avoid random failures on some window managers System.out.println ("About to click cell"); Rectangle r = sheet.table.getCellRect(1, 1, false); final MouseEvent me = new MouseEvent (sheet.table, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), MouseEvent.BUTTON1_MASK, r.x + 3, r.y + 3, 2, false); SwingUtilities.invokeLater(new Runnable() { public void run() { sheet.table.dispatchEvent(me); } }); sleep(); sleep(); System.out.println ("Now checking focus"); owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); assertTrue ("Focus owner should be custom editor, not " + owner, owner instanceof JTextArea); JComponent jc = (JComponent) owner; assertTrue ("Custom editor should have been invoked, but focus owner's top level ancestor is not a dialog", jc.getTopLevelAncestor() instanceof Dialog); Dialog d = (Dialog) jc.getTopLevelAncestor(); d.setVisible(false); } requestFocus (sheet.table); sleep(); owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); if (owner == sheet.table) { //sanity check to avoid random failures on some window managers pressKey(sheet.table, KeyEvent.VK_SPACE); sleep(); owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); assertTrue ("After pressing a key, focus owner should still be the table, not " + owner, sheet.table == owner); } }
Example 14
Source File: SimpleAssociation.java From jclic with GNU General Public License v2.0 | 4 votes |
@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(); }
Example 15
Source File: JavaRecorderHook.java From marathonv5 with Apache License 2.0 | 4 votes |
public boolean isContextMenuSequence(MouseEvent e) { return e.getID() == MouseEvent.MOUSE_PRESSED && inputEventGetModifiersExText(e.getModifiersEx()).equals(menuModifiers); }
Example 16
Source File: XButtonPeer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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 File: XButtonPeer.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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
Source File: DocumentSwitcherTable.java From netbeans with Apache License 2.0 | 4 votes |
boolean onMouseEvent( MouseEvent e ) { Point p = e.getPoint(); p = SwingUtilities.convertPoint((Component) e.getSource(), p, this); int selRow = getSelectedRow(); int selCol = getSelectedColumn(); if( selRow < 0 || selCol < 0 ) return false; Item item = ( Item ) getModel().getValueAt( selRow, selCol ); // #268040 - check whether the item is closable if (null != item && isClosable(item)) { Rectangle rect = getCellRect( selRow, selCol, false ); if( rect.contains( p ) ) { Dimension size = btnClose.getPreferredSize(); int x = rect.x+rect.width-size.width; int y = rect.y + (rect.height-size.height)/2; Rectangle btnRect = new Rectangle( x, y, size.width, size.height); boolean inButton = btnRect.contains( p ); boolean mustRepaint = inCloseButtonRect != inButton; inCloseButtonRect = inButton; if( inButton ) { if( e.getID() == MouseEvent.MOUSE_PRESSED ) { TabData tab = item.getTabData(); int tabIndex = displayer.getModel().indexOf( tab ); if( tabIndex >= 0 ) { TabActionEvent evt = new TabActionEvent( displayer, TabDisplayer.COMMAND_CLOSE, tabIndex); displayer.postActionEvent( evt ); return true; } } } if( mustRepaint && lastRow == selRow && lastCol == selCol ) repaint( btnRect ); lastCol = selCol; lastRow = selRow; return inButton; } } else { inCloseButtonRect = false; } return false; }
Example 19
Source File: TooltipWindow.java From netbeans with Apache License 2.0 | 4 votes |
public void eventDispatched(AWTEvent event) { if (event.getID() == MouseEvent.MOUSE_PRESSED || event.getID() == KeyEvent.KEY_PRESSED) { onClick(event); } }
Example 20
Source File: MouseEventUI.java From darklaf with MIT License | 4 votes |
@SuppressWarnings("Duplicates") private void redispatch(final MouseEvent originalEvent, final JXLayer<? extends V> layer) { if (layer.getView() != null) { if (originalEvent.getComponent() != layer.getGlassPane()) { originalEvent.consume(); } MouseEvent newEvent = null; Point realPoint = calculateTargetPoint(layer, originalEvent); Component realTarget = getTarget(layer, realPoint); if (realTarget != null) { realTarget = getListeningComponent(originalEvent, realTarget); } switch (originalEvent.getID()) { case MouseEvent.MOUSE_PRESSED : newEvent = transformMouseEvent(layer, originalEvent, realTarget, realPoint); if (newEvent != null) { lastPressedTarget = newEvent.getComponent(); } break; case MouseEvent.MOUSE_RELEASED : newEvent = transformMouseEvent(layer, originalEvent, lastPressedTarget, realPoint); lastPressedTarget = null; break; case MouseEvent.MOUSE_ENTERED : case MouseEvent.MOUSE_EXITED : generateEnterExitEvents(layer, originalEvent, realTarget, realPoint); break; case MouseEvent.MOUSE_MOVED : newEvent = transformMouseEvent(layer, originalEvent, realTarget, realPoint); generateEnterExitEvents(layer, originalEvent, realTarget, realPoint); break; case MouseEvent.MOUSE_DRAGGED : newEvent = transformMouseEvent(layer, originalEvent, lastPressedTarget, realPoint); generateEnterExitEvents(layer, originalEvent, realTarget, realPoint); break; case MouseEvent.MOUSE_CLICKED : newEvent = transformMouseEvent(layer, originalEvent, realTarget, realPoint); break; case (MouseEvent.MOUSE_WHEEL) : redispatchMouseWheelEvent((MouseWheelEvent) originalEvent, realTarget, layer); break; } dispatchMouseEvent(newEvent); } }