fsmvis.gui
Class SelectionHandler

java.lang.Object
  |
  +--fsmvis.gui.SelectionHandler

public class SelectionHandler
extends java.lang.Object


Field Summary
protected  java.util.List all
           
protected  java.util.LinkedList listeners
           
protected  java.util.LinkedList selectables
           
protected  java.util.List selected
           
protected  java.util.Set selectedIndices
           
protected  int size
           
 
Constructor Summary
SelectionHandler()
          constructor: Creates a new emepty Selection handler with an initial size of 0
SelectionHandler(int size)
          constructor: Creates a new selection handler that can initially handle up to size elements
 
Method Summary
 void addSelectableObject(Selectable s)
           
 void addSelectionChangedListener(SelectionChangedListener s)
          Adds a selection changed listener
 void addToSelected(java.util.List newSelect)
          Adds all of the indices in the newSelect array to the current selection
 java.util.List getSelected()
          returns the arrayList of selected states
 java.util.HashSet getSelectedIndices()
          returns the selected indices, uses the hashset class because it guarantees constant time, add, remove and importantly contains.
 boolean getState(int index)
          Returns the status of the data item located at index index.
protected  void notifyListeners()
          Method to be called whenever a change occurs in the selection, notifies all the listeners of this.
 void removeFromSelected(java.util.List newDeselect)
          Removes the indices specified in newDeselect from the currently selected indices.
 void removeSelectableObject(Selectable s)
           
 void removeSelectionChangedListener(SelectionChangedListener s)
          Removes a selection changed listener
 void selectAll()
          Selects all of the items in the selection.
 void selectNone()
          Selects none of the items, deselects all
protected  void setAllStates(boolean state)
          sets all of the states to the state indicated by the parameter, this can be used to select all items or to deselect all items
protected  void setStates(java.util.List indices, boolean state)
          Sets the states of the indices stored in indices to be state, internal method used by removefrom selected and add to selected.
 void updateSelection()
          method to be called by a selectable object when the selection has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

size

protected int size

selected

protected java.util.List selected

selectedIndices

protected java.util.Set selectedIndices

all

protected java.util.List all

selectables

protected java.util.LinkedList selectables

listeners

protected java.util.LinkedList listeners
Constructor Detail

SelectionHandler

public SelectionHandler()
constructor: Creates a new emepty Selection handler with an initial size of 0

SelectionHandler

public SelectionHandler(int size)
constructor: Creates a new selection handler that can initially handle up to size elements
Parameters:
size - The initial size of the selection
Method Detail

getSelected

public java.util.List getSelected()
returns the arrayList of selected states
Returns:
The selected states

getSelectedIndices

public java.util.HashSet getSelectedIndices()
returns the selected indices, uses the hashset class because it guarantees constant time, add, remove and importantly contains.
Returns:
The selected indices

getState

public boolean getState(int index)
Returns the status of the data item located at index index. If the specified index does not exist, then return false.
Parameters:
index - The location in the selected array
Returns:
The status of this index

updateSelection

public void updateSelection()
method to be called by a selectable object when the selection has changed.

addToSelected

public void addToSelected(java.util.List newSelect)
Adds all of the indices in the newSelect array to the current selection
Parameters:
newSelect - The arraylist of indices to be added

removeFromSelected

public void removeFromSelected(java.util.List newDeselect)
Removes the indices specified in newDeselect from the currently selected indices.
Parameters:
newDeselect - The items to be deselected

selectAll

public void selectAll()
Selects all of the items in the selection.

selectNone

public void selectNone()
Selects none of the items, deselects all

setStates

protected void setStates(java.util.List indices,
                         boolean state)
Sets the states of the indices stored in indices to be state, internal method used by removefrom selected and add to selected. Also changes the size of the selected elements to reflect the highest index that is passed to it.
Parameters:
indices - the indices that require their state set
state - The state to set them to

setAllStates

protected void setAllStates(boolean state)
sets all of the states to the state indicated by the parameter, this can be used to select all items or to deselect all items
Parameters:
state - The new desired state for all

addSelectableObject

public void addSelectableObject(Selectable s)

removeSelectableObject

public void removeSelectableObject(Selectable s)

addSelectionChangedListener

public void addSelectionChangedListener(SelectionChangedListener s)
Adds a selection changed listener
Parameters:
s -  

removeSelectionChangedListener

public void removeSelectionChangedListener(SelectionChangedListener s)
Removes a selection changed listener
Parameters:
s -  

notifyListeners

protected void notifyListeners()
Method to be called whenever a change occurs in the selection, notifies all the listeners of this.