org.opensourcephysics.drawing2d
Class Element

java.lang.Object
  extended by org.opensourcephysics.drawing2d.Element
All Implemented Interfaces:
Drawable, Interactive, LogMeasurable, Measurable
Direct Known Subclasses:
ElementImage, ElementPoints, ElementPolygon, ElementSegment, ElementShape, ElementText, ElementTrail, Group

public abstract class Element
extends java.lang.Object
implements Interactive, LogMeasurable

Title: Element

Description: A basic individual, interactive drawing element.

Interaction: An Element includes the following targets:

The actual position (and implementation) of the target depends on the element.

Version:
July 2008
Author:
Francisco Esquembre

Field Summary
static int TARGET_POSITION
          The id for the target that allows to reposition the element.
static int TARGET_SIZE
          The id for the target that allows to resize the element.
 
Constructor Summary
Element()
           
 
Method Summary
 void addInteractionListener(InteractionListener listener)
           
abstract  void draw(DrawingPanel _panel, java.awt.Graphics _g)
          Draws the element on a given Graphics2D.
abstract  Interactive findInteractive(DrawingPanel _panel, int _xpix, int _ypix)
          Gets the target that is under the (x,y) position of the screen.
 boolean getCanBeMeasured()
          The element measurable flag.
 java.lang.Object getDataObject()
          Returns the data object
 InteractionTarget getInteractionTarget(int target)
          Provides access to the element's targets
 java.lang.String getName()
          Gets the name of the element
 DrawingPanel getPanel()
          Returns the DrawingPanel in which it (or its final ancestor group) is displayed.
 double[] getPosition()
          Get the coordinates of the element
 double[] getSize()
          Get the size along the axes
 double getSizeX()
          Get the size along the X axis
 double getSizeY()
          Get the size along the Y axis
 Style getStyle()
          Gets the style of the element
 java.lang.Object getTransformation()
          Returns a copy of the element transformation
 double getX()
          Get the X coordinate of the element
 double getXMax()
          Gets the maximum x needed to draw this object.
 double getXMaxLogscale()
          Gets the maximum x needed to draw this object on a log scale.
 double getXMin()
          Gets the minimum x needed to draw this object.
 double getXMinLogscale()
          Gets the minimum x needed to draw this object on a log scale.
 double getY()
          Get the Y coordinate of the element
 double getYMax()
          Gets the maximum y needed to draw this object.
 double getYMaxLogscale()
          Gets the maximum y needed to draw this object on a log scale on a log scale.
 double getYMin()
          Gets the minimum y needed to draw this object.
 double getYMinLogscale()
          Gets the minimum y needed to draw this object on a log scale.
 boolean hasChanged()
          Returns whether the element has changed significantly.
 void invokeActions(InteractionEvent event)
          Invokes the interactionPerformed() methods on the registered interaction listeners.
 boolean isEnabled()
          Whether any of the targets is enabled.
 boolean isMeasured()
          Determines if information is available to set min/max values.
 boolean isVisible()
          Whether the element is visible
 void removeInteractionListener(InteractionListener listener)
           
 void setCanBeMeasured(boolean measured)
          Whether the element is taken into account when autoscaling
 void setDataObject(java.lang.Object _object)
          A place holder for data objects To be used internally by ControlElements
 void setElementChanged()
          Tells the element that it has changed.
 void setEnabled(boolean _enabled)
          Sets the enabled condition of all targets at once.
 void setName(java.lang.String _aName)
          Gives a name to the element.
 void setNeedToProject(boolean _need)
          Tells the element whether it should reproject its points because the panel has changed its projection parameters.
 void setPanel(DrawingPanel _panel)
          To be used internally by DrawingPanel only! Sets the panel for this element.
 void setPosition(double[] _pos)
          Set the coordinates of the element
 void setSize(double[] _size)
          Set the size along the axes
 void setSizeX(double _sizeX)
          Set the size along the X axis
 void setSizeXY(double _sizeX, double _sizeY)
          Set the size along the axes
 void setSizeY(double _sizeY)
          Set the size along the Y axis
 void setTransformation(java.lang.Object _transform)
          Sets the internal transformation of the element, that is, the transformation that converts the standard world axes to the body's internal reference axes.
 void setVisible(boolean _visible)
          Sets the visibility of the element
 void setX(double _x)
          Set the X coordinate of the element
 void setXY(double _x, double _y)
          Set the coordinates of the element
 void setY(double _y)
          Set the Y coordinate of the element
 double[] toBodyFrame(double[] vector)
          This method converts a double[] vector from the space's frame to the body's frame.
 double[] toSpaceFrame(double[] vector)
          This method transforms a double[] vector from the body's frame to the space's frame.
 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 java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TARGET_POSITION

