Java Code Examples for java.awt.event.MouseEvent.MOUSE_CLICKED

The following are Jave code examples for showing how to use MOUSE_CLICKED of the java.awt.event.MouseEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: marathonv5   File: NativeEventsTest.java   View Source Code Vote up 7 votes
public void singleClickGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_CLICKED;
    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 2
Project: OpenJSharp   File: XToolkit.java   View Source Code Vote up 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 3
Project: incubator-netbeans   File: BasicTabDisplayerUI.java   View Source Code Vote up 6 votes
private void potentialCommand (int idx, MouseEvent e, int state, TabCellRenderer tcr, Rectangle bounds) {
    String command = tcr.getCommandAtPoint (e.getPoint(), state, bounds,
            e.getButton(), e.getID(), e.getModifiersEx());
    if (command == null || TabDisplayer.COMMAND_SELECT == command) {
        if (e.isPopupTrigger()) {
            displayer.repaint();
            performCommand (TabDisplayer.COMMAND_POPUP_REQUEST, idx, e);
            return;
        } else if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() >= 2 && e.getButton() == MouseEvent.BUTTON1 ) {
            performCommand (TabDisplayer.COMMAND_MAXIMIZE, idx, e);
            return;
        }
    }

    if (command != null) {
        performCommand (command, lastPressedTab == -1 || lastPressedTab >=
            displayer.getModel().size() ? idx : lastPressedTab, e);
    }
}
 
