com.sas.swing.visuals.tableview
Class CellSelectionModel

com.sas.swing.visuals.tableview.CellSelectionModel
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, javax.swing.ListSelectionModel
Direct Known Subclasses:
OLAPColumnHeaderSelectionModel, OLAPRowHeaderSelectionModel

public class CellSelectionModel

See Also:
Serialized Form

Field Summary
protected  int anchorOrdinal
           
protected  java.util.BitSet extendedValue
           
protected  int firstAdjustedOrdinal
           
protected  int firstChangedOrdinal
           
protected  int lastAdjustedOrdinal
           
protected  int lastChangedOrdinal
           
protected  int leadOrdinal
           
protected static int MAX
           
protected  int maxOrdinal
           
protected static int MIN
           
protected  int minOrdinal
           
protected  TableView table
           
protected  java.util.BitSet value
          contains a ListSelectionModel for each column
 
Constructor Summary
CellSelectionModel()
          Constructs a default CellSelectionModel, setting the TableView to null.
CellSelectionModel(TableView table)
          Constructs a CellSelectionModel and sets the TableView to the given TableView.
 
Method Summary
 void addSelection(int row, int column)
          Adds the given cell to the selection
 void addSelectionInterval(int ordinal1, int ordinal2)
          Adds the block of cells defined by the ordinals.
 void addSelectionInterval(int row1, int column1, int row2, int column2)
          Adds the block of cells defined by the row-column pairs.
protected  void changeSelection(java.util.BitSet bits, int clearMin, int clearMax, int setMin, int setMax, boolean clearFirst)
           
protected  void changeSelection(int clearMin, int clearMax, int setMin, int setMax)
          Change the selection with the effect of first clearing the values in the inclusive range [clearMin, clearMax] then setting the values in the inclusive range [setMin, setMax].
protected  void changeSelection(int clearMin, int clearMax, int setMin, int setMax, boolean clearFirst)
           
protected  void changeTempSelection(int clearMin, int clearMax, int setMin, int setMax)
          Change the selection with the effect of first clearing the values in the inclusive range [clearMin, clearMax] then setting the values in the inclusive range [setMin, setMax].
protected  void changeTempSelection(int clearMin, int clearMax, int setMin, int setMax, boolean clearFirst)
           
protected  void clear(java.util.BitSet bits, int ordinal)
           
 void clearSelection()
          Clears all the selected cells
 java.lang.Object clone()
          Returns a clone of this selection model with the same selection.
protected  boolean contains(int a, int b, int i)
           
protected  int createOrdinal(int row, int column)
          Creates the ordinal value for the given row-column pair.
protected  void fireValueChanged()
           
protected  void fireValueChanged(boolean isAdjusting)
          Notifies listeners that we have ended a series of adjustments.
protected  void fireValueChanged(int firstOrdinal, int lastOrdinal)
          Notifies ListSelectionListeners that the value of the selection, in the closed interval firstIndex, lastIndex, has changed.
protected  void fireValueChanged(int firstOrdinal, int lastOrdinal, boolean isAdjusting)
           
 int getAnchorSelectionIndex()
          Returns the anchor cell for the selected cells.
 int getLeadSelectionIndex()
          Returns the lead cell for the selected cells.
 int getMaxSelectionIndex()
          Delegates to getMaxSelectionOrdinal().
 int getMaxSelectionOrdinal()
          Returns the last selected oridinal(cell), or -1 if nothing is selected.
 int getMinSelectionIndex()
          Delegates to getMinSelectionOrdinal().
 int getMinSelectionOrdinal()
          Returns the first selected oridinal(cell), or -1 if nothing is selected.
 TableView getTable()
          Returns the TableView associated with this cell selection model.
 void insertIndexInterval(int ordinal, int length, boolean before)
          Insert length indices beginning before/after ordinal.
 boolean isSelected(int row, int column)
           
 boolean isSelectedIndex(int ordinal)
          Returns true if the griven index(ordinal) is selected or not.
 boolean isSelectionEmpty()
          Returns true if no cells are selected, false otherwise.
