org.opensourcephysics.drawing2d
Class ElementTrail

java.lang.Object
  extended by org.opensourcephysics.drawing2d.Element
      extended by org.opensourcephysics.drawing2d.ElementTrail
All Implemented Interfaces:
Data, Drawable, Interactive, LogMeasurable, Measurable

public class ElementTrail
extends Element
implements Data

Title: ElementTrail

Description:

A trail of points on the screen.

This object is often used to show the path of a moving object. Points are added to a trail either with addPoint() or moveToPoint(). Trails can have many segments. A segment is a section of a Trail that has a starting point, a stopping point, and a color. The clear method removes all segments from the trail whereas the initialize method only removes data from the current segment.

Version:
June 2008/Revised December 2008
Author:
Francisco Esquembre

Field Summary
static int LINE_CONNECTION
          The next point will be connected to the previous one by a segment
static int NO_CONNECTION
          The next point will not be connected to the previous one
 
Fields inherited from class org.opensourcephysics.drawing2d.Element
TARGET_POSITION, TARGET_SIZE
 
Constructor Summary
ElementTrail()
           
 
Method Summary
 void addPoint(double[] point)
          Adds a new double[] point to the trail.
 void addPoint(double x, double y)
          Adds a new point to the trail.
 void addPoints(double[][] input)
          Adds an array of new double[] points to the trail.
 void addPoints(double[] xInput, double[] yInput)
          Adds an array of points to the trail.
 void clear()
          Clears all points from all segments of the trail.
 void draw(DrawingPanel _panel, java.awt.Graphics _g)
          Draws the element on a given Graphics2D.
 Interactive findInteractive(DrawingPanel _panel, int _xpix, int _ypix)
          Gets the target that is under the (x,y) position of the screen.
 java.lang.String[] getColumnNames()
          The column names to be used in the data display tool
 int getConnectionType()
          Gets the connection type.
 double[][] getData2D()
          Gets a 2D array of data.
 double[][][] getData3D()
          Gets a 3D array of data.
 java.util.List<Data> getDataList()
          Some Data objects (e.g., a Group) do not contain data, but a list of Data objects which do.
 java.util.ArrayList<Dataset> getDatasets()
          Gets a list of OSP Datasets.
 java.awt.Color[] getFillColors()
          Fill color to use for this data
 int getID()
          Returns a unique identifier for this Data
 java.awt.Color[] getLineColors()
          Line color to use for this data
 int getMaximumPoints()
          Returns the maximum number of points allowed for the trail
 int getSkipPoints()
          Returns the skip parameter of the trail.
 void initialize()
          Clears all points from the last segment of the trail, respecting previous segments.
 boolean isActive()
          Whether the trail is in active mode.
 boolean isClearAtInput()
          Whether the trail is in clear at input mode.
 boolean isMeasured()
          Determines if information is available to set min/max values.
 boolean isNoRepeat()
          Whether the trail is in no repeat mode.
 void moveToPoint(double[] point)
          Moves to the new point without drawing.
 void moveToPoint(double x, double y)
          Moves to the new point without drawing.
 void newSegment()
          Creates a new segment of the trail.
 void setActive(boolean _active)
          Set/unset the active state of the trail.
 void setClearAtInput(boolean _clear)
          Sets the trail to clear existing points when receiving a new point or array of points.
 void setConnectionType(int type)
          Sets the type of connection for the next point.
 void setID(int id)
          Sets the ID number of this Data
 void setMaximumPoints(int maximum)
          Sets the maximum number of points for the trail.
 void setNoRepeat(boolean _noRepeat)
          Sets the no repeat state of the trail.
 void setSkipPoints(int _skip)
          Sets the skip parameter.
 void setXLabel(java.lang.String _label)
          Sets the label of the X coordinate when the data is displayed in a table
 void setYLabel(java.lang.String _label)
          Sets the label of the Y coordinate when the data is displayed in a table
 