Example 4
Project: incubator-netbeans   File: PopupUtil.java   View Source Code Vote up 6 votes
public void eventDispatched(java.awt.AWTEvent aWTEvent) {
    if (aWTEvent instanceof MouseEvent) {
        MouseEvent mv = (MouseEvent)aWTEvent;
        if (mv.getID() == MouseEvent.MOUSE_CLICKED && mv.getClickCount() > 0) {
            //#118828
            if (! (aWTEvent.getSource() instanceof Component)) {
                hidePopup();
                return;
            }
            
            Component comp = (Component)aWTEvent.getSource();
            Container par = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N
            // Container barpar = SwingUtilities.getAncestorOfClass(PopupUtil.class, comp);
            // if (par == null && barpar == null) {
            if ( par == null ) {
                hidePopup();
            }
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: PopupUtil.java   View Source Code Vote up 6 votes
public void eventDispatched(java.awt.AWTEvent aWTEvent) {
    if (aWTEvent instanceof MouseEvent) {
        MouseEvent mv = (MouseEvent)aWTEvent;
        if (mv.getID() == MouseEvent.MOUSE_CLICKED && mv.getClickCount() > 0) {
            //#118828
            if (! (aWTEvent.getSource() instanceof Component)) {
                hidePopup();
                return;
            }
            
            Component comp = (Component)aWTEvent.getSource();
            Container par = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N
            // Container barpar = SwingUtilities.getAncestorOfClass(PopupUtil.class, comp);
            // if (par == null && barpar == null) {
            if ( par == null ) {
                hidePopup();
            }
        }
    }
}
 
Example 6
Project: incubator-netbeans   File: PopupUtil.java   View Source Code Vote up 6 votes
public void eventDispatched(java.awt.AWTEvent aWTEvent) {
    if (aWTEvent instanceof MouseEvent) {
        MouseEvent mv = (MouseEvent)aWTEvent;
        if (mv.getID() == MouseEvent.MOUSE_CLICKED && mv.getClickCount() > 0) {
            //#118828
            if (! (aWTEvent.getSource() instanceof Component)) {
                hidePopup();
                return;
            }
            
            Component comp = (Component)aWTEvent.getSource();
            Container par = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N
            // Container barpar = SwingUtilities.getAncestorOfClass(PopupUtil.class, comp);
            // if (par == null && barpar == null) {
            if ( par == null ) {
                hidePopup();
            }
        }
    }
}
 
Example 7
Project: jdk8u-jdk   File: XToolkit.java   View Source Code Vote up 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 8
Project: incubator-netbeans   File: HeapView.java   View Source Code Vote up 6 votes
/**
 * Processes a mouse event.
 *
 * @param e the MouseEvent
 */
@Override protected void processMouseEvent(MouseEvent e) {
    super.processMouseEvent(e);
    if (!e.isConsumed()) {
        if (e.isPopupTrigger()) {
            // Show a popup allowing to configure the various options
            showPopup(e.getX(), e.getY());
        }  else if (e.getID() == e.MOUSE_ENTERED) {
            containsMouse = true;
            cachedBorderVaild = false;
            repaint();
        } else if (e.getID() == e.MOUSE_EXITED) {
            containsMouse = false;
            cachedBorderVaild = false;
            repaint();
        }

    } 
    
    if (e.getID() == MouseEvent.MOUSE_CLICKED &&
            SwingUtilities.isLeftMouseButton(e) && 
            e.getClickCount() == 1) {
        // Trigger a gc
        GarbageCollectAction.get(GarbageCollectAction.class).performAction();;
    }
}
 
Example 9
Project: JDigitalSimulator   File: Simulation.java   View Source Code Vote up 6 votes
@Override protected void processMouseEvent(MouseEvent event) {
	super.processMouseEvent(event);
	switch(event.getID()) {
	case MouseEvent.MOUSE_CLICKED:
		if(event.getButton()!=MouseEvent.BUTTON1)
			return;
		Point point = applyZoom(event.getPoint());
		Component component = searchComponentAt(point);
		if(component==null) return;
		else if(component instanceof Interactable) {
			event = new RelativeMouseEvent(event, point, component.getLocation());
			if(Utilities.isOdd(event.getClickCount()))
				((Interactable) component).mouseClick(event);
			else ((Interactable) component).mouseDoubleClick(event);
		}
		if(!isSimulating()&&event.getButton()==MouseEvent.BUTTON1&&
				event.getClickCount()>=2)
			showComponentConfigurationDialog(component);
	}
}
 
Example 10
Project: alevin-svn2   File: AbstractSearchField.java   View Source Code Vote up 5 votes
@Override
protected void processMouseEvent(MouseEvent e) {
	if (isEditable()) {
		if (e.getID() == MouseEvent.MOUSE_ENTERED)
			this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		else if (e.getID() == MouseEvent.MOUSE_CLICKED
				&& e.getX() > this.getWidth() - 20 - getInsets().top) {
			this.setText("");
			return;
		}
	}
	super.processMouseEvent(e);
}
 
Example 11
Project: openjdk-jdk10   File: bug7146377.java   View Source Code Vote up 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 12
Project: openjdk-jdk10   File: XToolkit.java   View Source Code Vote up 5 votes
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
Project: incubator-netbeans   File: MouseUtils.java   View Source Code Vote up 5 votes
/** Returns true if parametr is a 'doubleclick event'
* @param e MouseEvent
* @return true if the event is a doubleclick
*/
public static boolean isDoubleClick(MouseEvent e) {
    // even number of clicks is considered like doubleclick
    // it works as well as 'normal testing against 2'
    // but on solaris finaly works and on Win32 works better
    //System.out.println ("Click COunt: "+e.getClickCount ()); // NOI18N
    // If you don't do this, then if anyone calls isDoubleClick from
    // say a mouseReleased method, then the immediately following mouseClicked
    // method from a single mouse click will give isDoubleClick=true
    if ((e.getID() != MouseEvent.MOUSE_CLICKED) || (e.getClickCount() == 0)) {
        return false;
    }

    return ((e.getClickCount() % 2) == 0) || isDoubleClickImpl(e);
}
 
Example 14
Project: jdk8u-jdk   File: bug6690791.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    MouseEvent me = new MouseEvent(new JLabel(), MouseEvent.MOUSE_CLICKED,
            System.currentTimeMillis(), MouseEvent.ALT_MASK,
            10, 10, 100, 100, 1, false, MouseEvent.BUTTON1);
    me.setSource(new Object());
    MenuSelectionManager.defaultManager().processMouseEvent(me);
}
 
Example 15
Project: marathonv5   File: NativeEventsTest.java   View Source Code Vote up 5 votes
public void rightClickGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_CLICKED;
    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.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_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);

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

}
 
