1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["javax.swing.RowFilter", "$.RowSorter"], "javax.swing.DefaultRowSorter", ["java.lang.IllegalArgumentException", "$.IndexOutOfBoundsException", "java.util.ArrayList", "$.Arrays", "$.Collections", "javax.swing.SortOrder"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.sortsOnUpdates = false;
5 this.viewToModel = null;
6 this.modelToView = null;
7 this.comparators = null;
8 this.$isSortable = null;
9 this.cachedSortKeys = null;
10 this.sortComparators = null;
12 this.filterEntry = null;
14 this.$useToString = null;
17 this.modelWrapper = null;
18 this.modelRowCount = 0;
19 if (!Clazz.isClassDefined ("javax.swing.DefaultRowSorter.FilterEntry")) {
20 javax.swing.DefaultRowSorter.$DefaultRowSorter$FilterEntry$ ();
22 Clazz.instantialize (this, arguments);
23 }, javax.swing, "DefaultRowSorter", javax.swing.RowSorter);
24 Clazz.makeConstructor (c$,
26 Clazz.superConstructor (this, javax.swing.DefaultRowSorter, []);
27 this.sortKeys = java.util.Collections.emptyList ();
30 Clazz.defineMethod (c$, "setModelWrapper",
31 function (modelWrapper) {
32 if (modelWrapper == null) {
33 throw new IllegalArgumentException ("modelWrapper most be non-null");
34 }var last = this.modelWrapper;
35 this.modelWrapper = modelWrapper;
37 this.modelStructureChanged ();
39 this.modelRowCount = this.getModelWrapper ().getRowCount ();
40 }}, "javax.swing.DefaultRowSorter.ModelWrapper");
41 Clazz.defineMethod (c$, "getModelWrapper",
43 return this.modelWrapper;
45 Clazz.overrideMethod (c$, "getModel",
47 return this.getModelWrapper ().getModel ();
49 Clazz.defineMethod (c$, "setSortable",
50 function (column, sortable) {
51 this.checkColumn (column);
52 if (this.$isSortable == null) {
53 this.$isSortable = Clazz.newBooleanArray (this.getModelWrapper ().getColumnCount (), false);
54 for (var i = this.$isSortable.length - 1; i >= 0; i--) {
55 this.$isSortable[i] = true;
57 }this.$isSortable[column] = sortable;
59 Clazz.defineMethod (c$, "isSortable",
61 this.checkColumn (column);
62 return (this.$isSortable == null) ? true : this.$isSortable[column];
64 Clazz.overrideMethod (c$, "setSortKeys",
66 var old = this.sortKeys;
67 if (sortKeys != null && sortKeys.size () > 0) {
68 var max = this.getModelWrapper ().getColumnCount ();
69 for (var key, $key = sortKeys.iterator (); $key.hasNext () && ((key = $key.next ()) || true);) {
70 if (key == null || key.getColumn () < 0 || key.getColumn () >= max) {
71 throw new IllegalArgumentException ("Invalid SortKey");
73 this.sortKeys = java.util.Collections.unmodifiableList ( new java.util.ArrayList (sortKeys));
75 this.sortKeys = java.util.Collections.emptyList ();
76 }if (!this.sortKeys.equals (old)) {
77 this.fireSortOrderChanged ();
78 if (this.viewToModel == null) {
81 this.sortExistingData ();
82 }}}, "java.util.List");
83 Clazz.overrideMethod (c$, "getSortKeys",
87 Clazz.defineMethod (c$, "setMaxSortKeys",
90 throw new IllegalArgumentException ("Invalid max");
91 }this.maxSortKeys = max;
93 Clazz.defineMethod (c$, "getMaxSortKeys",
95 return this.maxSortKeys;
97 Clazz.defineMethod (c$, "setSortsOnUpdates",
98 function (sortsOnUpdates) {
99 this.sortsOnUpdates = sortsOnUpdates;
101 Clazz.defineMethod (c$, "getSortsOnUpdates",
103 return this.sortsOnUpdates;
105 Clazz.defineMethod (c$, "setRowFilter",
107 this.filter = filter;
109 }, "javax.swing.RowFilter");
110 Clazz.defineMethod (c$, "getRowFilter",
114 Clazz.overrideMethod (c$, "toggleSortOrder",
116 this.checkColumn (column);
117 if (this.isSortable (column)) {
118 var keys = new java.util.ArrayList (this.getSortKeys ());
121 for (sortIndex = keys.size () - 1; sortIndex >= 0; sortIndex--) {
122 if (keys.get (sortIndex).getColumn () == column) {
125 if (sortIndex == -1) {
126 sortKey = new javax.swing.RowSorter.SortKey (column, javax.swing.SortOrder.ASCENDING);
127 keys.add (0, sortKey);
128 } else if (sortIndex == 0) {
129 keys.set (0, this.toggle (keys.get (0)));
131 keys.remove (sortIndex);
132 keys.add (0, new javax.swing.RowSorter.SortKey (column, javax.swing.SortOrder.ASCENDING));
133 }if (keys.size () > this.getMaxSortKeys ()) {
134 keys = keys.subList (0, this.getMaxSortKeys ());
135 }this.setSortKeys (keys);
137 Clazz.defineMethod (c$, "toggle",
139 if (key.getSortOrder () === javax.swing.SortOrder.ASCENDING) {
140 return new javax.swing.RowSorter.SortKey (key.getColumn (), javax.swing.SortOrder.DESCENDING);
141 }return new javax.swing.RowSorter.SortKey (key.getColumn (), javax.swing.SortOrder.ASCENDING);
142 }, "javax.swing.RowSorter.SortKey");
143 Clazz.overrideMethod (c$, "convertRowIndexToView",
145 if (this.modelToView == null) {
146 if (index < 0 || index >= this.getModelWrapper ().getRowCount ()) {
147 throw new IndexOutOfBoundsException ("Invalid index");
149 }return this.modelToView[index];
151 Clazz.overrideMethod (c$, "convertRowIndexToModel",
153 if (this.viewToModel == null) {
154 if (index < 0 || index >= this.getModelWrapper ().getRowCount ()) {
155 throw new IndexOutOfBoundsException ("Invalid index");
157 }return this.viewToModel[index].modelIndex;
159 Clazz.defineMethod (c$, "isUnsorted",
161 var keys = this.getSortKeys ();
162 var keySize = keys.size ();
163 return (keySize == 0 || keys.get (0).getSortOrder () === javax.swing.SortOrder.UNSORTED);
165 Clazz.defineMethod (c$, "sortExistingData",
167 var lastViewToModel = this.getViewToModelAsInts (this.viewToModel);
168 this.updateUseToString ();
169 this.cacheSortKeys (this.getSortKeys ());
170 if (this.isUnsorted ()) {
171 if (this.getRowFilter () == null) {
172 this.viewToModel = null;
173 this.modelToView = null;
176 for (var i = 0; i < this.modelToView.length; i++) {
177 if (this.modelToView[i] != -1) {
178 this.viewToModel[included].modelIndex = i;
179 this.modelToView[i] = included++;
182 java.util.Arrays.sort (this.viewToModel);
183 this.setModelToViewFromViewToModel (false);
184 }this.fireRowSorterChanged (lastViewToModel);
186 Clazz.defineMethod (c$, "sort",
189 var lastViewToModel = this.getViewToModelAsInts (this.viewToModel);
190 this.updateUseToString ();
191 if (this.isUnsorted ()) {
192 this.cachedSortKeys = new Array (0);
193 if (this.getRowFilter () == null) {
194 if (this.viewToModel != null) {
195 this.viewToModel = null;
196 this.modelToView = null;
200 this.initializeFilteredMapping ();
202 this.cacheSortKeys (this.getSortKeys ());
203 if (this.getRowFilter () != null) {
204 this.initializeFilteredMapping ();
206 this.createModelToView (this.getModelWrapper ().getRowCount ());
207 this.createViewToModel (this.getModelWrapper ().getRowCount ());
208 }java.util.Arrays.sort (this.viewToModel);
209 this.setModelToViewFromViewToModel (false);
210 }this.fireRowSorterChanged (lastViewToModel);
212 Clazz.defineMethod (c$, "updateUseToString",
214 var i = this.getModelWrapper ().getColumnCount ();
215 if (this.$useToString == null || this.$useToString.length != i) {
216 this.$useToString = Clazz.newBooleanArray (i, false);
217 }for (--i; i >= 0; i--) {
218 this.$useToString[i] = this.useToString (i);
221 Clazz.defineMethod (c$, "initializeFilteredMapping",
223 var rowCount = this.getModelWrapper ().getRowCount ();
226 var excludedCount = 0;
227 this.createModelToView (rowCount);
228 for (i = 0; i < rowCount; i++) {
229 if (this.include (i)) {
230 this.modelToView[i] = i - excludedCount;
232 this.modelToView[i] = -1;
235 this.createViewToModel (rowCount - excludedCount);
236 for (i = 0, j = 0; i < rowCount; i++) {
237 if (this.modelToView[i] != -1) {
238 this.viewToModel[j++].modelIndex = i;
241 Clazz.defineMethod (c$, "createModelToView",
242 function (rowCount) {
243 if (this.modelToView == null || this.modelToView.length != rowCount) {
244 this.modelToView = Clazz.newIntArray (rowCount, 0);
246 Clazz.defineMethod (c$, "createViewToModel",
247 function (rowCount) {
248 var recreateFrom = 0;
249 if (this.viewToModel != null) {
250 recreateFrom = Math.min (rowCount, this.viewToModel.length);
251 if (this.viewToModel.length != rowCount) {
252 var oldViewToModel = this.viewToModel;
253 this.viewToModel = new Array (rowCount);
254 System.arraycopy (oldViewToModel, 0, this.viewToModel, 0, recreateFrom);
256 this.viewToModel = new Array (rowCount);
258 for (i = 0; i < recreateFrom; i++) {
259 this.viewToModel[i].modelIndex = i;
261 for (i = recreateFrom; i < rowCount; i++) {
262 this.viewToModel[i] = new javax.swing.DefaultRowSorter.Row (this, i);
265 Clazz.defineMethod (c$, "cacheSortKeys",
267 var keySize = keys.size ();
268 this.sortComparators = new Array (keySize);
269 for (var i = 0; i < keySize; i++) {
270 this.sortComparators[i] = this.getComparator0 (keys.get (i).getColumn ());
272 this.cachedSortKeys = keys.toArray ( new Array (keySize));
273 }, "java.util.List");
274 Clazz.defineMethod (c$, "useToString",
276 return (this.getComparator (column) == null);
278 Clazz.defineMethod (c$, "setModelToViewFromViewToModel",
279 function (unsetFirst) {
282 for (i = this.modelToView.length - 1; i >= 0; i--) {
283 this.modelToView[i] = -1;
285 }for (i = this.viewToModel.length - 1; i >= 0; i--) {
286 this.modelToView[this.viewToModel[i].modelIndex] = i;
289 Clazz.defineMethod (c$, "getViewToModelAsInts",
290 function (viewToModel) {
291 if (viewToModel != null) {
292 var viewToModelI = Clazz.newIntArray (viewToModel.length, 0);
293 for (var i = viewToModel.length - 1; i >= 0; i--) {
294 viewToModelI[i] = viewToModel[i].modelIndex;
297 }return Clazz.newIntArray (0, 0);
299 Clazz.defineMethod (c$, "setComparator",
300 function (column, comparator) {
301 this.checkColumn (column);
302 if (this.comparators == null) {
303 this.comparators = new Array (this.getModelWrapper ().getColumnCount ());
304 }this.comparators[column] = comparator;
305 }, "~N,java.util.Comparator");
306 Clazz.defineMethod (c$, "getComparator",
308 this.checkColumn (column);
309 if (this.comparators != null) {
310 return this.comparators[column];
313 Clazz.defineMethod (c$, "getComparator0",
315 var comparator = this.getComparator (column);
316 if (comparator != null) {
320 Clazz.defineMethod (c$, "getFilterEntry",
321 function (modelIndex) {
322 if (this.filterEntry == null) {
323 this.filterEntry = Clazz.innerTypeInstance (javax.swing.DefaultRowSorter.FilterEntry, this, null);
324 }this.filterEntry.modelIndex = modelIndex;
325 return this.filterEntry;
327 Clazz.overrideMethod (c$, "getViewRowCount",
329 if (this.viewToModel != null) {
330 return this.viewToModel.length;
331 }return this.getModelWrapper ().getRowCount ();
333 Clazz.overrideMethod (c$, "getModelRowCount",
335 return this.getModelWrapper ().getRowCount ();
337 Clazz.defineMethod (c$, "allChanged",
339 this.modelToView = null;
340 this.viewToModel = null;
341 this.comparators = null;
342 this.$isSortable = null;
343 if (this.isUnsorted ()) {
346 this.setSortKeys (null);
348 Clazz.overrideMethod (c$, "modelStructureChanged",
351 this.modelRowCount = this.getModelWrapper ().getRowCount ();
353 Clazz.overrideMethod (c$, "allRowsChanged",
355 this.modelRowCount = this.getModelWrapper ().getRowCount ();
358 Clazz.overrideMethod (c$, "rowsInserted",
359 function (firstRow, endRow) {
360 this.checkAgainstModel (firstRow, endRow);
361 var newModelRowCount = this.getModelWrapper ().getRowCount ();
362 if (endRow >= newModelRowCount) {
363 throw new IndexOutOfBoundsException ("Invalid range");
364 }this.modelRowCount = newModelRowCount;
365 if (this.shouldOptimizeChange (firstRow, endRow)) {
366 this.rowsInserted0 (firstRow, endRow);
368 Clazz.overrideMethod (c$, "rowsDeleted",
369 function (firstRow, endRow) {
370 this.checkAgainstModel (firstRow, endRow);
371 if (firstRow >= this.modelRowCount || endRow >= this.modelRowCount) {
372 throw new IndexOutOfBoundsException ("Invalid range");
373 }this.modelRowCount = this.getModelWrapper ().getRowCount ();
374 if (this.shouldOptimizeChange (firstRow, endRow)) {
375 this.rowsDeleted0 (firstRow, endRow);
377 Clazz.defineMethod (c$, "rowsUpdated",
378 function (firstRow, endRow) {
379 this.checkAgainstModel (firstRow, endRow);
380 if (firstRow >= this.modelRowCount || endRow >= this.modelRowCount) {
381 throw new IndexOutOfBoundsException ("Invalid range");
382 }if (this.getSortsOnUpdates ()) {
383 if (this.shouldOptimizeChange (firstRow, endRow)) {
384 this.rowsUpdated0 (firstRow, endRow);
388 Clazz.defineMethod (c$, "rowsUpdated",
389 function (firstRow, endRow, column) {
390 this.checkColumn (column);
391 this.rowsUpdated (firstRow, endRow);
393 Clazz.defineMethod (c$, "checkAgainstModel",
394 function (firstRow, endRow) {
395 if (firstRow > endRow || firstRow < 0 || endRow < 0 || firstRow > this.modelRowCount) {
396 throw new IndexOutOfBoundsException ("Invalid range");
398 Clazz.defineMethod (c$, "include",
400 var filter = this.getRowFilter ();
401 if (filter != null) {
402 return filter.include (this.getFilterEntry (row));
405 Clazz.defineMethod (c$, "isTransformed",
407 return (this.viewToModel != null);
409 Clazz.defineMethod (c$, "insertInOrder",
410 function (toAdd, current) {
413 var max = toAdd.size ();
414 for (var i = 0; i < max; i++) {
415 index = java.util.Arrays.binarySearch (current, toAdd.get (i));
418 }System.arraycopy (current, last, this.viewToModel, last + i, index - last);
419 this.viewToModel[index + i] = toAdd.get (i);
422 System.arraycopy (current, last, this.viewToModel, last + max, current.length - last);
423 }, "java.util.List,~A");
424 Clazz.defineMethod (c$, "shouldOptimizeChange",
425 function (firstRow, lastRow) {
426 if (!this.isTransformed ()) {
428 }if (!this.sorted || (lastRow - firstRow) > Clazz.doubleToInt (this.viewToModel.length / 10)) {
433 Clazz.defineMethod (c$, "rowsInserted0",
434 function (firstRow, lastRow) {
435 var oldViewToModel = this.getViewToModelAsInts (this.viewToModel);
437 var delta = (lastRow - firstRow) + 1;
438 var added = new java.util.ArrayList (delta);
439 for (i = firstRow; i <= lastRow; i++) {
440 if (this.include (i)) {
441 added.add ( new javax.swing.DefaultRowSorter.Row (this, i));
444 for (i = this.modelToView.length - 1; i >= firstRow; i--) {
445 viewIndex = this.modelToView[i];
446 if (viewIndex != -1) {
447 this.viewToModel[viewIndex].modelIndex += delta;
449 if (added.size () > 0) {
450 java.util.Collections.sort (added);
451 var lastViewToModel = this.viewToModel;
452 this.viewToModel = new Array (this.viewToModel.length + added.size ());
453 this.insertInOrder (added, lastViewToModel);
454 }this.createModelToView (this.getModelWrapper ().getRowCount ());
455 this.setModelToViewFromViewToModel (true);
456 this.fireRowSorterChanged (oldViewToModel);
458 Clazz.defineMethod (c$, "rowsDeleted0",
459 function (firstRow, lastRow) {
460 var oldViewToModel = this.getViewToModelAsInts (this.viewToModel);
461 var removedFromView = 0;
464 for (i = firstRow; i <= lastRow; i++) {
465 viewIndex = this.modelToView[i];
466 if (viewIndex != -1) {
468 this.viewToModel[viewIndex] = null;
470 var delta = lastRow - firstRow + 1;
471 for (i = this.modelToView.length - 1; i > lastRow; i--) {
472 viewIndex = this.modelToView[i];
473 if (viewIndex != -1) {
474 this.viewToModel[viewIndex].modelIndex -= delta;
476 if (removedFromView > 0) {
477 var newViewToModel = new Array (this.viewToModel.length - removedFromView);
480 for (i = 0; i < this.viewToModel.length; i++) {
481 if (this.viewToModel[i] == null) {
482 System.arraycopy (this.viewToModel, last, newViewToModel, newIndex, i - last);
483 newIndex += (i - last);
486 System.arraycopy (this.viewToModel, last, newViewToModel, newIndex, this.viewToModel.length - last);
487 this.viewToModel = newViewToModel;
488 }this.createModelToView (this.getModelWrapper ().getRowCount ());
489 this.setModelToViewFromViewToModel (true);
490 this.fireRowSorterChanged (oldViewToModel);
492 Clazz.defineMethod (c$, "rowsUpdated0",
493 function (firstRow, lastRow) {
494 var oldViewToModel = this.getViewToModelAsInts (this.viewToModel);
497 var delta = lastRow - firstRow + 1;
499 if (this.getRowFilter () == null) {
500 var updated = new Array (delta);
501 for (j = 0, i = firstRow; i <= lastRow; i++, j++) {
502 updated[j] = this.viewToModel[this.modelToView[i]];
504 java.util.Arrays.sort (updated);
505 var intermediary = new Array (this.viewToModel.length - delta);
506 for (i = 0, j = 0; i < this.viewToModel.length; i++) {
507 modelIndex = this.viewToModel[i].modelIndex;
508 if (modelIndex < firstRow || modelIndex > lastRow) {
509 intermediary[j++] = this.viewToModel[i];
511 this.insertInOrder (java.util.Arrays.asList (updated), intermediary);
512 this.setModelToViewFromViewToModel (false);
514 var updated = new java.util.ArrayList (delta);
515 var newlyVisible = 0;
518 for (i = firstRow; i <= lastRow; i++) {
519 if (this.modelToView[i] == -1) {
520 if (this.include (i)) {
521 updated.add ( new javax.swing.DefaultRowSorter.Row (this, i));
524 if (!this.include (i)) {
527 updated.add (this.viewToModel[this.modelToView[i]]);
528 }this.modelToView[i] = -2;
531 java.util.Collections.sort (updated);
532 var intermediary = new Array (this.viewToModel.length - effected);
533 for (i = 0, j = 0; i < this.viewToModel.length; i++) {
534 modelIndex = this.viewToModel[i].modelIndex;
535 if (this.modelToView[modelIndex] != -2) {
536 intermediary[j++] = this.viewToModel[i];
538 if (newlyVisible != newlyHidden) {
539 this.viewToModel = new Array (this.viewToModel.length + newlyVisible - newlyHidden);
540 }this.insertInOrder (updated, intermediary);
541 this.setModelToViewFromViewToModel (true);
542 }this.fireRowSorterChanged (oldViewToModel);
544 Clazz.defineMethod (c$, "checkColumn",
546 if (column < 0 || column >= this.getModelWrapper ().getColumnCount ()) {
547 throw new IndexOutOfBoundsException ("column beyond range of TableModel");
549 c$.$DefaultRowSorter$FilterEntry$ = function () {
551 c$ = Clazz.decorateAsClass (function () {
552 Clazz.prepareCallback (this, arguments);
554 Clazz.instantialize (this, arguments);
555 }, javax.swing.DefaultRowSorter, "FilterEntry", javax.swing.RowFilter.Entry);
556 Clazz.overrideMethod (c$, "getModel",
558 return this.b$["javax.swing.DefaultRowSorter"].getModelWrapper ().getModel ();
560 Clazz.overrideMethod (c$, "getValueCount",
562 return this.b$["javax.swing.DefaultRowSorter"].getModelWrapper ().getColumnCount ();
564 Clazz.overrideMethod (c$, "getValue",
566 return this.b$["javax.swing.DefaultRowSorter"].getModelWrapper ().getValueAt (this.modelIndex, a);
568 Clazz.overrideMethod (c$, "getStringValue",
570 return this.b$["javax.swing.DefaultRowSorter"].getModelWrapper ().getStringValueAt (this.modelIndex, a);
572 Clazz.overrideMethod (c$, "getIdentifier",
574 return this.b$["javax.swing.DefaultRowSorter"].getModelWrapper ().getIdentifier (this.modelIndex);
579 c$ = Clazz.declareType (javax.swing.DefaultRowSorter, "ModelWrapper");
580 Clazz.makeConstructor (c$,
583 Clazz.defineMethod (c$, "getStringValueAt",
585 var c = this.getValueAt (a, b);
588 }var d = c.toString ();
595 c$ = Clazz.decorateAsClass (function () {
598 Clazz.instantialize (this, arguments);
599 }, javax.swing.DefaultRowSorter, "Row", null, Comparable);
600 Clazz.makeConstructor (c$,
604 }, "javax.swing.DefaultRowSorter,~N");
605 Clazz.overrideMethod (c$, "compareTo",
607 return this.sorter.compare (this.modelIndex, a.modelIndex);
608 }, "javax.swing.DefaultRowSorter.Row");