public static final int TARGET_POSITION
The id for the target that allows to reposition the element.

See Also:
Constant Field Values

TARGET_SIZE

public static final int TARGET_SIZE
The id for the target that allows to resize the element.

See Also:
Constant Field Values
Constructor Detail

Element

public Element()
Method Detail

setDataObject

public final void setDataObject(java.lang.Object _object)
A place holder for data objects To be used internally by ControlElements

Parameters:
_object - Object

getDataObject

public final java.lang.Object getDataObject()
Returns the data object

Returns:
Object

setPanel

public final void setPanel(DrawingPanel _panel)
To be used internally by DrawingPanel only! Sets the panel for this element.

Parameters:
_panel - DrawingPanel

getPanel

public final DrawingPanel getPanel()
Returns the DrawingPanel in which it (or its final ancestor group) is displayed.

Returns:
org.opensourcephysics.drawing.core.DrawingPanel

setName

public final void setName(java.lang.String _aName)
Gives a name to the element. Naming an element is optional, but the element may use its name to identify itself.

Parameters:
name - String

getName

public final java.lang.String getName()
Gets the name of the element

Returns:
String the name

setX

public final void setX(double _x)
Set the X coordinate of the element

Specified by:
setX in interface Interactive
Parameters:
x - double

getX

public final double getX()
Get the X coordinate of the element

Specified by:
getX in interface Interactive
Returns:
double

setY

public final void setY(double _y)
Set the Y coordinate of the element

Specified by:
setY in interface Interactive
Parameters:
y - double

getY

public final double getY()
Get the Y coordinate of the element

Specified by:
getY in interface Interactive
Returns:
double

setXY

public final void setXY(double _x,
                        double _y)
Set the coordinates of the element

Specified by:
setXY in interface Interactive
Parameters:
_x - double the x position
_y - double the y position

setPosition

public final void setPosition(double[] _pos)
Set the coordinates of the element

Parameters:
pos - double[] an array of dimension 2

getPosition

public final double[] getPosition()
Get the coordinates of the element

Returns:
double[]

setSizeX

public void setSizeX(double _sizeX)
Set the size along the X axis

Parameters:
sizeX - double

getSizeX

public final double getSizeX()
Get the size along the X axis

Returns:
double

setSizeY

public void setSizeY(double _sizeY)
Set the size along the Y axis

Parameters:
sizeY - double

getSizeY

public final double getSizeY()
Get the size along the Y axis

Returns:
double

setSizeXY

public void setSizeXY(double _sizeX,
                      double _sizeY)
Set the size along the axes

Parameters:
sizeX - double the size along the X axis
sizeY - double the size along the Y axis

setSize

public void setSize(double[] _size)
Set the size along the axes

Parameters:
size - double[] an array of the dimension 2

getSize

public final double[] getSize()
Get the size along the axes

Returns:
double[]

setCanBeMeasured

public void setCanBeMeasured(boolean measured)
Whether the element is taken into account when autoscaling

Parameters:
measured - boolean

getCanBeMeasured

public boolean getCanBeMeasured()
The element measurable flag. The actuable measurabilty may depend on other things, such as a trail with no points

Returns:
boolean the measurability flag as set by the user

getXMin

public double getXMin()
Description copied from interface: Measurable
Gets the minimum x needed to draw this object.

Specified by:
getXMin in interface Measurable
Returns:
minimum

getXMax

public double getXMax()
Description copied from interface: Measurable
Gets the maximum x needed to draw this object.

Specified by:
getXMax in interface Measurable
Returns:
maximum

getYMin

public double getYMin()
Description copied from interface: Measurable
Gets the minimum y needed to draw this object.

Specified by:
getYMin in interface Measurable
Returns:
minimum

getYMax

public double getYMax()
Description copied from interface: Measurable
Gets the maximum y needed to draw this object.

Specified by:
getYMax in interface Measurable
Returns:
minimum

getXMinLogscale

public double getXMinLogscale()
Description copied from interface: LogMeasurable
Gets the minimum x needed to draw this object on a log scale.

Specified by:
getXMinLogscale in interface LogMeasurable
Returns:
minimum

getXMaxLogscale