protected  void markAsDirty(int ordinal)
           
 void removeIndexInterval(int ordinal1, int ordinal2)
          Remove the indices in the interval ordinal1,ordinal2 (inclusive) from the selection model.
 void removeSelection(int row, int column)
          Removes the given cell to the selection
 void removeSelectionInterval(int ordinal1, int ordinal2)
          Removes the block of cells defined by the ordinals.
 void removeSelectionInterval(int row1, int column1, int row2, int column2)
          Removes the block of cells defined by the row-column pairs.
protected  void set(java.util.BitSet bits, int ordinal)
           
 void setAnchorSelectionCell(int row, int column)
          Set the anchor selection cell, leaving all selection values unchanged.
 void setAnchorSelectionIndex(int ordinal)
          Sets the anchor to the given index, updates the selection and fires a selection event.
 void setLeadSelectionCell(int row, int column)
          Sets the lead selection index, ensuring that values between the anchor and the new lead are either all selected or all deselected.
 void setLeadSelectionIndex(int ordinal)
          Sets the lead to the given index, updates the selection and fires a selection event.
 void setSelection(int row, int column)
          Sets the selection to the one cell defined by the row-column pair.
 void setSelectionInterval(int ordinal1, int ordinal2)
          Selects the block of cells defined by the ordinals.
 void setSelectionInterval(int row1, int column1, int row2, int column2)
          Selects the block of cells defined by the row-column pairs.
 void setTable(TableView newTable)
          Sets the TableView associated with this selection model to the given TableView.
 java.lang.String toString()
          Returns a string that displays and identifies this object's properties.
protected  void updateLeadAnchorOrdinals(int anchorOrdinal, int leadOrdinal)
           
protected  void updateSelectedValues()
           
protected  void validateMinAndMaxOrdinal()
           
 

Field Detail

MIN

protected static final int MIN
See Also:
Constant Field Values

MAX

protected static final int MAX
See Also:
Constant Field Values

value

protected java.util.BitSet value
contains a ListSelectionModel for each column


extendedValue

protected java.util.BitSet extendedValue

table

protected TableView table

firstAdjustedOrdinal

protected int firstAdjustedOrdinal

lastAdjustedOrdinal

protected int lastAdjustedOrdinal

firstChangedOrdinal

protected int firstChangedOrdinal

lastChangedOrdinal

protected int lastChangedOrdinal

anchorOrdinal

protected int anchorOrdinal

leadOrdinal

protected int leadOrdinal

minOrdinal

protected int minOrdinal

maxOrdinal

protected int maxOrdinal
Constructor Detail

CellSelectionModel

public CellSelectionModel()
Constructs a default CellSelectionModel, setting the TableView to null.


CellSelectionModel

public CellSelectionModel(TableView table)
Constructs a CellSelectionModel and sets the TableView to the given TableView.

Parameters:
table - the TableView associated with this selection model
Method Detail

setTable

public void setTable(TableView newTable)
Sets the TableView associated with this selection model to the given TableView. The TableView is used for its row and column count.

Parameters:
newTable - the new TableView associated with this selection model.
See Also:
getTable()

getTable

public TableView getTable()
Returns the TableView associated with this cell selection model.

Returns:
the TableView associated with this model or null if there isn't a TableView
See Also:
setTable(TableView)

getMinSelectionOrdinal

public int getMinSelectionOrdinal()
Returns the first selected oridinal(cell), or -1 if nothing is selected.

Returns:
the first selected cell ordinal
See Also:
createOrdinal(int, int)

getMaxSelectionOrdinal

public int getMaxSelectionOrdinal()
Returns the last selected oridinal(cell), or -1 if nothing is selected.

Returns:
the last selected cell ordinal
See Also:
createOrdinal(int, int)

isSelectionEmpty

public boolean isSelectionEmpty()
Returns true if no cells are selected, false otherwise.

Specified by:
isSelectionEmpty in interface javax.swing.ListSelectionModel
Overrides:
isSelectionEmpty in class javax.swing.DefaultListSelectionModel
Returns:
true if nothing is selected, false otherwise

setSelectionInterval

public void setSelectionInterval(int ordinal1,
                                 int ordinal2)
Selects the block of cells defined by the ordinals. Not all ordinals between the two ordinals will get selected since the two ordinals define a block(rectangle) of cells and not a continuous list of cells.

