com.sas.table
Class Selection

com.sas.table.Selection
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.collection.ContentsChangedSource, com.sas.collection.StaticCollectionInterface, com.sas.models.SelectionInterface, com.sas.models.StaticSelectionInterface, com.sas.PublicClonable, TableElementInterface, com.sas.util.Countable, com.sas.util.Enumerable, java.lang.Cloneable
Direct Known Subclasses:
CellSelection, CellVectorSelection

public abstract class Selection
implements TableElementInterface, com.sas.models.SelectionInterface, com.sas.collection.StaticCollectionInterface

Defines an abstract base class for representing TableView selections.

Selection anchors a hierarchy of classes that each represent a contiguous range of a particular table element. The hierarchy is divided into two general categories, cell selections and cell vector selections, which are represented by the subclasses CellSelection and CellVectorSelection (abstract class) respectively. Cell vector selections are divided into column selections (ColumnSelection) and row selections (RowSelection).

Selection implements TableElementInterface to allow the range of elements to be treated and manipulated just like a single element. It also allows the range to used as a collection by implementing StaticCollectionInterface.

Subclass note: SelectionChangedEvents should be created whenever the selection changes. These can be sent to all registered listeners via fireContentsChanged().

See Also:
CellSelection, CellVectorSelection, ColumnSelection, RowSelection

Field Summary
 
Fields inherited from interface com.sas.table.TableElementInterface
REFRESH_ALL, REFRESH_DATA, REFRESH_DATA_STYLE, REFRESH_LABEL, REFRESH_LABEL_STYLE, REFRESH_STYLE
 
Constructor Summary
Selection(TableElement anchor)
          Alias for Selection(anchor, anchor).
Selection(TableElement anchor, TableElement end)
          Constructs a new selection with the given extent.
 
Method Summary
 void addContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
          Add a listener for ContentsChangedEvent.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a listener for PropertyChangeEvent.
 void apply(com.sas.util.ApplyInterface action)
          Applies an action to every item in the selection.
 java.lang.Object clone()
          Clones the selection.
abstract  boolean contains(java.lang.Object item)
          Test for the presence of an item in the selection.
abstract  int count()
          Returns the number of items in the selection.
protected  void fireContentsChanged(com.sas.collection.ContentsChangedEvent event)
          Sends ContentsChangedEvent to all registered ContentsChangedEvent listeners.
protected  void firePropertyChange(java.beans.PropertyChangeEvent event)
          Sends PropertyChangeEvent to all registered PropertyChangeEvent listeners.
protected  void firePropertyChange(java.lang.String name, java.lang.Object oldValue, java.lang.Object newValue)
          Alias for firePropertyChange (new PropertyChangeEvent (this, name, oldValue, newValue)).
 java.lang.Object getAnchor()
          Returns the object that defines the anchored or non-floating end of the selection.
abstract  java.awt.Rectangle getDisplayedBounds()
          Returns a rectangle that represents the displayed area of the selection in the table view.
 java.lang.Object getEnd()
          Returns the object that defines the unanchored or floating end of the selection.
abstract  java.util.Enumeration getItems()
          Returns an enumeration of all the items in the selection.
 TableView getTableView()
          Returns the table view that contains this selection's items.
 boolean isDisplayed()
          Determines whether any part of the selection is displayed in the table (i.e. scrolled into view).
 boolean isModified()
          Determines whether any of the selection's items are modified.
 boolean isSelected()
          Determines whether any of the selection's items are selected in the table view.
protected abstract  Selection newSelection(TableElement anchor, TableElement end)
          Creates a new selection of the same class, but with different items.
protected  void onEndChanged(TableElement oldValue, TableElement newValue)
          Called by setEnd() to notify subclasses of a change to the end.
 void refresh(int flags)
          Refreshes the selection's items to their state as maintained by the table view's model.
 void removeContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
          Remove a listener for ContentsChangedEvent.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a listener for PropertyChangeEvent.
 void repaint()
          Repaints the selection in the table view.
 void setEnd(java.lang.Object newValue)
          Specifies the object that defines the unanchored or floating end of the selection.
 

