411363bc4b803f51e641389524f1beff7217cd08
[jalviewjs.git] / site / j2s / javax / swing / DefaultListSelectionModel.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["javax.swing.ListSelectionModel", "java.util.BitSet", "javax.swing.event.EventListenerList"], "javax.swing.DefaultListSelectionModel", ["java.lang.IllegalArgumentException", "javax.swing.event.ListSelectionEvent", "$.ListSelectionListener"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.selectionMode = 2;
5 this.minIndex = 2147483647;
6 this.maxIndex = -1;
7 this.anchorIndex = -1;
8 this.leadIndex = -1;
9 this.firstAdjustedIndex = 2147483647;
10 this.lastAdjustedIndex = -1;
11 this.isAdjusting = false;
12 this.firstChangedIndex = 2147483647;
13 this.lastChangedIndex = -1;
14 this.value = null;
15 this.listenerList = null;
16 this.leadAnchorNotificationEnabled = true;
17 Clazz.instantialize (this, arguments);
18 }, javax.swing, "DefaultListSelectionModel", null, [javax.swing.ListSelectionModel, Cloneable]);
19 Clazz.prepareFields (c$, function () {
20 this.value =  new java.util.BitSet (32);
21 this.listenerList =  new javax.swing.event.EventListenerList ();
22 });
23 Clazz.overrideMethod (c$, "getMinSelectionIndex", 
24 function () {
25 return this.isSelectionEmpty () ? -1 : this.minIndex;
26 });
27 Clazz.overrideMethod (c$, "getMaxSelectionIndex", 
28 function () {
29 return this.maxIndex;
30 });
31 Clazz.overrideMethod (c$, "getValueIsAdjusting", 
32 function () {
33 return this.isAdjusting;
34 });
35 Clazz.overrideMethod (c$, "getSelectionMode", 
36 function () {
37 return this.selectionMode;
38 });
39 Clazz.overrideMethod (c$, "setSelectionMode", 
40 function (selectionMode) {
41 switch (selectionMode) {
42 case 0:
43 case 1:
44 case 2:
45 this.selectionMode = selectionMode;
46 break;
47 default:
48 throw  new IllegalArgumentException ("invalid selectionMode");
49 }
50 }, "~N");
51 Clazz.overrideMethod (c$, "isSelectedIndex", 
52 function (index) {
53 return ((index < this.minIndex) || (index > this.maxIndex)) ? false : this.value.get (index);
54 }, "~N");
55 Clazz.overrideMethod (c$, "isSelectionEmpty", 
56 function () {
57 return (this.minIndex > this.maxIndex);
58 });
59 Clazz.overrideMethod (c$, "addListSelectionListener", 
60 function (l) {
61 this.listenerList.add (javax.swing.event.ListSelectionListener, l);
62 }, "javax.swing.event.ListSelectionListener");
63 Clazz.overrideMethod (c$, "removeListSelectionListener", 
64 function (l) {
65 this.listenerList.remove (javax.swing.event.ListSelectionListener, l);
66 }, "javax.swing.event.ListSelectionListener");
67 Clazz.defineMethod (c$, "getListSelectionListeners", 
68 function () {
69 return this.listenerList.getListeners (javax.swing.event.ListSelectionListener);
70 });
71 Clazz.defineMethod (c$, "fireValueChanged", 
72 function (isAdjusting) {
73 if (this.lastChangedIndex == -1) {
74 return;
75 }var oldFirstChangedIndex = this.firstChangedIndex;
76 var oldLastChangedIndex = this.lastChangedIndex;
77 this.firstChangedIndex = 2147483647;
78 this.lastChangedIndex = -1;
79 this.fireValueChanged (oldFirstChangedIndex, oldLastChangedIndex, isAdjusting);
80 }, "~B");
81 Clazz.defineMethod (c$, "fireValueChanged", 
82 function (firstIndex, lastIndex) {
83 this.fireValueChanged (firstIndex, lastIndex, this.getValueIsAdjusting ());
84 }, "~N,~N");
85 Clazz.defineMethod (c$, "fireValueChanged", 
86 function (firstIndex, lastIndex, isAdjusting) {
87 var listeners = this.listenerList.getListenerList ();
88 var e = null;
89 for (var i = listeners.length - 2; i >= 0; i -= 2) {
90 if (listeners[i] === javax.swing.event.ListSelectionListener) {
91 if (e == null) {
92 e =  new javax.swing.event.ListSelectionEvent (this, firstIndex, lastIndex, isAdjusting);
93 }(listeners[i + 1]).valueChanged (e);
94 }}
95 }, "~N,~N,~B");
96 Clazz.defineMethod (c$, "fireValueChanged", 
97  function () {
98 if (this.lastAdjustedIndex == -1) {
99 return;
100 }if (this.getValueIsAdjusting ()) {
101 this.firstChangedIndex = Math.min (this.firstChangedIndex, this.firstAdjustedIndex);
102 this.lastChangedIndex = Math.max (this.lastChangedIndex, this.lastAdjustedIndex);
103 }var oldFirstAdjustedIndex = this.firstAdjustedIndex;
104 var oldLastAdjustedIndex = this.lastAdjustedIndex;
105 this.firstAdjustedIndex = 2147483647;
106 this.lastAdjustedIndex = -1;
107 this.fireValueChanged (oldFirstAdjustedIndex, oldLastAdjustedIndex);
108 });
109 Clazz.defineMethod (c$, "getListeners", 
110 function (listenerType) {
111 return this.listenerList.getListeners (listenerType);
112 }, "Class");
113 Clazz.defineMethod (c$, "markAsDirty", 
114  function (r) {
115 this.firstAdjustedIndex = Math.min (this.firstAdjustedIndex, r);
116 this.lastAdjustedIndex = Math.max (this.lastAdjustedIndex, r);
117 }, "~N");
118 Clazz.defineMethod (c$, "set", 
119  function (r) {
120 if (this.value.get (r)) {
121 return;
122 }this.value.set (r);
123 this.markAsDirty (r);
124 this.minIndex = Math.min (this.minIndex, r);
125 this.maxIndex = Math.max (this.maxIndex, r);
126 }, "~N");
127 Clazz.defineMethod (c$, "clear", 
128  function (r) {
129 if (!this.value.get (r)) {
130 return;
131 }this.value.clear (r);
132 this.markAsDirty (r);
133 if (r == this.minIndex) {
134 for (this.minIndex = this.minIndex + 1; this.minIndex <= this.maxIndex; this.minIndex++) {
135 if (this.value.get (this.minIndex)) {
136 break;
137 }}
138 }if (r == this.maxIndex) {
139 for (this.maxIndex = this.maxIndex - 1; this.minIndex <= this.maxIndex; this.maxIndex--) {
140 if (this.value.get (this.maxIndex)) {
141 break;
142 }}
143 }if (this.isSelectionEmpty ()) {
144 this.minIndex = 2147483647;
145 this.maxIndex = -1;
146 }}, "~N");
147 Clazz.defineMethod (c$, "setLeadAnchorNotificationEnabled", 
148 function (flag) {
149 this.leadAnchorNotificationEnabled = flag;
150 }, "~B");
151 Clazz.defineMethod (c$, "isLeadAnchorNotificationEnabled", 
152 function () {
153 return this.leadAnchorNotificationEnabled;
154 });
155 Clazz.defineMethod (c$, "updateLeadAnchorIndices", 
156  function (anchorIndex, leadIndex) {
157 if (this.leadAnchorNotificationEnabled) {
158 if (this.anchorIndex != anchorIndex) {
159 if (this.anchorIndex != -1) {
160 this.markAsDirty (this.anchorIndex);
161 }this.markAsDirty (anchorIndex);
162 }if (this.leadIndex != leadIndex) {
163 if (this.leadIndex != -1) {
164 this.markAsDirty (this.leadIndex);
165 }this.markAsDirty (leadIndex);
166 }}this.anchorIndex = anchorIndex;
167 this.leadIndex = leadIndex;
168 }, "~N,~N");
169 Clazz.defineMethod (c$, "contains", 
170  function (a, b, i) {
171 return (i >= a) && (i <= b);
172 }, "~N,~N,~N");
173 Clazz.defineMethod (c$, "changeSelection", 
174  function (clearMin, clearMax, setMin, setMax, clearFirst) {
175 for (var i = Math.min (setMin, clearMin); i <= Math.max (setMax, clearMax); i++) {
176 var shouldClear = this.contains (clearMin, clearMax, i);
177 var shouldSet = this.contains (setMin, setMax, i);
178 if (shouldSet && shouldClear) {
179 if (clearFirst) {
180 shouldClear = false;
181 } else {
182 shouldSet = false;
183 }}if (shouldSet) {
184 this.set (i);
185 }if (shouldClear) {
186 this.clear (i);
187 }}
188 this.fireValueChanged ();
189 }, "~N,~N,~N,~N,~B");
190 Clazz.defineMethod (c$, "changeSelection", 
191  function (clearMin, clearMax, setMin, setMax) {
192 this.changeSelection (clearMin, clearMax, setMin, setMax, true);
193 }, "~N,~N,~N,~N");
194 Clazz.overrideMethod (c$, "clearSelection", 
195 function () {
196 this.removeSelectionIntervalImpl (this.minIndex, this.maxIndex, false);
197 });
198 Clazz.overrideMethod (c$, "setSelectionInterval", 
199 function (index0, index1) {
200 if (index0 == -1 || index1 == -1) {
201 return;
202 }if (this.getSelectionMode () == 0) {
203 index0 = index1;
204 }this.updateLeadAnchorIndices (index0, index1);
205 var clearMin = this.minIndex;
206 var clearMax = this.maxIndex;
207 var setMin = Math.min (index0, index1);
208 var setMax = Math.max (index0, index1);
209 this.changeSelection (clearMin, clearMax, setMin, setMax);
210 }, "~N,~N");
211 Clazz.overrideMethod (c$, "addSelectionInterval", 
212 function (index0, index1) {
213 if (index0 == -1 || index1 == -1) {
214 return;
215 }if (this.getSelectionMode () == 0) {
216 this.setSelectionInterval (index0, index1);
217 return;
218 }this.updateLeadAnchorIndices (index0, index1);
219 var clearMin = 2147483647;
220 var clearMax = -1;
221 var setMin = Math.min (index0, index1);
222 var setMax = Math.max (index0, index1);
223 if (this.getSelectionMode () == 1 && (setMax < this.minIndex - 1 || setMin > this.maxIndex + 1)) {
224 this.setSelectionInterval (index0, index1);
225 return;
226 }this.changeSelection (clearMin, clearMax, setMin, setMax);
227 }, "~N,~N");
228 Clazz.overrideMethod (c$, "removeSelectionInterval", 
229 function (index0, index1) {
230 this.removeSelectionIntervalImpl (index0, index1, true);
231 }, "~N,~N");
232 Clazz.defineMethod (c$, "removeSelectionIntervalImpl", 
233  function (index0, index1, changeLeadAnchor) {
234 if (index0 == -1 || index1 == -1) {
235 return;
236 }if (changeLeadAnchor) {
237 this.updateLeadAnchorIndices (index0, index1);
238 }var clearMin = Math.min (index0, index1);
239 var clearMax = Math.max (index0, index1);
240 var setMin = 2147483647;
241 var setMax = -1;
242 if (this.getSelectionMode () != 2 && clearMin > this.minIndex && clearMax < this.maxIndex) {
243 clearMax = this.maxIndex;
244 }this.changeSelection (clearMin, clearMax, setMin, setMax);
245 }, "~N,~N,~B");
246 Clazz.defineMethod (c$, "setState", 
247  function (index, state) {
248 if (state) {
249 this.set (index);
250 } else {
251 this.clear (index);
252 }}, "~N,~B");
253 Clazz.overrideMethod (c$, "insertIndexInterval", 
254 function (index, length, before) {
255 var insMinIndex = (before) ? index : index + 1;
256 var insMaxIndex = (insMinIndex + length) - 1;
257 for (var i = this.maxIndex; i >= insMinIndex; i--) {
258 this.setState (i + length, this.value.get (i));
259 }
260 var setInsertedValues = ((this.getSelectionMode () == 0) ? false : this.value.get (index));
261 for (var i = insMinIndex; i <= insMaxIndex; i++) {
262 this.setState (i, setInsertedValues);
263 }
264 var leadIndex = this.leadIndex;
265 if (leadIndex > index || (before && leadIndex == index)) {
266 leadIndex = this.leadIndex + length;
267 }var anchorIndex = this.anchorIndex;
268 if (anchorIndex > index || (before && anchorIndex == index)) {
269 anchorIndex = this.anchorIndex + length;
270 }if (leadIndex != this.leadIndex || anchorIndex != this.anchorIndex) {
271 this.updateLeadAnchorIndices (anchorIndex, leadIndex);
272 }this.fireValueChanged ();
273 }, "~N,~N,~B");
274 Clazz.overrideMethod (c$, "removeIndexInterval", 
275 function (index0, index1) {
276 var rmMinIndex = Math.min (index0, index1);
277 var rmMaxIndex = Math.max (index0, index1);
278 var gapLength = (rmMaxIndex - rmMinIndex) + 1;
279 for (var i = rmMinIndex; i <= this.maxIndex; i++) {
280 this.setState (i, this.value.get (i + gapLength));
281 }
282 var leadIndex = this.leadIndex;
283 if (leadIndex == 0 && rmMinIndex == 0) {
284 } else if (leadIndex > rmMaxIndex) {
285 leadIndex = this.leadIndex - gapLength;
286 } else if (leadIndex >= rmMinIndex) {
287 leadIndex = rmMinIndex - 1;
288 }var anchorIndex = this.anchorIndex;
289 if (anchorIndex == 0 && rmMinIndex == 0) {
290 } else if (anchorIndex > rmMaxIndex) {
291 anchorIndex = this.anchorIndex - gapLength;
292 } else if (anchorIndex >= rmMinIndex) {
293 anchorIndex = rmMinIndex - 1;
294 }if (leadIndex != this.leadIndex || anchorIndex != this.anchorIndex) {
295 this.updateLeadAnchorIndices (anchorIndex, leadIndex);
296 }this.fireValueChanged ();
297 }, "~N,~N");
298 Clazz.overrideMethod (c$, "setValueIsAdjusting", 
299 function (isAdjusting) {
300 if (isAdjusting != this.isAdjusting) {
301 this.isAdjusting = isAdjusting;
302 this.fireValueChanged (isAdjusting);
303 }}, "~B");
304 Clazz.overrideMethod (c$, "toString", 
305 function () {
306 var s = ((this.getValueIsAdjusting ()) ? "~" : "=") + this.value.toString ();
307 return this.getClass ().getName () + " " + Integer.toString (this.hashCode ()) + " " + s;
308 });
309 Clazz.defineMethod (c$, "clone", 
310 function () {
311 var clone = Clazz.superCall (this, javax.swing.DefaultListSelectionModel, "clone", []);
312 clone.value = this.value.clone ();
313 clone.listenerList =  new javax.swing.event.EventListenerList ();
314 return clone;
315 });
316 Clazz.overrideMethod (c$, "getAnchorSelectionIndex", 
317 function () {
318 return this.anchorIndex;
319 });
320 Clazz.overrideMethod (c$, "getLeadSelectionIndex", 
321 function () {
322 return this.leadIndex;
323 });
324 Clazz.overrideMethod (c$, "setAnchorSelectionIndex", 
325 function (anchorIndex) {
326 this.updateLeadAnchorIndices (anchorIndex, this.leadIndex);
327 this.fireValueChanged ();
328 }, "~N");
329 Clazz.defineMethod (c$, "moveLeadSelectionIndex", 
330 function (leadIndex) {
331 if (leadIndex == -1) {
332 if (this.anchorIndex != -1) {
333 return;
334 }}this.updateLeadAnchorIndices (this.anchorIndex, leadIndex);
335 this.fireValueChanged ();
336 }, "~N");
337 Clazz.overrideMethod (c$, "setLeadSelectionIndex", 
338 function (leadIndex) {
339 var anchorIndex = this.anchorIndex;
340 if (leadIndex == -1) {
341 if (anchorIndex == -1) {
342 this.updateLeadAnchorIndices (anchorIndex, leadIndex);
343 this.fireValueChanged ();
344 }return;
345 } else if (anchorIndex == -1) {
346 return;
347 }if (this.leadIndex == -1) {
348 this.leadIndex = leadIndex;
349 }var shouldSelect = this.value.get (this.anchorIndex);
350 if (this.getSelectionMode () == 0) {
351 anchorIndex = leadIndex;
352 shouldSelect = true;
353 }var oldMin = Math.min (this.anchorIndex, this.leadIndex);
354 var oldMax = Math.max (this.anchorIndex, this.leadIndex);
355 var newMin = Math.min (anchorIndex, leadIndex);
356 var newMax = Math.max (anchorIndex, leadIndex);
357 this.updateLeadAnchorIndices (anchorIndex, leadIndex);
358 if (shouldSelect) {
359 this.changeSelection (oldMin, oldMax, newMin, newMax);
360 } else {
361 this.changeSelection (newMin, newMax, oldMin, oldMax, false);
362 }}, "~N");
363 Clazz.defineStatics (c$,
364 "MIN", -1,
365 "MAX", 2147483647);
366 });