Class mxGraphSelectionModel
java.lang.Object
com.mxgraph.util.mxEventSource
com.mxgraph.view.mxGraphSelectionModel
Implements the selection model for a graph.
This class fires the following events:
mxEvent.UNDO fires after the selection was changed in changeSelection. The
edit property contains the mxUndoableEdit which contains the
mxSelectionChange.
mxEvent.CHANGE fires after the selection changes by executing an
mxSelectionChange. The added and removed
properties contain Collections of cells that have been added to or removed
from the selection, respectively.
NOTE: Due to a historic bug that cannot be changed at this point the
names of the properties are "reversed".
To add a change listener to the graph selection model:
addListener(
mxEvent.CHANGE, new mxIEventListener()
{
public void invoke(Object sender, mxEventObject evt)
{
mxGraphSelectionModel model = (mxSelectionModel) sender;
Collection added = (Collection) evt.getProperty("added");
Collection removed = (Collection) evt.getProperty("removed");
selectionChanged(model, added, removed);
}
});
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class mxEventSource
mxEventSource.mxIEventListener -
Field Summary
FieldsModifier and TypeFieldDescriptionHolds the selection cells.protected mxGraphReference to the enclosing graph.protected booleanSpecifies if only one selected item at a time is allowed.Fields inherited from class mxEventSource
eventListeners, eventsEnabled, eventSource -
Constructor Summary
ConstructorsConstructorDescriptionmxGraphSelectionModel(mxGraph graph) Constructs a new selection model for the specified graph. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given cell to the selection.voidprotected voidprotected voidcellRemoved(Object cell) protected voidchangeSelection(Collection<Object> added, Collection<Object> removed) voidclear()Clears the selection.getCell()Returns the first selected cell.Object[]getCells()Returns the selection cells.protected ObjectgetFirstSelectableCell(Object[] cells) Returns the first selectable cell in the given array of cells.booleanisEmpty()Returns true if no cells are selected.booleanisSelected(Object cell) Returns true if the given cell is selected.booleanvoidremoveCell(Object cell) Removes the given cell from the selection.voidremoveCells(Object[] cells) voidClears the selection and adds the given cell to the selection.voidClears the selection and adds the given cells.voidsetSingleSelection(boolean singleSelection) intsize()Returns the number of selected cells.Methods inherited from class mxEventSource
addListener, fireEvent, fireEvent, getEventSource, isEventsEnabled, removeListener, removeListener, setEventsEnabled, setEventSource
-
Field Details
-
graph
Reference to the enclosing graph. -
singleSelection
protected boolean singleSelectionSpecifies if only one selected item at a time is allowed. Default is false. -
cells
-
-
Constructor Details
-
mxGraphSelectionModel
Constructs a new selection model for the specified graph.- Parameters:
graph-
-
-
Method Details
-
isSingleSelection
public boolean isSingleSelection()- Returns:
- the singleSelection
-
setSingleSelection
public void setSingleSelection(boolean singleSelection) - Parameters:
singleSelection- the singleSelection to set
-
isSelected
Returns true if the given cell is selected.- Parameters:
cell-- Returns:
- Returns true if the given cell is selected.
-
isEmpty
public boolean isEmpty()Returns true if no cells are selected. -
size
public int size()Returns the number of selected cells. -
clear
public void clear()Clears the selection. -
getCell
Returns the first selected cell. -
getCells
Returns the selection cells. -
setCell
Clears the selection and adds the given cell to the selection. -
setCells
Clears the selection and adds the given cells. -
getFirstSelectableCell
-
addCell
Adds the given cell to the selection. -
addCells
-
removeCell
Removes the given cell from the selection. -
removeCells
-
changeSelection
-
cellAdded
-
cellRemoved
-