使用 JUNG 和 Java 实现鼠标事件
我用 JUNG 程序在 Java 中制作了一个 PluggableGraphMouse 和 2 个 EditingGraphMousePluggings。如果我将修饰符设置为左键单击和右键单击,则它工作得很好,这是 setModifiers 代码:
ovalMouse.setModifiers(MouseEvent.BUTTON1_MASK);
circleMouse.setModifiers(MouseEvent.BUTTON3_MASK);
但是我想要的是让左键单击做一件事,然后 SHIFT + 左键单击(而不是右键单击)执行其他。我已经尝试了所有我能想到的组合,但似乎无法让它发挥作用。以下是我尝试过的一些更合乎逻辑的组合,但不起作用:
//My logic here is Button1 AND Shift is down but this doesn't work
circleMouse.setModifiers(MouseEvent.BUTTON1_MASK & MouseEvent.SHIFT_DOWN_MASK);
// My logic here is Button1 AND Shift but this doesn't work either
circleMouse.setModifiers(MouseEvent.BUTTON1_MASK & MouseEvent.SHIFT_MASK);
// Also tried InputEvents but those didn't work either
circleMouse.setModifiers(InputEvent.BUTTON1_DOWN_MASK & InputEvent.SHIFT_DOWN_MASK);
如果有人知道正确的修饰符是什么,以便我可以使用按钮 1 来表示 ovalMouse,使用按钮 1 + Shift 来表示circleMouse,请告诉我。谢谢。
I made a PluggableGraphMouse and 2 EditingGraphMousePluggings in my Java with JUNG program. If I set the modifiers to be left click and right click it works perfectly fine, here is the setModifiers code:
ovalMouse.setModifiers(MouseEvent.BUTTON1_MASK);
circleMouse.setModifiers(MouseEvent.BUTTON3_MASK);
What I'd like however is to have left click do one thing and SHIFT + left click (instead of right click) do the other. I've tried every combination I can think of but I can't seem to get it to work. Here are some of the more logical combinations I've tried that don't work:
//My logic here is Button1 AND Shift is down but this doesn't work
circleMouse.setModifiers(MouseEvent.BUTTON1_MASK & MouseEvent.SHIFT_DOWN_MASK);
// My logic here is Button1 AND Shift but this doesn't work either
circleMouse.setModifiers(MouseEvent.BUTTON1_MASK & MouseEvent.SHIFT_MASK);
// Also tried InputEvents but those didn't work either
circleMouse.setModifiers(InputEvent.BUTTON1_DOWN_MASK & InputEvent.SHIFT_DOWN_MASK);
If anyone knows what the correct modifiers are so I can use button 1 for ovalMouse and button 1 + shift for circleMouse please let me know. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要过滤任何实现
MouseListener
的JUNG2
的 xxxGraphMousePlugin 鼠标事件中的 Shift+Button3:Update
因此,如果您想区分以下鼠标事件
BUTTON3
和SHIFT+BUTTON3
,下面的测试将向您展示:在上面
JUNG2
下的测试中:随着 SHIFT键:按
SHIFT+BUTTON3
(SHIFT键+鼠标右键)将显示“BUTTON3”和“SHIFT+BUTTON3”消息SHIFT键除外:按
任意键+BUTTON3
(任意键+鼠标右键)只会显示“BUTTON3”消息To filter Shift+Button3 in any
JUNG2
's xxxGraphMousePlugin mouse event that implementsMouseListener
:Update
So, if you want to differentiate a mouse event between
BUTTON3
andSHIFT+BUTTON3
, the following test will show you:In the above test under
JUNG2
:With the SHIFT key: pressing
SHIFT+BUTTON3
(SHIFT key + right-click mouse button) will show both "BUTTON3" and "SHIFT+BUTTON3" messagesExcept the SHIFT key: pressing
any key + BUTTON3
(any key + right-click mouse button) will only show "BUTTON3" message