com.xj.anylogic.engine.presentation
Class ShapeGroup

java.lang.Object
  extended by com.xj.anylogic.engine.presentation.Shape
      extended by com.xj.anylogic.engine.presentation.ShapeGroup
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, Locatable2D, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Shape3DGroup

public class ShapeGroup
extends Shape
implements com.xj.anylogic.engine.internal.Child

Persistent group shape. Contains a collection of shapes that can be either non-persistent (i.e. having ids), or persistent. Shapes may also be replicated. The user can add, remove and change shapes in the group dynamically.
Persistent shapes contained in a group have reference to that group.

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

Field Summary
 
Fields inherited from class com.xj.anylogic.engine.presentation.Shape
UNKNOWN_NAME
 
Constructor Summary
ShapeGroup(Presentable presentable)
          Constructs an empty group with default attributes.
ShapeGroup(Presentable presentable, boolean ispublic, double x, double y, double rotation, java.lang.Object... contents)
          Constructs a group with specific attributes and possibly with some content
 
Method Summary
 void add(int shape)
          Adds a non-persistent shape to the group.
 void add(ReplicatedShape<?> rshape)
          Adds a replicated shape to the group.
 void add(Shape shape)
          Adds a persistent shape to the group.
 void clear()
          Removes all shapes from the group.
 ShapeGroup clone()
          Creates and returns a copy of this group (i.e. new shape instance).
 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)
 void draw(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, boolean publicOnly)
          Draws the group of shapes in a given context
 java.lang.Object get(int i)
          Returns the shape (either object of class Shape or integer in case of non-persistent shape, or object of class ReplicatedShape) with the given index.
 Presentable getPresentable()
          Returns the presentable (ActiveObject or Experiment) where this group belongs to.
 java.util.ArrayList<java.lang.Object> getShapes()
          Returns the collection of shapes in the group (not a copy).
 int indexOf(java.lang.Object shape)
          Returns the index of the the specified shape (either object of class Shape or integer in case of non-persistent shape, or object of class ReplicatedShape) in this group, or -1 if this group does not contain the shape.
 boolean onClickAt(double px, double py, boolean publicOnly)
          Tests if any of the group shapes contains the point with the given coordinates and, if yes, executes the shape's reaction on click at that point.
 void onDraw(Panel panel, java.awt.Graphics2D g)
          A callback called by the group after the group has drawn itself (and only if the group drawing is needed - it is visible, etc.).
 boolean remove(int shape)
          Tries to remove a non-persistent shape from the group, returns false if the shape was not contained.
 boolean remove(ReplicatedShape<?> rshape)
          Tries to remove a replicated shape from the group, returns false if the shape was not contained.
 boolean remove(Shape shape)
          Tries to remove a persistent shape from the group, returns false if the shape was not contained.
 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
 int size()
          Returns the number of shapes in the group.
 
Methods inherited from class com.xj.anylogic.engine.presentation.Shape
canHandleClick, getGroup, getName, getRotation, getScaleX, getScaleY, getX, getY, isVisible, onClick, setPos, setRotation, setScale, setScale, setScaleX, setScaleY, setVisible, setX, setY
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeGroup

public ShapeGroup(Presentable presentable)
Constructs an empty group with default attributes.

Parameters:
presentable - the presentable object owning this shape

ShapeGroup

public ShapeGroup(Presentable presentable,
                  boolean ispublic,
                  double x,
                  double y,
                  double rotation,
                  java.lang.Object... contents)
Constructs a group with specific attributes and possibly with some content

Parameters:
presentable - the presentable object owning this shape
ispublic - if true, the shape is visible on container's presentation
x - the x coordinate of group
y - the y coordinate of group
rotation - the rotation of the group in radians
contents - the (possibly, empty) initial set of shapes (Shape objects, int ids, or ReplicatedShape objects)
Method Detail

getShapes

public java.util.ArrayList<java.lang.Object> getShapes()
Returns the collection of shapes in the group (not a copy). The collection can contain either members of type Integer for non-persistent shapes, of class Shape for persistent shapes, and of class ReplicatedShape for replicated shapes.

Returns:
the collection of shapes in the group

size

public int size()
Returns the number of shapes in the group.

Returns:
the number of shapes in the group

get

public java.lang.Object get(int i)
Returns the shape (either object of class Shape or integer in case of non-persistent shape, or object of class ReplicatedShape) with the given index.

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

indexOf

public int indexOf(java.lang.Object shape)
Returns the index of the the specified shape (either object of class Shape or integer in case of non-persistent shape, or object of class ReplicatedShape) in this group, or -1 if this group does not contain the shape.
More formally, returns the index i such that get( i ) == shape, or -1 if there is no such index.
Note that implementation of this method is very inefficient (has linear complexity)

Parameters:
shape - the shape to find index of
Returns:
the index of the shape or -1

add

public void add(Shape shape)
Adds a persistent shape to the group. Note that it is your responsibility to remove the shape from the another group, if any!

Parameters:
shape - the shape to add

add

public void add(int shape)
Adds a non-persistent shape to the group. Note that it is your responsibility to remove the shape from the another group, if any!

Parameters:
shape - the shape id to add

add

public void add(ReplicatedShape<?> rshape)
Adds a replicated shape to the group. Note that it is your responsibility to remove the shape from the another group, if any!

Parameters:
rshape - the replicated shape to add

remove

public boolean remove(Shape shape)
Tries to remove a persistent shape from the group, returns false if the shape was not contained.

Parameters:
shape - the shape to remove
Returns:
true if the group contained the shape, false otherwise

remove

public boolean remove(int shape)
Tries to remove a non-persistent shape from the group, returns false if the shape was not contained.

Parameters:
shape - the id of the shape to remove
Returns:
true if the group contained the shape, false otherwise

remove

public boolean remove(ReplicatedShape<?> rshape)
Tries to remove a replicated shape from the group, returns false if the shape was not contained.

Parameters:
rshape - the replicated shape to remove
Returns:
true if the group contained the shape, false otherwise

clear

public void clear()
Removes all shapes from the group.


onClickAt

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

Overrides:
onClickAt in class Shape
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)
Description copied from class: Shape
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)

Specified by:
contains in class Shape
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 void draw(Panel panel,
                 java.awt.Graphics2D g,
                 java.awt.geom.AffineTransform xform,
                 boolean publicOnly)
Draws the group of shapes in a given context

Specified by:
draw in class Shape
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

onDraw

public void onDraw(Panel panel,
                   java.awt.Graphics2D g)
A callback called by the group after the group has drawn itself (and only if the group drawing is needed - it is visible, etc.). May be overridden at subclasses.

Parameters:
panel - the panel where the drawing is done
g - the graphics where the drawing takes place

getPresentable

public Presentable getPresentable()
Returns the presentable (ActiveObject or Experiment) where this group belongs to.

Overrides:
getPresentable in class Shape
Returns:
the presentable where this group belongs to

restoreOwner

public void restoreOwner(java.lang.Object owner)
Description copied from class: Shape
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
Overrides:
restoreOwner in class Shape
Parameters:
owner - owner of this object, usually ActiveObject, Experiment or ShapeGroup

clone

public ShapeGroup clone()
Creates and returns a copy of this group (i.e. new shape instance).
The returned shape is the object of the same class
All shapes belonging to this group are cloned respectively
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

Overrides:
clone in class Shape


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