masghar / piccolo2d

Automatically exported from code.google.com/p/piccolo2d
0 stars 0 forks source link

Horizontal scrolling causes an exception #207

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by nls...@gmail.com on 7 Feb 2011 at 3:42

GoogleCodeExporter 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?

Original comment by heue...@gmail.com on 7 Feb 2011 at 5:07

GoogleCodeExporter 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...

Original comment by nls...@gmail.com on 7 Feb 2011 at 6:24

GoogleCodeExporter 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.

Original comment by heue...@gmail.com on 1 Nov 2011 at 7:34

GoogleCodeExporter 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...

Original comment by atdi...@gmail.com on 2 Nov 2011 at 1:39

GoogleCodeExporter 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,cli
ckCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(320,295),absolute(425,421),button=0,cl
ickCount=1]

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

Original comment by nls...@gmail.com on 2 Nov 2011 at 8:40

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter 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,cli
ckCount=1] 
java.awt.event.MouseEvent[MOUSE_RELEASED,(385,400),absolute(549,601),button=0,cl
ickCount=1]
java.awt.event.MouseEvent[MOUSE_PRESSED,(387,400),absolute(551,601),button=0,cli
ckCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(387,400),absolute(551,601),button=0,cl
ickCount=1]

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

OpenJDK Java 7:
java.awt.event.MouseEvent[MOUSE_PRESSED,(261,202),absolute(366,328),button=5,ext
Modifiers=Button5,clickCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(261,202),absolute(366,328),button=5,cl
ickCount=1]
java.awt.event.MouseEvent[MOUSE_PRESSED,(261,202),absolute(366,328),button=4,ext
Modifiers=Button4,clickCount=1]
java.awt.event.MouseEvent[MOUSE_RELEASED,(261,202),absolute(366,328),button=4,cl
ickCount=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.

Original comment by nls...@gmail.com on 3 Nov 2011 at 9:26

GoogleCodeExporter 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.

Original comment by heue...@gmail.com on 3 Nov 2011 at 9:48

GoogleCodeExporter 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."

Original comment by heue...@gmail.com on 23 Feb 2012 at 10:11

GoogleCodeExporter 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.

Original comment by heue...@gmail.com on 31 Aug 2012 at 8:12

GoogleCodeExporter commented 9 years ago
See related issue 241

Original comment by heue...@gmail.com on 31 Aug 2012 at 8:16

GoogleCodeExporter commented 9 years ago

Original comment by heue...@gmail.com on 26 Nov 2013 at 5:42