org.opensourcephysics.drawing2d
Class ElementPolygon

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

public class ElementPolygon
extends Element
implements Data

Title: ElementPolygon

Description: A Polygon 2D

Version:
July 2008
Author:
Francisco Esquembre

Field Summary
 
Fields inherited from class org.opensourcephysics.drawing2d.Element
TARGET_POSITION, TARGET_SIZE
 
Constructor Summary
ElementPolygon()
           
 
Method Summary
 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
 double[][] getData()
          Gets a copy of the data of the points for the polygon
 double[][] getData2D()
          Gets a 2D array of data.
 double[][][] getData3D()
          Gets a 3D array of data.
 double[][] getDataArray()
          Gets the actual array with the data of the points for the polygon
 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
 boolean isClosed()
          Gets whether the polygon is closed
 void setActionListener(java.awt.event.ActionListener _listener)
          Sets an action listener that will be called just before drawing.
 void setClosed(boolean closed)
          Sets whether the polygon is closed
 void setData(double[][] data)
          Sets the data for the points of the polygon.
 void setData(double[] xArray, double[] yArray)
          Sets the data for the points of the polygon.
 void setID(int id)
          Sets the ID number of this Data
 void updateHotSpot(InteractionTarget target, double[] point)
          This method updates the position or size of the element according to the position of the cursor during the interaction.
 
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, isMeasured, isVisible, removeInteractionListener, setCanBeMeasured, setDataObject, setElementChanged, setEnabled, setName, setNeedToProject, setPanel, setPosition, setSize, setSizeX, setSizeXY, setSizeY, setTransformation, setVisible, setX, setXY, setY, toBodyFrame, toSpaceFrame
 
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
 

Constructor Detail

ElementPolygon

public ElementPolygon()
Method Detail

setClosed

public void setClosed(boolean closed)
Sets whether the polygon is closed

Parameters:
closed - boolean

isClosed

public boolean isClosed()
Gets whether the polygon is closed

Returns:
boolean

setActionListener

public void setActionListener(java.awt.event.ActionListener _listener)
Sets an action listener that will be called just before drawing. This is used by ControlAnalyticCurve to make sure the extremes are correct when read from the parent drawing panel.

Parameters:
_listener -

setData

public void setData(double[][] data)
Sets the data for the points of the polygon. Each entry in the data array corresponds to one vertex. If the polygon is closed, the last point will be connected to the first one and the interior will be filled (unless the fill color of the style is set to null). The data array is copied, so subsequence changes to the original array do not affect the polygon, until the setData() method is invoked.

Parameters:
data - double[][] the double[nPoints][2] array with the data

setData

public void setData(double[] xArray,
                    double[] yArray)
Sets the data for the points of the polygon. Each entry in the data array corresponds to one vertex. If the polygon is closed, the last point will be connected to the first one and the interior will be filled (unless the fill color of the style is set to null). The data array is copied, so subsequence changes to the original array do not affect the polygon, until the setData() method is invoked. If the arrays have different lengths, the last element of the shortest array is repeated to match the longest array.

Parameters:
xArray - double[] the double[nPoints] array with the X coordinates
yArray - double[] the double[nPoints] array with the Y coordinates

getData

public double[][] getData()
Gets a copy of the data of the points for the polygon

Returns:
double[][] the double[nPoints][2] array with the data

getDataArray

public double[][] getDataArray()
Gets the actual array with the data of the points for the polygon

Returns:
double[][] the double[nPoints][2] array with the data

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

updateHotSpot

public void updateHotSpot(InteractionTarget target,
                          double[] point)
Description copied from class: Element
This method updates the position or size of the element according to the position of the cursor during the interaction. Notice that, for targetSize, if any of the sizes of the element is zero, this dimension cannot be changed.

Overrides:
updateHotSpot in class Element
Parameters:
target - InteractionTarget The target interacted
point - double[] The position of the cursor during the interaction

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