Class AbstractTextComponentValidator
- java.lang.Object
-
- org.openstreetmap.josm.gui.util.ChangeNotifier
-
- org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.FocusListener
,java.beans.PropertyChangeListener
,java.util.EventListener
,javax.swing.event.DocumentListener
- Direct Known Subclasses:
BoundingBoxSelectionPanel.LatitudeValidator
,BoundingBoxSelectionPanel.LongitudeValidator
,ChangesetIdTextField.ChangesetIdValidator
,DateValidator
,DefaultTextComponentValidator
,LatLonDialog.EastNorthValidator
,LatLonDialog.LatLonValidator
,OsmApiUrlInputPanel.ApiUrlValidator
,OsmIdTextField.OsmIdValidator
,TileSelectionBBoxChooser.TileAddressValidator
,TileSelectionBBoxChooser.TileCoordinateValidator
,TimeValidator
,UidInputFieldValidator
,UploadStrategySelectionPanel.ChunkSizeValidator
,UploadTextComponentValidator
public abstract class AbstractTextComponentValidator extends ChangeNotifier implements java.awt.event.ActionListener, java.awt.event.FocusListener, javax.swing.event.DocumentListener, java.beans.PropertyChangeListener
This is an abstract class for a validator on a text component. Subclasses implementvalidate()
.validate()
is invoked whenever- the content of the text component changes (the validator is a
DocumentListener
) - the text component loses focus (the validator is a
FocusListener
) - the text component is a
JosmTextField
and anActionEvent
is detected
- Since:
- 2688
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
AbstractTextComponentValidator.Status
-
Field Summary
Fields Modifier and Type Field Description protected static java.awt.Color
ERROR_BACKGROUND
protected static javax.swing.border.Border
ERROR_BORDER
protected static java.awt.Color
ERROR_COLOR
private java.lang.String
msg
private AbstractTextComponentValidator.Status
status
private javax.swing.text.JTextComponent
tc
protected static javax.swing.border.Border
VALID_BORDER
protected static java.awt.Color
VALID_COLOR
protected static java.awt.Color
WARNING_BACKGROUND
protected static javax.swing.border.Border
WARNING_BORDER
protected static java.awt.Color
WARNING_COLOR
protected static java.awt.Color
WARNING_FOREGROUND
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTextComponentValidator(javax.swing.text.JTextComponent tc)
Creates the validator and wires it to the text componenttc
.protected
AbstractTextComponentValidator(javax.swing.text.JTextComponent tc, boolean addActionListener)
Alternative constructor that allows to turn off the actionListener.protected
AbstractTextComponentValidator(javax.swing.text.JTextComponent tc, boolean addFocusListener, boolean addDocumentListener, boolean addActionListener)
Constructs a newAbstractTextComponentValidator
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
void
changedUpdate(javax.swing.event.DocumentEvent e)
private void
feedback(javax.swing.border.Border border, java.awt.Color background, java.lang.String tooltip, AbstractTextComponentValidator.Status status, java.lang.String msg)
protected void
feedbackDisabled()
protected void
feedbackInvalid(java.lang.String msg)
protected void
feedbackValid(java.lang.String msg)
protected void
feedbackWarning(java.lang.String msg)
void
focusGained(java.awt.event.FocusEvent e)
void
focusLost(java.awt.event.FocusEvent e)
javax.swing.text.JTextComponent
getComponent()
Replies the decorated text componentprivate boolean
hasChanged(java.lang.String msg, AbstractTextComponentValidator.Status status)
void
insertUpdate(javax.swing.event.DocumentEvent e)
abstract boolean
isValid()
Replies true if the current content of the decorated text component is valid; false otherwisevoid
propertyChange(java.beans.PropertyChangeEvent evt)
void
removeUpdate(javax.swing.event.DocumentEvent e)
abstract void
validate()
Implement in subclasses to validate the content of the text component.-
Methods inherited from class org.openstreetmap.josm.gui.util.ChangeNotifier
addChangeListener, fireStateChanged, removeChangeListener
-
-
-
-
Field Detail
-
ERROR_COLOR
protected static final java.awt.Color ERROR_COLOR
-
ERROR_BORDER
protected static final javax.swing.border.Border ERROR_BORDER
-
ERROR_BACKGROUND
protected static final java.awt.Color ERROR_BACKGROUND
-
WARNING_COLOR
protected static final java.awt.Color WARNING_COLOR
-
WARNING_BORDER
protected static final javax.swing.border.Border WARNING_BORDER
-
WARNING_FOREGROUND
protected static final java.awt.Color WARNING_FOREGROUND
-
WARNING_BACKGROUND
protected static final java.awt.Color WARNING_BACKGROUND
-
VALID_COLOR
protected static final java.awt.Color VALID_COLOR
-
VALID_BORDER
protected static final javax.swing.border.Border VALID_BORDER
-
tc
private final javax.swing.text.JTextComponent tc
-
status
private AbstractTextComponentValidator.Status status
-
msg
private java.lang.String msg
-
-
Constructor Detail
-
AbstractTextComponentValidator
protected AbstractTextComponentValidator(javax.swing.text.JTextComponent tc)
Creates the validator and wires it to the text componenttc
.- Parameters:
tc
- the text component. Must not be null.- Throws:
java.lang.IllegalArgumentException
- if tc is null
-
AbstractTextComponentValidator
protected AbstractTextComponentValidator(javax.swing.text.JTextComponent tc, boolean addActionListener)
Alternative constructor that allows to turn off the actionListener. This can be useful if the enter key stroke needs to be forwarded to the default button in a dialog.- Parameters:
tc
- text componentaddActionListener
-true
to add the action listener
-
AbstractTextComponentValidator
protected AbstractTextComponentValidator(javax.swing.text.JTextComponent tc, boolean addFocusListener, boolean addDocumentListener, boolean addActionListener)
Constructs a newAbstractTextComponentValidator
.- Parameters:
tc
- text componentaddFocusListener
-true
to add the focus listeneraddDocumentListener
-true
to add the document listeneraddActionListener
-true
to add the action listener
-
-
Method Detail
-
feedbackInvalid
protected void feedbackInvalid(java.lang.String msg)
-
feedbackWarning
protected void feedbackWarning(java.lang.String msg)
-
feedbackDisabled
protected void feedbackDisabled()
-
feedbackValid
protected void feedbackValid(java.lang.String msg)
-
hasChanged
private boolean hasChanged(java.lang.String msg, AbstractTextComponentValidator.Status status)
-
feedback
private void feedback(javax.swing.border.Border border, java.awt.Color background, java.lang.String tooltip, AbstractTextComponentValidator.Status status, java.lang.String msg)
-
getComponent
public javax.swing.text.JTextComponent getComponent()
Replies the decorated text component- Returns:
- the decorated text component
-
validate
public abstract void validate()
Implement in subclasses to validate the content of the text component.
-
isValid
public abstract boolean isValid()
Replies true if the current content of the decorated text component is valid; false otherwise- Returns:
- true if the current content of the decorated text component is valid
-
focusGained
public void focusGained(java.awt.event.FocusEvent e)
- Specified by:
focusGained
in interfacejava.awt.event.FocusListener
-
focusLost
public void focusLost(java.awt.event.FocusEvent e)
- Specified by:
focusLost
in interfacejava.awt.event.FocusListener
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
-
changedUpdate
public void changedUpdate(javax.swing.event.DocumentEvent e)
- Specified by:
changedUpdate
in interfacejavax.swing.event.DocumentListener
-
insertUpdate
public void insertUpdate(javax.swing.event.DocumentEvent e)
- Specified by:
insertUpdate
in interfacejavax.swing.event.DocumentListener
-
removeUpdate
public void removeUpdate(javax.swing.event.DocumentEvent e)
- Specified by:
removeUpdate
in interfacejavax.swing.event.DocumentListener
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
-