| java.lang.Object edu.hws.jcm.draw.CoordinateRect
CoordinateRect | public class CoordinateRect implements Tieable,Limits,Computable,InputObject(Code) | | A CoordinateRect represents a rectagular region in the xy-plane, specified
by values xmin,xmax,ymin,ymax. The conditions ymin < ymax and xmin < xmax
are enforced. (Values are swapped if necessary, and if min==max, they are
reset to -1 and +1. If any of the values are set to an infinite or NaN
value, then the coordinate rect won't display anything except the message
"Error: undefined limits".)
When the Rect is mapped onto the screen, there can be a gap of a specified
number of pixels between the min,max values and the edges of the rectangle
on the screen. If the gap is non-zero, then the actual range of coordinates
on the rect is larger than the range from the specifed min to max. (This is
done mainly so I could have axes that don't quite reach the edges of the rect.)
A CoordinateRect maintains a list of Drawable items. When the Rect's
draw() method is called, it calls the draw() method of each of the Drawable
items it contains. When its compute() method is called, it calls the
compute() method of any Drawable that is a Computable. When its checkInput()
method is called, it calls the checkInput() method of any Drawable that is
an InputObject.
A CoordinateRect represents a rectangular region in a DisplayCanvas.
It has a reference to that Canvas, which is set automatically when it is
added to the canvas. If the size, range, or gap on the CoordinateRect
change, it will ask the Canvas to redraw the area it occupies.
The values of xmin, xmax, ymin, ymax are exported as Value objects,
which can be used elsewhere in your program. The Value objects can
be obtained by calling getValueObject(). If you do this, you should
add the objects that depend on those values to a Controller and
register the Controller to listen for changes from this CoordinateRect
by calling the CoordinateRect.setOnChange(Controller) method.
|
Field Summary | |
final public static int | XMAX A constant for use with the getValueObject() method to specify which Value is to be returned. | final public static int | XMIN A constant for use with the getValueObject() method to specify which Value is to be returned. | final public static int | YMAX A constant for use with the getValueObject() method to specify which Value is to be returned. | final public static int | YMIN A constant for use with the getValueObject() method to specify which Value is to be returned. | protected boolean | changed Set to true when one of the limits or the gap has changed. | protected Vector | drawItems | protected Controller | onChange If non-null, this is the Controller that is notified when the limits change. | protected Tie | syncWith This contains other Limit objects with which the CoordinateRect is
synchronizing. |
Constructor Summary | |
public | CoordinateRect() Create a CoordinateRect with default limits: -5, 5, -5, 5. | public | CoordinateRect(double xmin, double xmax, double ymin, double ymax) Create a CoordinateRect with specified limits. |
Method Summary | |
public synchronized void | add(Drawable d) Add a drawable item to the CoordinateRect. | Draggable | checkDraggables(java.awt.event.MouseEvent evt) Check whether a mouse click (as specified in the MouseEvent parameter) is
a click on a Draggable item that wants to be dragged. | public void | checkInput() When this is called, the CoordinateRect will call the
checkInput method of any Drawable it contains that is
also an InputObject. | public void | clearRestoreBuffer() A CoordinateRect can store its current limits in a buffer. | public void | compute() When this is called, the CoordinateRect will call the compute method
of any Drawable it contains that is also a Computable. | protected void | doDraw(Graphics g) Draw all the Drawable items. | public void | draw(Graphics g, int width, int height) Draw in rect with upperleft corner (0,0) and specified width,height. | public synchronized void | draw(Graphics g, int left, int top, int width, int height) Draw in specified rect. | public double[] | equalizeAxes() Reset limits, if necessary, so scales on the axes are the same.
Only valid of the CoordinateRect has been drawn. | public Drawable | getDrawable(int i) Get the i-th Drawable in this Rect, or null if i is less than zero
or greater than or equal to the number of items. | public int | getDrawableCount() Returns the number of Drawable items that are in this CoordinateRect. | public int | getGap() Get the gap, in pixels, between the edges of
the CoordinateRect and the limits specified by xmin, xmax, ymin, and ymax. | public int | getHeight() Get the height in pixels of this CoordinateRect in the DisplayCanvas that contains it.
(This is only valid when the CoordinateRect has actually been displayed. | public int | getLeft() Get the left edge of this CoordinateRect in the DisplayCanvas that contains it.
(This is only valid when the CoordinateRect has actually been displayed. | public double[] | getLimits() Get an array containing the limits on the CoordinateRect in the order xmin, xmax, ymin, ymax. | public Controller | getOnChange() Get the controller that is notified when the limits on this
CoordinateRect change. | public double | getPixelHeight() Return the height of one pixel in this coordinate system.
(This is only valid when the CoordinateRect has actually been displayed. | public double | getPixelWidth() Return the width of one pixel in this coordinate system.
(This is only valid when the CoordinateRect has actually been displayed. | public long | getSerialNumber() Return the serial number of the CoordinateRect, which is incremented each time the limits change. | public int | getTop() Get the top edge of this CoordinateRect in the DisplayCanvas that contains it.
(This is only valid when the CoordinateRect has actually been displayed. | public Value | getValueObject(int which) Get a Value object representing one of the limits on this CoordinateRect. | public int | getWidth() Get the width in pixels of this CoordinateRect in the DisplayCanvas that contains it.
(This is only valid when the CoordinateRect has actually been displayed. | public double | getXmax() Get the maximum x-coordinate. | public double | getXmin() Get the mimimum x-coordinate. | public double | getYmax() Get the maximum x-coordinate. | public double | getYmin() Get the mimimum y-coordinate. | public void | notifyControllerOnChange(Controller c) Method required by InputObject interface; in this class, it calls the same method
recursively on any input objects containted in this CoordinateRect. | public double | pixelToX(int h) Convert a horizontal pixel coordinate into an x-coordinate.
(This is only valid when the CoordinateRect has actually been displayed. | public double | pixelToY(int y) Convert a vertical pixel coordinate into a y-coordinate.
(This is only valid when the CoordinateRect has actually been displayed. | public synchronized void | remove(Drawable d) Remove the given Drawable item, if present in this CoordinateRect. | public double[] | restore() A CoordinateRect can store its current limits in a buffer. | public void | setGap(int g) Set the gap. | public void | setLimits(double xmin, double xmax, double ymin, double ymax) | public void | setLimits(double[] d) Set the coordinate limits from array; extra elements in array are ignored. | public void | setOnChange(Controller c) Specify a controller to be notified when the limits on this
CoordinateRect change. | void | setOwner(DisplayCanvas canvas) This is meant to be called only by the DisplayCanvas class,
when this CoordinateRect is added to ta DisplayCanvas. | public void | setRestoreBuffer() Save current limits in buffer. | public void | setSyncWith(Tie tie) Set the Tie object that is used to synchronize this CoordinareRect with other objects. | public void | sync(Tie tie, Tieable newest) Part of the Tieable interface. | public int | xToPixel(double x) Convert an x-coodinate into a horizontal pixel coordinate.
(This is only valid when the CoordinateRect has actually been displayed. | public int | yToPixel(double y) Convert a y-coodinate into a vertical pixel coordinate.
(This is only valid when the CoordinateRect has actually been displayed. | public double[] | zoomIn() Change limits to zoom in by a factor of 2. | public double[] | zoomInOnPixel(int x, int y) Change limits to zoom in by a factor of 2, centered on a specified point. | public double[] | zoomOut() Change limits to zoom out by a factor of 2. | public double[] | zoomOutFromPixel(int x, int y) Change limits to zoom out by a factor of 2, centered on a specified point. |
XMAX | final public static int XMAX(Code) | | A constant for use with the getValueObject() method to specify which Value is to be returned.
XMAX specifies that the Value is the maximum x-coordinate on the CoordinateRect.
|
XMIN | final public static int XMIN(Code) | | A constant for use with the getValueObject() method to specify which Value is to be returned.
XMIN specifies that the Value is the minimum x-coordinate on the CoordinateRect.
|
YMAX | final public static int YMAX(Code) | | A constant for use with the getValueObject() method to specify which Value is to be returned.
YMAX specifies that the Value is the maximum y-coordinate on the CoordinateRect.
|
YMIN | final public static int YMIN(Code) | | A constant for use with the getValueObject() method to specify which Value is to be returned.
YMIN specifies that the Value is the minimum y-coordinate on the CoordinateRect.
|
changed | protected boolean changed(Code) | | Set to true when one of the limits or the gap has changed.
|
drawItems | protected Vector drawItems(Code) | | Drawable items contained in this CoordinateRect
|
onChange | protected Controller onChange(Code) | | If non-null, this is the Controller that is notified when the limits change.
|
syncWith | protected Tie syncWith(Code) | | This contains other Limit objects with which the CoordinateRect is
synchronizing. This is ordinarily managed by a LimitControlPanel,
so you don't have to worry about it. (However, you can also sync
several CoordinateRects even in the absense of a LimitControlPanel.
To do so, create the Tie that ties the CoordinateRect and pass it to
the setSyncWith() method of each CoordinateRect. It is NOT necessary
to add the Tie to a Controller. Synchronization is handled by the
CoordinateRects themselves.
|
CoordinateRect | public CoordinateRect()(Code) | | Create a CoordinateRect with default limits: -5, 5, -5, 5.
|
CoordinateRect | public CoordinateRect(double xmin, double xmax, double ymin, double ymax)(Code) | | Create a CoordinateRect with specified limits.
|
add | public synchronized void add(Drawable d)(Code) | | Add a drawable item to the CoordinateRect.
|
checkDraggables | Draggable checkDraggables(java.awt.event.MouseEvent evt)(Code) | | Check whether a mouse click (as specified in the MouseEvent parameter) is
a click on a Draggable item that wants to be dragged. If so, return that item. If not, return null.
This is meant to be called only by DisplayCanvas.
|
checkInput | public void checkInput()(Code) | | When this is called, the CoordinateRect will call the
checkInput method of any Drawable it contains that is
also an InputObject. This is ordinarly only called by a DisplayCanvas.
|
clearRestoreBuffer | public void clearRestoreBuffer()(Code) | | A CoordinateRect can store its current limits in a buffer. This method
clears that buffer.
|
compute | public void compute()(Code) | | When this is called, the CoordinateRect will call the compute method
of any Drawable it contains that is also a Computable.
This is ordinarly only called by a DisplayCanvas.
|
doDraw | protected void doDraw(Graphics g)(Code) | | Draw all the Drawable items. This is called by the draw() method and is not
meant to be called directly. However, it might be overridden in a subclass.
|
draw | public void draw(Graphics g, int width, int height)(Code) | | Draw in rect with upperleft corner (0,0) and specified width,height.
This is not ordinarily called directly.
|
draw | public synchronized void draw(Graphics g, int left, int top, int width, int height)(Code) | | Draw in specified rect. This is not ordinarily called directly.
|
equalizeAxes | public double[] equalizeAxes()(Code) | | Reset limits, if necessary, so scales on the axes are the same.
Only valid of the CoordinateRect has been drawn.
an array with the new limits, or null if limits don't change. |
getDrawable | public Drawable getDrawable(int i)(Code) | | Get the i-th Drawable in this Rect, or null if i is less than zero
or greater than or equal to the number of items.
Parameters: i - The number of the item to be returned, where the first item is number zero. |
getDrawableCount | public int getDrawableCount()(Code) | | Returns the number of Drawable items that are in this CoordinateRect.
|
getGap | public int getGap()(Code) | | Get the gap, in pixels, between the edges of
the CoordinateRect and the limits specified by xmin, xmax, ymin, and ymax.
|
getHeight | public int getHeight()(Code) | | Get the height in pixels of this CoordinateRect in the DisplayCanvas that contains it.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
getLeft | public int getLeft()(Code) | | Get the left edge of this CoordinateRect in the DisplayCanvas that contains it.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
getLimits | public double[] getLimits()(Code) | | Get an array containing the limits on the CoordinateRect in the order xmin, xmax, ymin, ymax.
|
getOnChange | public Controller getOnChange()(Code) | | Get the controller that is notified when the limits on this
CoordinateRect change. This can be null.
|
getPixelHeight | public double getPixelHeight()(Code) | | Return the height of one pixel in this coordinate system.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
getPixelWidth | public double getPixelWidth()(Code) | | Return the width of one pixel in this coordinate system.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
getSerialNumber | public long getSerialNumber()(Code) | | Return the serial number of the CoordinateRect, which is incremented each time the limits change.
Part of the Tieable interface.
Not meant to be called directly.
|
getTop | public int getTop()(Code) | | Get the top edge of this CoordinateRect in the DisplayCanvas that contains it.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
getValueObject | public Value getValueObject(int which)(Code) | | Get a Value object representing one of the limits on this CoordinateRect.
The parameter should be one of the constants CoordinateRect.XMIN,
CoordinateRect.XMAX, CoordinateRect.YMIN, or CoordinateRect.YMAX.
(If not, it is treated the same as YMAX).
|
getWidth | public int getWidth()(Code) | | Get the width in pixels of this CoordinateRect in the DisplayCanvas that contains it.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
getXmax | public double getXmax()(Code) | | Get the maximum x-coordinate.
|
getXmin | public double getXmin()(Code) | | Get the mimimum x-coordinate.
|
getYmax | public double getYmax()(Code) | | Get the maximum x-coordinate.
|
getYmin | public double getYmin()(Code) | | Get the mimimum y-coordinate.
|
notifyControllerOnChange | public void notifyControllerOnChange(Controller c)(Code) | | Method required by InputObject interface; in this class, it calls the same method
recursively on any input objects containted in this CoordinateRect. This is meant to
be called by JCMPanel.gatherInputs().
|
pixelToX | public double pixelToX(int h)(Code) | | Convert a horizontal pixel coordinate into an x-coordinate.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
pixelToY | public double pixelToY(int y)(Code) | | Convert a vertical pixel coordinate into a y-coordinate.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
remove | public synchronized void remove(Drawable d)(Code) | | Remove the given Drawable item, if present in this CoordinateRect.
|
restore | public double[] restore()(Code) | | A CoordinateRect can store its current limits in a buffer. These limits
can be restored by a call to this method. Only one level of
save/restore is provided. If limits have not been saved, then nothing happens.
The original limits on the CoordinateRect are saves automatically when
the CoordinateRect is first created.
an array containing new limits. |
setGap | public void setGap(int g)(Code) | | Set the gap. This is ignored if g is less than zero. This gap is the number of pixels
between the edges of the CoordinateRect and the limits specified by xmin, xmax, ymin, and ymax.
The default value is 5.
|
setLimits | public void setLimits(double xmin, double xmax, double ymin, double ymax)(Code) | | Set the limits on the CoordinteRect
Parameters: xmin - the minimum x-coordinate on the CoordinateRect Parameters: xmax - the maximum x-coordinate on the CoordinateRect Parameters: ymin - the minimum y-coordinate on the CoordinateRect Parameters: ymax - the maximum y-coordinate on the CoordinateRect |
setLimits | public void setLimits(double[] d)(Code) | | Set the coordinate limits from array; extra elements in array are ignored.
This is ignored if the array is null or has fewer than 4 members.
The order of values in the array is xmin, xmax, ymin, ymax.
|
setOnChange | public void setOnChange(Controller c)(Code) | | Specify a controller to be notified when the limits on this
CoordinateRect change.
|
setOwner | void setOwner(DisplayCanvas canvas)(Code) | | This is meant to be called only by the DisplayCanvas class,
when this CoordinateRect is added to ta DisplayCanvas.
|
setRestoreBuffer | public void setRestoreBuffer()(Code) | | Save current limits in buffer. They can be restored later by a call
to the restore() method. Only one level of
save/restore is provided.
|
setSyncWith | public void setSyncWith(Tie tie)(Code) | | Set the Tie object that is used to synchronize this CoordinareRect with other objects.
This is ordinarily called by a LimitControlPanel, so you don't have to worry about it.
|
sync | public void sync(Tie tie, Tieable newest)(Code) | | Part of the Tieable interface.
Not meant to be called directly.
|
xToPixel | public int xToPixel(double x)(Code) | | Convert an x-coodinate into a horizontal pixel coordinate.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
yToPixel | public int yToPixel(double y)(Code) | | Convert a y-coodinate into a vertical pixel coordinate.
(This is only valid when the CoordinateRect has actually been displayed. It is meant
mainly to be used by Drawables in this CoordinateRect.)
|
zoomIn | public double[] zoomIn()(Code) | | Change limits to zoom in by a factor of 2. A maximal zoom is enforced.
The center of the rectangle does not move.
an array of the new limits, or null if limits don't change. |
zoomInOnPixel | public double[] zoomInOnPixel(int x, int y)(Code) | | Change limits to zoom in by a factor of 2, centered on a specified point. A maximal zoom is enforced.
The point does not move. Only valid when CoordinateRect is
displayed in a rectangle on the screen.
Parameters: x - the horizontal pixel coordinate of the center point of the zoom Parameters: y - the vertical pixel coordinate of the center point of the zoom an array of the new limits, or null if limits don't change. |
zoomOut | public double[] zoomOut()(Code) | | Change limits to zoom out by a factor of 2. A maximal zoom is enforced.
The center of the rectangle does not move.
an array of the new limits, or null if limits don't change. |
zoomOutFromPixel | public double[] zoomOutFromPixel(int x, int y)(Code) | | Change limits to zoom out by a factor of 2, centered on a specified point. A maximal zoom is enforced.
The point (x,y) does not move. Valid only if CoordinateRect has been drawn.
Parameters: x - the horizontal pixel coordinate of the center point of the zoom Parameters: y - the vertical pixel coordinate of the center point of the zoom an array of the new limits, or null if limits don't change. |
|
|