com.xj.anylogic.engine.presentation
Class Shape

java.lang.Object
  extended by com.xj.anylogic.engine.presentation.Shape
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, Locatable2D, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
AbstractShapeGISMap, Shape3DObject, Shape3DPhantom, ShapeCAD, ShapeControl, ShapeEmbeddedObjectPresentation, ShapeGroup, ShapeImage, ShapeLine, ShapeLineFill, ShapePixel, ShapeText

public abstract class Shape
extends java.lang.Object
implements Locatable2D, java.io.Serializable, java.lang.Cloneable, com.xj.anylogic.engine.internal.Child

The base class for all persistent graphical shapes and also for all controls (persistent & not).
In general, shapes (rectangles, lines, text, etc.) can be non-persistent and persistent. Non-persistent shapes never exist as objects and are identifies by their id and index (for replicated shapes). When such shape is drawn, its properties are retrieved from the Presentable object using methods like getShapeX( id, index ). A non-persistent shape does not occupy any memory, which is a great advantage when you have a lot of active objects (e.g. agents) each having the presentation shapes. However, non-persistent shapes do not allow direct programmatic control, i.e. you cannot call methods like setWidth() - instead you need to specify a variable in the shape dynamic property Width and change that variable. If you would like to change the properties of the shapes explicitly by calling their methods, you should use persistent shapes. Persistent shape aslo has reference to the group they belong (in case that group is not persistent, that reference is null).

Author:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
Serialized Form

Field Summary
static java.lang.String UNKNOWN_NAME
          This string is returned by getName() for shapes with unknown names.
 
Constructor Summary
Shape()
           
 
Method Summary
 boolean canHandleClick(boolean publicOnly)
          Checks if the shape can handle mouse clicks in its current condition, namely with current public and visibility settings.
 Shape clone()
          Creates and returns a copy of this shape (i.e. new shape instance).
abstract  boolean contains(double px, double py)
          Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e. in the same system with the coordinates of this shape, x and y)
abstract  void draw(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, boolean publicOnly)
          Draws the shape in a given context
 ShapeGroup getGroup()
          Returns the group containing this shape.
 java.lang.String getName()
          If the shape is declared as field in a presentable object class (ActiveObject or Experiment), e.g. if it was drawn in the graphical editor, returns the name of the field, otherwise returns the string UNKNOWN_NAME.
 Presentable getPresentable()
          Returns the Presentable object (ActiveObject or Experiment) where this shape belongs to, or null.
 double getRotation()
          Returns the rotation of the shape.
 double getScaleX()
          Returns the scale of the shape along x axis
 double getScaleY()
          Returns the scale of the shape along y axis
 double getX()
          Returns the x coordinate of the shape.
 double getY()
          Returns the y coordinate of the shape.
 boolean isVisible()
          Returns the visibility of the shape.
 boolean onClick(double clickx, double clicky)
          Should be overridden to define the shape reaction on mouse click.
 boolean onClickAt(double px, double py, boolean publicOnly)
          Should be overridden to test if the shape contains the point with the given coordinates, and, if yes, execute the shape's reaction on click at that point.
 void restoreOwner(java.lang.Object owner)
          This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading
 void setPos(double x, double y)
          Sets both coordinates of the shape
 void setRotation(double r)
          Sets the rotation of the shape.
 void setScale(double s)
          Sets the same scale of the shape along both axes
 void setScale(double sx, double sy)
          Sets the scales of the shape along both axes
 void setScaleX(double sx)
          Sets the scale of the shape along x axis
 void setScaleY(double sy)
          Sets the scale of the shape along y axis
 void setVisible(boolean v)
          Sets the visibility of the shape.
 void setX(double x)
          Sets the x coordinate of the shape
 void setY(double y)
          Sets the y coordinate of the shape
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN_NAME

public static final java.lang.String UNKNOWN_NAME
This string is returned by getName() for shapes with unknown names.
The value of this constant depends on the selected Engine language locale

See Also:
getName(), Light3D.getName()
Constructor Detail

Shape

public Shape()
Method Detail

setVisible

public void setVisible(boolean v)
Sets the visibility of the shape.

Parameters:
v - visibility: true - visible, false - not

isVisible

public boolean isVisible()
Returns the visibility of the shape.

Returns:
visibility: true - visible, false - not

setX

public void setX(double x)
Sets the x coordinate of the shape

Parameters:
x - the new value of x coordinate

getX

public double getX()
Returns the x coordinate of the shape.

Specified by:
getX in interface Locatable2D
Returns:
the x coordinate of the shape

setY

public void setY(double y)
Sets the y coordinate of the shape

