com.ccg.values
Class ValuesEditorAdapter

java.lang.Object
  extended by com.ccg.values.ValuesEditorAdapter
All Implemented Interfaces:
ValuesEditor, ValuesHolder
Direct Known Subclasses:
TimeSpanEditor, ValuesEditorBean

public abstract class ValuesEditorAdapter
extends Object
implements ValuesEditor

Helper class to form a base for those wishing to implement a ValuesEditor.

This class serves as a good starting point for those wishing to implement a ValuesEditor. It provides the following common services:

If you derive a new class from this adapter, you will then need/want to implement the following:

The TimeSpanEditor implementation provides a example of how this class is used. See TimeSpanEditor.java for details.

Since:
1.0
Version:
$Revision: 1.3 $
Author:
$Author: pkb $
See Also:
ValuesEditor, TimeSpanEditor.java

Field Summary
 
Fields inherited from interface com.ccg.values.ValuesHolder
HAS_FROM, HAS_TO, HAS_TO_FROM
 
Constructor Summary
protected ValuesEditorAdapter()
          Constructs the object and makes it ready for the addition of listeners.
 
Method Summary
 void addChangeListener(ChangeListener cl)
          Add a "change listener" to notify if the user modifies ANY of the values in the Swing component.
 Object checkArgument(Object o)
          Verify that a object is of the type recognized by this class.
 Object createObjectInstance()
          Creates a new instance of a object (with default values set) which the editor is designed to work with.
protected  void fireChangeEvent()
          Notify all registered listeners that the user has changed something in the GUI.
 int getCapabilities()
          Determine what the ValuesHolder implementation supports.
protected  ChangeListener getProxyChangeListener()
          Get a "proxy" for ChangeEvents.
protected  DocumentListener getProxyDocumentListener()
          Get a "proxy" for DocumentEvents.
protected  InputMethodListener getProxyInputMethodListener()
          Get a "proxy" for InputMethodEvents.
protected  ItemListener getProxyItemListener()
          Get a "proxy" for ItemEvents.
protected  ListDataListener getProxyListDataListener()
          Get a "proxy" for ListDataEvents.
 TableModelListener getProxyTableModelListener()
          Get a "proxy" for TableModelEvents.
 void init(Lookup props)
          Set the properties to be used when constructing the visual component.
 void removeChangeListener(ChangeListener l)
          Remove a "change listener" that had been previously added.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.ccg.values.ValuesEditor
getComponent, validate
 
Methods inherited from interface com.ccg.values.ValuesHolder
fromObject, getObjectClass, toObject
 

Constructor Detail

ValuesEditorAdapter

protected ValuesEditorAdapter()
Constructs the object and makes it ready for the addition of listeners.

Since:
1.0
Method Detail

getCapabilities

public int getCapabilities()
Determine what the ValuesHolder implementation supports.

This method returns HAS_TO_FROM indicating that the ValuesHolder interface is fully supported. This means that values can be transferred in both directions - from the object to the GUI component and from the GUI component to the object. Any derived class which does not support either of these operations, will need to override this method and indicate what they do support.

Specified by:
getCapabilities in interface ValuesHolder
Returns:
A ValuesHolder.HAS_TO_FROM.
Since:
1.0
See Also:
ValuesHolder.getCapabilities()

createObjectInstance

public Object createObjectInstance()
Creates a new instance of a object (with default values set) which the editor is designed to work with.

This default implementation, simply uses the default constructor for the object class which is associated with the editor. Derived classes will want to override if they would like to change this (maybe the default constructor isn't what you'd like your default to be).

