edu.neu.ccs.gui
Class GeneralViewSupport

java.lang.Object
  extended byedu.neu.ccs.gui.GeneralViewSupport
All Implemented Interfaces:
JPTConstants, SwingConstants

public class GeneralViewSupport
extends Object
implements JPTConstants

GeneralViewSupport contains the common code to support the features of a GeneralView.

Since:
2.3
Version:
2.3

Field Summary
private  JComponent component
          The GeneralView seen as a JComponent.
static String DATA_TYPE
          Bound property name for the Stringable type returned by a TypedView or GeneralView.
static String DEFAULT_VIEW_STATE
          Bound property name for the default view state of a Displayable object.
private  String defaultViewState
          The default view state string.
private  StringableFactory factory
          The factory for creating Stringable objects from input data.
private  StringableFilter filter
          The filter used by this view object.
static String FILTER
          Bound property name for the filter property.
private  EventListenerList listenerList
          The EventListenerList for the GeneralView.
private  InputProperties properties
          The property list for this view object.
private  GeneralView view
          The GeneralView that uses this GeneralViewSupport object.
static String VIEW_STATE
          Bound property name for the view state of a Displayable object.
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
GeneralViewSupport(GeneralView view, EventListenerList listenerList, Class dataType, String errorPrompt, String dialogTitle, String suggestion)
          The constructor.
 
Method Summary
 void addMalformedDataListener(MalformedDataListener l)
          Registers the given MalformedDataListener to receive MalformedDataEvents when the view state data is found to be malformed and when the view state data is returned to a well-formed value.
 Stringable demandObject()
          Returns a Stringable object based on the view state of the view, the current data type and filter, and the mandatory model.
 Stringable demandObject(Class dataType, StringableFilter filter)
          Returns a Stringable object based on the view state of the view, the temporary data type and filter, and the mandatory model.
 Stringable demandObject(StringableFilter filter)
          Returns a Stringable object based on the view state of the view, the temporary filter, and the mandatory model.
protected  void fireDataMalformed(MalformedDataEvent event)
          Delivers MalformedDataEvents to registered listeners.
 Class getDataType()
          Returns the current class of objects returned when a model object is demanded or requested.
 String getDefaultViewState()
          Returns a String representation of the default view state for this object.
 StringableFilter getFilter()
          Returns the current filter used by this view.
 InputProperties getInputProperties()
          Returns the input properties for this view.
 GeneralView getView()
          Returns the view that uses this GeneralViewSupport object.
protected  boolean handleError(Stringable object, int inputModel, ParseException exception)
          Performs the error handling for an input operation.
 Stringable obtainObject(Stringable object)
          Returns a Stringable object based on the view state data type, and filter or throws a ParseException to be handled by other methods.
 void removeMalformedDataListener(MalformedDataListener l)
          De-registers the given MalformedDataListener from receiving MalformedDataEvents when the view state data is found to be malformed and when the view state data is returned to a well-formed value.
 Stringable requestObject()
          Returns a Stringable object based on the view state of the view, the current data type and filter, and the optional model.
 Stringable requestObject(Class dataType, StringableFilter filter)
          Returns a Stringable object based on the view state of the view, the temporary data type and filter, and the optional model.
 Stringable requestObject(StringableFilter filter)
          Returns a Stringable object based on the view state of the view, the temporary filter, and the optional model.
 void reset()
          Resets the view state of this object to the default view state for this object.
 void setDataType(Class dataType)
          Sets the current class of objects returned when a model object is demanded or requested.
 void setDefaultViewState(String data)
          Sets the default view state for this object to the data state represented by the given String data.
 void setErrorPromptTitleSuggestion(String errorPrompt, String dialogTitle, String suggestion)
          Sets the three input property Strings for an error dialog in a single method.
 void setFilter(StringableFilter filter)
          Sets the current filter used by the view to the given StringableFilter.
 void setInputProperties(InputProperties properties)
          Sets the input properties for this view to the provided input properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VIEW_STATE

public static final String VIEW_STATE
Bound property name for the view state of a Displayable object.

See Also:
Constant Field Values

