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
JosmTextFieldand anActionEventis detected
- Since:
- 2688
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classAbstractTextComponentValidator.Status
-
Field Summary
Fields Modifier and Type Field Description protected static java.awt.ColorERROR_BACKGROUNDprotected static javax.swing.border.BorderERROR_BORDERprotected static java.awt.ColorERROR_COLORprivate java.lang.Stringmsgprivate AbstractTextComponentValidator.Statusstatusprivate javax.swing.text.JTextComponenttcprotected static javax.swing.border.BorderVALID_BORDERprotected static java.awt.ColorVALID_COLORprotected static java.awt.ColorWARNING_BACKGROUNDprotected static javax.swing.border.BorderWARNING_BORDERprotected static java.awt.ColorWARNING_COLORprotected static java.awt.ColorWARNING_FOREGROUND
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTextComponentValidator(javax.swing.text.JTextComponent tc)Creates the validator and wires it to the text componenttc.protectedAbstractTextComponentValidator(javax.swing.text.JTextComponent tc, boolean addActionListener)Alternative constructor that allows to turn off the actionListener.protectedAbstractTextComponentValidator(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 voidactionPerformed(java.awt.event.ActionEvent e)voidchangedUpdate(javax.swing.event.DocumentEvent e)private voidfeedback(javax.swing.border.Border border, java.awt.Color background, java.lang.String tooltip, AbstractTextComponentValidator.Status status, java.lang.String msg)protected voidfeedbackDisabled()protected voidfeedbackInvalid(java.lang.String msg)protected voidfeedbackValid(java.lang.String msg)protected voidfeedbackWarning(java.lang.String msg)voidfocusGained(java.awt.event.FocusEvent e)voidfocusLost(java.awt.event.FocusEvent e)javax.swing.text.JTextComponentgetComponent()Replies the decorated text componentprivate booleanhasChanged(java.lang.String msg, AbstractTextComponentValidator.Status status)voidinsertUpdate(javax.swing.event.DocumentEvent e)abstract booleanisValid()Replies true if the current content of the decorated text component is valid; false otherwisevoidpropertyChange(java.beans.PropertyChangeEvent evt)voidremoveUpdate(javax.swing.event.DocumentEvent e)abstract voidvalidate()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-trueto 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-trueto add the focus listeneraddDocumentListener-trueto add the document listeneraddActionListener-trueto 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:
focusGainedin interfacejava.awt.event.FocusListener
-
focusLost
public void focusLost(java.awt.event.FocusEvent e)
- Specified by:
focusLostin interfacejava.awt.event.FocusListener
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
- Specified by:
actionPerformedin interfacejava.awt.event.ActionListener
-
changedUpdate
public void changedUpdate(javax.swing.event.DocumentEvent e)
- Specified by:
changedUpdatein interfacejavax.swing.event.DocumentListener
-
insertUpdate
public void insertUpdate(javax.swing.event.DocumentEvent e)
- Specified by:
insertUpdatein interfacejavax.swing.event.DocumentListener
-
removeUpdate
public void removeUpdate(javax.swing.event.DocumentEvent e)
- Specified by:
removeUpdatein interfacejavax.swing.event.DocumentListener
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
-