public final class DefaultComponentValueModel extends AbstractWrappedValueModel
The ComponentValueModel is similar to the Swing Action class. If you disable an Action, all buttons and menu items bound to that Action will be disabled. If you disable a ComponentValueModel, all components bound to that ComponentValueModel will be disabled. If you set the ComponentValueModel to invisible, the component bound to it will become invisible. If you set a ComponentValueModel to non-editable, the JTextComponents bound to it will become non-editable.
Since version 1.1, PresentationModels can vend ComponentValueModels
using #getComponentModel(String)
and
#getBufferedComponentModel(String)
. Multiple calls
to these factory methods return the same ComponentValueModel.
The BasicComponentFactory and the Bindings class check if the ValueModel provided to create/bind a Swing component is a ComponentValueModel. If so, the ComponentValueModel properties will be synchronized with the associated Swing component properties.
It is recommended to use ComponentValueModels only for those models that are bound to view components that require GUI state changes.
Example Code:
final class AlbumView { ... private void initComponents() { // No state modifications required for the name field. nameField = BasicComponentFactory.createTextField( presentationModel.getModel(Album.PROPERTY_NAME)); ... // Enablement shall change for the composer field composerField = BasicComponentFactory.createTextField( presentationModel.getComponentModel(Album.PROPERTY_COMPOSER)); ... } ... } public final class AlbumPresentationModel extends PresentationModel { ... private void updateComposerEnablement(boolean enabled) { getComponentModel(Album.PROPERTY_COMPOSER).setEnabled(enabled); } ... }
As of the Binding version 2.0 the ComponentValueModel feature is implemented for text components, radio buttons, check boxes, combo boxes, and lists. JColorChoosers bound using the Bindings class will ignore ComponentValueModel state.
PresentationModel.getComponentModel(String)
,
PresentationModel.getBufferedComponentModel(String)
,
Bindings
,
Serialized FormPROPERTY_VALUE
PROPERTY_EDITABLE, PROPERTY_ENABLED, PROPERTY_VISIBLE
Constructor and Description |
---|
DefaultComponentValueModel(ValueModel wrappee)
Constructs a DefaultComponentValueModel that wraps the given ValueModel
and adds
ComponentModel Properties. |
Modifier and Type | Method and Description |
---|---|
protected PropertyChangeListener |
createValueChangeHandler() |
Object |
getValue()
Returns this model's current subject value.
|
void |
setValue(Object newValue)
Sets the given value as new subject value.
|
getWrappee, isEditable, isEnabled, isVisible, release, setEditable, setEnabled, setVisible
addValueChangeListener, booleanValue, doubleValue, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, floatValue, getString, intValue, longValue, paramString, removeValueChangeListener, setValue, setValue, setValue, setValue, setValue, toString, valueString
createPropertyChangeSupport, firePropertyChange
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, fireMultiplePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addValueChangeListener, removeValueChangeListener
public DefaultComponentValueModel(ValueModel wrappee)
ComponentModel
Properties.wrappee
- the underlying or wrapped ValueModelpublic Object getValue()
public void setValue(Object newValue)
newValue
- the value to setprotected PropertyChangeListener createValueChangeHandler()
createValueChangeHandler
in class AbstractWrappedValueModel
Copyright © 2002-2015 JGoodies Software GmbH. All Rights Reserved.