com.xj.anylogic.engine.presentation
Class ShapeTextField

java.lang.Object
  extended by com.xj.anylogic.engine.presentation.Shape
      extended by com.xj.anylogic.engine.presentation.ShapeControl
          extended by com.xj.anylogic.engine.presentation.ShapeTextField
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, Locatable2D, java.awt.event.FocusListener, java.awt.event.KeyListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener

public class ShapeTextField
extends ShapeControl
implements java.awt.event.FocusListener, java.awt.event.KeyListener

TextField control. Embeds JTextField. User's text field. Calls presentable object's executeControlAction( id, index, text ); method on focus lost or Enter pressed.

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

Field Summary
 java.lang.String value
          The current text in the text field that can be accessed in the overridden action() method.
 
Fields inherited from class com.xj.anylogic.engine.presentation.ShapeControl
TYPE_DOUBLE, TYPE_INT, TYPE_STRING
 
Fields inherited from class com.xj.anylogic.engine.presentation.Shape
UNKNOWN_NAME
 
Constructor Summary
ShapeTextField(Presentable p, boolean ispublic, int x, int y, int width, int height, java.awt.Color backgroundColor, java.awt.Color textColor, java.awt.Font font)
          Creates a persistent text field control.
ShapeTextField(Presentable p, boolean ispublic, int x, int y, int width, int height, java.awt.Color backgroundColor, java.awt.Color textColor, java.awt.Font font, int valueType, double min, double max)
          Creates a persistent text field control.
 
Method Summary
 void action()
          Executes the action associated with a non-persistent text field.
 void focusGained(java.awt.event.FocusEvent arg0)
           
 void focusLost(java.awt.event.FocusEvent arg0)
           
 double getDoubleValue()
          Returns the current double value of the text field.
 int getIntValue()
          Returns the current int value of the text field.
 javax.swing.JComponent getJComponent()
          Returns the JTextField of this control.
 double getMax()
          Returns the maximum value of the text field.
 double getMin()
          Returns the minimum value of the text field.
 java.lang.String getText()
          Returns the text of the text field.
 void keyPressed(java.awt.event.KeyEvent key)
           
 void keyReleased(java.awt.event.KeyEvent arg0)
           
 void keyTyped(java.awt.event.KeyEvent arg0)
           
 void setBackgroundColor(java.awt.Color backgroundColor)
          Sets the background color of this text field.
 void setRange(double min, double max)
          Sets the minimum and maximum values of the text field with numeric value-type: ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT.
 void setRange(double min, double max, boolean callAction)
          Sets the minimum and maximum values of the text field with numeric value-type: ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT.
 void setText(double value)
          Sets the numeric value of the text field with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
 void setText(double value, boolean callAction)
          Sets the numeric value of the text field with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
 void setText(java.lang.String text)
          Sets the text of the text field
Doesn't execute user action code
If value-type is numeric and the given text isn't a valid number, nothing will be changed, and if text is a number but not within [min, max], it will be corrected to min or max
 void setText(java.lang.String text, boolean callAction)
          Sets the text of the text field
Executes user action code (if any exists) if callAction parameter is true
If value-type is numeric and the given text isn't a valid number, nothing will be changed, and if text is a number but not within [min, max], it will be corrected to min or max
 void setTextColor(java.awt.Color textColor)
          Sets the text color of this text field.
 void setValueToDefault()
          Sets the text of a non-persistent text field to what was provided as the default one.
 void update()
          Updates the specific properties of a text field that are to be updated on each frame: min/max.
 
Methods inherited from class com.xj.anylogic.engine.presentation.ShapeControl
clone, contains, draw, getHeight, getPresentable, getWidth, isEnabled, onClickAt, restoreOwner, setEnabled, setHeight, setWidth
 
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

value

public java.lang.String value
The current text in the text field that can be accessed in the overridden action() method.
Use getText() to obtain the current text from other places.

Constructor Detail

ShapeTextField

public ShapeTextField(Presentable p,
                      boolean ispublic,
                      int x,
                      int y,
                      int width,
                      int height,
                      java.awt.Color backgroundColor,
                      java.awt.Color textColor,
                      java.awt.Font font)
Creates a persistent text field control. You should override the action() method.
Created text box has value-type ShapeControl.TYPE_STRING

Parameters:
p - the presentable object owning this control
ispublic - if true, the control is visible on container's presentation
x - the x coordinate
y - the y coordinate
width - the width
height - the height
backgroundColor - the background color
textColor - the text color
font - the text font

ShapeTextField

