edu.washington.cs.supple.wlib.java2
Class ListWidget

java.lang.Object
  extended byedu.washington.cs.supple.render.AbstractWidget
      extended byedu.washington.cs.supple.render.SimpleWidget
          extended byedu.washington.cs.supple.wlib.java2.SimpleSwingWidget
              extended byedu.washington.cs.supple.wlib.java2.ListWidget
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, java.beans.PropertyChangeListener, SwingWidget, UnwrappedWidget, Widget
Direct Known Subclasses:
AbstractPointerListWidget, TableWidget

public class ListWidget
extends SimpleSwingWidget

Author:
kgajos

Field Summary
protected  javax.swing.JButton dataEdit
           
protected  SuppleType elementType
           
protected  boolean exactLength
           
protected  javax.swing.JList list
           
static java.lang.String LIST_SIZE_PROPERTY
           
static java.lang.String LIST_WIDTH_SCALE_PROPERTY
           
protected  int listLength
           
protected  javax.swing.JScrollPane listPane
           
protected  double listWidthScale
           
protected  javax.swing.event.ListSelectionListener selectionListener
           
protected  int selectionMode
           
protected  javax.swing.ListSelectionModel selectionModel
           
protected  boolean updatingWidget
           
protected  VectorType vtype
           
 
Fields inherited from class edu.washington.cs.supple.wlib.java2.SimpleSwingWidget
currentComponent, finalComponent
 
Fields inherited from class edu.washington.cs.supple.render.AbstractWidget
bag, cost, engaged, object, parent, stateVar, textLabel, type, widgetDescriptor, wrapper
 
Fields inherited from interface edu.washington.cs.supple.render.Widget
MAX_HINT, NO_BORDER, NO_NAME, TOP_LEVEL_WIDGET
 
Constructor Summary
ListWidget(UiObject object, int listSize, double widthScale)
          Does all of the common constructor work for lits
ListWidget(UiObject object, WidgetDescriptor wd, WidgetFactory f)
           
 
Method Summary
protected  void addLegalValues(java.util.Vector diff, java.util.Vector currentList)
          Adds the specified values to the list model; it uses the position of the new elements in the currentList to determine where they should be inserted.
 void addSelection(int row)
           
protected  javax.swing.JComponent buildList()
           
protected  void deleteLegalValues(java.util.Vector diff)
          Removes the specified values from the list model
 void disengage()
          Used to break the connection between the widget and the underlying ui object
protected  void displayDetails()
          Used when the underlying object is of UiObjectType or UiObjectValueVectorType it renders the detailed information about the selected values
 void engage()
          Used to tie the widgets with the underlying ui objects
protected  WidgetDescriptor generateWidgetDescriptor()
          Subclasses can override this method if their widget descriptor include extra information
protected  java.util.Vector getAddDiffs(java.util.Collection oldStuff, java.util.Collection newStuff)
          Creates a list of elements that are present in newStuff but not in oldStuff
protected  java.util.Vector getDeleteDiffs(java.util.Collection oldStuff, java.util.Collection newStuff)
          Creates a list of elements that are present in oldStuff but not in newStuff
 float getEffortEstimate(ActionDescription a)
          This method is hear temporarily until we implement it for all simple widgets
 double getLengthScale(int maxLength)
           
 int getListLength()
          Returns the lenght of the list widget rendered; 0 means that the list will be as long as the number of elements in the domain of the object displayed
protected  javax.swing.ListModel getListModel()
           
protected  javax.swing.ListSelectionModel getListSelectionModel()
           
protected  java.awt.Dimension getPreferredSize()
          Calculates the preferred size for this widget.
protected  javax.swing.event.ListSelectionListener getSelectionListener()
           
 javax.swing.JComponent getSwingComponent(int hints)
           
 WidgetProperties getWidgetProperties()
          Returns the corresponding WidgetProperties
 double getWidthScale()
          Returns the factor by which the width of this widget has been scaled down compared to the right width required to display all the elements without hiding or scrolling
protected  boolean isComponentReady()
           
 boolean isExactLength()
          Returns true if the list widget is precisely the same length as the domain of the underlying object
protected  boolean isSelectedIndex(int row)
           
protected  boolean isUpdating()
          This method lets you find out if the widget is in the process of updating itself (useful for breaking the cycle of change propagation between the widget and the underlying UiObject)
protected  void legalValuesChanged(java.beans.PropertyChangeEvent evt)
          reacts to the change in the list of legal values in the underlying object
 void removeSelection(int row)
           
static boolean rendersObject(UiObject object)
          A static method for testing the applicability of the widget given a type of the UI component to be rendered
 void setEnabled(boolean enabled)
          This method is exposed only so that wrappers can access it; others should stay away