public double getXMaxLogscale()
Description copied from interface: LogMeasurable
Gets the maximum x needed to draw this object on a log scale.

Specified by:
getXMaxLogscale in interface LogMeasurable
Returns:
maximum

getYMinLogscale

public double getYMinLogscale()
Description copied from interface: LogMeasurable
Gets the minimum y needed to draw this object on a log scale.

Specified by:
getYMinLogscale in interface LogMeasurable
Returns:
minimum

getYMaxLogscale

public double getYMaxLogscale()
Description copied from interface: LogMeasurable
Gets the maximum y needed to draw this object on a log scale on a log scale.

Specified by:
getYMaxLogscale in interface LogMeasurable
Returns:
maximum

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
Returns:
true if min/max values are valid

setVisible

public final void setVisible(boolean _visible)
Sets the visibility of the element

Parameters:
visible - boolean

isVisible

public final boolean isVisible()
Whether the element is visible

Returns:
boolean

getStyle

public final Style getStyle()
Gets the style of the element

Returns:
Style
See Also:
Style

hasChanged

public boolean hasChanged()
Returns whether the element has changed significantly. This can be used by implementing classes to help improve performance. Not final because Group overwrites it

Returns:
boolean

setElementChanged

public final void setElementChanged()
Tells the element that it has changed. Typically used by subclasses when they change something

Parameters:
change - Whether the element has changed

setTransformation

public final void setTransformation(java.lang.Object _transform)
                             throws java.lang.ClassCastException
Sets the internal transformation of the element, that is, the transformation that converts the standard world axes to the body's internal reference axes. The class of the object must be one of: (i.e. a 2D transformation for 2D elements, a 3D transformation for 3d objects, ...) The transformation is copied and cannot be accessed by users directly. This implies that changing the original transformation has no effect on the element unless a new setTransformation() is invoked. The transformation uses the body's position as its origin.

Parameters:
transformation - the new transformation
Throws:
java.lang.ClassCastException - if an object of a non-supported class is passed as argument

getTransformation

public final java.lang.Object getTransformation()
Returns a copy of the element transformation

Returns:
Object

toSpaceFrame

public final double[] toSpaceFrame(double[] vector)
This method transforms a double[] vector from the body's frame to the space's frame.

Parameters:
vector - double[] The original coordinates in the body frame
Returns:
double[] The same array once transformed

toBodyFrame

public final double[] toBodyFrame(double[] vector)
                           throws java.awt.geom.NoninvertibleTransformException
This method converts a double[] vector from the space's frame to the body's frame.

This only works properly if the internal transformation is not set (i.e. it is the identity) or if it is invertible. Otherwise, a call to this method will throw an UnsupportedOperationException exception.

Parameters:
vector - double[] The original coordinates in the space
Returns:
double[] The same array with the body coordinates
Throws:
java.awt.geom.NoninvertibleTransformException

draw

public abstract void draw(DrawingPanel _panel,
                          java.awt.Graphics _g)
Draws the element on a given Graphics2D. Required by Drawable (in Interactive)

Specified by:
draw in interface Drawable

setNeedToProject

public void setNeedToProject(boolean _need)
Tells the element whether it should reproject its points because the panel has changed its projection parameters. Or, the other way round, sets it to false if someone (typically methods in subclasses) took care of this already.


setEnabled

public void setEnabled(boolean _enabled)
Sets the enabled condition of all targets at once. Required by Interactive

Specified by:
setEnabled in interface Interactive

isEnabled

public boolean isEnabled()
Whether any of the targets is enabled. Required by Interactive

Specified by:
isEnabled in interface Interactive

getInteractionTarget

public final InteractionTarget getInteractionTarget(int target)
Provides access to the element's targets


addInteractionListener

public final void addInteractionListener(InteractionListener listener)

removeInteractionListener

public final void removeInteractionListener(InteractionListener listener)

invokeActions

public final void invokeActions(InteractionEvent event)
Invokes the interactionPerformed() methods on the registered interaction listeners.

Parameters:
event - InteractionEvent

findInteractive

public abstract Interactive findInteractive(DrawingPanel _panel,
                                            int _xpix,
                                            int _ypix)
Gets the target that is under the (x,y) position of the screen. Required by Interactive

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

updateHotSpot

public 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. Notice that, for targetSize, if any of the sizes of the element is zero, this dimension cannot be changed.

Parameters:
target - InteractionTarget The target interacted
point - double[] The position of the cursor during the interaction