G2D event refactoring
Original problem statement
- Currently there are two different event handling systems in Simantics which have overlapping and partially contradicting functionality:
- Events are handled at element level (higher level)
- Events are handled at G2d node level (lower level)
Both event handling systems may react to mouse / keyboard events without any coordination causing unexpected behaviour.
This causes problems to both end users and developers.
Problems to end-users:
- Diagram editor reacts to mouse events / selections / editing differently as expected by user
- Example bug. #570 (closed)
-
➡ frustration -
➡ mistakes
Problems to developers:
- Difficult to implement components with more advanced but easy-to-use UI (e.g. tool for drawing free graphics)
- Workarounds creep into the code
-
➡ more bugs -
➡ higher maintenance costs
-
Solution
- Give event handler at G2D node level the highest priority
- higher granularity in event handling, better UIs
- may require fixes to current components
- Use spatial tree to direct mouse events to correct nodes (based on current R-tree implementation
- maintain good performance
- Add possibility to capture mouse/keyboards events
- events should not leak to wrong nodes/elements while user is interacting with specific component
- Fix current workarounds (TextNode, RouteGraphNode, ...)
Opportunities
- Easier to use software
- Components with richer UI features
- Less effort for implementing new diagram components and new features for existing components
Threats
- May require changes to product specific components which are not part of Simantics platform
What was implemented
- Most evident event handling problems within current diagram components were fixed
- Implemented hover effect showing which component will receive mouse events
- Give priority for G2D node event handler to support components with richer UI
- Unification of selection visualization for text components
Problems
- Major changes to event handling would require major changes to all existing diagram components
Implementation Notes
To register hover effect for PointerInteractor
call the following code after constructing PointerInteractor
in your DiagramViewer
implementation:
pi.setHoverColorFilter(new DefaultHoverColorFilter());
This should be put behind some kind of configurable option to make it possible to enable on-demand.
Edited by Tuukka Lehtonen