Posted by
Aryeh Weiss on
URL: http://imagej.273.s1.nabble.com/how-to-use-MouseAdapter-tp5024620.html
I am try to do something interactive, and for this reason I need to
learn ho wot use MouseAdapter.
I began with this, and it works fine.:
from java.awt.event import MouseAdapter
class DliteMouseListener (MouseAdapter):
def __init__ (self):
self.xLoc = 0
self.yLoc = 0
def mouseClicked (self, e):
print 'In DliteMouseListener: e.getX() =', e.getX(), ',
e.getY() =', e.getY()
self.xLoc = e.getX()
self.yLoc = e.getY()
and this calls it:
dML = DliteMouseListener()
ic = inputImp.getCanvas()
ic.addMouseListener (dML)
So far, it works fine.
Now I want to be able to detect if the shift or control key is pressed,
so I looked up MouseEvent, and found
getMouseModifiersText(int modifiers), so I tried to use
e.getMouseModifiersText("Shift") or e.getMouseModifiersText("Control")
to check if the Shift or Control key is pressed during the event.
I get the following error in the Fiji ConsoleAttributeError:
'java.awt.event.MouseEvent' object has no attribute 'getModifierStateText'
I tried variations of this such as using MouseEvent.shiftKey , or
MouseEvent.ctrlKey, and again these attributes do not exist.
When I pretty-print the MouseEvent e, I see that it gives my the
coordinates, the absolute coordinates, the button number, and the
clickCount. (and indeed, e.button worked).
At this point I realize that I do not understand something basic about
how this works.
Can I modify the dML class to do this, or am I completely off target and
I need something completely different to do what I am trying to do?
Thanks in advance for any assistance.
--aryeh
--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel
Ph: 972-3-5317638
FAX: 972-3-7384051
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html