|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.event.MouseAdapter
javax.swing.event.MouseInputAdapter
skrueger.geotools.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 will normally be a rectangle. Other shapes could always 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)
(obligatory)getModel(java.awt.event.MouseEvent)
(optional)Component
component=... MouseSelectionTracker control=... component.addMouseListener(control);
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 called after the user selects a region with the mouse. |
void |
setXORColors(Color a,
Color b)
Specifies the colours to be used for drawing the outline of a box when the user selects a region. |
Methods inherited from class java.awt.event.MouseAdapter |
---|
mouseClicked, mouseEntered, mouseExited, mouseWheelMoved |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.awt.event.MouseListener |
---|
mouseClicked, mouseEntered, mouseExited |
Constructor Detail |
---|
public MouseSelectionTracker()
Method Detail |
---|
public void setXORColors(Color a, Color b)
a
colours will be replaced
by b
colours and vice versa.
protected Shape getModel(MouseEvent event)
Ellipse2D
vs Rectangle2D
) and their parameters
which are not linked to their position (for example, the rounding of a rectangle's
corners).
The shape returned will normally be from a class derived from RectangularShape
,
but could also be from the Line2D
class. Any other class risks throwing a
ClassCastException
when executed.
The default implementation always returns an object Rectangle
.
event
- Mouse coordinate when the button is pressed. This information can be used by
the derived classes which like to be informed of the position of the mouse before
chosing a geometric shape.
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)
:
MouseSelectionTracker
object only
draws a line between points), the object returned will belong to the Line2D
class.Rectangle2D
). There could always be situations where the object
returned is from another class, for example if the affine transform carries out a
rotation.
transform
- Affine transform which converts logical coordinates into pixel coordinates.
It is usually an affine transform which is used in a paint(...)
method to
draw shapes expressed in logical coordinates.
null
if no selection has yet been made.
NoninvertibleTransformException
- If the affine transform can't be inverted.public void mousePressed(MouseEvent event) throws ClassCastException
this
to observe the mouse movements.
mousePressed
in interface MouseListener
mousePressed
in class MouseAdapter
ClassCastException
- if getModel(java.awt.event.MouseEvent)
doesn't return a shape
from the class {link RectangularShape} or {link Line2D}.public void mouseDragged(MouseEvent event)
mouseDragged
in interface MouseMotionListener
mouseDragged
in class MouseAdapter
public void mouseReleased(MouseEvent event)
selectionPerformed(int, int, int, int)
with
the bounds of the selected region as parameters.
mouseReleased
in interface MouseListener
mouseReleased
in class MouseAdapter
public void mouseMoved(MouseEvent event)
this
is no longer
interested in being informed about mouse movements.
mouseMoved
in interface MouseMotionListener
mouseMoved
in class MouseAdapter
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |