com.yospace.yae.yogi
Class DefaultSelectionModel

java.lang.Object
  |
  +--com.yospace.yae.yogi.DefaultSelectionModel
All Implemented Interfaces:
SelectionModel

public class DefaultSelectionModel
extends java.lang.Object
implements SelectionModel

Default implementation of the SelectionModel interface. Selections are stored as intervals in order to minimise the expense of storing large numbers of selections. Selection modes can be set using the constants provided in the SelectionModel interface.


Fields inherited from interface com.yospace.yae.yogi.SelectionModel
SELECTION_MODE_MULTIPLE_INTERVAL, SELECTION_MODE_NONE, SELECTION_MODE_SINGLE, SELECTION_MODE_SINGLE_INTERVAL
 
Constructor Summary
DefaultSelectionModel()
          Default constructor.
DefaultSelectionModel(int selectionMode)
          Constructor initialising the selection model to a specified mode
 
Method Summary
 int[] clearSelections()
          Clears all selections in the selection model.
 int getMaxSelectionIndex()
          Gets the highest index currently selected.
 int getMinSelectionIndex()
          Gets the lowest index currently selected.
 int getSelectedIndex()
          Returns an int denoting the index currently selected, or -1 if none are selected.
 int[] getSelectedIndices()
          Returns an int array containing all currently selected elements.
 int getSelectionMode()
          Gets the current selection mode, will be one of: SelectionModel.SELECTION_MODE_NONE, SelectionModel.SELECTION_MODE_SINGLE, SelectionModel.SELECTION_MODE_SINGLE_INTERVAL.
 boolean isSelected(int index)
          Returns the selection status of a specified element.
 void removeSelection(int index)
          Removes a specified selection from the selection model.
 void removeSelections(int[] indices)
          Removes the specified selections from the selection model.
 int[] setSelectedIndex(int index, boolean selected, int listSize)
          Sets the element specified by index to the specified boolean state.
 int[] setSelectedIndices(int[] indices, boolean selected, int listSize)
          Sets the element specified by index to the specified boolean state.
 void setSelectionMode(int selectionMode)
          Sets the selection mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultSelectionModel

public DefaultSelectionModel()
Default constructor. Creates an empty selection model to store multiple selection intervals.

DefaultSelectionModel

public DefaultSelectionModel(int selectionMode)
Constructor initialising the selection model to a specified mode
Parameters:
selectionMode - the selection mode.
Method Detail

getSelectionMode

public int getSelectionMode()
Gets the current selection mode, will be one of: SelectionModel.SELECTION_MODE_NONE, SelectionModel.SELECTION_MODE_SINGLE, SelectionModel.SELECTION_MODE_SINGLE_INTERVAL. SelectionModel.SELECTION_MODE_MULTIPLE_INTERVAL.
Specified by:
getSelectionMode in interface SelectionModel
Returns:
the current selection mode.

setSelectionMode

public void setSelectionMode(int selectionMode)
Sets the selection mode. Must be one of: SelectionModel.SELECTION_MODE_NONE, SelectionModel.SELECTION_MODE_SINGLE, SelectionModel.SELECTION_MODE_SINGLE_INTERVAL. SelectionModel.SELECTION_MODE_MULTIPLE_INTERVAL. NB. Calling this method may alter the contents of the selection model. For example, if multiple intervals are selected and the mode then set to single selection, all the intervals other than that at index 0 will be deleted.
Specified by:
setSelectionMode in interface SelectionModel
Parameters:
selectionMode - the new selection mode

getMinSelectionIndex

public int getMinSelectionIndex()
Gets the lowest index currently selected.
Specified by:
getMinSelectionIndex in interface SelectionModel
Returns:
the lowest index currently selected.

getMaxSelectionIndex

public int getMaxSelectionIndex()
Gets the highest index currently selected.
Specified by:
getMaxSelectionIndex in interface SelectionModel
Returns:
the highest index currently selected.

isSelected

public boolean isSelected(int index)
Returns the selection status of a specified element.
Specified by:
isSelected in interface SelectionModel
Parameters:
index - the specified element.
Returns:
true if the element is currently selected, false if not.

getSelectedIndex

public int getSelectedIndex()
Returns an int denoting the index currently selected, or -1 if none are selected. If this method is called and multiple values have been selected, only the first element is returned.
Specified by:
getSelectedIndex in interface SelectionModel
Returns:
the selected index.

getSelectedIndices

public int[] getSelectedIndices()
Returns an int array containing all currently selected elements. Will return an array of 0 elements if no elements are selected.
Specified by:
getSelectedIndices in interface SelectionModel
Returns:
an array of the selected indices.

setSelectedIndex

public int[] setSelectedIndex(int index,
                              boolean selected,
                              int listSize)
Sets the element specified by index to the specified boolean state.
Specified by:
setSelectedIndex in interface SelectionModel
Parameters:
index - element to set
selected - the state to set the element to
listSize - size of the list
Returns:
an array listing the first and last indexes of items that have been updated as a result of this operation.

setSelectedIndices

public int[] setSelectedIndices(int[] indices,
                                boolean selected,
                                int listSize)
Sets the element specified by index to the specified boolean state.
Specified by:
setSelectedIndices in interface SelectionModel
Parameters:
indices - elements to set
selected - the state to set the element to
listSize - size of the list
Returns:
an array listing the first and last indexes of items that have been updated as a result of this operation.

clearSelections

public int[] clearSelections()
Clears all selections in the selection model.
Specified by:
clearSelections in interface SelectionModel
Returns:
an array listing the first and last indexes of items that have been updated as a result of this operation.

removeSelection

public void removeSelection(int index)
Removes a specified selection from the selection model.
Specified by:
removeSelection in interface SelectionModel
Parameters:
index - the index of the selection being removed

removeSelections

public void removeSelections(int[] indices)
Removes the specified selections from the selection model.
Parameters:
indices - the indices of the selections to remove.

Copyright 2002 Yospace Holdings Ltd. All Rights Reserved.