protected  void setUpdating(boolean b)
           
 java.lang.String toString()
           
protected  void updateDetailsState(java.util.Collection curValues)
          Updates the active/inactive state of the Details button
protected  void updateSelection()
           
protected  void updateSelection(int startIndex, int endIndex)
          Updates the selection based on the current value of the underlying object; uses the limiting indices to do the work only within small bounds if they are known; bounds are inclusive
protected  void updateValue(int startIndex, int endIndex)
          Called when the user manipulates the list and the selection changes
protected  void valueChanged(java.beans.PropertyChangeEvent evt)
          Subclasses should override this method if they want to update display the value of the underlying type changes
 
Methods inherited from class edu.washington.cs.supple.wlib.java2.SimpleSwingWidget
getConcreteWidget, getSize, refreshDisplay
 
Methods inherited from class edu.washington.cs.supple.render.SimpleWidget
childIterator, hasChildren
 
Methods inherited from class edu.washington.cs.supple.render.AbstractWidget
anotherPropertyChanged, clone, clone, dismissCurrentView, displayDynamic, equals, executeAction, getBag, getConcreteWidget, getCost, getParent, getPath, getSizeCache, getTextLabel, getType, getUiObject, getWidgetDescriptor, indexChanged, isEngaged, isEquivalent, likelyValuesChanged, propertyChange, reportActionExecutionEvent, reportValueChangedEvent, setBag, setCost, setParent, setSizeCache, setValue, setWrapper, unwrapWidget
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.washington.cs.supple.render.Widget
childIterator, clone, clone, getBag, getConcreteWidget, getCost, getPath, getSizeCache, getTextLabel, getType, getUiObject, getWidgetDescriptor, hasChildren, isEngaged, isEquivalent, setBag, setCost, setParent, setSizeCache, setWrapper, unwrapWidget
 

Field Detail

listLength

protected int listLength

LIST_SIZE_PROPERTY

public static final java.lang.String LIST_SIZE_PROPERTY
See Also:
Constant Field Values

LIST_WIDTH_SCALE_PROPERTY

public static final java.lang.String LIST_WIDTH_SCALE_PROPERTY
See Also:
Constant Field Values

listWidthScale

protected double listWidthScale

exactLength

protected boolean exactLength

vtype

protected VectorType vtype

elementType

protected SuppleType elementType

list

protected javax.swing.JList list

listPane

protected javax.swing.JScrollPane listPane

dataEdit

protected javax.swing.JButton dataEdit

selectionListener

protected javax.swing.event.ListSelectionListener selectionListener

selectionMode

protected int selectionMode

updatingWidget

protected boolean updatingWidget

selectionModel

protected javax.swing.ListSelectionModel selectionModel
Constructor Detail

ListWidget

public ListWidget(UiObject object,
                  int listSize,
                  double widthScale)
Does all of the common constructor work for lits

Parameters:
object - the corresponding UiObject
listSize - the size of the displayed list element. If set to 0, the displayed list size will be the same as the size of the domain of the object. Finally, if the domain is not going to change in size (and listSize is 0), then list will be rendered without the scroll bars.

ListWidget

public ListWidget(UiObject object,
                  WidgetDescriptor wd,
                  WidgetFactory f)
Method Detail

getListLength

public int getListLength()
Returns the lenght of the list widget rendered; 0 means that the list will be as long as the number of elements in the domain of the object displayed

Returns:
the lenght of the list widget

getLengthScale

public double getLengthScale(int maxLength)

getWidthScale

public double getWidthScale()
Returns the factor by which the width of this widget has been scaled down compared to the right width required to display all the elements without hiding or scrolling

Returns:

isExactLength

public boolean isExactLength()
Returns true if the list widget is precisely the same length as the domain of the underlying object


getWidgetProperties

public WidgetProperties getWidgetProperties()
Description copied from interface: Widget
Returns the corresponding WidgetProperties

Specified by:
getWidgetProperties in interface Widget
Overrides:
getWidgetProperties in class SimpleSwingWidget
Returns:
properties associated with this widget

generateWidgetDescriptor

protected WidgetDescriptor generateWidgetDescriptor()
Description copied from class: AbstractWidget
Subclasses can override this method if their widget descriptor include extra information

Overrides:
generateWidgetDescriptor in class AbstractWidget
Returns:
a new widget descriptor for this widge

getEffortEstimate

public float getEffortEstimate(ActionDescription a)
Description copied from class: SimpleWidget
This method is hear temporarily until we implement it for all simple widgets

Specified by:
getEffortEstimate in interface Widget
Overrides:
getEffortEstimate in class SimpleWidget

rendersObject

public static boolean rendersObject(UiObject object)
A static method for testing the applicability of the widget given a type of the UI component to be rendered

Returns:
true for instances of enumerable vector types

getSwingComponent

public javax.swing.JComponent getSwingComponent(int hints)
Parameters:
hints - specifies the variant of the widget to be rendered
Returns:
a renderable component

buildList

protected javax.swing.JComponent buildList()

displayDetails

protected void displayDetails()
Used when the underlying object is of UiObjectType or UiObjectValueVectorType it renders the detailed information about the selected values


getPreferredSize

protected java.awt.Dimension getPreferredSize()
Calculates the preferred size for this widget. If listSize is set to 0, then it will use the current size of the domain of the corresponding UI object to detrmine the height.

Returns:
the preferred size for this widget

getSelectionListener

protected javax.swing.event.ListSelectionListener getSelectionListener()

isUpdating

protected boolean isUpdating()
This method lets you find out if the widget is in the process of updating itself (useful for breaking the cycle of change propagation between the widget and the underlying UiObject)

Returns:
true if the widget is updating itself, false otherwise

setUpdating

protected void setUpdating(boolean b)

updateValue

protected void updateValue(int startIndex,
                           int endIndex)
Called when the user manipulates the list and the selection changes

Parameters:
startIndex - index of the first changed element in the list
endIndex - index of the last changed element in the list

getListModel

protected javax.swing.ListModel getListModel()

getListSelectionModel

protected javax.swing.ListSelectionModel getListSelectionModel()

isSelectedIndex

protected boolean isSelectedIndex(int row)

addSelection

public void addSelection(int row)

removeSelection

public void removeSelection(int row)

updateSelection

protected void updateSelection()

updateSelection

protected void updateSelection(int startIndex,
                               int endIndex)
Updates the selection based on the current value of the underlying object; uses the limiting indices to do the work only within small bounds if they are known; bounds are inclusive

Parameters:
startIndex -
endIndex -

isComponentReady

protected boolean isComponentReady()

updateDetailsState

protected void updateDetailsState(java.util.Collection curValues)
Updates the active/inactive state of the Details button

Parameters:
curValues - the current values held by the underlying variable

getAddDiffs

protected java.util.Vector getAddDiffs(java.util.Collection oldStuff,
                                       java.util.Collection newStuff)
Creates a list of elements that are present in newStuff but not in oldStuff

Parameters:
oldStuff - old list
newStuff - new list
Returns:
a list of things to add to oldStuff so that its membership would be the same as that of newStuff

getDeleteDiffs

protected java.util.Vector getDeleteDiffs(java.util.Collection oldStuff,
                                          java.util.Collection newStuff)
Creates a list of elements that are present in oldStuff but not in newStuff

Parameters:
oldStuff - old list
newStuff - new list
Returns:
a list of things to delete from oldStuff so that its membership would be the same as that of newStuff

addLegalValues

protected void addLegalValues(java.util.Vector diff,
                              java.util.Vector currentList)
Adds the specified values to the list model; it uses the position of the new elements in the currentList to determine where they should be inserted.

Parameters:
diff -
currentList -

deleteLegalValues

protected void deleteLegalValues(java.util.Vector diff)
Removes the specified values from the list model

Parameters:
diff -

legalValuesChanged

protected void legalValuesChanged(java.beans.PropertyChangeEvent evt)
reacts to the change in the list of legal values in the underlying object

Overrides:
legalValuesChanged in class AbstractWidget
Parameters:
evt - property change event with details

valueChanged

protected void valueChanged(java.beans.PropertyChangeEvent evt)
Description copied from class: AbstractWidget
Subclasses should override this method if they want to update display the value of the underlying type changes

Overrides:
valueChanged in class AbstractWidget
Parameters:
evt - property change event with details

toString

public java.lang.String toString()
Overrides:
toString in class AbstractWidget

disengage

public void disengage()
Description copied from interface: Widget
Used to break the connection between the widget and the underlying ui object

Specified by:
disengage in interface Widget
Overrides:
disengage in class AbstractWidget

engage

public void engage()
Description copied from interface: Widget
Used to tie the widgets with the underlying ui objects

Specified by:
engage in interface Widget
Overrides:
engage in class SimpleSwingWidget

setEnabled

public void setEnabled(boolean enabled)
Description copied from interface: Widget
This method is exposed only so that wrappers can access it; others should stay away

Specified by:
setEnabled in interface Widget
Overrides:
setEnabled in class AbstractWidget
Parameters:
enabled - indicates if the underlying object is active