Constructor Detail

Selection

public Selection(TableElement anchor)
Alias for Selection(anchor, anchor).

Parameters:
anchor - The value to assign the anchor property.

Selection

public Selection(TableElement anchor,
                 TableElement end)
Constructs a new selection with the given extent.

Parameters:
anchor - The value to assign the anchor property.
end - The value to assign the end property.
See Also:
getAnchor(), getEnd()
Method Detail

addContentsChangedListener

public void addContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
Add a listener for ContentsChangedEvent. If the listener is already registered for this event, nothing happens.

Specified by:
addContentsChangedListener in interface com.sas.collection.ContentsChangedSource
Parameters:
listener - The listener to add.
See Also:
removeContentsChangedListener(com.sas.collection.ContentsChangedListener)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a listener for PropertyChangeEvent. If the listener is already registered for this event, nothing happens.

Specified by:
addPropertyChangeListener in interface com.sas.beans.PropertyChangeSource
Parameters:
listener - The listener to add.
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener)

apply

public void apply(com.sas.util.ApplyInterface action)
Applies an action to every item in the selection. The action is specified by passing an implementation of the ApplyInterface and applied by calling the interface's apply() method with each item in succession. The application of the action continues until all items have been operated on, or until ApplyInterface.ABORT is returned from action.apply(item).

Specified by:
apply in interface com.sas.collection.StaticCollectionInterface
Parameters:
action - An implementation of ApplyInterface.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones the selection. Implemented as return newSelection ((TableElement)getAnchor(), (TableElement)getEnd());.

Specified by:
clone in interface com.sas.collection.StaticCollectionInterface
Specified by:
clone in interface com.sas.PublicClonable
Overrides:
clone in class java.lang.Object
Returns:
A new selection equivalent to this one.
Throws:
java.lang.CloneNotSupportedException - if the object could not be cloned.
See Also:
newSelection(com.sas.table.TableElement, com.sas.table.TableElement)

contains

public abstract boolean contains(java.lang.Object item)
Test for the presence of an item in the selection.

Specified by:
contains in interface com.sas.collection.StaticCollectionInterface
Specified by:
contains in interface com.sas.models.StaticSelectionInterface
Parameters:
item - The item to search for.
Returns:
true if the selection contains the item and false otherwise.

count

public abstract int count()
Returns the number of items in the selection.

Specified by:
count in interface com.sas.util.Countable
Returns:
The number of items in the selection.

getAnchor

public java.lang.Object getAnchor()
Returns the object that defines the anchored or non-floating end of the selection.

Specified by:
getAnchor in interface com.sas.models.StaticSelectionInterface
Returns:
The value of the anchor property.

getDisplayedBounds

public abstract java.awt.Rectangle getDisplayedBounds()
Returns a rectangle that represents the displayed area of the selection in the table view. The rectangle will be empty (have a width and height of zero) when no part of the selection is displayed.

Returns:
The displayed location and size of the selection.
See Also:
isDisplayed()

getEnd

public java.lang.Object getEnd()
Returns the object that defines the unanchored or floating end of the selection.

Specified by:
getEnd in interface com.sas.models.StaticSelectionInterface
Returns:
The value of the end property.
See Also:
setEnd(java.lang.Object)

getItems

public abstract java.util.Enumeration getItems()
Returns an enumeration of all the items in the selection.

Specified by:
getItems in interface com.sas.util.Enumerable
Returns:
An enumeration of the selection's items.

getTableView

public TableView getTableView()
Returns the table view that contains this selection's items.

Specified by:
getTableView in interface TableElementInterface
Returns:
The value of the tableView property (will never be null).

isDisplayed

public final boolean isDisplayed()
Determines whether any part of the selection is displayed in the table (i.e. scrolled into view). Alias for !getDisplayedBounds().isEmpty().

Specified by:
isDisplayed in interface TableElementInterface
Returns:
true if any of the items are displayed, and false otherwise.
See Also:
getDisplayedBounds()

isModified

public boolean isModified()
Determines whether any of the selection's items are modified.

Specified by:
isModified in interface TableElementInterface
Returns:
true if any of the items are modified, and false otherwise.