DEFAULT_VIEW_STATE

public static final String DEFAULT_VIEW_STATE
Bound property name for the default view state of a Displayable object.

See Also:
Constant Field Values

DATA_TYPE

public static final String DATA_TYPE
Bound property name for the Stringable type returned by a TypedView or GeneralView.

See Also:
Constant Field Values

FILTER

public static final String FILTER
Bound property name for the filter property.

See Also:
Constant Field Values

view

private GeneralView view
The GeneralView that uses this GeneralViewSupport object.


listenerList

private EventListenerList listenerList
The EventListenerList for the GeneralView.


component

private JComponent component
The GeneralView seen as a JComponent.


factory

private StringableFactory factory
The factory for creating Stringable objects from input data.


properties

private InputProperties properties
The property list for this view object.


filter

private StringableFilter filter
The filter used by this view object.


defaultViewState

private String defaultViewState
The default view state string.

Constructor Detail

GeneralViewSupport

public GeneralViewSupport(GeneralView view,
                          EventListenerList listenerList,
                          Class dataType,
                          String errorPrompt,
                          String dialogTitle,
                          String suggestion)

The constructor.

The given GeneralView view is the view that uses this GeneralViewSupport object and must not be null. In addition, the view must be a derived object from JComponent

The given EventListenerList list is the listener list of the given GeneralView view and must not be null.

The given data type is the Stringable data type for the view. If this parameter is null it is set to XString.class.

The parameters error prompt, dialog title, and suggestion set defaults for the error dialog box and may be null.

Parameters:
view - the view that uses this support class
listenerList - the listener list of the view
dataType - the Stringable data type
errorPrompt - the error prompt of an error dialog
dialogTitle - the dialog title of an error dialog
suggestion - the suggestion for an error dialog
Throws:
NullPointerException - if the view or listener list is null
IllegalArgumentException - if the view is not derived from JComponent
Method Detail

getView

public GeneralView getView()
Returns the view that uses this GeneralViewSupport object.

Returns:
the encapsulated view

setDataType

public void setDataType(Class dataType)
Sets the current class of objects returned when a model object is demanded or requested.

Parameters:
dataType - the new class of objects for model objects
Throws:
Error - if the given data type is not assignable from the Stringable reference type
See Also:
getDataType()

getDataType

public Class getDataType()
Returns the current class of objects returned when a model object is demanded or requested.

Returns:
the current class of a model object
See Also:
setDataType(Class)

setFilter

public void setFilter(StringableFilter filter)
Sets the current filter used by the view to the given StringableFilter.

Parameters:
filter - the filter to be used

getFilter

public StringableFilter getFilter()
Returns the current filter used by this view.

Returns:
the current filter

obtainObject

public Stringable obtainObject(Stringable object)
                        throws ParseException

Returns a Stringable object based on the view state data type, and filter or throws a ParseException to be handled by other methods.

Normally, this method is not called directly, but it is provided for the convenience of callers that want to implement their own error handler for ParseExceptions.

Parameters:
object - the initial default object
Returns:
the object as adjusted by the view state and filter
Throws:
ParseException - if an error occurs
ParseException

demandObject

public Stringable demandObject()
Returns a Stringable object based on the view state of the view, the current data type and filter, and the mandatory model.

Returns:
a Stringable model object
See Also:
requestObject(), obtainObject(Stringable)

requestObject

public Stringable requestObject()
                         throws CancelledException
Returns a Stringable object based on the view state of the view, the current data type and filter, and the optional model.

Returns:
a Stringable model object
Throws:
CancelledException - if the user cancelled after an error was detected
CancelledException
See Also:
demandObject(), obtainObject(Stringable)

demandObject

public Stringable demandObject(StringableFilter filter)
Returns a Stringable object based on the view state of the view, the temporary filter, and the mandatory model.

Parameters:
filter - the temporary filter to use
Returns:
a Stringable model object
See Also:
demandObject(), requestObject(Class, StringableFilter)

requestObject

public Stringable requestObject(StringableFilter filter)
                         throws CancelledException
