com.planetalia.dynject.sources
Class SwingSource

java.lang.Object
  extended by com.planetalia.dynject.sources.SwingSource
All Implemented Interfaces:
IValueSource

public class SwingSource
extends java.lang.Object
implements IValueSource

Creates a source that reads its values from the fields of a Swing or AWT form. The name of each property is taken to be the name1 of some component in a Swing form, whereas the value of the property is read from the user-editable property of that component. Depending on the component, that property varies. Currently, the following components are supported:

ClassProperty used
javax.swing.text.JTextComponenttext
javax.swing.JColorChoosercolor
javax.swing.JComboBoxselectedItem
javax.swing.JFileChooserselectedFile.absolutePath
javax.swing.JLabeltext
javax.swing.JComboBoxselectedItem
javax.swing.JListselectedValue
javax.swing.JSlidervalue
javax.swing.JSpinnervalue
javax.swing.AbstractButtonselected
javax.swing.JScrollBarvalue
javax.swing.JProgressBarvalue
java.awt.TextComponenttext
java.awt.Scrollbarvalue
java.awt.Checkboxstate
java.awt.Labeltext
java.awt.ChoiceselectedItem


1 "Name" in this case can mean two things. First, the system tries to locate a component whose name property (as in getName()) equals the requested property name. If that fails, then the system tries to locate a field whose name (as in field name) equals the requested property name, and reads it using reflection.

Author:
Alexander Hristov

Constructor Summary
SwingSource(java.awt.Container container)
          Creates a Swing source using the specified container as property source
 
Method Summary
protected  java.awt.Component findComponent(java.lang.String propertyName)
          Locates the component that is associated to the specified property name.
 ClassPreferences getPropertyClass(java.lang.String propertyName)
          Returns the class preferences for a property
 java.util.Set getPropertyNames()
          Returns the set of all existing properties at the time of invocation.
 java.lang.Object getValue(java.lang.String propertyName)
          Provides the value of a specific property
 boolean propertyExists(java.lang.String propertyName)
          Checks whether a specific property exists.
 void setValue(java.lang.String propertyName, java.lang.Object value)
          Sets the value of a specific property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingSource

public SwingSource(java.awt.Container container)
Creates a Swing source using the specified container as property source

Parameters:
container - Container to use
Method Detail

findComponent

protected java.awt.Component findComponent(java.lang.String propertyName)
Locates the component that is associated to the specified property name.

Parameters:
propertyName - Requested property name
Returns:
Component that corresponds to that property, or null if no such component exists

getValue

public java.lang.Object getValue(java.lang.String propertyName)
Description copied from interface: IValueSource
Provides the value of a specific property

Specified by:
getValue in interface IValueSource
Parameters:
propertyName - Name of the requested property. Assumed to exist.
Returns:
Property value

propertyExists

public boolean propertyExists(java.lang.String propertyName)
Description copied from interface: IValueSource
Checks whether a specific property exists. Not that a nonexistant property and a proprerty with a null value are not the same situation

Specified by:
propertyExists in interface IValueSource
Parameters:
propertyName - Name of the requested property
Returns:
True if the property exists, false otherwise

getPropertyClass

public ClassPreferences getPropertyClass(java.lang.String propertyName)
Description copied from interface: IValueSource
Returns the class preferences for a property

Specified by:
getPropertyClass in interface IValueSource
Parameters:
propertyName - Name of the property
Returns:
List of class preferences for that property

getPropertyNames

public java.util.Set getPropertyNames()
Description copied from interface: IValueSource
Returns the set of all existing properties at the time of invocation.

Specified by:
getPropertyNames in interface IValueSource
Returns:
Set of property names

setValue

public void setValue(java.lang.String propertyName,
                     java.lang.Object value)
Description copied from interface: IValueSource
Sets the value of a specific property. It's the callers responsability to provide a correct data type for that property. This is an optional operation. Some sources do not support writing properties to them

Specified by:
setValue in interface IValueSource
Parameters:
propertyName - Name of the requested property.
value - Property value.