下面列出了java.awt.event.MouseEvent#MOUSE_RELEASED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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();
}
}
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);
}
}
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);
}
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;
}
}
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();
}
}
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;
}
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});
}
@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();
}
}
}
}
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;
}
@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;
}
}
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();
}
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;
}
@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();
}
private boolean isForwardEvent(MouseEvent e) {
int eventID = e.getID();
return eventID == MouseEvent.MOUSE_PRESSED ||
eventID == MouseEvent.MOUSE_RELEASED ||
eventID == MouseEvent.MOUSE_WHEEL;
}
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());
}
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;
}
}
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;
}
}
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;
}
}
@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();
}