piccolo2d / piccolo2d.java

Structured 2D Graphics Framework
http://piccolo2d.org
Other
51 stars 14 forks source link

Horizontal scrolling causes an exception #207

Closed mro closed 9 years ago

mro commented 9 years ago

Originally reported on Google Code with ID 207

What steps will reproduce the problem?
1. Create a PFrame, e.g. by starting GraphEditorExample
2. Use horizontal scrolling, e.g. via touchpad or tilt-wheel mouse

What is the expected output? What do you see instead?
No output is expected, but the following exception is thrown:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: mousePressed without
buttons specified
    at org.piccolo2d.PCanvas$MouseEventInputSource.mousePressed(PCanvas.java:785)
    at java.awt.Component.processMouseEvent(Component.java:6264)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6032)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4235)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Furthermore, the API does not offer a convenient way to make use of horizontal scrolling
events.

What version of the product are you using? On what operating system?
Piccolo2D.Java 1.3 / SVN trunk at r1103
Ubuntu 10.10

Please provide any additional information below.

Reported by nlskrg on 2011-02-07 15:42:07

mro commented 9 years ago
Interesting!

What hardware are you using specifically?  Do AWT and Swing apps have the correct behaviour,
or is this just a limitation of the Swing --> Piccolo2D mouse event conversion process?

Reported by heuermh on 2011-02-07 17:07:39

mro commented 9 years ago
Good point, actually horizontal scrolling does not work with AWT and Swing apps, but
it does work in Eclipse. However, other applications do not throw an exception. Horizontal
scrolling results in a MouseEvent with getButton() returning MouseEvent.NOBUTTON causing
the Piccolo2D conversion process to throw the exception. Maybe this is a Java Swing
issue...

Reported by nlskrg on 2011-02-07 18:24:45

mro commented 9 years ago
I would assert Piccolo2D shouldn't throw an exception if getButton() returns MouseEvent.NOBUTTON
then.  There may be some confusion between MouseEvent.MOUSE_DRAGGED and MouseEvent.MOUSE_MOVED
though, see e.g. PCanvas.java, lines 729-734 and 744-749.

Reported by heuermh on 2011-11-01 19:34:36

mro commented 9 years ago
Line 761 creates the button value based on the raw event's getModifiers() (see call
to copyButtonsFromModifiers).

For the device you are talking about, does event.getModifiers() or event.getModifiersEx()
give any indication of a special button press? Maybe there is a natural translation
from that to some state we can track...

Reported by atdixon on 2011-11-02 01:39:47

mro commented 9 years ago
Unfortunately, the event does store much information in this case since horizontal scroll
wheel support seems not to be implemented in AWT/Swing. I have found this related feature
request:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6440198

Currently on my system two events are generated with the following properties:
java.awt.event.MouseEvent[MOUSE_PRESSED,(320,295),absolute(425,421),button=0,clickCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(320,295),absolute(425,421),button=0,clickCount=1]

The methods getModifiers() and getModifiersEx() return 0 for these events. Both events
cause an exception, I have only reported the fist one above.

Reported by nlskrg on 2011-11-02 20:40:29

mro commented 9 years ago
Actually it is not even possible to distinguish right from left scrolling with the events
fired by Sun Java 6. I have also tested this with OpenJDK Java 6/7 with the following
results for right tilt followed by left tilt:

Sun Java 6:
java.awt.event.MouseEvent[MOUSE_PRESSED,(385,400),absolute(549,601),button=0,clickCount=1]

java.awt.event.MouseEvent[MOUSE_RELEASED,(385,400),absolute(549,601),button=0,clickCount=1]
java.awt.event.MouseEvent[MOUSE_PRESSED,(387,400),absolute(551,601),button=0,clickCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(387,400),absolute(551,601),button=0,clickCount=1]

OpenJDK Java 6:
java.awt.event.MouseEvent[MOUSE_PRESSED,(245,274),absolute(350,400),button=0,clickCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(245,274),absolute(350,400),button=0,clickCount=1]
java.awt.event.MouseEvent[MOUSE_PRESSED,(311,274),absolute(416,400),button=0,clickCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(311,274),absolute(416,400),button=0,clickCount=1]

OpenJDK Java 7:
java.awt.event.MouseEvent[MOUSE_PRESSED,(261,202),absolute(366,328),button=5,extModifiers=Button5,clickCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(261,202),absolute(366,328),button=5,clickCount=1]
java.awt.event.MouseEvent[MOUSE_PRESSED,(261,202),absolute(366,328),button=4,extModifiers=Button4,clickCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(261,202),absolute(366,328),button=4,clickCount=1]

With Java 7 it might be possible to implement a workaround since button 4 and 5 are
used to indicate left and right scrolling, but this might be system dependent.

I would suggest just to ignore these events for now instead of throwing an exception
until Java officially supports horizontal scrolling.

Reported by nlskrg on 2011-11-03 21:26:16

mro commented 9 years ago
+1 to ignoring these events for now instead of throwing an exception for the release-1.3
branch.

A comment in the Sun bug above describes a workaround for OSX

"Apple have added a workaround for this in Radar #4631846 - horizontal scrolling creates
a MouseWheelEvent with the "Shift" modifier set. This is a much lower impact method
than that specified above and works quite well. Any chance it could be extended across
platform?"

For svn trunk I think Piccolo2D should forward on events to the best of its ability,
and add support to e.g. PInputEvent for these platform-specific workarounds, in case
clients wish to implement horizontal scrolling on their own.

Reported by heuermh on 2011-11-03 21:48:06

mro commented 9 years ago
I ran into this unexpectedly on linux with a mouse that had buttons 4-5 mismapped as
6-7 when testing issue 236.

I also wanted to forward this note I received from an AWT engineer:

"[H]orizontal scrolling is indeed a problem in AWT/Swing. We don't have public API
for that (but we do for vertical/wheel events). It can be introduced in JDK8, but given
the current status of AWT and Swing, I don't think it makes much sense.

However, some of the Swing controls (e.g. JScrollPane) support horizontal scrolling
emulation. When mouse wheel is rotated with Shift being pressed, horizontal scrolling
takes place. In Mac OS X Port, we translated native horizontal events (e.g. from MacBook/Pro
touchpad) into Shift+MouseWheel, so it should also work."

Reported by heuermh on 2012-02-23 22:11:15

mro commented 9 years ago
Fixed on branches/release-1.3.1

$ svn commit -m "Issue 207 ; ignore mouse pressed and released events with button MouseEvent.NOBUTTON
instead of throwing an exception" .
Committed revision 1174.

and svn trunk

$ svn commit -m "Issue 207 ; ignore mouse pressed and released events with button MouseEvent.NOBUTTON
instead of throwing an exception" .
Committed revision 1175.

Will create a new issue for button 4/5 support + horizontal scrolling emulation.

Reported by heuermh on 2012-08-31 20:12:18

mro commented 9 years ago
See related issue 241

Reported by heuermh on 2012-08-31 20:16:08

mro commented 9 years ago

Reported by heuermh on 2013-11-26 17:42:20