Specified by:
createObjectInstance in interface ValuesEditor
Returns:
Newly allocated and initialized object (should be suitable for either the fromObject or toObject implementation.
Since:
1.0

init

public void init(Lookup props)
Set the properties to be used when constructing the visual component.

The adapter makes the assumption that no special properties are recognized by your implemenation (it simply ignores the properties passed and returns).

Specified by:
init in interface ValuesEditor
Parameters:
props - Set of properties (implementation dependent) to initialize object with (must not be null).
Since:
1.0

addChangeListener

public final void addChangeListener(ChangeListener cl)
Add a "change listener" to notify if the user modifies ANY of the values in the Swing component.

This method allows developers to determine when the state of the graphical component becomes "dirty" (modified by the user).

Specified by:
addChangeListener in interface ValuesEditor
Parameters:
cl - The ChangeListener to notify of modifications.
Since:
1.0

removeChangeListener

public final void removeChangeListener(ChangeListener l)
Remove a "change listener" that had been previously added.

Specified by:
removeChangeListener in interface ValuesEditor
Parameters:
cl - The ChangeListener to remove from the notification list.
Since:
1.0

fireChangeEvent

protected final void fireChangeEvent()
Notify all registered listeners that the user has changed something in the GUI.

This method will invoke the stateChanged method on each ChangeListener which has been added.

Since:
1.0

getProxyChangeListener

protected final ChangeListener getProxyChangeListener()
Get a "proxy" for ChangeEvents.

The object returned by this method can be added as a "proxy" for events. When a event occurs, it will be "proxied" into a ChangeEvent and delivered for the object as a whole.

Returns:
A ChangeListener which will invoke the fireChangeEvent() when it is triggered.
Since:
1.0

getProxyTableModelListener

public TableModelListener getProxyTableModelListener()
Get a "proxy" for TableModelEvents.

The object returned by this method can be added as a "proxy" for events. When a event occurs, it will be "proxied" into a TableModelEvent and delivered for the object as a whole.

Returns:
A TableModelListener which will invoke the fireChangeEvent() when it is triggered.
Since:
1.0

getProxyInputMethodListener

protected final InputMethodListener getProxyInputMethodListener()
Get a "proxy" for InputMethodEvents.

The object returned by this method can be added as a "proxy" for events. When a event occurs, it will be "proxied" into a ChangeEvent and delivered for the object as a whole.

Returns:
A getInputMethodListener which will invoke the fireChangeEvent() when it is triggered.
Since:
1.0

getProxyDocumentListener

protected final DocumentListener getProxyDocumentListener()
Get a "proxy" for DocumentEvents.

The object returned by this method can be added as a "proxy" for events. When a event occurs, it will be "proxied" into a ChangeEvent and delivered for the object as a whole.

Returns:
A getDocumentListener which will invoke the fireChangeEvent() when it is triggered.
Since:
1.0

getProxyListDataListener

protected final ListDataListener getProxyListDataListener()
Get a "proxy" for ListDataEvents.

The object returned by this method can be added as a "proxy" for events. When a event occurs, it will be "proxied" into a ChangeEvent and delivered for the object as a whole.

Returns:
A ListDataListener which will invoke the fireChangeEvent() when it is triggered.
Since:
1.0

getProxyItemListener

protected final ItemListener getProxyItemListener()
Get a "proxy" for ItemEvents.

The object returned by this method can be added as a "proxy" for events. When a event occurs, it will be "proxied" into a ChangeEvent and delivered for the object as a whole.

Returns:
A ItemListener which will invoke the fireChangeEvent() when it is triggered.
Since:
1.0

checkArgument

public final Object checkArgument(Object o)
                           throws NullPointerException,
                                  IllegalArgumentException
Verify that a object is of the type recognized by this class.

This method is typically used by the toObject and fromObject methods. It verifies that the object is of the proper type (and throws an exception if not). For example, in the implementation of the TimeSpanEditor might use it in the following manner:


  public Class getObjectClass() {
    return TimeSpan.class;
  }
 
  public void fromObject(Object o) throws ... {
    TimeSpan ts = (TimeSpan) checkArgument(o);
    ...
  }
 

Returns:
The object passed (never returns null)
Throws:
NullPointerException - If you pass null.
IllegalArgumentException - If the object you pass is not a instance of the object class supported.
Since:
1.0


Copyright 1998-1998-2006 null. All Rights Reserved.