本文整理汇总了Java中java.awt.event.MouseEvent.MOUSE_PRESSED属性的典型用法代码示例。如果您正苦于以下问题:Java MouseEvent.MOUSE_PRESSED属性的具体用法?Java MouseEvent.MOUSE_PRESSED怎么用?Java MouseEvent.MOUSE_PRESSED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.event.MouseEvent
的用法示例。
在下文中一共展示了MouseEvent.MOUSE_PRESSED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: eventDispatched
@Override public void eventDispatched(AWTEvent event) {
if (ignoreMouseEvents) {
return;
}
Component root = SwingUtilities.getRoot((Component) event.getSource());
if (root instanceof IRecordingArtifact || root.getName().startsWith("###")) {
return;
}
if (!(event instanceof MouseEvent)) {
return;
}
MouseEvent mouseEvent = (MouseEvent) event;
mouseEvent.consume();
if (event.getID() == MouseEvent.MOUSE_PRESSED) {
disposeOverlay();
Component mouseComponent = SwingUtilities.getDeepestComponentAt(mouseEvent.getComponent(), mouseEvent.getX(),
mouseEvent.getY());
if (mouseComponent == null) {
return;
}
mouseEvent = SwingUtilities.convertMouseEvent(mouseEvent.getComponent(), mouseEvent, mouseComponent);
setComponent(mouseComponent, mouseEvent.getPoint(), true);
return;
}
}
示例3: pressGeneratesSameEvents
public void pressGeneratesSameEvents() throws Throwable {
events = MouseEvent.MOUSE_PRESSED;
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());
}
示例4: eventDispatched
/**
* Popup should be closed under some circumstances. Namely when mouse is
* pressed or released outside of popup or when key is pressed during the
* time popup is visible.
*/
public void eventDispatched(AWTEvent event) {
if (event.getSource() == this) {
return;
}
if (event instanceof MouseEvent) {
if (event.getID() == MouseEvent.MOUSE_RELEASED) {
long time = System.currentTimeMillis();
// check if button was just slowly clicked
if (time - invocationTime > 500) {
if (!onSwitcherTable((MouseEvent) event)) {
// Don't take any chances
hideCurrentPopup();
}
}
} else if (event.getID() == MouseEvent.MOUSE_PRESSED) {
if (!onSwitcherTable((MouseEvent) event)) {
// Don't take any chances
if (event.getSource() != invokingComponent) {
// If it's the invoker, don't do anything - it will
// generate another call to invoke(), which will do the
// hiding - if we do it here, it will get shown again
// when the button processes the event
hideCurrentPopup();
}
}
}
} else if (event instanceof KeyEvent) {
if (event.getID() == KeyEvent.KEY_PRESSED) {
Toolkit.getDefaultToolkit().removeAWTEventListener(this);
hideCurrentPopup();
}
}
}
示例5: handleJavaMouseEvent
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;
}
}
示例6: handleEvent
@Override
public void handleEvent(java.awt.AWTEvent e) {
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
emulateActivation(true);
}
super.handleEvent(e);
}
示例7: 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();
}
示例8: processMouseEvent
@Override
protected void processMouseEvent(MouseEvent e) {
switch(e.getID()) {
case MouseEvent.MOUSE_PRESSED:
selectionDisabled = false;
break;
case MouseEvent.MOUSE_RELEASED:
selectionDisabled = false;
break;
case MouseEvent.MOUSE_CLICKED:
selectionDisabled = false;
break;
case MouseEvent.MOUSE_ENTERED:
selectionDisabled = false;
break;
case MouseEvent.MOUSE_EXITED:
selectionDisabled = false;
break;
case MouseEvent.MOUSE_MOVED:
break;
case MouseEvent.MOUSE_DRAGGED:
if (selectionDisabled) {
//System.err.println("\nDrag DISABLED.");
return ;
}
break;
case MouseEvent.MOUSE_WHEEL:
break;
}
super.processMouseEvent(e);
}
示例9: eventDispatched
@Override
public void eventDispatched(AWTEvent event) {
if (event.getID() == MouseEvent.MOUSE_PRESSED) {
onClick(event);
/*
} else if (event.getID() == KeyEvent.KEY_PRESSED) {
if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_ESCAPE) {
shutdown();
}
*/
}
}
示例10: processEventImpl
private void processEventImpl(AWTEvent e) {
super.processEvent(e);
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
if (isFocusable()) requestFocus();
else button.requestFocus();
}
}
示例11: 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;
}
示例12: processMouseEvent
/** Forwards mouse events to a renderer (tree).
*/
private void processMouseEvent(MouseEvent e) {
if (shouldIgnore(e)) {
return;
}
Point p = e.getPoint();
int row = table.rowAtPoint(p);
int column = table.columnAtPoint(p);
// The autoscroller can generate drag events outside the Table's range.
if ((column == -1) || (row == -1)) {
return;
}
// for automatic jemmy testing purposes
if ((getEditingColumn() == column) && (getEditingRow() == row)) {
return;
}
boolean changeSelection = true;
if (isTreeColumn(column)) {
TreePath path = tree.getPathForRow(TreeTable.this.rowAtPoint(e.getPoint()));
Rectangle r = tree.getPathBounds(path);
if ((e.getX() >= (r.x - positionX)) && (e.getX() <= (r.x - positionX + r.width))
|| isLocationInExpandControl( path, p )
|| e.getID() == MouseEvent.MOUSE_RELEASED || e.getID() == MouseEvent.MOUSE_CLICKED ) {
changeSelection = false;
}
}
if (table.getSelectionModel().isSelectedIndex(row) && e.isPopupTrigger()) {
return;
}
if (table.editCellAt(row, column, e)) {
setDispatchComponent(e);
repostEvent(e);
}
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
table.requestFocus();
}
CellEditor editor = table.getCellEditor();
if (changeSelection && ((editor == null) || editor.shouldSelectCell(e))) {
setValueIsAdjusting(true);
table.changeSelection(row, column,
Utilities.isMac() ? e.isMetaDown() : e.isControlDown(), //use META key on Mac to toggle selection
e.isShiftDown());
setValueIsAdjusting(false);
}
}
示例13: 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;
}
示例14: testClickInvokesCustomEditor
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);
}
}
示例15: handleJavaMouseEvent
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)
{
@SuppressWarnings("deprecation")
final int modifiers = e.getModifiers();
action(e.getWhen(), modifiers);
}
pressed = false;
armed = false;
repaint();
}
break;
case MouseEvent.MOUSE_ENTERED:
if (pressed)
armed = true;
break;
case MouseEvent.MOUSE_EXITED:
armed = false;
break;
}
}