001: /*
002: * @(#)GraphSelectionModel.java 0.1 03-JUL-04
003: *
004: * Copyright (c) 2001-2004 Gaudenz Alder
005: *
006: */
007: package org.jgraph.graph;
008:
009: import java.beans.PropertyChangeListener;
010:
011: import org.jgraph.event.GraphSelectionListener;
012:
013: /**
014: * This interface represents the current state of the selection for
015: * the graph component.
016: * <p>
017: *
018: * A GraphSelectionModel can be configured to allow only one
019: * cell (<code>SINGLE_GRAPH_SELECTION</code>) or a number of
020: * cells (<code>MULTIPLE_GRAPH_SELECTION</code>).
021: *
022: * @version 0.1 1/1/02
023: * @author Gaudenz Alder
024: */
025:
026: public interface GraphSelectionModel {
027:
028: /** Selection can only contain one cell at a time. */
029: public static final int SINGLE_GRAPH_SELECTION = 1;
030:
031: /** Selection can contain any number of items. */
032: public static final int MULTIPLE_GRAPH_SELECTION = 4;
033:
034: /**
035: * Sets the selection model, which must be either
036: * SINGLE_GRAPH_SELECTION or MULTIPLE_GRAPH_SELECTION.
037: * <p>
038: * This may change the selection if the current selection is not valid
039: * for the new mode.
040: */
041: void setSelectionMode(int mode);
042:
043: /**
044: * Sets if the selection model allows the selection
045: * of children.
046: */
047: void setChildrenSelectable(boolean flag);
048:
049: /**
050: * Returns true if the selection model allows the selection
051: * of children.
052: */
053: boolean isChildrenSelectable();
054:
055: /**
056: * Returns the current selection mode, either
057: * <code>SINGLE_GRAPH_SELECTION</code> or
058: * <code>MULTIPLE_GRAPH_SELECTION</code>.
059: */
060: int getSelectionMode();
061:
062: /**
063: * Sets the selection to cell. If this represents a change, then
064: * the GraphSelectionListeners are notified. If <code>cell</code> is
065: * null, this has the same effect as invoking <code>clearSelection</code>.
066: *
067: * @param cell new cell to select
068: */
069: void setSelectionCell(Object cell);
070:
071: /**
072: * Sets the selection to cells. If this represents a change, then
073: * the GraphSelectionListeners are notified. If <code>cells</code> is
074: * null, this has the same effect as invoking <code>clearSelection</code>.
075: *
076: * @param cells new selection
077: */
078: void setSelectionCells(Object[] cells);
079:
080: /**
081: * Adds cell to the current selection. If cell is not currently
082: * in the selection the GraphSelectionListeners are notified. This has
083: * no effect if <code>cell</code> is null.
084: *
085: * @param cell the new cell to add to the current selection
086: */
087: void addSelectionCell(Object cell);
088:
089: /**
090: * Adds cells to the current selection. If any of the cells are
091: * not currently in the selection the GraphSelectionListeners
092: * are notified. This has no effect if <code>cells</code> is null.
093: *
094: * @param cells the new cells to add to the current selection
095: */
096: void addSelectionCells(Object[] cells);
097:
098: /**
099: * Removes cell from the selection. If cell is in the selection
100: * the GraphSelectionListeners are notified. This has no effect if
101: * <code>cell</code> is null.
102: *
103: * @param cell the cell to remove from the selection
104: */
105: void removeSelectionCell(Object cell);
106:
107: /**
108: * Removes cells from the selection. If any of the cells in
109: * <code>cells</code> are in the selection, the
110: * GraphSelectionListeners are notified. This method has no
111: * effect if <code>cells</code> is null.
112: *
113: * @param cells the cells to remove from the selection
114: */
115: void removeSelectionCells(Object[] cells);
116:
117: /**
118: * Returns the cells that are currently selectable.
119: */
120: Object[] getSelectables();
121:
122: /**
123: * Returns the first cell in the selection. How first is defined is
124: * up to implementors.
125: */
126: Object getSelectionCell();
127:
128: /**
129: * Returns the cells in the selection. This will return null (or an
130: * empty array) if nothing is currently selected.
131: */
132: Object[] getSelectionCells();
133:
134: /**
135: * Returns the number of cells that are selected.
136: */
137: int getSelectionCount();
138:
139: /**
140: * Returns true if the cell, <code>cell</code>, is in the current
141: * selection.
142: */
143: boolean isCellSelected(Object cell);
144:
145: /**
146: * Returns true if the cell, <code>cell</code>,
147: * has selected children.
148: */
149: boolean isChildrenSelected(Object cell);
150:
151: /**
152: * Returns true if the selection is currently empty.
153: */
154: boolean isSelectionEmpty();
155:
156: /**
157: * Empties the current selection. If this represents a change in the
158: * current selection, the selection listeners are notified.
159: */
160: void clearSelection();
161:
162: /**
163: * Adds a PropertyChangeListener to the listener list.
164: * The listener is registered for all properties.
165: * <p>
166: * A PropertyChangeEvent will get fired when the selection mode
167: * changes.
168: *
169: * @param listener the PropertyChangeListener to be added
170: */
171: void addPropertyChangeListener(PropertyChangeListener listener);
172:
173: /**
174: * Removes a PropertyChangeListener from the listener list.
175: * This removes a PropertyChangeListener that was registered
176: * for all properties.
177: *
178: * @param listener the PropertyChangeListener to be removed
179: */
180: void removePropertyChangeListener(PropertyChangeListener listener);
181:
182: /**
183: * Adds x to the list of listeners that are notified each time the
184: * set of selected Objects changes.
185: *
186: * @param x the new listener to be added
187: */
188: void addGraphSelectionListener(GraphSelectionListener x);
189:
190: /**
191: * Removes x from the list of listeners that are notified each time
192: * the set of selected Objects changes.
193: *
194: * @param x the listener to remove
195: */
196: void removeGraphSelectionListener(GraphSelectionListener x);
197: }
|