FMouseAdapter == more responsive/reliable clicking
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
FMouseAdapter == more responsive/reliable clicking
by drdev » 30 Oct 2013, 16:03
My biggest issue with Java, which I've discovered through working with Forge, is that the mouseClick event is only raised if the mouse doesn't move even a single pixel between mouse down and mouse up. As a result, any component that uses this event to trigger some action has usability problems where clicking it seemingly fails half the time. We've solved this for some components by using mousePressed or mouseReleased instead, but some places that use mousePressed really shouldn't, since the action should be cancelable by dragging the mouse away (which may itself do some drag action), and those using mouseReleased are triggered incorrectly if you mouse down outside the component and release inside.
Another issue I've noticed with our own code is that many mouse event handlers don't bother to check the button clicked, so the left, right, and middle mouse buttons all do the same thing when really only the left button should. I've fixed a few of these since I started on Forge, but there are still many others, and it's easy to forget to check the button.
My solution to these problems was to create FMouseAdapter, a new class that extends MouseAdapter and raises more specific events for each mouse button, including a more forgiving click event, as well as a specific double click event that's fired on the second mouse down if the first mouse down and up was a click. Note that a click in this case is defined as a mouse down and mouse up both inside the same component, regardless of the path the mouse takes in between.
For components that have special drag handling, an optional boolean parameter can be passed to the constructor to indicate such, which then tweaks it so the click events aren't raised if the mouse moves more than a couple pixels, which would start a drag. There's also a new DragDrop event that fires for such components if the mouse moves too much to be a click, which should replace mouseReleased for handling ending a drag operation.
Here's the full API of functions that can be overridden. Note that the base MouseAdapter functions like mousePressed can not be overridden.
onLeftMouseDown(e) - replaces mousePressed
onLeftMouseUp(e) - replaces mouseReleased
onLeftClick(e) - replaces mouseClicked
onLeftDoubleClick(e) - replaces mousePressed/Released/Clicked with e.getClickCount() == 2
onLeftMouseDragging(e) - replaces mouseDragged
onLeftMouseDragDrop(e) - replaces mouseReleased for ending drag action
*** same 6 functions for "Middle" and "Right" mouse buttons ***
onMouseEnter(e) - replaces mouseEntered
onMouseExit(e) - replaces mouseExited
Moving forward, I'd recommend FMouseAdapter be used in place of MouseAdapter wherever possible. I've already taken the liberty of updating FLabel, DeckLister, and the column headers for ItemTables to use it, and I plan to update others over time.
Let me know if you have any questions or concerns.
Thanks.
-Dan
Another issue I've noticed with our own code is that many mouse event handlers don't bother to check the button clicked, so the left, right, and middle mouse buttons all do the same thing when really only the left button should. I've fixed a few of these since I started on Forge, but there are still many others, and it's easy to forget to check the button.
My solution to these problems was to create FMouseAdapter, a new class that extends MouseAdapter and raises more specific events for each mouse button, including a more forgiving click event, as well as a specific double click event that's fired on the second mouse down if the first mouse down and up was a click. Note that a click in this case is defined as a mouse down and mouse up both inside the same component, regardless of the path the mouse takes in between.
For components that have special drag handling, an optional boolean parameter can be passed to the constructor to indicate such, which then tweaks it so the click events aren't raised if the mouse moves more than a couple pixels, which would start a drag. There's also a new DragDrop event that fires for such components if the mouse moves too much to be a click, which should replace mouseReleased for handling ending a drag operation.
Here's the full API of functions that can be overridden. Note that the base MouseAdapter functions like mousePressed can not be overridden.
onLeftMouseDown(e) - replaces mousePressed
onLeftMouseUp(e) - replaces mouseReleased
onLeftClick(e) - replaces mouseClicked
onLeftDoubleClick(e) - replaces mousePressed/Released/Clicked with e.getClickCount() == 2
onLeftMouseDragging(e) - replaces mouseDragged
onLeftMouseDragDrop(e) - replaces mouseReleased for ending drag action
*** same 6 functions for "Middle" and "Right" mouse buttons ***
onMouseEnter(e) - replaces mouseEntered
onMouseExit(e) - replaces mouseExited
Moving forward, I'd recommend FMouseAdapter be used in place of MouseAdapter wherever possible. I've already taken the liberty of updating FLabel, DeckLister, and the column headers for ItemTables to use it, and I plan to update others over time.
Let me know if you have any questions or concerns.
Thanks.
-Dan
- drdev
- Programmer
- Posts: 1958
- Joined: 27 Jul 2013, 02:07
- Has thanked: 189 times
- Been thanked: 565 times
1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 60 guests