Example 16
Project: marathonv5   File: RComponent.java   View Source Code Vote up 5 votes
public void processEvent(AWTEvent event) {
    setIndexOfType(super.getIndexOfType());
    if (event instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) event;

        switch (me.getID()) {
        case MouseEvent.MOUSE_ENTERED:
            mouseEntered(me);
            break;
        case MouseEvent.MOUSE_PRESSED:
            mousePressed(me);
            break;
        case MouseEvent.MOUSE_RELEASED:
            mouseReleased(me);
            break;
        case MouseEvent.MOUSE_CLICKED:
            mouseClicked(me);
            break;
        case MouseEvent.MOUSE_EXITED:
            mouseExited(me);
            break;
        }
    } else if (event instanceof KeyEvent) {
        KeyEvent ke = (KeyEvent) event;
        switch (ke.getID()) {
        case KeyEvent.KEY_PRESSED:
            keyPressed(ke);
            break;
        case KeyEvent.KEY_RELEASED:
            keyReleased(ke);
            break;
        case KeyEvent.KEY_TYPED:
            keyTyped(ke);
            break;
        }
    }
}
 
Example 17
Project: openjdk-jdk10   File: bug6690791.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    MouseEvent me = new MouseEvent(new JLabel(), MouseEvent.MOUSE_CLICKED,
            System.currentTimeMillis(), MouseEvent.ALT_MASK,
            10, 10, 100, 100, 1, false, MouseEvent.BUTTON1);
    me.setSource(new Object());
    MenuSelectionManager.defaultManager().processMouseEvent(me);
}
 
Example 18
Project: incubator-netbeans   File: SheetTable.java   View Source Code Vote up 4 votes
/**  Returns true if a mouse event occured over the custom editor button.
 *   This is used to supply button specific tooltips and launch the custom
 *   editor without needing to instantiate a real button */
private boolean onCustomEditorButton(MouseEvent e) {
    //see if we're in the approximate bounds of the custom editor button
    Point pt = e.getPoint();
    int row = rowAtPoint(pt);
    int col = columnAtPoint(pt);
    FeatureDescriptor fd = getSheetModel().getPropertySetModel().getFeatureDescriptor(row);
    if( null == fd ) {
        //prevent NPE when the activated Node has been destroyed and a new one hasn't been set yet
        return false;
    }

    //see if the event happened over the custom editor button
    boolean success;

    if (PropUtils.noCustomButtons) {
        //#41412 - impossible to invoke custom editor on props w/ no inline
        //edit mode if the no custom buttons switch is set
        success = false;
    } else {
        success = e.getX() > (getWidth() - PropUtils.getCustomButtonWidth());
    }

    //if it's a mouse button event, then we're not showing a tooltip, we're
    //deciding if we should display a custom editor.  For read-only props that
    //support one, we should return true, since clicking the non-editable cell
    //is not terribly useful.
    if (
        (e.getID() == MouseEvent.MOUSE_PRESSED) || (e.getID() == MouseEvent.MOUSE_RELEASED) ||
            (e.getID() == MouseEvent.MOUSE_CLICKED)
    ) {
        //We will show the custom editor for any click on the text value
        //of a property that looks editable but sets canEditAsText to false -
        //the click means the user is trying to edit something, so to just
        //swallow the gesture is confusing
        success |= Boolean.FALSE.equals(fd.getValue("canEditAsText"));

        if (!success && fd instanceof Property) {
            PropertyEditor pe = PropUtils.getPropertyEditor((Property) fd);

            if ((pe != null) && pe.supportsCustomEditor()) {
                //Undocumented but used in Studio - in NB 3.5 and earlier, returning null from getAsText()
                //was a way to make a property non-editable
                success |= (pe.isPaintable() && (pe.getAsText() == null) && (pe.getTags() == null));
            }
        }
    }

    try {
        if (success) { //NOI18N

            if (fd instanceof Property && (col == 1)) {
                boolean supp = PropUtils.getPropertyEditor((Property) fd).supportsCustomEditor();

                return (supp);
            }
        }
    } catch (IllegalStateException ise) {
        //See bugtraq 4941073 - if a property accessed via Reflection throws
        //an unexpected exception (try customize bean on a vanilla GenericServlet
        //to produce this) when the getter is accessed, then we are already
        //displaying "Error fetching property value" in the value area of
        //the propertysheet.  No point in distracting the user with a 
        //stack trace - it's not our bug.
        Logger.getLogger(SheetTable.class.getName()).log(Level.WARNING, null, ise);
    }

    return false;
}
 
