public abstract class ValidationListenerFactory<CompType,ModelType>
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
protected |
ValidationListenerFactory(java.lang.Class<CompType> componentType,
java.lang.Class<ModelType> modelType) |
Modifier and Type | Method and Description |
---|---|
protected abstract ValidationListener<CompType> |
createListener(CompType component,
ValidationStrategy strategy,
ValidationUI validationUI,
Validator<ModelType> validator) |
static <CType,MType> |
createValidationListener(CType component,
ValidationStrategy strategy,
ValidationUI validationUI,
Validator<MType> validator)
Create a ValidationListener for a specific type of component, which accepts
Validators of a given type.
|
public static <CType,MType> ValidationListener<CType> createValidationListener(CType component, ValidationStrategy strategy, ValidationUI validationUI, Validator<MType> validator)
JList + Integer[]
JList[] + ListSelectionModel
JTextComponent + Document
JTextComponent + String
JComboBox + ComboBoxModel
JComboBox + String
AbstractButton[] + ButtonModel[]
AbstractButton[] + Integer
ListenerFor
, so that it can be located correctly.
Example:@SwingValidationListenerFactory.ListenerFor(componentType=JColorChooser.class, modelObjectType=Color.class) public class ColorChooserValidationListenerFactory extends SwingValidationListenerFactory{ @Override protected ValidationListener createListener( JColorChooser component, ValidationStrategy strategy, ValidationUI validationUI, Validator validator) { //This cast is safe - this method will never be called unless //the type has first been checked return new ColorChooserListener(component, validationUI, (Validator ) validator); } static final class ColorChooserListener extends AbstractValidationListener implements PropertyChangeListener { ColorChooserListener (JColorChooser comp, ValidationUI ui, Validator validator) { super (comp, ui, color); comp.addPropertyChangeListener("color", this); } @Override protected Color getModelObject(JColorChooser comp) { return comp.getColor(); } public void propertyChange(PropertyChangeEvent evt) { performValidation(); } } }
CType
- The component type.MType
- The type of object the Validator acceptscomponent
- A component of CType or a subclassstrategy
- The validation strategy to usevalidationUI
- A validation UI, typically the component decoratorvalidator
- A validator that accepts ModelType argumentsprotected abstract ValidationListener<CompType> createListener(CompType component, ValidationStrategy strategy, ValidationUI validationUI, Validator<ModelType> validator)