本文整理汇总了Java中java.awt.event.MouseEvent.MOUSE_CLICKED属性的典型用法代码示例。如果您正苦于以下问题:Java MouseEvent.MOUSE_CLICKED属性的具体用法?Java MouseEvent.MOUSE_CLICKED怎么用?Java MouseEvent.MOUSE_CLICKED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.event.MouseEvent
的用法示例。
在下文中一共展示了MouseEvent.MOUSE_CLICKED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: singleClickGeneratesSameEvents
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());
}
示例2: isRightMouseButton
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;
}
示例3: potentialCommand
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);
}
}
示例4: eventDispatched
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();
}
}
}
}
示例5: processMouseEvent
/**
* 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();;
}
}
示例6: processMouseEvent
@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);
}
}
示例7: processMouseEvent
@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);
}
示例8: eventToString
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();
}
示例9: isLeftMouseButton
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;
}
示例10: isDoubleClick
/** 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);
}
示例11: main
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);
}
示例12: rightClickGeneratesSameEvents
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());
}
示例13: processEvent
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;
}
}
}
示例14: onCustomEditorButton
/** 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;
}
示例15: simulateClick
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);
}