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