public class TextField
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
TextField.FocusLossListener
Listener called when the user stops editing a text field.
|
static interface |
TextField.TextChangeListener
Listener called when the text field context changes.
|
Modifier and Type | Field and Description |
---|---|
private java.awt.geom.Rectangle2D |
bounds
Text field bounds.
|
private boolean |
center
True if text in this text field is centred.
|
private TextField.TextChangeListener |
changeListener
Listener called when the text field text changes.
|
private java.awt.Color |
color
The accent color for this text field.
|
private boolean |
focus
Whether this text field has focus.
|
private TextField.FocusLossListener |
focusListener
Listener called when this text field loses focus.
|
private java.awt.Color |
foreground
The foreground (text) colour.
|
private java.lang.String |
text
Current text field text.
|
Constructor and Description |
---|
TextField(java.awt.Color color)
Constructs a new text field with the given accent color.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getText()
Gets the text in this text field.
|
void |
giveFocus()
Gives focus to this text field.
|
void |
handleKeyEvent(java.awt.event.KeyEvent event)
Handles a key event on this text field.
|
void |
handleMouseClick(java.awt.geom.Point2D loc)
Handles a mouse event on this text field.
|
boolean |
hasFocus()
Checks if this text field currently has focus.
|
void |
removeFocus()
Removes the focus from this text field.
|
protected void |
render(java.awt.Graphics2D g,
double x,
double y,
double width,
double height)
Renders this text field.
|
void |
setCentred(boolean center)
Sets whether the text in this text field should be centred.
|
void |
setChangeListener(TextField.TextChangeListener listener)
Sets the change listener for this text field.
|
void |
setFocusListener(TextField.FocusLossListener listener)
Sets the focus loss listener for this text field.
|
void |
setForegroundColor(java.awt.Color color)
Sets the foreground (text) colour for this text field.
|
void |
setText(java.lang.String text)
Sets the text for this text field.
|
private java.awt.Color color
private java.awt.geom.Rectangle2D bounds
private java.lang.String text
private boolean focus
private boolean center
private TextField.TextChangeListener changeListener
private TextField.FocusLossListener focusListener
private java.awt.Color foreground
public TextField(java.awt.Color color)
color
- The accent color.public void setCentred(boolean center)
center
- True to center the text in this text field.public void setChangeListener(TextField.TextChangeListener listener)
listener
- The new change listener.ChangeListener
public void setFocusListener(TextField.FocusLossListener listener)
listener
- The new focus listener.TextField.FocusLossListener
public void setForegroundColor(java.awt.Color color)
color
- The new foreground colour.public java.lang.String getText()
public boolean hasFocus()
public void setText(java.lang.String text)
text
- The new text or
null
to clear the text.public void removeFocus()
public void giveFocus()
public void handleKeyEvent(java.awt.event.KeyEvent event)
event
- The event to handle.public void handleMouseClick(java.awt.geom.Point2D loc)
loc
- The location that was clicked.protected void render(java.awt.Graphics2D g, double x, double y, double width, double height)
g
- The graphics context to use.x
- The x coordinate of the top left corner.y
- The y coordinate of the top left corner.width
- The width of the text field.height
- The height of the text field.