|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.xj.anylogic.engine.presentation.Shape
public abstract class Shape
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).
| 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 |
|---|
public static final java.lang.String UNKNOWN_NAME
getName() for shapes with unknown names.
getName(),
Light3D.getName()| Constructor Detail |
|---|
public Shape()
| Method Detail |
|---|
public void setVisible(boolean v)
v - visibility: true - visible, false - notpublic boolean isVisible()
public void setX(double x)
x - the new value of x coordinatepublic double getX()
getX in interface Locatable2Dpublic void setY(double y)
y - the new value of y coordinatepublic double getY()
getY in interface Locatable2D
public void setPos(double x,
double y)
x - the new value of x coordinatey - the new value of y coordinatepublic void setRotation(double r)
r - the new value of rotation in radianspublic double getRotation()
public void setScaleX(double sx)
sx - the new value of scale along x axis, 1 = keep original sizepublic double getScaleX()
public void setScaleY(double sy)
sy - the new value of scale along y axis, 1 = keep original sizepublic double getScaleY()
public void setScale(double sx,
double sy)
sx - the new value of scale along x axis, 1 = keep original sizesy - the new value of scale along y axis, 1 = keep original sizepublic void setScale(double s)
s - the new value of scale along both axis, 1 = keep original sizepublic ShapeGroup getGroup()
public java.lang.String getName()
UNKNOWN_NAME.
For replicated shapes returns the name of the field with the index of the shape
in square brackets.
UNKNOWN_NAMEpublic Presentable getPresentable()
public boolean canHandleClick(boolean publicOnly)
publicOnly - if true, non public shape would not handle clicks
public boolean onClickAt(double px,
double py,
boolean publicOnly)
px - the x coordinate of the clickpy - the y coordinate of the clickpublicOnly - if true, not public shape returns false
public boolean onClick(double clickx,
double clicky)
clickx - the x coordinate of the click relative to the shapeclicky - the y coordinate of the click relative to the shape
public abstract boolean contains(double px,
double py)
px - the x coordinate relative to this shape's containerpy - the y coordinate relative to this shape's container
public abstract void draw(Panel panel,
java.awt.Graphics2D g,
java.awt.geom.AffineTransform xform,
boolean publicOnly)
panel - the panel where the drawing is doneg - the graphics where the drawing takes placexform - the "original" transform that must be restored before drawingpublicOnly - if true, the shape is only drawn if it is publicpublic void restoreOwner(java.lang.Object owner)
restoreOwner in interface com.xj.anylogic.engine.internal.Childowner - owner of this object, usually ActiveObject,
Experiment or
ShapeGrouppublic Shape clone()
clone in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||