isSelected

public boolean isSelected()
Determines whether any of the selection's items are selected in the table view.

Specified by:
isSelected in interface TableElementInterface
Returns:
true if any of the items are selected, and false otherwise.

refresh

public void refresh(int flags)
Refreshes the selection's items to their state as maintained by the table view's model. What gets refreshed -- data and/or style info -- is controlled by flags.

Specified by:
refresh in interface TableElementInterface
Parameters:
flags - Bitmask of REFRESH_* bitflags.

repaint

public void repaint()
Repaints the selection in the table view.

Specified by:
repaint in interface TableElementInterface

removeContentsChangedListener

public void removeContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
Remove a listener for ContentsChangedEvent. If the listener is not registered for this event, nothing happens.

Specified by:
removeContentsChangedListener in interface com.sas.collection.ContentsChangedSource
Parameters:
listener - The listener to remove.
See Also:
addContentsChangedListener(com.sas.collection.ContentsChangedListener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a listener for PropertyChangeEvent. If the listener is not registered for this event, nothing happens.

Specified by:
removePropertyChangeListener in interface com.sas.beans.PropertyChangeSource
Parameters:
listener - The listener to remove.
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)

setEnd

public void setEnd(java.lang.Object newValue)
Specifies the object that defines the unanchored or floating end of the selection. If there are listeners for ContentsChangedEvent, calls onEndChanged().

Specified by:
setEnd in interface com.sas.models.SelectionInterface
Parameters:
newValue - The new value to assign the end property.
Throws:
java.lang.NullPointerException - If newValue is null.
java.lang.ClassCastException - If newValue is not a TableElement.
See Also:
getEnd(), onEndChanged(com.sas.table.TableElement, com.sas.table.TableElement), addContentsChangedListener(com.sas.collection.ContentsChangedListener)

fireContentsChanged

protected void fireContentsChanged(com.sas.collection.ContentsChangedEvent event)
Sends ContentsChangedEvent to all registered ContentsChangedEvent listeners. (The listener list is copied first, so the event is sent only to each item which is in the list at the time of this copy, even if adds or removes are performed after the send has started.)

Parameters:
event - The event to send.
See Also:
addContentsChangedListener(com.sas.collection.ContentsChangedListener), firePropertyChange(PropertyChangeEvent)

firePropertyChange

protected void firePropertyChange(java.beans.PropertyChangeEvent event)
Sends PropertyChangeEvent to all registered PropertyChangeEvent listeners. (The listener list is copied first, so the event is sent only to each item which is in the list at the time of this copy, even if adds or removes are performed after the send has started.)

Parameters:
event - The event to send.
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener), firePropertyChange(String,Object,Object), fireContentsChanged(com.sas.collection.ContentsChangedEvent)

firePropertyChange

protected final void firePropertyChange(java.lang.String name,
                                        java.lang.Object oldValue,
                                        java.lang.Object newValue)
Alias for firePropertyChange (new PropertyChangeEvent (this, name, oldValue, newValue)).

Parameters:
name - property name.
oldValue - previous value of the property.
newValue - current value of the property.
See Also:
firePropertyChange(PropertyChangeEvent)

newSelection

protected abstract Selection newSelection(TableElement anchor,
                                          TableElement end)
Creates a new selection of the same class, but with different items. Allows a base class operation to create a new subclass instance. Used by clone().

Parameters:
anchor - The value to assign the anchor property.
end - The value to assign the end property.
Returns:
A new selection with the same class as this, but with different items.
See Also:
clone()

onEndChanged

protected void onEndChanged(TableElement oldValue,
                            TableElement newValue)
Called by setEnd() to notify subclasses of a change to the end. The default implementation fires a generic ContentsChangedEvent. A subclass can override to provide more details about the change. Method is not driven if there are no ContentsChanged listeners.

Parameters:
oldValue - The previous value of end.
newValue - The current value of end.
See Also:
setEnd(java.lang.Object), fireContentsChanged(com.sas.collection.ContentsChangedEvent)



Copyright © 2009 SAS Institute Inc. All Rights Reserved.