com.xj.anylogic.engine.presentation
Class ReplicatedShape<T extends Shape>

java.lang.Object
  extended by com.xj.anylogic.engine.presentation.ReplicatedShape<T>
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, java.io.Serializable, java.lang.Cloneable

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

Persistent replicated shape - a container for a number of shapes of the same type but possibly different properties. Both the number of shapes and their properties may change dynamically.

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

Constructor Summary
ReplicatedShape()
           
 
Method Summary
 ReplicatedShape<T> clone()
          Creates and returns a copy of this replicated shape (i.e. new instance).
 boolean contains(double px, double py)
          Tests if any of the shapes in this replicated shape contains the point with the given coordinates
 int createShapes()
          Creates missing and removes redundant shapes so that current number of shapes in this replicated shape equals value returned by getReplication()
abstract  T createShapeWithStaticProperties(int index)
          Creates a new shape with static properties already set.
 void draw(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, boolean publicOnly)
          Draws the replicated shape in a given context, adding and removing the shapes as needed.
 T get(int i)
          Returns the shape with the given index.
 ShapeGroup getGroup()
          Returns the group containing this replicated shape.
abstract  int getReplication()
          Returns the current number of shapes in replicated shape.
 int indexOf(T shape)
          Returns the index of a given shape in this replicated shape.
 boolean onClickAt(double px, double py, boolean publicOnly)
          Tests if any of the shapes in this replicated shape contains the point with the given coordinates and, if yes, executes 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 setShapeDynamicProperties(T shape, int index)
          Sets the dynamic properties of a shape with the given index.
 int size()
          Returns the current number of shapes, which may not always equal to what is returned by getReplication().
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplicatedShape

public ReplicatedShape()
Method Detail

size

public int size()
Returns the current number of shapes, which may not always equal to what is returned by getReplication().

Returns:
the current number of shapes

indexOf

public int indexOf(T shape)
Returns the index of a given shape in this replicated shape.

Parameters:
shape - the shape
Returns:
the index of the shape, -1 if the shape is not in this replicated shape

get

public T get(int i)
Returns the shape with the given index.

Parameters:
i - the index
Returns:
the shape with the given index

getReplication

public abstract int getReplication()
Returns the current number of shapes in replicated shape. Must be defined in a subclass.


createShapeWithStaticProperties

public abstract T createShapeWithStaticProperties(int index)
Creates a new shape with static properties already set. Must be defined in a subclass.

Parameters:
index - the desired shape index
Returns:
a new shape

setShapeDynamicProperties

public void setShapeDynamicProperties(T shape,
                                      int index)
Sets the dynamic properties of a shape with the given index. By default does nothing.

Parameters:
shape - the shape
index - the shape index

getGroup

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

Returns:
the group containing this replicated shape

onClickAt

public boolean onClickAt(double px,
                         double py,
                         boolean publicOnly)
Tests if any of the shapes in this replicated shape contains the point with the given coordinates and, if yes, executes the shape's reaction on click at that point.

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

contains

public boolean contains(double px,
                        double py)
Tests if any of the shapes in this replicated shape contains the point with the given coordinates

Parameters:
px - the x coordinate of the click
py - the y coordinate of the click
Returns:
true if if any of the shapes in this replicated shape contains the point, false otherwise

draw

public void draw(Panel panel,
                 java.awt.Graphics2D g,
                 java.awt.geom.AffineTransform xform,
                 boolean publicOnly)
Draws the replicated shape in a given context, adding and removing the shapes as needed.

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

createShapes

public int createShapes()
Creates missing and removes redundant shapes so that current number of shapes in this replicated shape equals value returned by getReplication()

Returns:
current number of shapes in this replicated shape

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 final ReplicatedShape<T> clone()
Creates and returns a copy of this replicated shape (i.e. new instance).
The returned shape is the object of the same class
All shapes of this replicated shape are cloned respectively
If this shape belongs to some group, its clone will also be added to that group
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.