AnyLogic
Expand
Font size
All Implemented Interfaces:
com.anylogic.engine.internal.Child, Locatable2D, AggregatableAnimationElement, HasLevel, LevelElement, SVGElement, UsdElement, Serializable, 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

Modifier and TypeFieldDescription
Stringvalue
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.

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

Fields inherited from interface com.anylogic.engine.presentation.UsdElement

ID_NOT_SET

Constructor Summary

ConstructorDescription
ShapeTextField(Presentable p, boolean ispublic, double x, double y, double width, double height, Color backgroundColor, Color textColor, boolean enabled, Font font)
Creates a persistent text field control.
ShapeTextField(Presentable p, boolean ispublic, double x, double y, double width, double height, Color backgroundColor, Color textColor, boolean enabled, 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, Color backgroundColor, Color textColor, Font font)
Deprecated.
may be removed in future releases
ShapeTextField(Presentable p, boolean ispublic, double x, double y, double width, double height, Color backgroundColor, Color textColor, Font font, ShapeControl.ValueType valueType, double min, double max)
Deprecated.
may be removed in future releases

Method Summary

Modifier and TypeMethodDescription
voidexecuteUserAction(String value)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
doublegetDoubleValue()
Returns the current double value of the text field.
Method throws an exception when the value isn't a number.
intgetIntValue()
Returns the current int value of the text field.
Method throws an exception when the value isn't a number.
doublegetMax()
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
doublegetMin()
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
StringgetText()
Returns the text of the text field.
voidsetBackgroundColor(Color backgroundColor)
Sets the background color of this text field.
voidsetRange(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
voidsetRange(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
voidsetText(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
voidsetText(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
voidsetText(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
voidsetText(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
voidsetTextColor(Color textColor)
Sets the text color of this text field.

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 java.lang.Object

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

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

initializeInternal, postInitialize

Field Details

value

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

ShapeTextField

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

ShapeTextField

public ShapeTextField(Presentable p,
 boolean ispublic,
 double x,
 double y,
 double width,
 double height,
 Color backgroundColor,
 Color textColor,
 boolean enabled,
 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,
 Color backgroundColor,
 Color textColor,
 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,
 Color backgroundColor,
 Color textColor,
 boolean enabled,
 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 Details

setBackgroundColor

public void setBackgroundColor(Color backgroundColor)
Sets the background color of this text field.
Parameters:
backgroundColor - the desired background Color

setTextColor

public void setTextColor(Color textColor)
Sets the text color of this text field.
Parameters:
textColor - the desired text Color

setText

public void setText(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(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 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(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