AnyLogic
Expand
Font size
All Implemented Interfaces:
com.anylogic.engine.internal.Child, Locatable2D, AggregatableAnimationElement, HasLevel, LevelElement, SVGElement, java.io.Serializable, java.lang.Cloneable

public class ShapeTextField
extends ShapeInputControl
TextField control. Embeds JTextField. User's text field. Calls presentable object's executeControlAction( id, index, text ); method on focus lost or Enter pressed.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from class com.anylogic.engine.presentation.ShapeControl

ShapeControl.ValueType

Field Summary

Fields 
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.
Modifier and Type Field Description

Fields inherited from class com.anylogic.engine.presentation.ShapeControl

TYPE_DOUBLE, TYPE_INT, TYPE_STRING

Fields inherited from class com.anylogic.engine.presentation.Shape

UNKNOWN_NAME

Constructor Summary

Constructors 
ShapeTextField​(Presentable p, boolean ispublic, double x, double y, double width, double height, java.awt.Color backgroundColor, java.awt.Color textColor, boolean enabled, java.awt.Font font)
Creates a persistent text field control.
ShapeTextField​(Presentable p, boolean ispublic, double x, double y, double width, double height, java.awt.Color backgroundColor, java.awt.Color textColor, boolean enabled, java.awt.Font font, ShapeControl.ValueType valueType, double min, double max)
Creates a persistent text field control.
ShapeTextField​(Presentable p, boolean ispublic, double x, double y, double width, double height, java.awt.Color backgroundColor, java.awt.Color textColor, java.awt.Font font)
Deprecated.
may be removed in future releases
ShapeTextField​(Presentable p, boolean ispublic, double x, double y, double width, double height, java.awt.Color backgroundColor, java.awt.Color textColor, java.awt.Font font, ShapeControl.ValueType valueType, double min, double max)
Deprecated.
may be removed in future releases
Constructor Description

Method Summary

All Methods Instance Methods Concrete Methods 
void executeUserAction​(java.lang.String value)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
double getDoubleValue()
Returns the current double value of the text field.
Method throws an exception when the value isn't a number.
int getIntValue()
Returns the current int value of the text field.
Method throws an exception when the value isn't a number.
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
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
java.lang.String getText()
Returns the text of the text field.
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.
Doesn't execute user action code
Leaving both min and max with zeroes will result in unlimited range.
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
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
Leaving both min and max with zeroes will result in unlimited range.
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
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
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
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.
Modifier and Type Method Description

Methods inherited from class com.anylogic.engine.presentation.ShapeInputControl

postSVGShapeSpecificAttributes

Methods inherited from class com.anylogic.engine.presentation.ShapeControl

action, clone, contains, executeAction, getHeight, getPresentable, getWidth, isEnabled, randomPointInside, restoreOwner, setEnabled, setHeight, setValueToDefault, setWidth

Methods inherited from class com.anylogic.engine.presentation.Shape

canHandleClick, findSVGElement, getDrawMode, getGroup, getLevel, getName, getRotation, getScaleX, getScaleY, getSVGId, getX, getY, isJava2DSwingPresentation, isPublic_xjal, isSVGPresentation, isVisible, onAggregatorVisibilityChanged, onClick, randomPointInside, removeSVGFromOwner, removeSVGImage, resetSVGState, setLevel, setPos, setPos, setPublic_xjal, setRotation, setScale, setScale, setScaleX, setScaleY, setVisible, setX, setY, updateDynamicProperties, updateDynamicPropertiesStructural, updateSVGProperties

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods inherited from interface com.anylogic.engine.markup.AggregatableAnimationElement

initializeInternal, postInitialize

Field Detail

value

@AnyLogicInternalAPI
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

@Deprecated
public ShapeTextField​(Presentable p,
                      boolean ispublic,
                      double x,
                      double y,
                      double width,
                      double height,
                      java.awt.Color backgroundColor,
                      java.awt.Color textColor,
                      java.awt.Font font)
Deprecated.
may be removed in future releases

ShapeTextField

public ShapeTextField​(Presentable p,
                      boolean ispublic,
                      double x,
                      double y,
                      double width,
                      double height,
                      java.awt.Color backgroundColor,
                      java.awt.Color textColor,
                      boolean enabled,
                      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
enabled - the initial enabled state
font - the text font

ShapeTextField

@Deprecated
public ShapeTextField​(Presentable p,
                      boolean ispublic,
                      double x,
                      double y,
                      double width,
                      double height,
                      java.awt.Color backgroundColor,
                      java.awt.Color textColor,
                      java.awt.Font font,
                      ShapeControl.ValueType valueType,
                      double min,
                      double max)
Deprecated.
may be removed in future releases

ShapeTextField

public ShapeTextField​(Presentable p,
                      boolean ispublic,
                      double x,
                      double y,
                      double width,
                      double height,
                      java.awt.Color backgroundColor,
                      java.awt.Color textColor,
                      boolean enabled,
                      java.awt.Font font,
                      ShapeControl.ValueType 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
enabled - the initial enabled state
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

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

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
Leaving both min and max with zeroes will result in unlimited range.
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
Leaving both min and max with zeroes will result in unlimited range.
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, leaving both min and max with zeroes will result in unlimited range
max - the new maximum value, leaving both min and max with zeroes will result in unlimited range
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

executeUserAction

@AnyLogicInternalAPI
public void executeUserAction​(java.lang.String value)
Description copied from interface: SVGElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
executeUserAction in interface SVGElement
Overrides:
executeUserAction in class Shape
How can we improve this article?