|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectMouseAdapter
MouseInputAdapter
MouseSelectionTracker
public abstract class MouseSelectionTracker
Controller which allows the user to select a region of a component. The user must click on a point in the component, then drag the mouse pointer whilst keeping the button pressed. During the dragging, the shape which is drawn is usually a rectangle. But other shapes can be used such as, for example, an ellipse. To use this class, it is necessary to create a derived class which defines the following methods:
selectionPerformed(int, int, int, int) (mandatory)getModel(java.awt.event.MouseEvent) (optional)This controller should then be registered with one, and only one, component using the following syntax:
Component component = ... MouseSelectionTracker control = ... component.addMouseListener(control);
| display/geotk-widgets-swing (download) | View source code for this class |
| Constructor Summary | |
|---|---|
MouseSelectionTracker()
Constructs an object which will allow rectangular regions to be selected using the mouse. |
|
| Method Summary | |
|---|---|
protected Shape |
getModel(MouseEvent event)
Returns the geometric shape to use for marking the boundaries of a region. |
Shape |
getSelectedArea(AffineTransform transform)
Returns the geometric shape surrounding the last region to be selected by the user. |
void |
mouseDragged(MouseEvent event)
Informs this controller that the mouse has been dragged. |
void |
mouseMoved(MouseEvent event)
Informs this controller that the mouse has been moved but not as a result of the user selecting a region. |
void |
mousePressed(MouseEvent event)
Informs this controller that the mouse button has been pressed. |
void |
mouseReleased(MouseEvent event)
Informs this controller that the mouse button has been released. |
protected abstract void |
selectionPerformed(int ox,
int oy,
int px,
int py)
Method which is automatically invoked after the user selects a region with the mouse. |
void |
setXORColors(Color a,
Color b)
Specifies the colors to be used for drawing the outline of a box when the user selects a region. |
| Methods inherited from class MouseAdapter |
|---|
mouseClicked, mouseEntered, mouseExited, mouseWheelMoved |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface MouseListener |
|---|
mouseClicked, mouseEntered, mouseExited |
| Constructor Detail |
|---|
public MouseSelectionTracker()
| Method Detail |
|---|
public void setXORColors(Color a,
Color b)
a colors will be replaced by b colors and vice versa.
a - The color to be replaced by color b.b - The color replacing the color a.protected Shape getModel(MouseEvent event)
Ellipse2D vs Rectangle2D) and their parameters which are
not related to their position (for example, the arc size of a rectangle with rounded corners).
The shape returned will usually be an instance of a class derived from RectangularShape,
but could also be an instance of the Line2D class. Any other class risks
throwing a ClassCastException when executed.
The default implementation always returns an instance of Rectangle.
event - Mouse coordinate when the button is pressed. This information can be used by
subclasses overriding this method if the mouse location is relevant to the choice
of a geometric shape.
RectangularShape or Line2D, or null
to indicate that we do not want to make a selection.
protected abstract void selectionPerformed(int ox,
int oy,
int px,
int py)
ox - x coordinate of the mouse when the user pressed the mouse button.oy - y coordinate of the mouse when the user pressed the mouse button.px - x coordinate of the mouse when the user released the mouse button.py - y coordinate of the mouse when the user released the mouse button.
public Shape getSelectedArea(AffineTransform transform)
throws NoninvertibleTransformException
getModel(java.awt.event.MouseEvent):
Line2D (which means that this
MouseSelectionTracker only draws a line between points), the
object returned will belong to the Line2D class.Rectangle2D. There could be situations where the returned object
is an instance of an another class, for example if the affine transform performs a
rotation.
transform - Affine transform which converts logical coordinates into pixel coordinates.
This is usually the same transform than the one used for drawing in a
Graphics2D object.
null if no selection has yet been made.
NoninvertibleTransformException - If the affine transform can't be inverted.
public void mousePressed(MouseEvent event)
throws ClassCastException
MouseSelectionTracker to observe the mouse movements.
mousePressed in interface MouseListenermousePressed in class MouseAdapterevent - Contains mouse coordinates where the button has been pressed.
ClassCastException - if getModel(java.awt.event.MouseEvent) doesn't return a shape
from the class RectangularShape or Line2D.public void mouseDragged(MouseEvent event)
mouseDragged in interface MouseMotionListenermouseDragged in class MouseAdapterevent - Contains mouse coordinates when the cursor is being dragged.public void mouseReleased(MouseEvent event)
selectionPerformed(int, int, int, int) with the bounds of the selected region as parameters.
mouseReleased in interface MouseListenermouseReleased in class MouseAdapterevent - Contains mouse coordinates where the button has been released.public void mouseMoved(MouseEvent event)
MouseSelectionTracker is no longer interested in being informed about
mouse movements.
Note: Normally not necessary, but it seems that this listener sometimes stays registered when it shouldn't.
mouseMoved in interface MouseMotionListenermouseMoved in class MouseAdapterevent - Contains mouse coordinates when the cursor is being moved.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||