| javax.swing.event.MouseInputAdapter org.geotools.gui.swing.MouseReshapeTracker
MouseReshapeTracker | class MouseReshapeTracker extends MouseInputAdapter implements Shape(Code) | | Controls the position and size of a rectangle which the user can move
with their mouse. For example, this class can be used as follows:
public class MyClass extends JPanel
{
private final MouseReshapeTracker slider = new MouseReshapeTracker()
{
protected void
MouseReshapeTracker.clipChangeRequested clipChangeRequested (double xmin, double xmax, double ymin, double ymax) {
// Indicates what must be done if the user tries to move the
// rectangle outside the permitted limits.
// This method is optional.
}
protected void
MouseReshapeTracker.stateChanged stateChanged (boolean isAdjusting) {
// Method automatically called each time the user
// changes the position of the rectangle.
// Code here what it should do in this case.
}
};
private final AffineTransform transform = AffineTransform.getScaleInstance(10, 10);
public MyClass() {
slider.
MouseReshapeTracker.setFrame setFrame (0, 0, 1, 1);
slider.
MouseReshapeTracker.setClip setClip (0, 100, 0, 1);
slider.
MouseReshapeTracker.setTransform setTransform (transform);
addMouseMotionListener(slider);
addMouseListener (slider);
}
public void paintComponent(Graphics graphics) {
AffineTransform tr=...
Graphics2D g = (Graphics2D) graphics;
g.transform(transform);
g.setColor(new Color(128, 64, 92, 64));
g.fill (slider);
}
}
version: $Id: MouseReshapeTracker.java 22710 2006-11-12 18:04:54Z desruisseaux $ author: Martin Desruisseaux |
Constructor Summary | |
public | MouseReshapeTracker() Constructs an object capable of moving and resizing a rectangular
shape through mouse movements. | public | MouseReshapeTracker(RectangularShape shape) Constructs an object capable of moving and resizing a rectangular shape
through mouse movements.
Parameters: shape - Rectangular geometric shape. |
Method Summary | |
public synchronized JComponent | addEditor(Format format, int side, Component toRepaint) Adds an editor in which the user can explicitly specify the
coordinates of one of the edges of the rectangle. | protected void | clipChangeRequested(double xmin, double xmax, double ymin, double ymax) Method called automatically when a change in the clip is required.
This method can be called, for example, when the user manually edits
the position of the rectangle in a text field, and the new position
falls outside the current clip. | public boolean | contains(Point2D point) Indicates whether the rectangular shape contains the specified point. | public boolean | contains(double x, double y) Indicates whether the rectangular shape contains the specified point. | public boolean | contains(Rectangle2D rect) Indicates whether the rectangular shape contains the specified
rectangle. | public boolean | contains(double x, double y, double width, double height) Indicates whether the rectangular shape contains the specified
rectangle. | public Rectangle | getBounds() Returns the position and the bounds of the rectangle. | public Rectangle2D | getBounds2D() Returns the position and the bounds of the rectangle. | public double | getCenterX() Returns the x coordinate of the centre of the rectangle
(logical coordinate, not pixel coordinate). | public double | getCenterY() Returns the y coordinate of the centre of the rectangle
(logical coordinate, not pixel coordinate). | public Rectangle2D | getClip() Returns the bounds between which the rectangle can move. | public Rectangle2D | getFrame() Returns the position and the bounds of the rectangle. | public double | getHeight() Returns the height of the rectangle. | public double | getMaxX() Returns the maximum x coordinate of the rectangle
(the logical coordinate, not the pixel coordinate). | public double | getMaxY() Returns the maximum y coordinate of the rectangle
(the logical coordinate, not the pixel coordinate). | public double | getMinX() Returns the minimum x coordinate of the rectangle
(the logical coordinate, not the pixel coordinate). | public double | getMinY() Returns the minimum y coordinate of the rectangle
(the logical coordinate, not the pixel coordinate). | public PathIterator | getPathIterator(AffineTransform transform) Returns a path iterator for the rectangular shape to be drawn. | public PathIterator | getPathIterator(AffineTransform transform, double flatness) Returns a path iterator for the rectangular shape to be drawn. | public double | getWidth() Returns the width of the rectangle. | public boolean | intersects(Rectangle2D rect) Indicates whether the rectangular shape intersects the specified
rectangle. | public boolean | intersects(double x, double y, double width, double height) Indicates whether the rectangular shape intersects the specified
rectangle. | public boolean | isAdjustable(int side) Indicates whether the size of a rectangle can be modified using
a specified edge. | public boolean | isEditorsSynchronized(int axis) When the position of one of the rectangle's edges is edited manually,
specifies whether the opposite edge should also be adjusted. | public boolean | isEmpty() Indicates whether the rectangle is empty. | public boolean | isMoveable() Indicates whether the rectangle can be moved with the mouse. | public void | mouseDragged(MouseEvent e) Method called automatically during mouse drags. | public void | mouseMoved(MouseEvent event) Method called automatically during mouse movements. | public void | mousePressed(MouseEvent e) Method called automatically when the user presses a mouse button
anywhere within the component. | public void | mouseReleased(MouseEvent event) Method called automatically when the user releases the mouse button. | public synchronized void | removeEditor(JComponent editor) Removes an editor from the list of those which display the
coordinates of the visor. | public void | setAdjustable(int side, boolean adjustable) Specifies whether the size of the rectangle can be modified using the
specified edge. | final public void | setClip(Rectangle2D rect) Defines the bounds between which the rectangle can move. | final public void | setClip(double x, double y, double width, double height) Defines the bounds between which the rectangle can move. | public void | setClipMinMax(double xmin, double xmax, double ymin, double ymax) Defines the bounds between which the rectangle can move. | public void | setEditorsSynchronized(int axis, boolean state) When the position of one of the rectangle's edges is edited manually,
specifies whether the opposite edge should also be adjusted. | final public boolean | setFrame(Rectangle2D frame) Defines a new position and bounds for the rectangle. | public boolean | setFrame(double x, double y, double width, double height) Defines a new position and bounds for the rectangle. | public void | setMoveable(boolean moveable) Specifies whether the rectangle can be moved with the mouse. | public void | setTransform(AffineTransform newTransform) Declares the affine transform which will transform the logical
coordinates into pixel coordinates. | final public void | setX(double min, double max) Defines the new range of values covered by the rectangle according to
the x axis. | final public void | setY(double min, double max) Defines the new range of values covered by the rectangle according to
the y axis. | protected void | stateChanged(boolean isAdjusting) Method called automatically after the position and
size of the visor has changed. | protected void | stateWillChange(boolean isAdjusting) Method called automatically before the position
or the size of the visor has changed. | public String | toString() Returns a character string representing this object. | public void | updateEditors() Updates the text in the editors. |
MouseReshapeTracker | public MouseReshapeTracker()(Code) | | Constructs an object capable of moving and resizing a rectangular
shape through mouse movements. The rectangle will be positioned, by
default at the coordinates (0,0). Its width and height will be null.
|
MouseReshapeTracker | public MouseReshapeTracker(RectangularShape shape)(Code) | | Constructs an object capable of moving and resizing a rectangular shape
through mouse movements.
Parameters: shape - Rectangular geometric shape. This shape does not have to bea rectangle. It could, for example, be a circle. Thecoordinates of this shape will be the initial coordinates of thevisor. They are logical coordinates and not pixel coordinatesNote that the constructor retains a direct reference to thisshape, without creating a clone. As a consequence, any modification carried out on the geometric shape will haverepercussions for this objet MouseReshapeTracker and vice versa. |
addEditor | public synchronized JComponent addEditor(Format format, int side, Component toRepaint) throws IllegalArgumentException(Code) | | Adds an editor in which the user can explicitly specify the
coordinates of one of the edges of the rectangle. Each time
the user drags the rectangle, the text appearing in this editor
will automatically be updated. If the user explicitly enters
a new value in this editor, the position of the rectangle will be
adjusted.
Parameters: format - Format to use for writing and interpreting the valuesin the editor. Parameters: side - Edge of the rectangle whose coordinates will becontrolled by the editor. It should be one of thefollowing constants:These constants designate the edge visible on screen. For example, NORTH always designates the top edge on the screen.However, this could correspond to another edge of the logicalshape this depending on the affine transform which was specified during the last call to MouseReshapeTracker.setTransform. For example, AffineTransform.getScaleInstance(+1,-1) has the effect ofinverting the y axis so that the ymax valuesappear to the North rather than the ymin values. Parameters: toRepaint - Component to repaint after a field has been edited,or null if there isn't one. An editor in which the user can specify the position ofone of the edges of the geometric shape. throws: IllegalArgumentException - if side isn't oneof the recognised codes. |
clipChangeRequested | protected void clipChangeRequested(double xmin, double xmax, double ymin, double ymax)(Code) | | Method called automatically when a change in the clip is required.
This method can be called, for example, when the user manually edits
the position of the rectangle in a text field, and the new position
falls outside the current clip. This method does not have to
accept a clip change. It can do nothing, which is the same as
refusing any change. It can also always unconditionally accept any
change by calling
MouseReshapeTracker.setClipMinMax . Finally, it can reach a
compromise solution by imposing certain conditions on the changes.
The default implementation does nothing, which means that no
automatic change in the clip will be authorised.
|
contains | public boolean contains(Point2D point)(Code) | | Indicates whether the rectangular shape contains the specified point.
This point should be expressed in logical coordinates.
|
contains | public boolean contains(double x, double y)(Code) | | Indicates whether the rectangular shape contains the specified point.
This point should be expressed in logical coordinates.
|
contains | public boolean contains(Rectangle2D rect)(Code) | | Indicates whether the rectangular shape contains the specified
rectangle. This rectangle should be expressed in logical
coordinates. This method can conservatively return
false as permitted by the
Shape specification.
|
contains | public boolean contains(double x, double y, double width, double height)(Code) | | Indicates whether the rectangular shape contains the specified
rectangle. This rectangle must be expressed in logical
coordinates. This method can conservatively return
false as permitted by the
Shape specification.
|
getBounds | public Rectangle getBounds()(Code) | | Returns the position and the bounds of the rectangle. These
bounds can be slightly bigger than those returned by
MouseReshapeTracker.getFrame since
getBounds2D() returns the
bounds of the rectangle visible on screen, which can have certain
minimum bounds.
|
getBounds2D | public Rectangle2D getBounds2D()(Code) | | Returns the position and the bounds of the rectangle. These
bounds can be slightly bigger than those returned by
MouseReshapeTracker.getFrame since
getBounds2D() returns the
bounds of the rectangle visible on screen, which can have certain
minimum bounds.
|
getCenterX | public double getCenterX()(Code) | | Returns the x coordinate of the centre of the rectangle
(logical coordinate, not pixel coordinate).
|
getCenterY | public double getCenterY()(Code) | | Returns the y coordinate of the centre of the rectangle
(logical coordinate, not pixel coordinate).
|
getClip | public Rectangle2D getClip()(Code) | | Returns the bounds between which the rectangle can move.
These bounds are specified in logical coordinates.
|
getHeight | public double getHeight()(Code) | | Returns the height of the rectangle. This height is expressed
in logical coordinates, not pixel coordinates.
|
getMaxX | public double getMaxX()(Code) | | Returns the maximum x coordinate of the rectangle
(the logical coordinate, not the pixel coordinate).
|
getMaxY | public double getMaxY()(Code) | | Returns the maximum y coordinate of the rectangle
(the logical coordinate, not the pixel coordinate).
|
getMinX | public double getMinX()(Code) | | Returns the minimum x coordinate of the rectangle
(the logical coordinate, not the pixel coordinate).
|
getMinY | public double getMinY()(Code) | | Returns the minimum y coordinate of the rectangle
(the logical coordinate, not the pixel coordinate).
|
getWidth | public double getWidth()(Code) | | Returns the width of the rectangle. This width is expressed
in logical coordinates, not pixel coordinates.
|
intersects | public boolean intersects(Rectangle2D rect)(Code) | | Indicates whether the rectangular shape intersects the specified
rectangle. This rectangle must be expressed in logical coordinates.
This method can conservatively return
true as permitted by
the
Shape specification.
|
intersects | public boolean intersects(double x, double y, double width, double height)(Code) | | Indicates whether the rectangular shape intersects the specified
rectangle. This rectangle must be expressed in logical coordinates.
This method can conservatively return
true as permitted by
the
Shape specification.
|
isAdjustable | public boolean isAdjustable(int side)(Code) | | Indicates whether the size of a rectangle can be modified using
a specified edge. The specified edge must be one of the following
constants:
These constants designate the edge which is visible on screen. For
example,
NORTH always designates the top edge on the
screen. However, this could correspond to another edge of the logical
shape
this depending on the affine transform which was
specified during the last call to
MouseReshapeTracker.setTransform . For example,
AffineTransform.getScaleInstance(+1,-1) has the effect of
inverting the y axis so that the ymax values
appear to the North rather than the ymin values.
|
isEditorsSynchronized | public boolean isEditorsSynchronized(int axis) throws IllegalArgumentException(Code) | | When the position of one of the rectangle's edges is edited manually,
specifies whether the opposite edge should also be adjusted. By default,
the edges are not synchronised.
Parameters: axis - SwingConstants.HORIZONTAL to determine thesynchronisation of the left and right edges, orSwingConstants.VERTICAL to determine thesynchronisation of the top and bottom edges. true if the specified edges are synchronised,or false if not throws: IllegalArgumentException - if axis isn't one of the valid codes. |
isEmpty | public boolean isEmpty()(Code) | | Indicates whether the rectangle is empty. This will be
the case if the width and / or height is null.
|
isMoveable | public boolean isMoveable()(Code) | | Indicates whether the rectangle can be moved with the mouse. By default,
it can be moved but not resized.
|
mouseDragged | public void mouseDragged(MouseEvent e)(Code) | | Method called automatically during mouse drags. The default
implementation applies the mouse movement to the rectangle and notifies
the component where the event which it needs to redraw, at least in
part, came from.
|
mouseMoved | public void mouseMoved(MouseEvent event)(Code) | | Method called automatically during mouse movements. The default
implementation checks whether the cursor is inside the rectangle or on
one of its edges, and adjusts the mouse pointer icon accordingly.
|
mousePressed | public void mousePressed(MouseEvent e)(Code) | | Method called automatically when the user presses a mouse button
anywhere within the component. The default implementation
checks if the button was pressed whilst the mouse cursor was
within the rectangle. If so, this object will track the mouse drags
to move or resize the rectangle.
|
mouseReleased | public void mouseReleased(MouseEvent event)(Code) | | Method called automatically when the user releases the mouse button.
The default implementation calls
MouseReshapeTracker.stateChanged with the
argument
false , in order to inform the derived classes
that the changes are finished.
|
removeEditor | public synchronized void removeEditor(JComponent editor)(Code) | | Removes an editor from the list of those which display the
coordinates of the visor.
Parameters: editor - Editor to remove. |
setAdjustable | public void setAdjustable(int side, boolean adjustable)(Code) | | Specifies whether the size of the rectangle can be modified using the
specified edge. The specified edge must be one of the following
constants:
These constants designate the edge which is visible on screen. For
example,
NORTH always designates the top edge on the
screen. However, this could correspond to another edge of the logical
shape
this depending on the affine transform which was
specified during the last call to
MouseReshapeTracker.setTransform . For example,
AffineTransform.getScaleInstance(+1,-1) has the effect of
inverting the y axis so that the ymax values
appear to the North rather than the ymin values.
|
setClip | final public void setClip(Rectangle2D rect)(Code) | | Defines the bounds between which the rectangle can move.
This method manages infinities correctly if the specified
rectangle has redefined its
getMaxX() and
getMaxY() methods correctly.
See Also: MouseReshapeTracker.setClipMinMax |
setClip | final public void setClip(double x, double y, double width, double height)(Code) | | Defines the bounds between which the rectangle can move. This method
simply calls
MouseReshapeTracker.setClipMinMax setClipMinMax(...) with the
appropriate parameters. It is defined in order to avoid confusion
amongst programmers used to Java2D conventions. If you want to
specify infinite values (in order to widen the visor's bounds to all
possible values along certain axes), you must use
MouseReshapeTracker.setClipMinMax setClipMinMax(...) rather than
setClip(...) .
|
setClipMinMax | public void setClipMinMax(double xmin, double xmax, double ymin, double ymax)(Code) | | Defines the bounds between which the rectangle can move. Note that this
method's arguments don't correspond to the normal arguments of
java.awt.geom.Rectangle2D . Java2D convention demands
that we specify a rectangle using a quadruplet
(
x ,
y ,
width ,
height )
However, this is a bad choice in the context of almost all the methods
in our library. As well as complicating most calculations (if you need
convincing, just count the number of occurrences of the expression
x+width even in the geometric classes of Java2D),
it is incapable of correctly representing a rectangle which has one or
more coordinates stretching to infinity. A better convention would
have been to use the minimum and maximum values according to
x and y, as this method does.
This method's arguments define the minimum and maximum values that the
logical coordinates of the rectangle can take.
The values
java.lang.Double.NEGATIVE_INFINITY and
java.lang.Double.POSITIVE_INFINITY are valid for indicating
that the visor can extend across all values according to certain axes.
The value
java.lang.Double.NaN for a given argument indicates
that we want to keep the old value. If the visor doesn't fit
completely within the new bounds, it will be moved and resized as needed
in order to make it fit.
|
setEditorsSynchronized | public void setEditorsSynchronized(int axis, boolean state) throws IllegalArgumentException(Code) | | When the position of one of the rectangle's edges is edited manually,
specifies whether the opposite edge should also be adjusted. By default,
the edges are not synchronised.
Parameters: axis - SwingConstants.HORIZONTAL to change thesynchronisation of the left and right edges, orSwingConstants.VERTICAL to change the synchronisation of the top and bottom edges. Parameters: state - true to synchronise the edges, or false to desynchronise. throws: IllegalArgumentException - if axis isn't one of the valid codes. |
setFrame | final public boolean setFrame(Rectangle2D frame)(Code) | | Defines a new position and bounds for the rectangle. The coordinates
passed to this method should be logical coordinates rather than pixel
coordinates. If the range of values covered by the rectangle is
limited by a call to
MouseReshapeTracker.setClip , the rectangle will be
moved and resized as needed to fit into the permitted region.
true if the rectangle's coordinates have changed. See Also: MouseReshapeTracker.getFrame |
setFrame | public boolean setFrame(double x, double y, double width, double height)(Code) | | Defines a new position and bounds for the rectangle. The coordinates
passed to this method should be logical coordinates rather than pixel
coordinates. If the range of values covered by the rectangle is
limited by a call to
MouseReshapeTracker.setClip , the rectangle will be
moved and resized as needed to fit into the permitted region.
true if the rectangle's coordinates have changed. See Also: MouseReshapeTracker.setX See Also: MouseReshapeTracker.setY |
setMoveable | public void setMoveable(boolean moveable)(Code) | | Specifies whether the rectangle can be moved with the mouse. The value
false indicates that the rectangle cannot be moved, but can
still be resized if
MouseReshapeTracker.setAdjustable has been called with the
appropriate parameters.
|
setTransform | public void setTransform(AffineTransform newTransform)(Code) | | Declares the affine transform which will transform the logical
coordinates into pixel coordinates. This is the affine transform
specified in
java.awt.Graphics2D.transform at the moment that
this is drawn. The information contained in this affine
transform is necessary for several of this class's methods to work.
It is the programmer's responsability to ensure that this
information is always up-to-date. By default,
MouseReshapeTracker uses an identity transform.
|
stateChanged | protected void stateChanged(boolean isAdjusting)(Code) | | Method called automatically after the position and
size of the visor has changed. The call to
stateChanged must have been preceded by a call to
MouseReshapeTracker.stateWillChange . The
derived classes can redefine this method to take the necessary
actions when a change has just been actioned. They must not, however,
call any method which risks modifying the state of this object. The
default implementation does nothing.
Parameters: isAdjusting - true if the user is stillmodifying the position of the visor, false if they have released the mouse button. |
stateWillChange | protected void stateWillChange(boolean isAdjusting)(Code) | | Method called automatically before the position
or the size of the visor has changed. A call to
stateWillChange is normally followed by a call to
MouseReshapeTracker.stateChanged , except if the expected change
didn't ultimately occur. The derived classes can redefine this method
to take the necessary actions when a change is on the point of being
actioned. They must not, however, call any method which risks modifying
the state of this object. The default implementation does nothing.
Parameters: isAdjusting - true if the user is stillmodifying the position of the visor, false if they have released the mouse button. |
toString | public String toString()(Code) | | Returns a character string representing this object.
|
updateEditors | public void updateEditors()(Code) | | Updates the text in the editors. Each editor added by the
method
MouseReshapeTracker.addEditor addEditor(...) will have its
text reformatted. This method can be called, for example,
after changing the format used by the editors. It is not
necessary to call this method each time the mouse moves;
it is done automatically.
|
|
|