Specified by:
setSelectionInterval in interface javax.swing.ListSelectionModel
Overrides:
setSelectionInterval in class javax.swing.DefaultListSelectionModel
Parameters:
ordinal1 - the upper left corner of the block of cells
ordinal2 - the lower right corner of the block of cells
See Also:
createOrdinal(int, int)

addSelectionInterval

public void addSelectionInterval(int ordinal1,
                                 int ordinal2)
Adds the block of cells defined by the ordinals. Not all ordinals between the two ordinals will get selected since the two ordinals define a block(rectangle) of cells and not a continuous list of cells.

Specified by:
addSelectionInterval in interface javax.swing.ListSelectionModel
Overrides:
addSelectionInterval in class javax.swing.DefaultListSelectionModel
Parameters:
ordinal1 - the upper left corner of the block of cells
ordinal2 - the lower right corner of the block of cells
See Also:
createOrdinal(int, int)

removeSelectionInterval

public void removeSelectionInterval(int ordinal1,
                                    int ordinal2)
Removes the block of cells defined by the ordinals. Not all ordinals between the two ordinals will get selected since the two ordinals define a block(rectangle) of cells and not a continuous list of cells.

Specified by:
removeSelectionInterval in interface javax.swing.ListSelectionModel
Overrides:
removeSelectionInterval in class javax.swing.DefaultListSelectionModel
Parameters:
ordinal1 - the upper left corner of the block of cells
ordinal2 - the lower right corner of the block of cells
See Also:
createOrdinal(int, int)

getMinSelectionIndex

public int getMinSelectionIndex()
Delegates to getMinSelectionOrdinal().

Specified by:
getMinSelectionIndex in interface javax.swing.ListSelectionModel
Overrides:
getMinSelectionIndex in class javax.swing.DefaultListSelectionModel
Returns:
the int returned from getMinSelectionOrdinal().
See Also:
createOrdinal(int, int), getMinSelectionOrdinal()

getMaxSelectionIndex

public int getMaxSelectionIndex()
Delegates to getMaxSelectionOrdinal().

Specified by:
getMaxSelectionIndex in interface javax.swing.ListSelectionModel
Overrides:
getMaxSelectionIndex in class javax.swing.DefaultListSelectionModel
Returns:
the int returned from getMaxSelectionOrdinal().
See Also:
createOrdinal(int, int), getMaxSelectionOrdinal()

isSelectedIndex

public boolean isSelectedIndex(int ordinal)
Returns true if the griven index(ordinal) is selected or not.

Specified by:
isSelectedIndex in interface javax.swing.ListSelectionModel
Overrides:
isSelectedIndex in class javax.swing.DefaultListSelectionModel
Parameters:
ordinal - the ordinal(cell) in question
Returns:
true if the cell is selected, false otherwise
See Also:
createOrdinal(int, int)

getAnchorSelectionIndex

public int getAnchorSelectionIndex()
Returns the anchor cell for the selected cells.

Specified by:
getAnchorSelectionIndex in interface javax.swing.ListSelectionModel
Overrides:
getAnchorSelectionIndex in class javax.swing.DefaultListSelectionModel
Returns:
the anchor ordinal(cell)
See Also:
setAnchorSelectionIndex(int), createOrdinal(int, int)

getLeadSelectionIndex

public int getLeadSelectionIndex()
Returns the lead cell for the selected cells.

Specified by:
getLeadSelectionIndex in interface javax.swing.ListSelectionModel
Overrides:
getLeadSelectionIndex in class javax.swing.DefaultListSelectionModel
Returns:
the lead ordinal(cell)
See Also:
setLeadSelectionIndex(int), createOrdinal(int, int)

setAnchorSelectionIndex

public void setAnchorSelectionIndex(int ordinal)
Sets the anchor to the given index, updates the selection and fires a selection event.

Specified by:
setAnchorSelectionIndex in interface javax.swing.ListSelectionModel
Overrides:
setAnchorSelectionIndex in class javax.swing.DefaultListSelectionModel
Parameters:
ordinal - the ordinal to set the anchor of the selection to
See Also:
getAnchorSelectionIndex(), createOrdinal(int, int)

setLeadSelectionIndex

