Package diva.canvas.interactor
Class BasicSelectionModel
- java.lang.Object
-
- diva.canvas.interactor.BasicSelectionModel
-
- All Implemented Interfaces:
SelectionModel
public class BasicSelectionModel extends java.lang.Object implements SelectionModel
A basic implementation of the SelectionModel interface. This model requires that each object in the selection be an instance of Figure. When each item is added to the selection, the model gets its interactor, and if it is an instance of SelectionInteractor, gets a selection renderer from the interactor and uses it to highlight the selected figures.- Version:
- $Id$
- Author:
- Michael Shilman
-
-
Field Summary
-
Fields inherited from interface diva.canvas.interactor.SelectionModel
MULTIPLE_SELECTION, SINGLE_SELECTION
-
-
Constructor Summary
Constructors Constructor Description BasicSelectionModel()Construct an empty selection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSelection(java.lang.Object sel)Add an object to the selection.voidaddSelectionListener(SelectionListener l)Add a selection listener to this model.voidaddSelections(java.lang.Object[] sels)Add an array of objects to the selection and highlight the selected objects.voidclearSelection()Clear the selection.booleancontainsSelection(java.lang.Object sel)Test if the selection contains the given objectvoiddispatchSelectionEvent(SelectionEvent e)Dispatch a selection event to all registered listenersjava.lang.ObjectgetFirstSelection()Return the first selection in the list.java.lang.ObjectgetLastSelection()Return the last selection in the list.java.util.IteratorgetSelection()Return an iterator over the selected objects.java.lang.Object[]getSelectionAsArray()Return the contents of the selection as an array.intgetSelectionCount()Return the number of selected objects.intgetSelectionMode()Return the mode of the selection, either SINGLE_SELECTION or MULTIPLE_SELECTION.voidremoveSelection(java.lang.Object sel)Remove an object from the selection.voidremoveSelectionListener(SelectionListener l)Remove a listener from the list of listeners.voidsetSelectionMode(int mode)Set the selection mode, either SINGLE_SELECTION or MULTIPLE_SELECTION.
-
-
-
Method Detail
-
addSelectionListener
public void addSelectionListener(SelectionListener l)
Add a selection listener to this model.- Specified by:
addSelectionListenerin interfaceSelectionModel
-
addSelection
public void addSelection(java.lang.Object sel)
Add an object to the selection. The model highlights the selection. If the given object is null, then it is not added to the selection, but if the selection model is a single selection, the current selection is cleared.- Specified by:
addSelectionin interfaceSelectionModel
-
addSelections
public void addSelections(java.lang.Object[] sels)
Add an array of objects to the selection and highlight the selected objects.- Specified by:
addSelectionsin interfaceSelectionModel
-
clearSelection
public void clearSelection()
Clear the selection. The model should remove highlighting from the previously selected objects.- Specified by:
clearSelectionin interfaceSelectionModel
-
containsSelection
public boolean containsSelection(java.lang.Object sel)
Test if the selection contains the given object- Specified by:
containsSelectionin interfaceSelectionModel
-
dispatchSelectionEvent
public void dispatchSelectionEvent(SelectionEvent e)
Dispatch a selection event to all registered listeners
-
getFirstSelection
public java.lang.Object getFirstSelection()
Return the first selection in the list.- Specified by:
getFirstSelectionin interfaceSelectionModel
-
getLastSelection
public java.lang.Object getLastSelection()
Return the last selection in the list.- Specified by:
getLastSelectionin interfaceSelectionModel
-
getSelection
public java.util.Iterator getSelection()
Return an iterator over the selected objects.- Specified by:
getSelectionin interfaceSelectionModel
-
getSelectionAsArray
public java.lang.Object[] getSelectionAsArray()
Return the contents of the selection as an array. This method is typically used by clients that need to pass the selection contents to another object that does not know about selection models, and which needs to traverse the selection contents multiple times.- Specified by:
getSelectionAsArrayin interfaceSelectionModel
-
getSelectionCount
public int getSelectionCount()
Return the number of selected objects.- Specified by:
getSelectionCountin interfaceSelectionModel
-
getSelectionMode
public int getSelectionMode()
Return the mode of the selection, either SINGLE_SELECTION or MULTIPLE_SELECTION.- Specified by:
getSelectionModein interfaceSelectionModel
-
removeSelection
public void removeSelection(java.lang.Object sel)
Remove an object from the selection.- Specified by:
removeSelectionin interfaceSelectionModel
-
removeSelectionListener
public void removeSelectionListener(SelectionListener l)
Remove a listener from the list of listeners.- Specified by:
removeSelectionListenerin interfaceSelectionModel
-
setSelectionMode
public void setSelectionMode(int mode)
Set the selection mode, either SINGLE_SELECTION or MULTIPLE_SELECTION.- Specified by:
setSelectionModein interfaceSelectionModel
-
-