1 Clazz.declarePackage ("javax.swing.tree");
2 Clazz.load (["javax.swing.tree.TreeSelectionModel", "javax.swing.event.EventListenerList"], ["javax.swing.tree.PathPlaceHolder", "$.DefaultTreeSelectionModel"], ["java.lang.Boolean", "$.StringBuffer", "java.util.BitSet", "$.Hashtable", "$.Vector", "javax.swing.DefaultListSelectionModel", "javax.swing.event.SwingPropertyChangeSupport", "$.TreeSelectionEvent", "$.TreeSelectionListener"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.changeSupport = null;
6 this.listenerList = null;
8 this.listSelectionModel = null;
9 this.selectionMode = 0;
13 this.uniquePaths = null;
14 this.lastPaths = null;
15 this.tempPaths = null;
16 Clazz.instantialize (this, arguments);
17 }, javax.swing.tree, "DefaultTreeSelectionModel", null, [Cloneable, javax.swing.tree.TreeSelectionModel]);
18 Clazz.prepareFields (c$, function () {
19 this.listenerList = new javax.swing.event.EventListenerList ();
21 Clazz.makeConstructor (c$,
23 this.listSelectionModel = new javax.swing.DefaultListSelectionModel ();
24 this.selectionMode = 4;
25 this.leadIndex = this.leadRow = -1;
26 this.uniquePaths = new java.util.Hashtable ();
27 this.lastPaths = new java.util.Hashtable ();
28 this.tempPaths = new Array (1);
30 Clazz.overrideMethod (c$, "setRowMapper",
31 function (newMapper) {
32 this.rowMapper = newMapper;
33 this.resetRowSelection ();
34 }, "javax.swing.tree.RowMapper");
35 Clazz.overrideMethod (c$, "getRowMapper",
37 return this.rowMapper;
39 Clazz.overrideMethod (c$, "setSelectionMode",
41 var oldMode = this.selectionMode;
42 this.selectionMode = mode;
43 if (this.selectionMode != 1 && this.selectionMode != 2 && this.selectionMode != 4) this.selectionMode = 4;
44 if (oldMode != this.selectionMode && this.changeSupport != null) this.changeSupport.firePropertyChange ("selectionMode", new Integer (oldMode), new Integer (this.selectionMode));
46 Clazz.overrideMethod (c$, "getSelectionMode",
48 return this.selectionMode;
50 Clazz.overrideMethod (c$, "setSelectionPath",
52 if (path == null) this.setSelectionPaths (null);
54 var newPaths = new Array (1);
56 this.setSelectionPaths (newPaths);
57 }}, "javax.swing.tree.TreePath");
58 Clazz.overrideMethod (c$, "setSelectionPaths",
65 if (paths == null) newCount = 0;
66 else newCount = paths.length;
67 if (this.selection == null) oldCount = 0;
68 else oldCount = this.selection.length;
69 if ((newCount + oldCount) != 0) {
70 if (this.selectionMode == 1) {
72 paths = new Array (1);
75 }} else if (this.selectionMode == 2) {
76 if (newCount > 0 && !this.arePathsContiguous (paths)) {
77 paths = new Array (1);
81 var beginLeadPath = this.leadPath;
82 var cPaths = new java.util.Vector (newCount + oldCount);
83 this.lastPaths.clear ();
85 for (newCounter = 0; newCounter < newCount; newCounter++) {
86 if (paths[newCounter] != null && this.lastPaths.get (paths[newCounter]) == null) {
88 this.lastPaths.put (paths[newCounter], Boolean.TRUE);
89 if (this.uniquePaths.get (paths[newCounter]) == null) {
90 cPaths.addElement ( new javax.swing.tree.PathPlaceHolder (paths[newCounter], true));
91 }this.leadPath = paths[newCounter];
94 if (validCount == 0) {
96 } else if (validCount != newCount) {
97 var keys = this.lastPaths.keys ();
98 newSelection = new Array (validCount);
100 while (keys.hasMoreElements ()) {
101 newSelection[validCount++] = keys.nextElement ();
104 newSelection = new Array (paths.length);
105 System.arraycopy (paths, 0, newSelection, 0, paths.length);
106 }for (oldCounter = 0; oldCounter < oldCount; oldCounter++) if (this.selection[oldCounter] != null && this.lastPaths.get (this.selection[oldCounter]) == null) cPaths.addElement ( new javax.swing.tree.PathPlaceHolder (this.selection[oldCounter], false));
108 this.selection = newSelection;
109 var tempHT = this.uniquePaths;
110 this.uniquePaths = this.lastPaths;
111 this.lastPaths = tempHT;
112 this.lastPaths.clear ();
113 if (this.selection != null) this.insureUniqueness ();
114 this.updateLeadIndex ();
115 this.resetRowSelection ();
116 if (cPaths.size () > 0) this.notifyPathChange (cPaths, beginLeadPath);
118 Clazz.overrideMethod (c$, "addSelectionPath",
121 var toAdd = new Array (1);
123 this.addSelectionPaths (toAdd);
124 }}, "javax.swing.tree.TreePath");
125 Clazz.overrideMethod (c$, "addSelectionPaths",
127 var newPathLength = ((paths == null) ? 0 : paths.length);
128 if (newPathLength > 0) {
129 if (this.selectionMode == 1) {
130 this.setSelectionPaths (paths);
131 } else if (this.selectionMode == 2 && !this.canPathsBeAdded (paths)) {
132 if (this.arePathsContiguous (paths)) {
133 this.setSelectionPaths (paths);
135 var newPaths = new Array (1);
136 newPaths[0] = paths[0];
137 this.setSelectionPaths (newPaths);
142 var beginLeadPath = this.leadPath;
144 if (this.selection == null) oldCount = 0;
145 else oldCount = this.selection.length;
146 this.lastPaths.clear ();
147 for (counter = 0, validCount = 0; counter < newPathLength; counter++) {
148 if (paths[counter] != null) {
149 if (this.uniquePaths.get (paths[counter]) == null) {
151 if (cPaths == null) cPaths = new java.util.Vector ();
152 cPaths.addElement ( new javax.swing.tree.PathPlaceHolder (paths[counter], true));
153 this.uniquePaths.put (paths[counter], Boolean.TRUE);
154 this.lastPaths.put (paths[counter], Boolean.TRUE);
155 }this.leadPath = paths[counter];
157 if (this.leadPath == null) {
158 this.leadPath = beginLeadPath;
159 }if (validCount > 0) {
160 var newSelection = new Array (oldCount + validCount);
161 if (oldCount > 0) System.arraycopy (this.selection, 0, newSelection, 0, oldCount);
162 if (validCount != paths.length) {
163 var newPaths = this.lastPaths.keys ();
165 while (newPaths.hasMoreElements ()) {
166 newSelection[counter++] = newPaths.nextElement ();
169 System.arraycopy (paths, 0, newSelection, oldCount, validCount);
170 }this.selection = newSelection;
171 this.insureUniqueness ();
172 this.updateLeadIndex ();
173 this.resetRowSelection ();
174 this.notifyPathChange (cPaths, beginLeadPath);
175 } else this.leadPath = beginLeadPath;
176 this.lastPaths.clear ();
178 Clazz.overrideMethod (c$, "removeSelectionPath",
181 var rPath = new Array (1);
183 this.removeSelectionPaths (rPath);
184 }}, "javax.swing.tree.TreePath");
185 Clazz.overrideMethod (c$, "removeSelectionPaths",
187 if (paths != null && this.selection != null && paths.length > 0) {
188 if (!this.canPathsBeRemoved (paths)) {
189 this.clearSelection ();
191 var pathsToRemove = null;
192 for (var removeCounter = paths.length - 1; removeCounter >= 0; removeCounter--) {
193 if (paths[removeCounter] != null) {
194 if (this.uniquePaths.get (paths[removeCounter]) != null) {
195 if (pathsToRemove == null) pathsToRemove = new java.util.Vector (paths.length);
196 this.uniquePaths.remove (paths[removeCounter]);
197 pathsToRemove.addElement ( new javax.swing.tree.PathPlaceHolder (paths[removeCounter], false));
199 if (pathsToRemove != null) {
200 var removeCount = pathsToRemove.size ();
201 var beginLeadPath = this.leadPath;
202 if (removeCount == this.selection.length) {
203 this.selection = null;
205 var pEnum = this.uniquePaths.keys ();
207 this.selection = new Array (this.selection.length - removeCount);
208 while (pEnum.hasMoreElements ()) {
209 this.selection[validCount++] = pEnum.nextElement ();
211 }if (this.leadPath != null && this.uniquePaths.get (this.leadPath) == null) {
212 if (this.selection != null) {
213 this.leadPath = this.selection[this.selection.length - 1];
215 this.leadPath = null;
216 }} else if (this.selection != null) {
217 this.leadPath = this.selection[this.selection.length - 1];
219 this.leadPath = null;
220 }this.updateLeadIndex ();
221 this.resetRowSelection ();
222 this.notifyPathChange (pathsToRemove, beginLeadPath);
224 Clazz.overrideMethod (c$, "getSelectionPath",
226 if (this.selection != null) return this.selection[0];
229 Clazz.overrideMethod (c$, "getSelectionPaths",
231 if (this.selection != null) {
232 var pathSize = this.selection.length;
233 var result = new Array (pathSize);
234 System.arraycopy (this.selection, 0, result, 0, pathSize);
238 Clazz.overrideMethod (c$, "getSelectionCount",
240 return (this.selection == null) ? 0 : this.selection.length;
242 Clazz.overrideMethod (c$, "isPathSelected",
244 return (path != null) ? (this.uniquePaths.get (path) != null) : false;
245 }, "javax.swing.tree.TreePath");
246 Clazz.overrideMethod (c$, "isSelectionEmpty",
248 return (this.selection == null);
250 Clazz.overrideMethod (c$, "clearSelection",
252 if (this.selection != null) {
253 var selSize = this.selection.length;
254 var newness = Clazz.newBooleanArray (selSize, false);
255 for (var counter = 0; counter < selSize; counter++) newness[counter] = false;
257 var event = new javax.swing.event.TreeSelectionEvent (this, this.selection, newness, this.leadPath, null);
258 this.leadPath = null;
259 this.leadIndex = this.leadRow = -1;
260 this.uniquePaths.clear ();
261 this.selection = null;
262 this.resetRowSelection ();
263 this.fireValueChanged (event);
265 Clazz.overrideMethod (c$, "addTreeSelectionListener",
267 this.listenerList.add (javax.swing.event.TreeSelectionListener, x);
268 }, "javax.swing.event.TreeSelectionListener");
269 Clazz.overrideMethod (c$, "removeTreeSelectionListener",
271 this.listenerList.remove (javax.swing.event.TreeSelectionListener, x);
272 }, "javax.swing.event.TreeSelectionListener");
273 Clazz.defineMethod (c$, "getTreeSelectionListeners",
275 return this.listenerList.getListeners (javax.swing.event.TreeSelectionListener);
277 Clazz.defineMethod (c$, "fireValueChanged",
279 var listeners = this.listenerList.getListenerList ();
280 for (var i = listeners.length - 2; i >= 0; i -= 2) {
281 if (listeners[i] === javax.swing.event.TreeSelectionListener) {
282 (listeners[i + 1]).valueChanged (e);
284 }, "javax.swing.event.TreeSelectionEvent");
285 Clazz.defineMethod (c$, "getListeners",
286 function (listenerType) {
287 return this.listenerList.getListeners (listenerType);
289 Clazz.overrideMethod (c$, "getSelectionRows",
291 if (this.rowMapper != null && this.selection != null) {
292 var rows = this.rowMapper.getRowsForPaths (this.selection);
295 for (var counter = rows.length - 1; counter >= 0; counter--) {
296 if (rows[counter] == -1) {
299 if (invisCount > 0) {
300 if (invisCount == rows.length) {
303 var tempRows = Clazz.newIntArray (rows.length - invisCount, 0);
304 for (var counter = rows.length - 1, visCounter = 0; counter >= 0; counter--) {
305 if (rows[counter] != -1) {
306 tempRows[visCounter++] = rows[counter];
312 Clazz.overrideMethod (c$, "getMinSelectionRow",
314 return this.listSelectionModel.getMinSelectionIndex ();
316 Clazz.overrideMethod (c$, "getMaxSelectionRow",
318 return this.listSelectionModel.getMaxSelectionIndex ();
320 Clazz.overrideMethod (c$, "isRowSelected",
322 return this.listSelectionModel.isSelectedIndex (row);
324 Clazz.overrideMethod (c$, "resetRowSelection",
326 this.listSelectionModel.clearSelection ();
327 if (this.selection != null && this.rowMapper != null) {
330 var rows = this.rowMapper.getRowsForPaths (this.selection);
331 for (var counter = 0, maxCounter = this.selection.length; counter < maxCounter; counter++) {
332 aRow = rows[counter];
334 this.listSelectionModel.addSelectionInterval (aRow, aRow);
336 if (this.leadIndex != -1 && rows != null) {
337 this.leadRow = rows[this.leadIndex];
338 } else if (this.leadPath != null) {
339 this.tempPaths[0] = this.leadPath;
340 rows = this.rowMapper.getRowsForPaths (this.tempPaths);
341 this.leadRow = (rows != null) ? rows[0] : -1;
344 }this.insureRowContinuity ();
345 } else this.leadRow = -1;
347 Clazz.overrideMethod (c$, "getLeadSelectionRow",
351 Clazz.overrideMethod (c$, "getLeadSelectionPath",
353 return this.leadPath;
355 Clazz.overrideMethod (c$, "addPropertyChangeListener",
356 function (listener) {
357 if (this.changeSupport == null) {
358 this.changeSupport = new javax.swing.event.SwingPropertyChangeSupport (this);
359 }this.changeSupport.addPropertyChangeListener (listener);
360 }, "java.beans.PropertyChangeListener");
361 Clazz.overrideMethod (c$, "removePropertyChangeListener",
362 function (listener) {
363 if (this.changeSupport == null) {
365 }this.changeSupport.removePropertyChangeListener (listener);
366 }, "java.beans.PropertyChangeListener");
367 Clazz.defineMethod (c$, "getPropertyChangeListeners",
369 if (this.changeSupport == null) {
370 return new Array (0);
371 }return this.changeSupport.getPropertyChangeListeners ();
373 Clazz.defineMethod (c$, "insureRowContinuity",
375 if (this.selectionMode == 2 && this.selection != null && this.rowMapper != null) {
376 var lModel = this.listSelectionModel;
377 var min = lModel.getMinSelectionIndex ();
379 for (var counter = min, maxCounter = lModel.getMaxSelectionIndex (); counter <= maxCounter; counter++) {
380 if (!lModel.isSelectedIndex (counter)) {
381 if (counter == min) {
382 this.clearSelection ();
384 var newSel = new Array (counter - min);
385 var selectionIndex = this.rowMapper.getRowsForPaths (this.selection);
386 for (var i = 0; i < selectionIndex.length; i++) {
387 if (selectionIndex[i] < counter) {
388 newSel[selectionIndex[i] - min] = this.selection[i];
390 this.setSelectionPaths (newSel);
393 }} else if (this.selectionMode == 1 && this.selection != null && this.selection.length > 1) {
394 this.setSelectionPath (this.selection[0]);
396 Clazz.defineMethod (c$, "arePathsContiguous",
398 if (this.rowMapper == null || paths.length < 2) return true;
400 var bitSet = new java.util.BitSet (32);
404 var pathCount = paths.length;
406 var tempPath = new Array (1);
407 tempPath[0] = paths[0];
408 min = this.rowMapper.getRowsForPaths (tempPath)[0];
409 for (counter = 0; counter < pathCount; counter++) {
410 if (paths[counter] != null) {
411 tempPath[0] = paths[counter];
412 var rows = this.rowMapper.getRowsForPaths (tempPath);
416 if (anIndex == -1 || anIndex < (min - pathCount) || anIndex > (min + pathCount)) return false;
417 if (anIndex < min) min = anIndex;
418 if (!bitSet.get (anIndex)) {
419 bitSet.set (anIndex);
422 var maxCounter = validCount + min;
423 for (counter = min; counter < maxCounter; counter++) if (!bitSet.get (counter)) return false;
427 Clazz.defineMethod (c$, "canPathsBeAdded",
429 if (paths == null || paths.length == 0 || this.rowMapper == null || this.selection == null || this.selectionMode == 4) return true;
431 var bitSet = new java.util.BitSet ();
432 var lModel = this.listSelectionModel;
435 var min = lModel.getMinSelectionIndex ();
436 var max = lModel.getMaxSelectionIndex ();
437 var tempPath = new Array (1);
439 for (counter = min; counter <= max; counter++) {
440 if (lModel.isSelectedIndex (counter)) bitSet.set (counter);
443 tempPath[0] = paths[0];
444 min = max = this.rowMapper.getRowsForPaths (tempPath)[0];
445 }for (counter = paths.length - 1; counter >= 0; counter--) {
446 if (paths[counter] != null) {
447 tempPath[0] = paths[counter];
448 var rows = this.rowMapper.getRowsForPaths (tempPath);
452 min = Math.min (anIndex, min);
453 max = Math.max (anIndex, max);
454 if (anIndex == -1) return false;
455 bitSet.set (anIndex);
457 for (counter = min; counter <= max; counter++) if (!bitSet.get (counter)) return false;
461 Clazz.defineMethod (c$, "canPathsBeRemoved",
463 if (this.rowMapper == null || this.selection == null || this.selectionMode == 4) return true;
465 var bitSet = new java.util.BitSet ();
467 var pathCount = paths.length;
471 var tempPath = new Array (1);
473 this.lastPaths.clear ();
474 for (counter = 0; counter < pathCount; counter++) {
475 if (paths[counter] != null) {
476 this.lastPaths.put (paths[counter], Boolean.TRUE);
478 for (counter = this.selection.length - 1; counter >= 0; counter--) {
479 if (this.lastPaths.get (this.selection[counter]) == null) {
480 tempPath[0] = this.selection[counter];
481 rows = this.rowMapper.getRowsForPaths (tempPath);
482 if (rows != null && rows[0] != -1 && !bitSet.get (rows[0])) {
484 if (min == -1) min = rows[0];
485 else min = Math.min (min, rows[0]);
486 bitSet.set (rows[0]);
488 this.lastPaths.clear ();
489 if (validCount > 1) {
490 for (counter = min + validCount - 1; counter >= min; counter--) if (!bitSet.get (counter)) return false;
494 Clazz.defineMethod (c$, "notifyPathChange",
495 function (changedPaths, oldLeadSelection) {
496 var cPathCount = changedPaths.size ();
497 var newness = Clazz.newBooleanArray (cPathCount, false);
498 var paths = new Array (cPathCount);
500 for (var counter = 0; counter < cPathCount; counter++) {
501 placeholder = changedPaths.elementAt (counter);
502 newness[counter] = placeholder.isNew;
503 paths[counter] = placeholder.path;
505 var event = new javax.swing.event.TreeSelectionEvent (this, paths, newness, oldLeadSelection, this.leadPath);
506 this.fireValueChanged (event);
507 }, "java.util.Vector,javax.swing.tree.TreePath");
508 Clazz.defineMethod (c$, "updateLeadIndex",
510 if (this.leadPath != null) {
511 if (this.selection == null) {
512 this.leadPath = null;
513 this.leadIndex = this.leadRow = -1;
515 this.leadRow = this.leadIndex = -1;
516 for (var counter = this.selection.length - 1; counter >= 0; counter--) {
517 if (this.selection[counter] === this.leadPath) {
518 this.leadIndex = counter;
524 Clazz.defineMethod (c$, "insureUniqueness",
527 Clazz.overrideMethod (c$, "toString",
529 var selCount = this.getSelectionCount ();
530 var retBuffer = new StringBuffer ();
532 if (this.rowMapper != null) rows = this.rowMapper.getRowsForPaths (this.selection);
534 retBuffer.append (this.getClass ().getName () + " " + this.hashCode () + " [ ");
535 for (var counter = 0; counter < selCount; counter++) {
536 if (rows != null) retBuffer.append (this.selection[counter].toString () + "@" + Integer.toString (rows[counter]) + " ");
537 else retBuffer.append (this.selection[counter].toString () + " ");
539 retBuffer.append ("]");
540 return retBuffer.toString ();
542 Clazz.defineMethod (c$, "clone",
544 var clone = Clazz.superCall (this, javax.swing.tree.DefaultTreeSelectionModel, "clone", []);
545 clone.changeSupport = null;
546 if (this.selection != null) {
547 var selLength = this.selection.length;
548 clone.selection = new Array (selLength);
549 System.arraycopy (this.selection, 0, clone.selection, 0, selLength);
550 }clone.listenerList = new javax.swing.event.EventListenerList ();
551 clone.listSelectionModel = this.listSelectionModel.clone ();
552 clone.uniquePaths = new java.util.Hashtable ();
553 clone.lastPaths = new java.util.Hashtable ();
554 clone.tempPaths = new Array (1);
557 Clazz.defineStatics (c$,
558 "SELECTION_MODE_PROPERTY", "selectionMode");
559 c$ = Clazz.decorateAsClass (function () {
562 Clazz.instantialize (this, arguments);
563 }, javax.swing.tree, "PathPlaceHolder");
564 Clazz.makeConstructor (c$,
565 function (path, isNew) {
568 }, "javax.swing.tree.TreePath,~B");