Parameters:
y - the new value of y coordinate

getY

public double getY()
Returns the y coordinate of the shape.

Specified by:
getY in interface Locatable2D
Returns:
the y coordinate of the shape

setPos

public void setPos(double x,
                   double y)
Sets both coordinates of the shape

Parameters:
x - the new value of x coordinate
y - the new value of y coordinate

setRotation

public void setRotation(double r)
Sets the rotation of the shape.

Parameters:
r - the new value of rotation in radians

getRotation

public double getRotation()
Returns the rotation of the shape.

Returns:
the rotation of the shape in radians, clockwise

setScaleX

public void setScaleX(double sx)
Sets the scale of the shape along x axis

Parameters:
sx - the new value of scale along x axis, 1 = keep original size

getScaleX

public double getScaleX()
Returns the scale of the shape along x axis

Returns:
the scale of the shape along x axis, 1 = keep original size

setScaleY

public void setScaleY(double sy)
Sets the scale of the shape along y axis

Parameters:
sy - the new value of scale along y axis, 1 = keep original size

getScaleY

public double getScaleY()
Returns the scale of the shape along y axis

Returns:
the scale of the shape along y axis, 1 = keep original size

setScale

public void setScale(double sx,
                     double sy)
Sets the scales of the shape along both axes

Parameters:
sx - the new value of scale along x axis, 1 = keep original size
sy - the new value of scale along y axis, 1 = keep original size

setScale

public void setScale(double s)
Sets the same scale of the shape along both axes

Parameters:
s - the new value of scale along both axis, 1 = keep original size

getGroup

public ShapeGroup getGroup()
Returns the group containing this shape.

Returns:
the group containing this shape

getName

public java.lang.String getName()
If the shape is declared as field in a presentable object class (ActiveObject or Experiment), e.g. if it was drawn in the graphical editor, returns the name of the field, otherwise returns the string UNKNOWN_NAME. For replicated shapes returns the name of the field with the index of the shape in square brackets.
This method is designed to be used for debug/development purposes only. It has a very inefficient implementation and fails in the models exported as applets

Returns:
the name of the corresponding field or UNKNOWN_NAME

getPresentable

public Presentable getPresentable()
Returns the Presentable object (ActiveObject or Experiment) where this shape belongs to, or null.

Returns:
the Presentable that owns this shape, or null

canHandleClick

public boolean canHandleClick(boolean publicOnly)
Checks if the shape can handle mouse clicks in its current condition, namely with current public and visibility settings.

Parameters:
publicOnly - if true, non public shape would not handle clicks
Returns:
true if a click can be handled, otherwise false

onClickAt

public boolean onClickAt(double px,
                         double py,
                         boolean publicOnly)
Should be overridden to test if the shape contains the point with the given coordinates, and, if yes, execute the shape's reaction on click at that point. This base implementation does nothing and return false

Parameters:
px - the x coordinate of the click
py - the y coordinate of the click
publicOnly - if true, not public shape returns false
Returns:
true if the click has been handled AND further click processing is not needed, false otherwise

onClick

public boolean onClick(double clickx,
                       double clicky)
Should be overridden to define the shape reaction on mouse click. The click coordinates are definitely within the shape bounds if this method is called. By default, does nothing and returns false.

Parameters:
clickx - the x coordinate of the click relative to the shape
clicky - the y coordinate of the click relative to the shape
Returns:
true if further click processing is not needed, false otherwise

contains

public abstract boolean contains(double px,
                                 double py)
Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e. in the same system with the coordinates of this shape, x and y)

Parameters:
px - the x coordinate relative to this shape's container
py - the y coordinate relative to this shape's container
Returns:
true if the shape contains the point with the given coordinates

draw

public abstract void draw(Panel panel,
                          java.awt.Graphics2D g,
                          java.awt.geom.AffineTransform xform,
                          boolean publicOnly)
Draws the shape in a given context

Parameters:
panel - the panel where the drawing is done
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
publicOnly - if true, the shape is only drawn if it is public

restoreOwner

public void restoreOwner(java.lang.Object owner)
This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading

Specified by:
restoreOwner in interface com.xj.anylogic.engine.internal.Child
Parameters:
owner - owner of this object, usually ActiveObject, Experiment or ShapeGroup

clone

public Shape clone()
Creates and returns a copy of this shape (i.e. new shape instance).
The returned shape is the object of the same class
The returned copy isn't automatically added to the group this shape belongs to.
The clone is created in the context of the same experiment or active object

Note that cloning of GIS shape, controls and charts is not supported

Overrides:
clone in class java.lang.Object


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.