public void setLeadSelectionIndex(int ordinal)
Sets the lead to the given index, updates the selection and fires a selection event.

Specified by:
setLeadSelectionIndex in interface javax.swing.ListSelectionModel
Overrides:
setLeadSelectionIndex in class javax.swing.DefaultListSelectionModel
Parameters:
ordinal - the ordinal to set the lead of the selection to
See Also:
getLeadSelectionIndex(), createOrdinal(int, int)

insertIndexInterval

public void insertIndexInterval(int ordinal,
                                int length,
                                boolean before)
Insert length indices beginning before/after ordinal. This is typically called to sync the selection model with a corresponding change in the data model.

Specified by:
insertIndexInterval in interface javax.swing.ListSelectionModel
Overrides:
insertIndexInterval in class javax.swing.DefaultListSelectionModel
Parameters:
ordinal - the ordinal(cell) to insert before or after
length - the number of indices to insert
before - true for before, false for after
See Also:
createOrdinal(int, int)

removeIndexInterval

public void removeIndexInterval(int ordinal1,
                                int ordinal2)
Remove the indices in the interval ordinal1,ordinal2 (inclusive) from the selection model. This is typically called to sync the selection model width a corresponding change in the data model.

Specified by:
removeIndexInterval in interface javax.swing.ListSelectionModel
Overrides:
removeIndexInterval in class javax.swing.DefaultListSelectionModel
Parameters:
ordinal1 - the first ordinal
ordinal2 - the last ordinal
See Also:
createOrdinal(int, int)

addSelection

public void addSelection(int row,
                         int column)
Adds the given cell to the selection

Parameters:
row - the row index
column - the column index

setSelection

public void setSelection(int row,
                         int column)
Sets the selection to the one cell defined by the row-column pair.

Parameters:
row - the row index of the cell to select
column - the column index of the cell to select

setSelectionInterval

public void setSelectionInterval(int row1,
                                 int column1,
                                 int row2,
                                 int column2)
Selects the block of cells defined by the row-column pairs.

Parameters:
row1 - the row index of the first cell
column1 - the column index of the first cell
row2 - the row index of the last cell
column2 - the column index of the last cell

addSelectionInterval

public void addSelectionInterval(int row1,
                                 int column1,
                                 int row2,
                                 int column2)
Adds the block of cells defined by the row-column pairs.

Parameters:
row1 - the row index of the first cell
column1 - the column index of the first cell
row2 - the row index of the last cell
column2 - the column index of the last cell

removeSelection

public void removeSelection(int row,
                            int column)
Removes the given cell to the selection

Parameters:
row - the row index
column - the column index

removeSelectionInterval

public void removeSelectionInterval(int row1,
                                    int column1,
                                    int row2,
                                    int column2)
Removes the block of cells defined by the row-column pairs.

Parameters:
row1 - the row index of the first cell
column1 - the column index of the first cell
row2 - the row index of the last cell
column2 - the column index of the last cell

setAnchorSelectionCell

public void setAnchorSelectionCell(int row,
                                   int column)
Set the anchor selection cell, leaving all selection values unchanged. If leadAnchorNotificationEnabled is true, send a notification covering the old and new anchor cells.

Parameters:
row - the row index of the cell
column - the column index of the cell
See Also:
getAnchorSelectionIndex(), setLeadSelectionIndex(int)

setLeadSelectionCell

public void setLeadSelectionCell(int row,
                                 int column)
Sets the lead selection index, ensuring that values between the anchor and the new lead are either all selected or all deselected. If the value at the anchor index is selected, first clear all the values in the range [anchor, oldLeadIndex], then select all the values values in the range [anchor, newLeadIndex], where oldLeadIndex is the old leadIndex and newLeadIndex is the new one.

If the value at the anchor index is not selected, do the same thing in reverse selecting values in the old range and deslecting values in the new one.

Generate a single event for this change and notify all listeners. For the purposes of generating minimal bounds in this event, do the operation in a single pass; that way the first and last index inside the ListSelectionEvent that is broadcast will refer to cells that actually changed value because of this method. If, instead, this operation were done in two steps the effect on the selection state would be the same but two events would be generated and the bounds around the changed values would be wider, including cells that had been first cleared only to later be set.

