View Javadoc

1   // START LICENSE
2   // JSet - a Java JSet card board game implementation
3   // Copyright (C) 2004 Jerome Lacoste
4   //
5   // This program is free software; you can redistribute it and/or modify
6   // it under the terms of the GNU General Public License as published by
7   // the Free Software Foundation; either version 2 of the License, or (at
8   // your option) any later version.
9   //
10  // This program is distributed in the hope that it will be useful, but
11  // WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // General Public License for more details.
14  //
15  // You should have received a copy of the GNU General Public License
16  // along with this program; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  // END LICENSE
19  
20  package org.cb.cardboard;
21  
22  import java.util.EventListener;
23  
24  /***
25   * The listener that's notified when a board selection value changes.
26   *
27   * @see BoardSelectionModel
28   *
29   * @author jerome@coffeebreaks.org - last modified by $LastModifiedBy$
30   * @version $Id: BoardSelectionModel.java 78 2004-04-13 04:25:57Z jerome $
31   */
32  public interface BoardSelectionModel extends EventListener
33  {
34    /***
35     * A value for the selectionMode property: select one list index
36     * at a time.
37     *
38     * @see #setSelectionMode
39     */
40    int SINGLE_SELECTION = 0;
41  
42    /***
43     * A value for the selectionMode property: select one contiguous
44     * range of indices at a time.
45     *
46     * @see #setSelectionMode
47     */
48    int SINGLE_INTERVAL_SELECTION = 1;
49  
50    /***
51     * A value for the selectionMode property: select one or more
52     * contiguous ranges of indices at a time.
53     *
54     * @see #setSelectionMode
55     */
56    int MULTIPLE_INTERVAL_SELECTION = 2;
57  
58  
59    /***
60     * Change the selection to be between index0 and index1 inclusive.
61     * If this represents a change to the current selection, then
62     * notify each ListSelectionListener. Note that index0 doesn't have
63     * to be less than or equal to index1.
64     *
65     * @param index0 one end of the interval.
66     * @param index1 other end of the interval
67     * @see #addBoardSelectionListener(org.cb.cardboard.BoardSelectionListener)
68     */
69    void setSelectionInterval(int index0, int index1);
70  
71  
72    /***
73     * Change the selection to be the set union of the current selection
74     * and the indices between index0 and index1 inclusive.  If this represents
75     * a change to the current selection, then notify each
76     * ListSelectionListener. Note that index0 doesn't have to be less
77     * than or equal to index1.
78     *
79     * @param index0 one end of the interval.
80     * @param index1 other end of the interval
81     * @see #addBoardSelectionListener
82     */
83    void addSelectionInterval(int index0, int index1);
84  
85  
86    /***
87     * Change the selection to be the set difference of the current selection
88     * and the indices between index0 and index1 inclusive.  If this represents
89     * a change to the current selection, then notify each
90     * ListSelectionListener.  Note that index0 doesn't have to be less
91     * than or equal to index1.
92     *
93     * @param index0 one end of the interval.
94     * @param index1 other end of the interval
95     * @see #addBoardSelectionListener
96     */
97    void removeSelectionInterval(int index0, int index1);
98  
99  
100   /***
101    * @return the first selected index or -1 if the selection is empty.
102    */
103   int getMinSelectionIndex();
104 
105 
106   /***
107    * @return the last selected index or -1 if the selection is empty.
108    */
109   int getMaxSelectionIndex();
110 
111 
112   /***
113    * @return <code>true</code> if the specified index is selected.
114    *
115    */
116   boolean isSelectedIndex(int index);
117 
118 
119   /***
120    * Return the first index argument from the most recent call to
121    * setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().
122    * The most recent index0 is considered the "anchor" and the most recent
123    * index1 is considered the "lead".  Some interfaces display these
124    * indices specially, e.g. Windows95 displays the lead index with a
125    * dotted yellow outline.
126    *
127    * @return the anchor selection index
128    *
129    * @see #getLeadSelectionIndex
130    * @see #setSelectionInterval
131    * @see #addSelectionInterval
132    */
133   int getAnchorSelectionIndex();
134 
135 
136   /***
137    * Set the anchor selection index.
138    *
139    * @see #getAnchorSelectionIndex
140    */
141   void setAnchorSelectionIndex(int index);
142 
143 
144   /***
145    * Return the second index argument from the most recent call to
146    * setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().
147    *
148    * @see #getAnchorSelectionIndex
149    * @see #setSelectionInterval
150    * @see #addSelectionInterval
151    */
152   int getLeadSelectionIndex();
153 
154   /***
155    * Set the lead selection index.
156    *
157    * @see #getLeadSelectionIndex
158    */
159   void setLeadSelectionIndex(int index);
160 
161   /***
162    * Change the selection to the empty set.  If this represents
163    * a change to the current selection then notify each ListSelectionListener.
164    *
165    * @see #addBoardSelectionListener
166    */
167   void clearSelection();
168 
169   /***
170    * @return <code>true<code> if no indices are selected.
171    */
172   boolean isSelectionEmpty();
173 
174   /***
175    * Insert length indices beginning before/after index.  This is typically
176    * called to sync the selection model with a corresponding change
177    * in the data model.
178    */
179   void insertIndexInterval(int index, int length, boolean before);
180 
181   /***
182    * Remove the indices in the interval index0,index1 (inclusive) from
183    * the selection model.  This is typically called to sync the selection
184    * model width a corresponding change in the data model.
185    */
186   void removeIndexInterval(int index0, int index1);
187 
188   /***
189    * This property is true if upcoming changes to the value
190    * of the model should be considered a single event. For example
191    * if the model is being updated in response to a user drag,
192    * the value of the valueIsAdjusting property will be set to true
193    * when the drag is initiated and be set to false when
194    * the drag is finished.  This property allows listeners to
195    * to update only when a change has been finalized, rather
196    * than always handling all of the intermediate values.
197    *
198    * @param valueIsAdjusting The new value of the property.
199    * @see #getValueIsAdjusting
200    */
201   void setValueIsAdjusting(boolean valueIsAdjusting);
202 
203   /***
204    * Returns true if the value is undergoing a series of changes.
205    *
206    * @return <code>true</code> if the value is currently adjusting
207    * @see #setValueIsAdjusting
208    */
209   boolean getValueIsAdjusting();
210 
211   /***
212    * Set the selection mode. The following selectionMode values are allowed:
213    * <ul>
214    * <li> <code>SINGLE_SELECTION</code>
215    * Only one list index can be selected at a time.  In this
216    * mode the setSelectionInterval and addSelectionInterval
217    * methods are equivalent, and only the second index
218    * argument (the "lead index") is used.
219    * <li> <code>SINGLE_INTERVAL_SELECTION</code>
220    * One contiguous index interval can be selected at a time.
221    * In this mode setSelectionInterval and addSelectionInterval
222    * are equivalent.
223    * <li> <code>MULTIPLE_INTERVAL_SELECTION</code>
224    * In this mode, there's no restriction on what can be selected.
225    * </ul>
226    *
227    * @see #getSelectionMode
228    */
229   void setSelectionMode(int selectionMode);
230 
231   /***
232    * Returns the current selection mode.
233    *
234    * @return The value of the selectionMode property.
235    * @see #setSelectionMode
236    */
237   int getSelectionMode();
238 
239   /***
240    * Add a listener to the list that's notified each time a change
241    * to the selection occurs.
242    *
243    * @param x the ListSelectionListener
244    * @see #removeBoardSelectionListener
245    * @see #setSelectionInterval
246    * @see #addSelectionInterval
247    * @see #removeSelectionInterval
248    * @see #clearSelection
249    * @see #insertIndexInterval
250    * @see #removeIndexInterval
251    */
252   void addBoardSelectionListener(BoardSelectionListener x);
253 
254   /***
255    * Remove a listener from the list that's notified each time a
256    * change to the selection occurs.
257    *
258    * @param x the ListSelectionListener
259    * @see #addBoardSelectionListener
260    */
261   void removeBoardSelectionListener(BoardSelectionListener x);
262 }