Graphics Reference
In-Depth Information
Classes for Capturing Mouse Events
Interactive mouse or key operations can be implemented effectively by event-driven
programming. We call operations such as pressing a mouse button or a key events.
Event-driven programmingshouldconstantly checkfortheoccurrenceofevents and
perform prescribed executions when a particular event happens.
In the JasplotPanelDragLayerUI and JasplotPanelPopupLayer-
UI classes, we define a MouseInputHandler class that implements a Mouse-
InputListener defined in Swing todetect mouse events. Whenthis class creates
its object, the system starts to check for the defined mouse events.
Classes for Interpreting Mouse Events
We wish to interpret mouse events differently according to context. his is e ciently
realized by applying the “State” design pattern.
Statepatternallowsanobjecttoalteritsbehaviorwhenitsinternalstatechanges.
he object will appear to change its class (Gamma et al., ).
he State pattern defines a context class to present a single interface to the outside
world. It defines an abstract state base class and represents different states as sub-
classesofit.Wethendefinestate-specific behaviorintheappropriatestatesubclasses.
We maintain a private reference to the current state in the context class, and change
the state by changing the current state reference.
In Jasplot, a DragLayerState interface characterizes state classes. It declares
methodstodecidethebehaviorofmouseevents,suchas mousePressed , mouse-
Moved , mouseDragged and mouseReleased .heyareimplementedbyclasses
such as BrushingState , DragGestureState , DragLayerState ,
DraggingState ,etc. Oneof these classesis set to state fieldin the Jasplot-
PanelDragLayerUI classandexecutedby,forexample,thecall state.mouse-
Pressed(MouseEvent e) .hus,the mousePressed method causes differ-
Figure . . Classes for interpreting mouse events
Search WWH ::




Custom Search