Returns a Stringable object based on the view state of the view, the temporary filter, and the optional model.

Parameters:
filter - the temporary filter to use
Returns:
a Stringable model object
Throws:
CancelledException - if the user cancelled after an error was detected
CancelledException
See Also:
requestObject(), demandObject(Class, StringableFilter)

demandObject

public Stringable demandObject(Class dataType,
                               StringableFilter filter)
Returns a Stringable object based on the view state of the view, the temporary data type and filter, and the mandatory model.

Parameters:
dataType - the temporary data type to use
filter - the temporary filter to use
Returns:
a Stringable model object
See Also:
demandObject(), requestObject(Class, StringableFilter)

requestObject

public Stringable requestObject(Class dataType,
                                StringableFilter filter)
                         throws CancelledException
Returns a Stringable object based on the view state of the view, the temporary data type and filter, and the optional model.

Parameters:
dataType - the temporary data type to use
filter - the temporary filter to use
Returns:
a Stringable model object
Throws:
CancelledException - if the user cancelled after an error was detected
CancelledException
See Also:
requestObject(), demandObject(Class, StringableFilter)

setInputProperties

public void setInputProperties(InputProperties properties)

Sets the input properties for this view to the provided input properties.

If the given input properties list is null, the property list for this view is set to the base property list containing default property values.

Parameters:
properties - the new input properties for the view
See Also:
getInputProperties()

getInputProperties

public InputProperties getInputProperties()
Returns the input properties for this view.

Returns:
the input properties
See Also:
setInputProperties(InputProperties)

setErrorPromptTitleSuggestion

public void setErrorPromptTitleSuggestion(String errorPrompt,
                                          String dialogTitle,
                                          String suggestion)
Sets the three input property Strings for an error dialog in a single method.

Parameters:
errorPrompt - the error prompt of an error dialog
dialogTitle - the dialog title of an error dialog
suggestion - the suggestion for an error dialog

setDefaultViewState

public void setDefaultViewState(String data)
Sets the default view state for this object to the data state represented by the given String data.

Parameters:
data - the new default data state for this object
See Also:
getDefaultViewState(), reset()

getDefaultViewState

public String getDefaultViewState()
Returns a String representation of the default view state for this object.

Returns:
the default view state as a String
See Also:
setDefaultViewState(String), reset()

reset

public void reset()
Resets the view state of this object to the default view state for this object.


addMalformedDataListener

public void addMalformedDataListener(MalformedDataListener l)
Registers the given MalformedDataListener to receive MalformedDataEvents when the view state data is found to be malformed and when the view state data is returned to a well-formed value.

Parameters:
l - the listener to register
See Also:
removeMalformedDataListener(MalformedDataListener), Fragile, EventListenerList

removeMalformedDataListener

public void removeMalformedDataListener(MalformedDataListener l)
De-registers the given MalformedDataListener from receiving MalformedDataEvents when the view state data is found to be malformed and when the view state data is returned to a well-formed value.

Parameters:
l - the listener to de-register
See Also:
addMalformedDataListener(MalformedDataListener), Fragile, EventListenerList

handleError

protected boolean handleError(Stringable object,
                              int inputModel,
                              ParseException exception)

Performs the error handling for an input operation.

Derived classes of support class may override this method and implement their own error handling strategy.

This method must either provide a correct value for the Stringable object and return true, or must return false if the object is still in error or if the user cancelled the error handling procedure.

The input model must be either JPTConstants.MANDATORY or JPTConstants.OPTIONAL.

Parameters:
object - an object of the appropriate type whose state could not be set from the view state of this view and must therefore be set to a valid view state by this error handler
inputModel - the input model for the input operation that resulted in the error
exception - the ParseException that was thrown to signal the error condition
Returns:
whether or not the error was corrected through this error handling strategy

fireDataMalformed

protected void fireDataMalformed(MalformedDataEvent event)
Delivers MalformedDataEvents to registered listeners.

Parameters:
event - the MalformedDataEvent to deliver
See Also:
addMalformedDataListener(MalformedDataListener), removeMalformedDataListener(MalformedDataListener), Fragile, EventListenerList