KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > ListSelectionModel


1 /*
2  * @(#)ListSelectionModel.java 1.21 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing;
9
10 import javax.swing.event.*;
11
12 /**
13  * This interface represents the current state of the
14  * selection for any of the components that display a
15  * list of values with stable indices. The selection is
16  * modeled as a set of intervals, each interval represents
17  * a contiguous range of selected list elements.
18  * The methods for modifying the set of selected intervals
19  * all take a pair of indices, index0 and index1, that represent
20  * a closed interval, i.e. the interval includes both index0 and
21  * index1.
22  *
23  * @version 1.21 12/19/03
24  * @author Hans Muller
25  * @author Philip Milne
26  * @see DefaultListSelectionModel
27  */

28
29 public interface ListSelectionModel
30 {
31     /**
32      * A value for the selectionMode property: select one list index
33      * at a time.
34      *
35      * @see #setSelectionMode
36      */

37     int SINGLE_SELECTION = 0;
38
39     /**
40      * A value for the selectionMode property: select one contiguous
41      * range of indices at a time.
42      *
43      * @see #setSelectionMode
44      */

45     int SINGLE_INTERVAL_SELECTION = 1;
46
47     /**
48      * A value for the selectionMode property: select one or more
49      * contiguous ranges of indices at a time.
50      *
51      * @see #setSelectionMode
52      */

53     int MULTIPLE_INTERVAL_SELECTION = 2;
54
55
56     /**
57      * Change the selection to be between index0 and index1 inclusive.
58      * If this represents a change to the current selection, then
59      * notify each ListSelectionListener. Note that index0 doesn't have
60      * to be less than or equal to index1.
61      *
62      * @param index0 one end of the interval.
63      * @param index1 other end of the interval
64      * @see #addListSelectionListener
65      */

66     void setSelectionInterval(int index0, int index1);
67
68
69     /**
70      * Change the selection to be the set union of the current selection
71      * and the indices between index0 and index1 inclusive. If this represents
72      * a change to the current selection, then notify each
73      * ListSelectionListener. Note that index0 doesn't have to be less
74      * than or equal to index1.
75      *
76      * @param index0 one end of the interval.
77      * @param index1 other end of the interval
78      * @see #addListSelectionListener
79      */

80     void addSelectionInterval(int index0, int index1);
81
82
83     /**
84      * Change the selection to be the set difference of the current selection
85      * and the indices between index0 and index1 inclusive. If this represents
86      * a change to the current selection, then notify each
87      * ListSelectionListener. Note that index0 doesn't have to be less
88      * than or equal to index1.
89      *
90      * @param index0 one end of the interval.
91      * @param index1 other end of the interval
92      * @see #addListSelectionListener
93      */

94     void removeSelectionInterval(int index0, int index1);
95
96
97     /**
98      * Returns the first selected index or -1 if the selection is empty.
99      */

100     int getMinSelectionIndex();
101
102
103     /**
104      * Returns the last selected index or -1 if the selection is empty.
105      */

106     int getMaxSelectionIndex();
107
108
109     /**
110      * Returns true if the specified index is selected.
111      */

112     boolean isSelectedIndex(int index);
113
114     
115     /**
116      * Return the first index argument from the most recent call to
117      * setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().
118      * The most recent index0 is considered the "anchor" and the most recent
119      * index1 is considered the "lead". Some interfaces display these
120      * indices specially, e.g. Windows95 displays the lead index with a
121      * dotted yellow outline.
122      *
123      * @see #getLeadSelectionIndex
124      * @see #setSelectionInterval
125      * @see #addSelectionInterval
126      */

127     int getAnchorSelectionIndex();
128
129
130     /**
131      * Set the anchor selection index.
132      *
133      * @see #getAnchorSelectionIndex
134      */

135     void setAnchorSelectionIndex(int index);
136
137
138     /**
139      * Return the second index argument from the most recent call to
140      * setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().
141      *
142      * @see #getAnchorSelectionIndex
143      * @see #setSelectionInterval
144      * @see #addSelectionInterval
145      */

146     int getLeadSelectionIndex();
147
148     /**
149      * Set the lead selection index.
150      *
151      * @see #getLeadSelectionIndex
152      */

153     void setLeadSelectionIndex(int index);
154
155     /**
156      * Change the selection to the empty set. If this represents
157      * a change to the current selection then notify each ListSelectionListener.
158      *
159      * @see #addListSelectionListener
160      */

161     void clearSelection();
162
163     /**
164      * Returns true if no indices are selected.
165      */

166     boolean isSelectionEmpty();
167     
168     /**
169      * Insert length indices beginning before/after index. This is typically
170      * called to sync the selection model with a corresponding change
171      * in the data model.
172      */

173     void insertIndexInterval(int index, int length, boolean before);
174
175     /**
176      * Remove the indices in the interval index0,index1 (inclusive) from
177      * the selection model. This is typically called to sync the selection
178      * model width a corresponding change in the data model.
179      */

180     void removeIndexInterval(int index0, int index1);
181
182     /**
183      * This property is true if upcoming changes to the value
184      * of the model should be considered a single event. For example
185      * if the model is being updated in response to a user drag,
186      * the value of the valueIsAdjusting property will be set to true
187      * when the drag is initiated and be set to false when
188      * the drag is finished. This property allows listeners to
189      * to update only when a change has been finalized, rather
190      * than always handling all of the intermediate values.
191      *
192      * @param valueIsAdjusting The new value of the property.
193      * @see #getValueIsAdjusting
194      */

195     void setValueIsAdjusting(boolean valueIsAdjusting);
196
197     /**
198      * Returns true if the value is undergoing a series of changes.
199      * @return true if the value is currently adjusting
200      * @see #setValueIsAdjusting
201      */

202     boolean getValueIsAdjusting();
203
204     /**
205      * Set the selection mode. The following selectionMode values are allowed:
206      * <ul>
207      * <li> <code>SINGLE_SELECTION</code>
208      * Only one list index can be selected at a time. In this
209      * mode the setSelectionInterval and addSelectionInterval
210      * methods are equivalent, and only the second index
211      * argument (the "lead index") is used.
212      * <li> <code>SINGLE_INTERVAL_SELECTION</code>
213      * One contiguous index interval can be selected at a time.
214      * In this mode setSelectionInterval and addSelectionInterval
215      * are equivalent.
216      * <li> <code>MULTIPLE_INTERVAL_SELECTION</code>
217      * In this mode, there's no restriction on what can be selected.
218      * </ul>
219      *
220      * @see #getSelectionMode
221      */

222     void setSelectionMode(int selectionMode);
223
224     /**
225      * Returns the current selection mode.
226      * @return The value of the selectionMode property.
227      * @see #setSelectionMode
228      */

229     int getSelectionMode();
230
231     /**
232      * Add a listener to the list that's notified each time a change
233      * to the selection occurs.
234      *
235      * @param x the ListSelectionListener
236      * @see #removeListSelectionListener
237      * @see #setSelectionInterval
238      * @see #addSelectionInterval
239      * @see #removeSelectionInterval
240      * @see #clearSelection
241      * @see #insertIndexInterval
242      * @see #removeIndexInterval
243      */

244     void addListSelectionListener(ListSelectionListener x);
245
246     /**
247      * Remove a listener from the list that's notified each time a
248      * change to the selection occurs.
249      *
250      * @param x the ListSelectionListener
251      * @see #addListSelectionListener
252      */

253     void removeListSelectionListener(ListSelectionListener x);
254 }
255
256
Popular Tags