nl.lxtreme.ols.util.swing.validation
Class JComponentInputVerifier

java.lang.Object
  extended by javax.swing.InputVerifier
      extended by nl.lxtreme.ols.util.swing.validation.JComponentInputVerifier
All Implemented Interfaces:
KeyListener, EventListener

public class JComponentInputVerifier
extends InputVerifier
implements KeyListener

Author:
jawi

Constructor Summary
JComponentInputVerifier(IValidator aValidator)
          Creates a new AbstractValidator instance.
JComponentInputVerifier(String aMessage, IValidator aValidator)
          Creates a new AbstractValidator instance.
 
Method Summary
static JComponentInputVerifier create(Class<?> aType)
          Creates an instance of this InputVerifier for the given type.
static JComponentInputVerifier create(Class<?> aType, String aMessage)
          Creates an instance of this InputVerifier for the given type.
protected  Object getInputValue(Component aComponent)
          Tries to obtain the actual value of a given component.
protected  String getMessage()
          Returns the message to use when validation fails.
 void keyPressed(KeyEvent aEvent)
           
 void keyReleased(KeyEvent aEvent)
           
 void keyTyped(KeyEvent aEvent)
           
 boolean verify(JComponent aInput)
           
 
Methods inherited from class javax.swing.InputVerifier
shouldYieldFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JComponentInputVerifier

public JComponentInputVerifier(IValidator aValidator)
Creates a new AbstractValidator instance.

Parameters:
aValidator - the validator to use for verifying the input.

JComponentInputVerifier

public JComponentInputVerifier(String aMessage,
                               IValidator aValidator)
Creates a new AbstractValidator instance.

Parameters:
aMessage - the message to use when validation fails;
aValidator - the validator to use for verifying the input.
Method Detail

create

public static JComponentInputVerifier create(Class<?> aType)
Creates an instance of this InputVerifier for the given type.

Parameters:
aType - the type to create an input verifier for, cannot be null.
Returns:
an input verifier instance, never null.

create

public static JComponentInputVerifier create(Class<?> aType,
                                             String aMessage)
Creates an instance of this InputVerifier for the given type.

Parameters:
aType - the type to create an input verifier for, cannot be null;
aMessage - the message to display in case the verification failed.
Returns:
an input verifier instance, never null.

keyPressed

public final void keyPressed(KeyEvent aEvent)
Specified by:
keyPressed in interface KeyListener
See Also:
KeyListener.keyPressed(java.awt.event.KeyEvent)

keyReleased

public final void keyReleased(KeyEvent aEvent)
Specified by:
keyReleased in interface KeyListener
See Also:
KeyListener.keyReleased(java.awt.event.KeyEvent)

keyTyped

public final void keyTyped(KeyEvent aEvent)
Specified by:
keyTyped in interface KeyListener
See Also:
KeyListener.keyTyped(java.awt.event.KeyEvent)

verify

public final boolean verify(JComponent aInput)
Specified by:
verify in class InputVerifier
See Also:
InputVerifier.verify(javax.swing.JComponent)

getInputValue

protected Object getInputValue(Component aComponent)
Tries to obtain the actual value of a given component.

Parameters:
aComponent - the (Swing) component to get the value of, can be null.
Returns:
the component's value, or null if this value is unknown.

getMessage

protected String getMessage()
Returns the message to use when validation fails.

Returns:
a message, might be null.


Copyright © 2012 L'Xtreme IT consultancy. All Rights Reserved.