Methods inherited from class org.opensourcephysics.drawing2d.Element
addInteractionListener, getCanBeMeasured, getDataObject, getInteractionTarget, getName, getPanel, getPosition, getSize, getSizeX, getSizeY, getStyle, getTransformation, getX, getXMax, getXMaxLogscale, getXMin, getXMinLogscale, getY, getYMax, getYMaxLogscale, getYMin, getYMinLogscale, hasChanged, invokeActions, isEnabled, isVisible, removeInteractionListener, setCanBeMeasured, setDataObject, setElementChanged, setEnabled, setName, setNeedToProject, setPanel, setPosition, setSize, setSizeX, setSizeXY, setSizeY, setTransformation, setVisible, setX, setXY, setY, toBodyFrame, toSpaceFrame, updateHotSpot
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opensourcephysics.display.Data
getName
 

Field Detail

NO_CONNECTION

public static final int NO_CONNECTION
The next point will not be connected to the previous one

See Also:
Constant Field Values

LINE_CONNECTION

public static final int LINE_CONNECTION
The next point will be connected to the previous one by a segment

See Also:
Constant Field Values
Constructor Detail

ElementTrail

public ElementTrail()
Method Detail

setActive

public void setActive(boolean _active)
Set/unset the active state of the trail. The trail does not use this state, but just keeps an internal value that programs can consult in order not to add data to the trail. In other words, a trail will always honor an addPoint() command. But programs can consult this internal value to decide whether or not to send data to a trail. Default value is true.

Parameters:
_active -

isActive

public boolean isActive()
Whether the trail is in active mode.

Returns:

setNoRepeat

public void setNoRepeat(boolean _noRepeat)
Sets the no repeat state of the trail. When set, a trail will ignore (x,y) points which equal the last added point.

Parameters:
_noRepeat -

isNoRepeat

public boolean isNoRepeat()
Whether the trail is in no repeat mode. Default value is false.

Returns:

setClearAtInput

public void setClearAtInput(boolean _clear)
Sets the trail to clear existing points when receiving a new point or array of points.

Parameters:
_clear -

isClearAtInput

public boolean isClearAtInput()
Whether the trail is in clear at input mode.

Returns:

setSkipPoints

public void setSkipPoints(int _skip)
Sets the skip parameter. When the skip parameter is larger than zero, the trail only considers one of every 'skip' points. That is, if skip is 3, the trail will consider only every third point sent to it. The default is zero, meaning all points must be considered.

Parameters:
_skip -

getSkipPoints

public int getSkipPoints()
Returns the skip parameter of the trail.

Returns:

setXLabel

public void setXLabel(java.lang.String _label)
Sets the label of the X coordinate when the data is displayed in a table

Parameters:
_label -

setYLabel

public void setYLabel(java.lang.String _label)
Sets the label of the Y coordinate when the data is displayed in a table

Parameters:
_label -

addPoint

public void addPoint(double x,
                     double y)
Adds a new point to the trail.

Parameters:
x - double The X coordinate of the point.
y - double The Y coordinate of the point.

addPoint

public void addPoint(double[] point)
Adds a new double[] point to the trail.

Parameters:
point - double[] The double[2] array with the coordinates of the point.

moveToPoint

public void moveToPoint(double x,
                        double y)
Moves to the new point without drawing.

Parameters:
x - double The X coordinate of the point.
y - double The Y coordinate of the point.

moveToPoint

public void moveToPoint(double[] point)
Moves to the new point without drawing. (Equivalent to setting the connection type to NO_CONNECTION and adding one single point, then setting the type back to its previous value.)

Parameters:
point - double[] The double[2] array with the coordinates of the point.

addPoints

public void addPoints(double[][] input)
Adds an array of new double[] points to the trail.

Parameters:
point - double[][] The double[nPoints][2] array with the coordinates of the points.
input -

addPoints

public void addPoints(double[] xInput,
                      double[] yInput)
Adds an array of points to the trail.