This method can be used in the mouseDragged method of a UI class to extend a selection.

Parameters:
row - the row index of the cell
column - the column index of the cell
See Also:
getLeadSelectionIndex(), setAnchorSelectionIndex(int)

clearSelection

public void clearSelection()
Clears all the selected cells

Specified by:
clearSelection in interface javax.swing.ListSelectionModel
Overrides:
clearSelection in class javax.swing.DefaultListSelectionModel

updateSelectedValues

protected void updateSelectedValues()

isSelected

public boolean isSelected(int row,
                          int column)
Returns:
true, if the specified cell is selected, false otherwise
See Also:
createOrdinal(int, int)

set

protected void set(java.util.BitSet bits,
                   int ordinal)

clear

protected void clear(java.util.BitSet bits,
                     int ordinal)

markAsDirty

protected void markAsDirty(int ordinal)

contains

protected boolean contains(int a,
                           int b,
                           int i)

updateLeadAnchorOrdinals

protected void updateLeadAnchorOrdinals(int anchorOrdinal,
                                        int leadOrdinal)

validateMinAndMaxOrdinal

protected void validateMinAndMaxOrdinal()

changeSelection

protected void changeSelection(java.util.BitSet bits,
                               int clearMin,
                               int clearMax,
                               int setMin,
                               int setMax,
                               boolean clearFirst)

changeSelection

protected void changeSelection(int clearMin,
                               int clearMax,
                               int setMin,
                               int setMax,
                               boolean clearFirst)

changeSelection

protected void changeSelection(int clearMin,
                               int clearMax,
                               int setMin,
                               int setMax)
Change the selection with the effect of first clearing the values in the inclusive range [clearMin, clearMax] then setting the values in the inclusive range [setMin, setMax]. Do this in one pass so that no values are cleared if they would later be set.


changeTempSelection

protected void changeTempSelection(int clearMin,
                                   int clearMax,
                                   int setMin,
                                   int setMax,
                                   boolean clearFirst)

changeTempSelection

protected void changeTempSelection(int clearMin,
                                   int clearMax,
                                   int setMin,
                                   int setMax)
Change the selection with the effect of first clearing the values in the inclusive range [clearMin, clearMax] then setting the values in the inclusive range [setMin, setMax]. Do this in one pass so that no values are cleared if they would later be set.


createOrdinal

protected int createOrdinal(int row,
                            int column)
Creates the ordinal value for the given row-column pair. The ordinals are numbered 0 through getTable().getRowCount() * getTable().getColumnCount() - 1 with the ordinal mapping to 0 being the cell located at 0, 0. The ordinals increase by 1 going across columns and by the going across rows.

Parameters:
row - the row index
column - the column index
Returns:
an integer in the range of 0 to getTable().getRowCount() * getTable().getColumnCount() - 1 if the cell is valid

fireValueChanged

protected void fireValueChanged(boolean isAdjusting)
Notifies listeners that we have ended a series of adjustments.

Overrides:
fireValueChanged in class javax.swing.DefaultListSelectionModel

fireValueChanged

protected void fireValueChanged(int firstOrdinal,
                                int lastOrdinal)
Notifies ListSelectionListeners that the value of the selection, in the closed interval firstIndex, lastIndex, has changed.

Overrides:
fireValueChanged in class javax.swing.DefaultListSelectionModel

fireValueChanged

protected void fireValueChanged(int firstOrdinal,
                                int lastOrdinal,
                                boolean isAdjusting)
Overrides:
fireValueChanged in class javax.swing.DefaultListSelectionModel
Parameters:
firstIndex - the first index in the interval
lastIndex - the last index in the interval
isAdjusting - true if this is the final change in a series of adjustments
See Also:
EventListenerList

fireValueChanged

protected void fireValueChanged()

toString

public java.lang.String toString()
Returns a string that displays and identifies this object's properties.

Overrides:
toString in class javax.swing.DefaultListSelectionModel
Returns:
a String representation of this object

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a clone of this selection model with the same selection. listenerLists are not duplicated.

Overrides:
clone in class javax.swing.DefaultListSelectionModel
Throws:
java.lang.CloneNotSupportedException - if the selection model does not both (a) implement the Cloneable interface and (b) define a clone method.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.