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;
9 this.firstAdjustedIndex = 2147483647;
10 this.lastAdjustedIndex = -1;
11 this.isAdjusting = false;
12 this.firstChangedIndex = 2147483647;
13 this.lastChangedIndex = -1;
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 ();
23 Clazz.overrideMethod (c$, "getMinSelectionIndex",
25 return this.isSelectionEmpty () ? -1 : this.minIndex;
27 Clazz.overrideMethod (c$, "getMaxSelectionIndex",
31 Clazz.overrideMethod (c$, "getValueIsAdjusting",
33 return this.isAdjusting;
35 Clazz.overrideMethod (c$, "getSelectionMode",
37 return this.selectionMode;
39 Clazz.overrideMethod (c$, "setSelectionMode",
40 function (selectionMode) {
41 switch (selectionMode) {
45 this.selectionMode = selectionMode;
48 throw new IllegalArgumentException ("invalid selectionMode");
51 Clazz.overrideMethod (c$, "isSelectedIndex",
53 return ((index < this.minIndex) || (index > this.maxIndex)) ? false : this.value.get (index);
55 Clazz.overrideMethod (c$, "isSelectionEmpty",
57 return (this.minIndex > this.maxIndex);
59 Clazz.overrideMethod (c$, "addListSelectionListener",
61 this.listenerList.add (javax.swing.event.ListSelectionListener, l);
62 }, "javax.swing.event.ListSelectionListener");
63 Clazz.overrideMethod (c$, "removeListSelectionListener",
65 this.listenerList.remove (javax.swing.event.ListSelectionListener, l);
66 }, "javax.swing.event.ListSelectionListener");
67 Clazz.defineMethod (c$, "getListSelectionListeners",
69 return this.listenerList.getListeners (javax.swing.event.ListSelectionListener);
71 Clazz.defineMethod (c$, "fireValueChanged",
72 function (isAdjusting) {
73 if (this.lastChangedIndex == -1) {
75 }var oldFirstChangedIndex = this.firstChangedIndex;
76 var oldLastChangedIndex = this.lastChangedIndex;
77 this.firstChangedIndex = 2147483647;
78 this.lastChangedIndex = -1;
79 this.fireValueChanged (oldFirstChangedIndex, oldLastChangedIndex, isAdjusting);
81 Clazz.defineMethod (c$, "fireValueChanged",
82 function (firstIndex, lastIndex) {
83 this.fireValueChanged (firstIndex, lastIndex, this.getValueIsAdjusting ());
85 Clazz.defineMethod (c$, "fireValueChanged",
86 function (firstIndex, lastIndex, isAdjusting) {
87 var listeners = this.listenerList.getListenerList ();
89 for (var i = listeners.length - 2; i >= 0; i -= 2) {
90 if (listeners[i] === javax.swing.event.ListSelectionListener) {
92 e = new javax.swing.event.ListSelectionEvent (this, firstIndex, lastIndex, isAdjusting);
93 }(listeners[i + 1]).valueChanged (e);
96 Clazz.defineMethod (c$, "fireValueChanged",
98 if (this.lastAdjustedIndex == -1) {
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);
109 Clazz.defineMethod (c$, "getListeners",
110 function (listenerType) {
111 return this.listenerList.getListeners (listenerType);
113 Clazz.defineMethod (c$, "markAsDirty",
115 this.firstAdjustedIndex = Math.min (this.firstAdjustedIndex, r);
116 this.lastAdjustedIndex = Math.max (this.lastAdjustedIndex, r);
118 Clazz.defineMethod (c$, "set",
120 if (this.value.get (r)) {
123 this.markAsDirty (r);
124 this.minIndex = Math.min (this.minIndex, r);
125 this.maxIndex = Math.max (this.maxIndex, r);
127 Clazz.defineMethod (c$, "clear",
129 if (!this.value.get (r)) {
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)) {
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)) {
143 }if (this.isSelectionEmpty ()) {
144 this.minIndex = 2147483647;
147 Clazz.defineMethod (c$, "setLeadAnchorNotificationEnabled",
149 this.leadAnchorNotificationEnabled = flag;
151 Clazz.defineMethod (c$, "isLeadAnchorNotificationEnabled",
153 return this.leadAnchorNotificationEnabled;
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;
169 Clazz.defineMethod (c$, "contains",
171 return (i >= a) && (i <= b);
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) {
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);
194 Clazz.overrideMethod (c$, "clearSelection",
196 this.removeSelectionIntervalImpl (this.minIndex, this.maxIndex, false);
198 Clazz.overrideMethod (c$, "setSelectionInterval",
199 function (index0, index1) {
200 if (index0 == -1 || index1 == -1) {
202 }if (this.getSelectionMode () == 0) {
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);
211 Clazz.overrideMethod (c$, "addSelectionInterval",
212 function (index0, index1) {
213 if (index0 == -1 || index1 == -1) {
215 }if (this.getSelectionMode () == 0) {
216 this.setSelectionInterval (index0, index1);
218 }this.updateLeadAnchorIndices (index0, index1);
219 var clearMin = 2147483647;
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);
226 }this.changeSelection (clearMin, clearMax, setMin, setMax);
228 Clazz.overrideMethod (c$, "removeSelectionInterval",
229 function (index0, index1) {
230 this.removeSelectionIntervalImpl (index0, index1, true);
232 Clazz.defineMethod (c$, "removeSelectionIntervalImpl",
233 function (index0, index1, changeLeadAnchor) {
234 if (index0 == -1 || index1 == -1) {
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;
242 if (this.getSelectionMode () != 2 && clearMin > this.minIndex && clearMax < this.maxIndex) {
243 clearMax = this.maxIndex;
244 }this.changeSelection (clearMin, clearMax, setMin, setMax);
246 Clazz.defineMethod (c$, "setState",
247 function (index, state) {
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));
260 var setInsertedValues = ((this.getSelectionMode () == 0) ? false : this.value.get (index));
261 for (var i = insMinIndex; i <= insMaxIndex; i++) {
262 this.setState (i, setInsertedValues);
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 ();
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));
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 ();
298 Clazz.overrideMethod (c$, "setValueIsAdjusting",
299 function (isAdjusting) {
300 if (isAdjusting != this.isAdjusting) {
301 this.isAdjusting = isAdjusting;
302 this.fireValueChanged (isAdjusting);
304 Clazz.overrideMethod (c$, "toString",
306 var s = ((this.getValueIsAdjusting ()) ? "~" : "=") + this.value.toString ();
307 return this.getClass ().getName () + " " + Integer.toString (this.hashCode ()) + " " + s;
309 Clazz.defineMethod (c$, "clone",
311 var clone = Clazz.superCall (this, javax.swing.DefaultListSelectionModel, "clone", []);
312 clone.value = this.value.clone ();
313 clone.listenerList = new javax.swing.event.EventListenerList ();
316 Clazz.overrideMethod (c$, "getAnchorSelectionIndex",
318 return this.anchorIndex;
320 Clazz.overrideMethod (c$, "getLeadSelectionIndex",
322 return this.leadIndex;
324 Clazz.overrideMethod (c$, "setAnchorSelectionIndex",
325 function (anchorIndex) {
326 this.updateLeadAnchorIndices (anchorIndex, this.leadIndex);
327 this.fireValueChanged ();
329 Clazz.defineMethod (c$, "moveLeadSelectionIndex",
330 function (leadIndex) {
331 if (leadIndex == -1) {
332 if (this.anchorIndex != -1) {
334 }}this.updateLeadAnchorIndices (this.anchorIndex, leadIndex);
335 this.fireValueChanged ();
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 ();
345 } else if (anchorIndex == -1) {
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;
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);
359 this.changeSelection (oldMin, oldMax, newMin, newMax);
361 this.changeSelection (newMin, newMax, oldMin, oldMax, false);
363 Clazz.defineStatics (c$,