Parameters:
xInput - double The double[] array with the X coordinates of the points.
yInput - double The double[] array with the Y coordinates of the points.

setMaximumPoints

public void setMaximumPoints(int maximum)
Sets the maximum number of points for the trail. Once the maximum is reached, adding a new point will cause remotion of the first one. This is useful to keep trails down to a reasonable size, since very long trails can slow down the rendering (in certain implementations). If the value is 0 (the default) the trail grows forever without discarding old points.

Parameters:
maximum - int

getMaximumPoints

public int getMaximumPoints()
Returns the maximum number of points allowed for the trail

Returns:
int

setConnectionType

public void setConnectionType(int type)
Sets the type of connection for the next point.

Parameters:
type - int

getConnectionType

public int getConnectionType()
Gets the connection type.

See Also:
setConnectionType(int)

clear

public void clear()
Clears all points from all segments of the trail.


initialize

public void initialize()
Clears all points from the last segment of the trail, respecting previous segments.


newSegment

public void newSegment()
Creates a new segment of the trail.


setID

public void setID(int id)
Description copied from interface: Data
Sets the ID number of this Data

Specified by:
setID in interface Data
Parameters:
id - the ID number

getID

public int getID()
Description copied from interface: Data
Returns a unique identifier for this Data

Specified by:
getID in interface Data
Returns:
the ID number

getData2D

public double[][] getData2D()
Description copied from interface: Data
Gets a 2D array of data. The first column, double[0][] often contains x-values; Remaining columns often contain y values. May return null if data not yet generated or object does not support 2D data.

Specified by:
getData2D in interface Data
Returns:
double[][]

getData3D

public double[][][] getData3D()
Description copied from interface: Data
Gets a 3D array of data. May return null if data not yet generated or object does not support 3D data.

Specified by:
getData3D in interface Data
Returns:
double[][][]

getColumnNames

public java.lang.String[] getColumnNames()
Description copied from interface: Data
The column names to be used in the data display tool

Specified by:
getColumnNames in interface Data
Returns:
an array of names

getLineColors

public java.awt.Color[] getLineColors()
Description copied from interface: Data
Line color to use for this data

Specified by:
getLineColors in interface Data
Returns:
a color

getFillColors

public java.awt.Color[] getFillColors()
Description copied from interface: Data
Fill color to use for this data

Specified by:
getFillColors in interface Data
Returns:
a color

getDataList

public java.util.List<Data> getDataList()
Description copied from interface: Data
Some Data objects (e.g., a Group) do not contain data, but a list of Data objects which do. This method is used by Data displaying tools to create as many pages as needed.

Specified by:
getDataList in interface Data
Returns:
a list of Data objects, or null if this object contains data

getDatasets

public java.util.ArrayList<Dataset> getDatasets()
Description copied from interface: Data
Gets a list of OSP Datasets. May return null if data not yet generated or object does not support Datasets.

Specified by:
getDatasets in interface Data
Returns:
list of Datasets

draw

public void draw(DrawingPanel _panel,
                 java.awt.Graphics _g)
Description copied from class: Element
Draws the element on a given Graphics2D. Required by Drawable (in Interactive)

Specified by:
draw in interface Drawable
Specified by:
draw in class Element

findInteractive

public Interactive findInteractive(DrawingPanel _panel,
                                   int _xpix,
                                   int _ypix)
Description copied from class: Element
Gets the target that is under the (x,y) position of the screen. Required by Interactive

Specified by:
findInteractive in interface Interactive
Specified by:
findInteractive in class Element
Parameters:
_panel - org.opensourcephysics.display.DrawingPanel The drawing panel which originated the call
_xpix - int
_ypix - int
Returns:
Interactive

isMeasured

public boolean isMeasured()
Description copied from interface: Measurable
Determines if information is available to set min/max values. Objects that store data should return false if data is null.

Specified by:
isMeasured in interface Measurable
Overrides:
isMeasured in class Element
Returns:
true if min/max values are valid