Class Coordinates
Class Coordinates
java.lang.Object
|
+----Coordinates
-
public class
Coordinates
-
extends Object
Coordinates is an object that manages conversions between
coordinate systems. There are three kinds of coordinates:
- VIRTUAL: Each vertex has an x and y coordinate that are
potentially infinite. These coordinates only change when the
vertex's physical location in space is actually changed. As
vertices are placed farther and farther out in the positive and
negative directions, these coordinates get larger and larger. There
may be limitations on how far someone could actually go based on the
maximum size of a double.
- SCREEN: Position of a vertex in pixels from the top-left of
the current location of the window. These coordinates are
different after a scroll or zoom occurs.
- UNIT: The actual positions of vertices are mapped onto a unit
square. We don't actually use these coordinates, but maintain a way
for referencing them in this way in case filters prefer this type of
view. These coordinates change whenever vertices
are added of removed in such a way that the minimum rectangle
containing all vertices is changed.
There should be a single Coordinates object for each canvas that is
viewing a graph.
Coordinates maintains a pair of scrollbars and information about the
current position, size, and zoom-level of the canvas. Coordinates
must be informed upon any of the following occurences:
- adding a new vertex to the graph
- deleting a vertex from the graph
- changing the size of the canvas
- changing the zoom level
-
Coordinates(int, int)
-
create a window of initial size `width' by `height' pixels.
-
Coordinates()
-
default constructor is 100 by 100 window.
-
addV(Vertex)
-
inform Coordinates that the vertex `V' has been added to the graph.
-
canvasResize(int, int)
-
inform Coordinates that the size of the canvas has changed.
-
delAll(Vertex)
-
inform Coordinates that all vertices have been deleted from the
graph.
-
delV(Vertex, Vertex)
-
inform Coordinates that the vertex `V' has been deleted from the
graph.
-
disable()
-
greys out the scrollbars and makes them unusable.
-
enable()
-
reverses the effect of disable.
-
getMag()
-
returns the current zoom level.
-
getsbX()
-
gets the AWT scrollbar object that is the horizontal scrollbar
used by this Coordinates.
-
getsbY()
-
gets the AWT scrollbar object that is the vertical scrollbar
used by this Coordinates.
-
magRange(double, double, double, double)
-
!WARNING! This method has never been tested! !WARNING!
magnify the rectangle between P1 and P2.
-
setMag(double)
-
change zoom level to `newmag'.
-
toString()
-
prints internal information about the coordinates.
-
xStoV(int)
-
screen: x coordinate in the screen coordinate system
returns: `screen' in virtual coordinates.
-
xUtoV(double)
-
unit: x coordinate in the unit coordinate system
returns: `unit' in virtual coordinates.
-
xVtoS(double)
-
virtual: x coordinate in the virtual coordinate system
returns: virtual in screen coordinates.
-
xVtoU(double)
-
virtual: x coordinate in the virtual coordinate system
returns: virtual in unit coordinates.
-
yStoV(int)
-
screen: y coordinate in the screen coordinate system
returns: `screen' in virtual coordinates.
-
yUtoV(double)
-
unit: y coordinate in the unit coordinate system
returns: `unit' in virtual coordinates.
-
yVtoS(double)
-
virtual: y coordinate in the virtual coordinate system
returns: `virtual' in screen coordinates.
-
yVtoU(double)
-
virtual: y coordinate in the virtual coordinate system
returns: virtual in unit coordinates.
Coordinates
public Coordinates(int width,
int height)
-
create a window of initial size `width' by `height' pixels.
Coordinates
public Coordinates()
-
default constructor is 100 by 100 window.
toString
public String toString()
-
prints internal information about the coordinates.
-
Overrides:
-
toString in class Object
disable
public void disable()
-
greys out the scrollbars and makes them unusable.
enable
public void enable()
-
reverses the effect of disable.
xVtoS
public int xVtoS(double virtual)
-
virtual: x coordinate in the virtual coordinate system
returns: virtual in screen coordinates.
yVtoS
public int yVtoS(double virtual)
-
virtual: y coordinate in the virtual coordinate system
returns: `virtual' in screen coordinates.
xStoV
public double xStoV(int screen)
-
screen: x coordinate in the screen coordinate system
returns: `screen' in virtual coordinates.
yStoV
public double yStoV(int screen)
-
screen: y coordinate in the screen coordinate system
returns: `screen' in virtual coordinates.
xVtoU
public double xVtoU(double virtual)
-
virtual: x coordinate in the virtual coordinate system
returns: virtual in unit coordinates.
yVtoU
public double yVtoU(double virtual)
-
virtual: y coordinate in the virtual coordinate system
returns: virtual in unit coordinates.
xUtoV
public double xUtoV(double unit)
-
unit: x coordinate in the unit coordinate system
returns: `unit' in virtual coordinates.
yUtoV
public double yUtoV(double unit)
-
unit: y coordinate in the unit coordinate system
returns: `unit' in virtual coordinates.
getsbX
public Scrollbar getsbX()
-
gets the AWT scrollbar object that is the horizontal scrollbar
used by this Coordinates.
getsbY
public Scrollbar getsbY()
-
gets the AWT scrollbar object that is the vertical scrollbar
used by this Coordinates.
addV
public void addV(Vertex V)
-
inform Coordinates that the vertex `V' has been added to the graph.
delV
public void delV(Vertex V,
Vertex Vlist)
-
inform Coordinates that the vertex `V' has been deleted from the
graph.
`Vlist' is the "first" vertex in the graph. It represents a list
of vertices that are used to calculate the new minimum rectangle
containing all vertices. Typically, a call of delV is something like
"delV(vertexToDelete, graph.getV())".
delAll
public void delAll(Vertex emptyObjList)
-
inform Coordinates that all vertices have been deleted from the
graph.
`Vlist' is the "first" vertex in the graph. It represents a list
of vertices that are used to calculate the new minimum rectangle
containing all vertices. Typically, a call of delAll is something like
"delAll(graph.getV())".
canvasResize
public void canvasResize(int width,
int height)
-
inform Coordinates that the size of the canvas has changed.
Typically, a call of canvasResize is something like
"canvasResize(canvas.size().width, canvas.size().height)".
setMag
public void setMag(double newmag)
-
change zoom level to `newmag'.
Magnification is the number of virtual coordinates per pixel
coordinate. Doubling the magnification halves the size of objects
on the screen.
getMag
public double getMag()
-
returns the current zoom level.
Magnification is the number of virtual coordinates per pixel
coordinate. Doubling the magnification halves the size of objects
on the screen.
magRange
public void magRange(double p1x,
double p1y,
double p2x,
double p2y)
-
!WARNING! This method has never been tested! !WARNING!
magnify the rectangle between P1 and P2.
note that this will actually magnify less than that amount in one
dimension in order to preserve the aspect ratio.