1. /*
  2. * @(#)TreeSelectionModel.java 1.14 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.tree;
  8. import javax.swing.event.*;
  9. import java.beans.PropertyChangeListener;
  10. /**
  11. * This interface represents the current state of the selection for
  12. * the tree component. It will keep track of the selected rows, but
  13. * in order to select by row you will need to go directly to the tree.
  14. * <p>resetRowSelection is called from any of the methods that update
  15. * the selected paths.
  16. *
  17. * @version 1.14 11/29/01
  18. * @author Scott Violet
  19. */
  20. public interface TreeSelectionModel
  21. {
  22. /** Selection can only contain one path at a time. */
  23. public static final int SINGLE_TREE_SELECTION = 1;
  24. /** Selection can only be contiguous. This will only be enforced if
  25. * a RowMapper instance is provided. */
  26. public static final int CONTIGUOUS_TREE_SELECTION = 2;
  27. /** Selection can contain any number of items that are not necessarily
  28. * contiguous. */
  29. public static final int DISCONTIGUOUS_TREE_SELECTION = 4;
  30. /**
  31. * Sets the selection model, which must be one of SINGLE_TREE_SELECTION,
  32. * CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
  33. */
  34. void setSelectionMode(int mode);
  35. /**
  36. * Returns the selection mode.
  37. */
  38. int getSelectionMode();
  39. /**
  40. * Sets the selection to path. If this represents a change, then
  41. * the TreeSelectionListeners are notified.
  42. *
  43. * @param path new path to select
  44. */
  45. void setSelectionPath(TreePath path);
  46. /**
  47. * Sets the selection to the the paths. If this represents a
  48. * change the TreeSelectionListeners are notified.
  49. *
  50. * @param paths new selection.
  51. */
  52. void setSelectionPaths(TreePath[] paths);
  53. /**
  54. * Adds path to the current selection. If path is not currently
  55. * in the selection the TreeSelectionListeners are notified.
  56. *
  57. * @param path the new path to add to the current selection.
  58. */
  59. void addSelectionPath(TreePath path);
  60. /**
  61. * Adds paths to the current selection. If any of the paths in
  62. * paths are not currently in the selection the TreeSelectionListeners
  63. * are notified.
  64. *
  65. * @param path the new path to add to the current selection.
  66. */
  67. void addSelectionPaths(TreePath[] paths);
  68. /**
  69. * Removes path from the selection. If path is in the selection
  70. * The TreeSelectionListeners are notified.
  71. *
  72. * @param path the path to remove from the selection.
  73. */
  74. void removeSelectionPath(TreePath path);
  75. /**
  76. * Removes paths from the selection. If any of the paths in paths
  77. * are in the selection the TreeSelectionListeners are notified.
  78. *
  79. * @param path the path to remove from the selection.
  80. */
  81. void removeSelectionPaths(TreePath[] paths);
  82. /**
  83. * Returns the first path in the selection.
  84. */
  85. TreePath getSelectionPath();
  86. /**
  87. * Returns the paths in the selection.
  88. */
  89. TreePath[] getSelectionPaths();
  90. /**
  91. * Returns the number of paths that are selected.
  92. */
  93. int getSelectionCount();
  94. /**
  95. * Returns true if the path, path, is in the current selection.
  96. */
  97. boolean isPathSelected(TreePath path);
  98. /**
  99. * Returns true if the selection is currently empty.
  100. */
  101. boolean isSelectionEmpty();
  102. /**
  103. * Empties the current selection. If this represents a change in the
  104. * current selection, the selection listeners are notified.
  105. */
  106. void clearSelection();
  107. /**
  108. * Sets the RowMapper instance. This instance is used to determine
  109. * what row corresponds to what path.
  110. */
  111. void setRowMapper(RowMapper newMapper);
  112. /**
  113. * Returns the RowMapper instance that is able to map a path to a
  114. * row.
  115. */
  116. RowMapper getRowMapper();
  117. /**
  118. * Returns all of the currently selected rows.
  119. */
  120. int[] getSelectionRows();
  121. /**
  122. * Gets the first selected row.
  123. */
  124. int getMinSelectionRow();
  125. /**
  126. * Gets the last selected row.
  127. */
  128. int getMaxSelectionRow();
  129. /**
  130. * Returns true if the row identitifed by row is selected.
  131. */
  132. boolean isRowSelected(int row);
  133. /**
  134. * Updates what rows are selected. This can be externally called in
  135. * case the location of the paths change, but not the actual paths.
  136. * You do not normally need to call this.
  137. */
  138. void resetRowSelection();
  139. /**
  140. * Returns the lead selection index. That is the last index that was
  141. * added.
  142. */
  143. int getLeadSelectionRow();
  144. /**
  145. * Returns the last path that was added.
  146. */
  147. TreePath getLeadSelectionPath();
  148. /**
  149. * Add a PropertyChangeListener to the listener list.
  150. * The listener is registered for all properties.
  151. * <p>
  152. * A PropertyChangeEvent will get fired in response to an
  153. * explicit setFont, setBackground, or SetForeground on the
  154. * current component. Note that if the current component is
  155. * inheriting its foreground, background, or font from its
  156. * container, then no event will be fired in response to a
  157. * change in the inherited property.
  158. *
  159. * @param listener The PropertyChangeListener to be added
  160. */
  161. void addPropertyChangeListener(PropertyChangeListener listener);
  162. /**
  163. * Remove a PropertyChangeListener from the listener list.
  164. * This removes a PropertyChangeListener that was registered
  165. * for all properties.
  166. *
  167. * @param listener The PropertyChangeListener to be removed
  168. */
  169. void removePropertyChangeListener(PropertyChangeListener listener);
  170. /**
  171. * Adds x to the list of listeners that are notified each time the
  172. * selection changes.
  173. *
  174. * @param x the new listener to be added.
  175. */
  176. void addTreeSelectionListener(TreeSelectionListener x);
  177. /**
  178. * Removes x from the list of listeners that are notified each time
  179. * the selection changes.
  180. *
  181. * @param x the listener to remove.
  182. */
  183. void removeTreeSelectionListener(TreeSelectionListener x);
  184. }