com.xj.anylogic.engine.presentation
Class ShapeControl

java.lang.Object
  extended by com.xj.anylogic.engine.presentation.Shape
      extended by com.xj.anylogic.engine.presentation.ShapeControl
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, Locatable2D, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Chart, ShapeButton, ShapeCheckBox, ShapeComboBox, ShapeFileChooser, ShapeListBox, ShapeProgressBar, ShapeRadioButtonGroup, ShapeSlider, ShapeTextField, ShapeWindow3D

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

The base class for all controls, i.e. presentation shapes that have JComponents, (like buttons, sliders, text fields, and also charts) both persistent and not persistent. The non-persistent controls are idetified by their owner Presentable object, id and index.
The concept of persistent and non-persistent controls helps you to save significant amount of memory at runtime, which is critical when you have a lot of active objects, e.g. agents, each with its own controls/charts on the presentation. It works in the following way. If you have marked control as persistent, it will always exist during the active object lifetime. If you mark it as non-persistent, it will only exist when it is displayed. Therefore if you are viewing the presentation of one agent at a time, the non-persistent controls of other agents will not take any memory.
The only limitation of non-persistent controls is that you cannot access them programmatically while they are not visible. While they are visible, you can access them by calling getShapeControl( id, index ) and then call its methods, however the changes you make this way will be lost if the control disappears from the view and is displayed again. With persistent controls you can call their methods any time, just like you do with any normal objects.
If you do not have a lot of active objects and thus do not care about the momory occupied by the controls, you can have all your controls as persistent.

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

Field Summary
static int TYPE_DOUBLE
          Control value-type constant for double number editing mode, applicable for ShapeSlider, ShapeTextField, ShapeComboBox.
static int TYPE_INT
          Control value-type constant for int number editing mode, applicable for ShapeSlider, ShapeTextField, ShapeComboBox.
static int TYPE_STRING
          Control value-type constant for String editing mode, applicable for ShapeTextField, ShapeComboBox.
 
Fields inherited from class com.xj.anylogic.engine.presentation.Shape
UNKNOWN_NAME
 
Method Summary
abstract  void action()
          Executes the action associated with the control.
 Shape clone()
          Cloning of controls is not supported
(Other shapes except GIS and charts allow cloning)
This method throws UnsupportedOperationException if called
 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 a persistent control in a given context
 double getHeight()
          Returns the height of the control.
abstract  javax.swing.JComponent getJComponent()
          Returns the JComponent of this control.
 Presentable getPresentable()
          Returns the presentable object owning the control
 double getWidth()
          Returns the width of the control.
 boolean isEnabled()
          Tests if the coltrol is enabled or disabled.
 boolean onClickAt(double px, double py, boolean publicOnly)
          Tests if the control 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 setEnabled(boolean yes)
          Sets the control enabled or disabled
 void setHeight(double h)
          Sets the height of the control.
 void setValueToDefault()
          Sets the value of a non-persistent control to what was provided as the default one.
 void setWidth(double w)
          Sets the width of the control.
 void update()
          Updates the speific properties of a (non-persistent) control that are to be updated on each frame.
 
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
 

Field Detail

TYPE_DOUBLE

public static final int TYPE_DOUBLE
Control value-type constant for double number editing mode, applicable for ShapeSlider, ShapeTextField, ShapeComboBox.
See constructors of these controls

See Also:
Constant Field Values

TYPE_INT

public static final int TYPE_INT
Control value-type constant for int number editing mode, applicable for ShapeSlider, ShapeTextField, ShapeComboBox.
See constructors of these controls

See Also:
Constant Field Values

TYPE_STRING

public static final int TYPE_STRING
Control value-type constant for String editing mode, applicable for ShapeTextField, ShapeComboBox.
See constructors of these controls

See Also:
Constant Field Values
Method Detail

action

public abstract void action()
Executes the action associated with the control. This method must be overridden for persistent controls.


getJComponent

public abstract javax.swing.JComponent getJComponent()
Returns the JComponent of this control.


setEnabled

public void setEnabled(boolean yes)
Sets the control enabled or disabled

Parameters:
yes - the new enabled state

isEnabled

public boolean isEnabled()
Tests if the coltrol is enabled or disabled.

Returns:
true if enabled, otherwise false

setValueToDefault

public void setValueToDefault()
Sets the value of a non-persistent control to what was provided as the default one.


setWidth

public void setWidth(double w)
Sets the width of the control.

Parameters:
w - the new width

getWidth

public double getWidth()
Returns the width of the control.

Returns:
the width of the control

setHeight

public void setHeight(double h)
Sets the height of the control.

Parameters:
h - the new height

getHeight

public double getHeight()
Returns the height of the control.

Returns:
the height of the control

onClickAt

public boolean onClickAt(double px,
                         double py,
                         boolean publicOnly)
Tests if the control 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

getPresentable

public Presentable getPresentable()
Returns the presentable object owning the control

Overrides:
getPresentable in class Shape
Returns:
the presentable object owning the control

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

update

public void update()
Updates the speific properties of a (non-persistent) control that are to be updated on each frame.


draw

public void draw(Panel panel,
                 java.awt.Graphics2D g,
                 java.awt.geom.AffineTransform xform,
                 boolean publicOnly)
Draws a persistent control 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

clone

public Shape clone()
Cloning of controls is not supported
(Other shapes except GIS and charts allow cloning)
This method throws UnsupportedOperationException if called

Overrides:
clone in class Shape


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