- All Implemented Interfaces:
Graph.Graphic
,NamedObjectOps
By default, an instance of GraphView is constructed so that it is
visible and so that its zorder is the smallest (most negative) integer
that can be represented by the primitive type long
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Mode for setting zoom values in GraphView factories. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTo
(Graph graph, Graphics2D g2d, Graphics2D g2dGCS) Add this object to a graph.boolean
Determine if this named object can be deleted.protected Object
clone()
Creates and returns a copy of this object.protected boolean
Return the default value of the angle-relative flag.final boolean
delete()
Delete an object.final boolean
Determine if an object is being deleted.final String
getName()
Get an object's name.protected Simulation
Get the object namer for a named object.double
Get the graph height in graph coordinate space excluding the offsets.double
Get the graph width in graph coordinate space excluding the offsets.void
initialize
(double xgcs, double ygcs, double xf, double yf, double scaleX, double scaleY, double zoom) Initializer.final boolean
Determine if an object has been deleted.boolean
Determine if an object is interned in a object namer's tables.void
printConfiguration
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print this simulation object's configuration.void
printState
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print this simulation object's state.void
setAngle
(double theta) Set the rotation.void
setLogZoomRate
(double zoomRate) Set the zoom rate logarithmicly.void
setLogZoomRate
(double zoomTarget, double deltaT) Set the zoom rate logarithmicly to zoom to a target value in a specified time.void
setPosition
(double x, double y, double angle) Set an object's position and orientation.void
setZoom
(double zoom) Set the zoom factor.void
update
(double t, long simtime) Update the object's state to that at a specified time.Methods inherited from class org.bzdev.anim2d.DirectedObject2D
angleIsRelative, clearPath, getAngularVelocity, getDistance, getInitialPathTime, getInitialS, getInitialU, getMaxPathParameter, getPathAcceleration, getPathAngle, getPathDxDu, getPathDyDu, getPathInversionLimit, getPathLength, getPathLength, getPathVelocity, getPathX, getPathY, getS, getS, getU, getU, getUpdatedTime, hasPath, isClosedPath, pathExists, setAngleByF, setAngleBySF, setAngleRelative, setAngularAcceleration, setAngularVelocity, setDistanceByF, setDistanceBySF, setPath, setPath, setPath, setPath, setPath, setPath, setPath, setPath, setPathAcceleration, setPathAngle, setPathAngleByF, setPathAngleBySF, setPathAngularAcceleration, setPathAngularVelocity, setPathImplementation, setPathInversionLimit, setPathVelocity
Methods inherited from class org.bzdev.anim2d.PlacedAnimationObject2D
getAddToTransform, getAngle, getBBXMax, getBBXMin, getBBYMax, getBBYMin, getReferencePointX, getReferencePointY, getRefPointName, getX, getY, setPosition, setRefPoint, setRefPoint, setRefPointBounds, setRefPointBounds, setRefPointByFraction, setRefPointByName
Methods inherited from class org.bzdev.anim2d.AnimationObject2D
addToFrame, addToFrame, getAnimation, getZorder, isVisible, setVisible, setZorder, setZorder
Methods inherited from class org.bzdev.devqsim.SimObject
addSimulationListener, addTraceSet, bindCallable, bindCallable, bindCallable, bindCallable, bindRunnable, bindRunnable, bindRunnable, bindRunnable, callableObject, callableScript, callScriptFunction, callScriptMethod, clearTraceSets, evalScript, getEventListenerList, getScriptObject, getTraceSets, onDelete, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printState, printState, printState, printState, printState, printState, putScriptObject, removeSimulationListener, removeTraceSet, runnableObject, runnableScript, scheduleCall, scheduleCall, scheduleCall, scheduleCall, scheduleCallObject, scheduleScript, scheduleTask, scheduleTask, scheduleTask, scheduleTask, scheduleTaskObject, scheduleTaskScript, startImmediateTask, startImmediateTask, trace, trace, unscheduledTaskThread, unscheduledTaskThread, update, usesTraceSet
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.graphs.Graph.Graphic
boundingBox
Methods inherited from interface org.bzdev.obnaming.NamedObjectOps
canDelete, delete, deletePending, getName, isDeleted, isInterned
-
Constructor Details
-
GraphView
Constructor.- Parameters:
animation
- the animationname
- the name of the object; null for an automatically generated nameintern
- true if the object can be looked up by using the methods inSimulation
; false otherwise.- Throws:
IllegalArgumentException
- typically means a name is already in use- See Also:
-
-
Method Details
-
initialize
public void initialize(double xgcs, double ygcs, double xf, double yf, double scaleX, double scaleY, double zoom) Initializer. The description of the arguments makes use of terminology defined by theGraph
class.The location (xgcs,ygcs) in graph coordinate space will be positioned at a specific point in user space. This point is located at (xlo+ xf*(w -xlo -xuo), h - (ylo + yf*(h-ylo-yuo))) in user space, where
xlo is the graph's lower x offset in user space. xuo is the graph's upper x offset in user space. ylo is the graph's lower y offset in user space. yuo is the graphs' upper y offset in user space. w is the width of the graph in user space. h is the height of the graph in user space. The scale factors scaleX and scaleY are the amount by which to multiple a distance in graph coordinate space along the X and Y axes respectively to get the corresponding distance in user space. The zoom parameter is basically the magnification, so a value of 2.0 makes the image appear twice as big.
To rotate the view about the point (xgcs, ycgs), use the methods
DirectedObject2D.setAngle(double)
orDirectedObject2D.setPathAngle(double)
(possibly callingDirectedObject2D.setAngleRelative(boolean)
if the angle should be relative to a path). Objects in the view will appear to rotate in the opposite direction of the view's rotation. The setPath methods forDirectedObject2D
can also be used, as can methods that set angular velocity, angular acceleration, etc.As an example, if (xgsc, ygsc) = (500.0, 0.0), and xf and yf are both 0.5, the point (500.0, 0.0) in graph coordinate space will appear in the middle of the frame. The factors scaleX and scaleY determine how graph coordinate space is scaled to be displayed in the frame when the zoom factor is 1.0. The view can subsequently be moved and zoomed. If the graph view is moved to 600.0, 0.0), then the point (600.0, 0.0) will be in the middle of the frame.
The effect is that one can 'pan' over user space, zooming in and out as appropriate. As a subclass of DirectedObject2D, one can specify a path to follow and control the motion along that path.
- Parameters:
xgcs
- the x coordinate of a point in graph coordinate space that will be positioned at a specified location on the graphygcs
- the y coordinate of a point in graph coordinate space that will be positioned at a specified location on the graphxf
- the fractional distance from the graph's left offset to its right offset at which the point xgcs in graph coordinate space appearsyf
- the fractional distance from the graph's lower offset to its upper offset at which the point ygcs in graph coordinate space appearsscaleX
- the scale factor for the X directionscaleY
- the scale factor for the Y directionzoom
- the zoom level, which must be a positive real number- Throws:
IllegalStateException
- initialize was called multiple times
-
defaultAngleRelative
protected boolean defaultAngleRelative()Return the default value of the angle-relative flag. This method returnsfalse
unless overridden.- Overrides:
defaultAngleRelative
in classDirectedObject2D
- Returns:
- the default value for setPath methods
- See Also:
-
setZoom
public void setZoom(double zoom) Set the zoom factor.- Parameters:
zoom
- the zoom factor.
-
setAngle
public void setAngle(double theta) Set the rotation. The argument gives the angle the graph view rotates in the counterclockwise direction in graph coordinate space space, causing objects in graph coordinate space to rotate clockwise.- Overrides:
setAngle
in classDirectedObject2D
- Parameters:
theta
- the rotation in radians
-
setPosition
public void setPosition(double x, double y, double angle) Set an object's position and orientation. The argument gives the angle the graph view rotates in the counterclockwise direction in graph coordinate space, causing objects in graph coordinate space to rotate clockwise. The coordinates (x,y) are the coordinates of the view's reference point, which will appear at a specific location in the frame determined when the view was initialized.- Overrides:
setPosition
in classDirectedObject2D
- Parameters:
x
- the x coordinate in graph coordinate spacey
- the y coordinate in graph coordinate spaceangle
- the angle giving the view's orientation in radians
-
setLogZoomRate
public void setLogZoomRate(double zoomRate) Set the zoom rate logarithmicly. The zoom factor will change with time as exp(zoomRate * t);- Parameters:
zoomRate
- the logarithmic zoom rate
-
setLogZoomRate
public void setLogZoomRate(double zoomTarget, double deltaT) Set the zoom rate logarithmicly to zoom to a target value in a specified time.- Parameters:
zoomTarget
- the target zoom value after a time interval of deltaT elapsesdeltaT
- the time interval for the zoom factor to change from its current value to the target value
-
update
public void update(double t, long simtime) Description copied from class:DirectedObject2D
Update the object's state to that at a specified time. The values of t passed to this method should form an increasing sequence. The default implementation's behavior depends on whether functions are provided. A distance function, path velocity, path acceleration, or angle function is not used when there is no path, although the angular acceleration and angular velocity will be used if these are nonzero.- If a distance function is provided, that function is used to determine the new value of s (the distance along the path from its start) at time τ, with the path velocity and acceleration determined by that function's first and second derivatives (if not implemented, the path velocity and/or acceleration is set to Double.NaN). The time τ is the difference between the current time t and the time time0 at which the path traversal starts.
- If a distance function is not provided, the path velocity and path acceleration are used to determine the new value of s, and the path velocity is updated as well.
- If an angle function is provided, that function is used to determine the new angle, and its derivatives, if implemented provide the angular velocity and angular acceleration. The time argument $tau; is the difference between the current time t and the time time0 at which the path traversal starts. If the path was set with the flag angleRelative set to true, the angle is added to the tangent at the object's new position along the path; otherwise the angle is measured counterclockwise from the direction of the positive X axis.
- If an angle function is not provided the path angular velocity and path angular acceleration are used to compute the change in angle from the last time update was called. If the path was set with the flag angleRelative set to true, the angle is added to the angle of the tangent to the path at its new location; otherwise the angle is measured counterclockwise from the direction of the positive X axis.
DirectedObject2D.setPath(org.bzdev.geom.BasicSplinePath2D,double,double,boolean,double)
orDirectedObject2D.setPath(AnimationPath2D,double,double,boolean,double)
, but may be subsequently changed by callingDirectedObject2D.setAngleRelative(boolean)
.If a velocity or acceleration has the value Double.NaN, it is treated as if its value were 0.0. In cases where one needs to obtain the previous value of s, one can override this method and obtain the previous value by calling
DirectedObject2D.getS()
before callingsuper.update
.- Overrides:
update
in classDirectedObject2D
- Parameters:
t
- the time for which the object should be calculated.simtime
- the simulation time
-
addTo
Add this object to a graph. A GraphView is a special case. There should be only on in use per graph. It will set up the graph so that the graph displays a particular range in graph coordinate space. Angles refer to the view, not the object. Graphic operations at a particular time should be performed after a graph'sadd
method is called for any GraphView defined for the graph, and afterupdate
is called with the current time as its argument.- Parameters:
graph
- the graph on which this object should be drawng2d
- (ignored but needed by Graph.Graphics interface)g2dGCS
- (ignored but needed by Graph.Graphics interface)- Throws:
IllegalStateException
- initialize was not called
-
gwidth
Get the graph width in graph coordinate space excluding the offsets.- Parameters:
graph
- the graph- Returns:
- the graph width in graph coordinate space, excluding any offsets
- Throws:
IllegalStateException
- initialize was not called
-
gheight
Get the graph height in graph coordinate space excluding the offsets.- Parameters:
graph
- the graph- Returns:
- the graph height in graph coordinate space, excluding any offsets
- Throws:
IllegalStateException
- initialize was not called
-
printConfiguration
Print this simulation object's configuration. Documentation for the use of this method is provided by the documentation for theSimObject
methodSimObject.printConfiguration(String,String,boolean,PrintWriter)
.When the second argument has a value of true, the object name and class name will be printed in a standard format with its indentation provided by the iPrefix argument. In addition, the configuration that is printed includes the following items.
Defined in
AnimationObject2D
:- the Z-order.
- whether or not this object is visible.
PlacedAnimationObject2D
:- the reference-point name (if any).
- the reference point location.
- the reference point bounds (minimum and maximum X and Y values for the rectangle to which the reference point names refer).
DirectedObject2D
:- the path this object will follow: either the name of an
instance of AnimationPath2D or the configuration of a
BasicSplinePath2D as provided by its method
BasicSplinePath2D.printTable(String,Appendable)
. - the distance along a path for its starting point (the initial distance).
- the initial value of the path's parameter.
- the time at which a path traversal should start.
- the initial value for whether or not the angle for the object is relative to the path's tangent or absolute.
- the distance function.
- a flag indicating if the distance function is set.
- the path velocity.
- the path acceleration.
- the path inversion limit (described in the documentation for
DirectedObject2D.getPathInversionLimit()
.
GraphView
:- the X reference point fractional position.
- the Y reference point fractional position.
- the X scale factor.
- the Y scale factor.
- the X initial position.
- the Y initial position.
- the initial zoom factor.
- Overrides:
printConfiguration
in classDirectedObject2D
- Parameters:
iPrefix
- the prefix to use for an initial line when printName is true with null treated as an empty stringprefix
- a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is trueprintName
- requests printing the name of an objectout
- the output print writer
-
printState
Print this simulation object's state. Documentation for the use of this method is provided by the documentation for theSimObject
methodSimObject.printState(String,String,boolean,PrintWriter)
.When the third argument has a value of true, the object name and class name will be printed in a standard format with its indentation provided by the iPrefix argument. In addition, the state that is printed includes the following items.
Defined in
PlacedAnimationObject2D
:- the X coordinate of this object.
- the Y coordinate of this object.
- the angle for this object, measured counterclockwise.
DirectedObject2D
:- the name of the path (if any) this object can follow.
- the path parameter.
- the path distance.
- the angle-relative flag.
- the velocity along the path (NaN if undefined). When a distance function is used, its derivative, if implemented, determines this value.
- the acceleration along the path (NaN if undefined). When a distance function is used, its second derivative, if implemented, determines this value.
- the path angle. The angle is measured relative to the path's tangent in the direction of an increasing path parameter when the angle-relative flag is true; otherwise it is measured relative to the X axis. Angles are measured counterclockwise.
- the angular velocity. When a path-angle function is used, its derivative, if implemented, determines this value.
- the angular acceleration. When a path-angle function is used, its derivative, if implemented, determines this value.
- the angular acceleration. When a path-angle function is used, its derivative, if implemented, determines this value.
- the time at which this data was last updated.
GraphView
:- the zoom factor.
- the zoom rate (which is logarithmic).
- Overrides:
printState
in classDirectedObject2D
- Parameters:
iPrefix
- the prefix to use for an initial line when printName is true with null treated as an empty stringprefix
- a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is trueprintName
- requests printing the name of an objectout
- the output print writer
-
clone
Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
- a clone could not be created- See Also:
-
isInterned
public boolean isInterned()Determine if an object is interned in a object namer's tables.- Specified by:
isInterned
in interfaceNamedObjectOps
- Returns:
- true if the object is interned; false if not
-
getObjectNamer
Get the object namer for a named object.- Returns:
- the object namer for this named object
-
getName
Get an object's name.- Specified by:
getName
in interfaceNamedObjectOps
- Returns:
- the name of the object
-
canDelete
public boolean canDelete()Determine if this named object can be deleted. A named object can be deleted if the method delete has not been called and if the object is not in a state that prevents the object from being deleted. Subclasses that override this method must call canDelete() for their superclasses and return false if the superclass' canDelete method returns false. The default method returns true if delete() has not been called and returned true.- Specified by:
canDelete
in interfaceNamedObjectOps
- Returns:
- true if this object can be deleted; false otherwise
-
delete
public final boolean delete()Delete an object. An object can only be deleted once. If this method returns true, the object (if interned) will have been removed from the object namer tables.The implementations provided by
DefaultNamedObect
and generated because of a@NamedObject
annotation provide a protected method named onDelete. A subclass that overrides onDelete() must call the onDelete method of its superclass after it's onDelete method has been called and any cleanup actions performed. In some cases, this may happen at a later time (e.g., if a thread is used for some of the cleanup operations or if it is otherwise necessary to wait).- Specified by:
delete
in interfaceNamedObjectOps
- Returns:
- true if the deletion request was accepted; false otherwise
-
isDeleted
public final boolean isDeleted()Determine if an object has been deleted. An object is deleted if the method delete() has been called and returned true.- Specified by:
isDeleted
in interfaceNamedObjectOps
- Returns:
- true if deleted; false otherwise
-
deletePending
public final boolean deletePending()Determine if an object is being deleted. An deletion is pending if the method delete() has been called and returned true but the deletion has not been completed.- Specified by:
deletePending
in interfaceNamedObjectOps
- Returns:
- true if deletion is pending; false otherwise
-