public ShapeTextField(Presentable p,
                      boolean ispublic,
                      int x,
                      int y,
                      int width,
                      int height,
                      java.awt.Color backgroundColor,
                      java.awt.Color textColor,
                      java.awt.Font font,
                      int valueType,
                      double min,
                      double max)
Creates a persistent text field control. You should override the action() method.

Parameters:
p - the presentable object owning this control
ispublic - if true, the control is visible on container's presentation
x - the x coordinate
y - the y coordinate
width - the width
height - the height
backgroundColor - the background color
textColor - the text color
font - the text font
valueType - the type of the value edited in the text field, supported types: ShapeControl.TYPE_STRING, ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT
min - the minimum value of the text field with numeric value-type: ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT
Ignored if value-type is ShapeControl.TYPE_STRING
max - the maximum value of the text field with numeric value-type: ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT
Ignored if value-type is ShapeControl.TYPE_STRING
Method Detail

action

public void action()
Executes the action associated with a non-persistent text field. This method must be overridden for persistent text fields.

Specified by:
action in class ShapeControl

getJComponent

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

Specified by:
getJComponent in class ShapeControl

setBackgroundColor

public void setBackgroundColor(java.awt.Color backgroundColor)
Sets the background color of this text field.

Parameters:
backgroundColor - the desired background Color

setTextColor

public void setTextColor(java.awt.Color textColor)
Sets the text color of this text field.

Parameters:
textColor - the desired text Color

setValueToDefault

public void setValueToDefault()
Sets the text of a non-persistent text field to what was provided as the default one.
Doesn't execute user action code

Overrides:
setValueToDefault in class ShapeControl

setText

public void setText(java.lang.String text)
Sets the text of the text field
Doesn't execute user action code
If value-type is numeric and the given text isn't a valid number, nothing will be changed, and if text is a number but not within [min, max], it will be corrected to min or max

Parameters:
text - the new text

setText

public void setText(java.lang.String text,
                    boolean callAction)
Sets the text of the text field
Executes user action code (if any exists) if callAction parameter is true
If value-type is numeric and the given text isn't a valid number, nothing will be changed, and if text is a number but not within [min, max], it will be corrected to min or max

Parameters:
text - the new text
callAction - if true user action code (if any exists) will be executed

setText

public void setText(double value)
Sets the numeric value of the text field with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
Doesn't execute user action code

Parameters:
value - the new value (double or int)

setText

public void setText(double value,
                    boolean callAction)
Sets the numeric value of the text field with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
Executes user action code (if any exists) if callAction parameter is true

Parameters:
value - the new value (double or int)
callAction - if true user action code (if any exists) will be executed

getText

public java.lang.String getText()
Returns the text of the text field.

Returns:
the text of the text field

getIntValue

public int getIntValue()
Returns the current int value of the text field.
Method throws an exception when the value isn't a number.

Returns:
the current int value of the text field

getDoubleValue

public double getDoubleValue()
Returns the current double value of the text field.
Method throws an exception when the value isn't a number.

Returns:
the current double value of the text field

setRange

public void setRange(double min,
                     double max)
Sets the minimum and maximum values of the text field with numeric value-type: ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT.
Doesn't execute user action code
If text field is configured to work with int values (see ShapeControl.TYPE_INT), the given [min, max] range may be automatically corrected to have integer bounds (within the given double bounds)
This method does nothing if the text field already has such range

Parameters:
min - the new minimum value
max - the new maximum value

setRange

public void setRange(double min,
                     double max,
                     boolean callAction)
Sets the minimum and maximum values of the text field with numeric value-type: ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT.
If current text field value changes, executes user action code (if any exists) in the same thread - if callAction parameter is true
If text field is configured to work with int values (see ShapeControl.TYPE_INT), the given [min, max] range may be automatically corrected to have integer bounds (within the given double bounds)
This method does nothing if the text field already has such range

Parameters:
min - the new minimum value
max - the new maximum value
callAction - if true user action code (if any exists) will be executed if current text field value changes

getMin

public double getMin()
Returns the minimum value of the text field.
This method may only be used in text fields with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT

Returns:
the minimum value of the text field

getMax

public double getMax()
Returns the maximum value of the text field.
This method may only be used in text fields with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT

Returns:
the maximum value of the text field

update

public void update()
Updates the specific properties of a text field that are to be updated on each frame: min/max.

Overrides:
update in class ShapeControl

focusGained

public void focusGained(java.awt.event.FocusEvent arg0)
Specified by:
focusGained in interface java.awt.event.FocusListener

focusLost

public void focusLost(java.awt.event.FocusEvent arg0)
Specified by:
focusLost in interface java.awt.event.FocusListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent key)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent arg0)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent arg0)
Specified by:
keyTyped in interface java.awt.event.KeyListener


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