Example 19
Project: owa-notifier   File: WindowNotificationTest.java   View Source Code Vote up 4 votes
public void simulateClick() {
	JPanel panel = new JPanel();
	setPanel(panel);
	MouseEvent me = new MouseEvent(panel, MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), 0, 10, 10, 1, false);
	panel.dispatchEvent(me);
}
 
Example 20
Project: ramus   File: CloseableTabbedPane.java   View Source Code Vote up 4 votes
/**
 * Processes all caught <code>MouseEvent</code>s.
 *
 * @param e the <code>MouseEvent</code>
 */
private void processMouseEvents(MouseEvent e) {
    int tabNumber = getUI().tabForCoordinate(this, e.getX(), e.getY());
    if (tabNumber < 0)
        return;
    CloseTabIcon icon = (CloseTabIcon) getIconAt(tabNumber);
    if (icon != null) {
        Rectangle rect = icon.getBounds();
        Point pos = headerViewport == null ? new Point() : headerViewport
                .getViewPosition();
        Rectangle drawRect = new Rectangle(rect.x - pos.x, rect.y - pos.y,
                rect.width, rect.height);

        if (e.getID() == MouseEvent.MOUSE_PRESSED) {
            icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
            repaint(drawRect);
        } else if (e.getID() == MouseEvent.MOUSE_MOVED
                || e.getID() == MouseEvent.MOUSE_DRAGGED
                || e.getID() == MouseEvent.MOUSE_CLICKED) {
            pos.x += e.getX();
            pos.y += e.getY();
            if (rect.contains(pos)) {
                if (e.getID() == MouseEvent.MOUSE_CLICKED) {
                    int selIndex = getSelectedIndex();
                    if (fireCloseTab(selIndex)) {
                        if (selIndex > 0) {
                            // to prevent uncatchable null-pointers
                            Rectangle rec = getUI().getTabBounds(this,
                                    selIndex - 1);

                            MouseEvent event = new MouseEvent((Component) e
                                    .getSource(), e.getID() + 1, System
                                    .currentTimeMillis(), e.getModifiers(),
                                    rec.x, rec.y, e.getClickCount(), e
                                    .isPopupTrigger(), e
                                    .getButton());
                            dispatchEvent(event);
                        }
                        // the tab is being closed
                        // removeTabAt(tabNumber);
                        remove(selIndex);
                    } else {
                        icon.mouseover = false;
                        icon.mousepressed = false;
                        repaint(drawRect);
                    }
                } else {
                    icon.mouseover = true;
                    icon.mousepressed = e.getModifiers() == MouseEvent.BUTTON1_MASK;
                }
            } else {
                icon.mouseover = false;
            }
            repaint(drawRect);
        }
    }
}