changeset 268:8181c2557b4c

Further work on RT-18904: Controls.ListView-Rotate performance dropped up to 0 fps in fx2.1-b08. Improving the event being fired when selection is shifted to not include -1 values, and to short-circuit earlier if not selection shifting is required.
author jgiles
date Tue, 17 Jan 2012 11:43:56 +1300
parents f7a12e20b2ba
children 6beb94343169
files javafx-ui-controls/src/javafx/scene/control/MultipleSelectionModelBase.java
diffstat 1 files changed, 32 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/javafx/scene/control/MultipleSelectionModelBase.java	Mon Jan 16 15:33:07 2012 +1300
+++ b/javafx-ui-controls/src/javafx/scene/control/MultipleSelectionModelBase.java	Tue Jan 17 11:43:56 2012 +1300
@@ -162,10 +162,10 @@
     @Override public ObservableList<Integer> getSelectedIndices() {
         return selectedIndicesSeq;
     }
-    private void setSelectedIndices(BitSet rows) {
-        this.selectedIndices.clear();
-        this.selectedIndices.or(rows);
-    }
+//    private void setSelectedIndices(BitSet rows) {
+//        this.selectedIndices.clear();
+//        this.selectedIndices.or(rows);
+//    }
 
     private final ReadOnlyUnbackedObservableList selectedItemsSeq;
     @Override public ObservableList<T> getSelectedItems() {
@@ -217,17 +217,35 @@
         if (position < 0) return;
         if (shift == 0) return;
         
+        int selectedIndicesCardinality = selectedIndices.cardinality(); // number of true bits
+        if (selectedIndicesCardinality == 0) return;
+        
+        int selectedIndicesSize = selectedIndices.size();   // number of bits reserved 
+        
+        int[] perm = new int[selectedIndicesSize];
+        int idx = 0;
+        
         if (shift > 0) {
             for (int iter = 0; iter < shift; iter++) {
-                for (int i = selectedIndices.size() - 1; i >= position && i >= 0; i--) {
-                    selectedIndices.set(i+1, selectedIndices.get(i));
+                for (int i = selectedIndicesSize - 1; i >= position && i >= 0; i--) {
+                    boolean selected = selectedIndices.get(i);
+                    selectedIndices.set(i+1, selected);
+                    
+                    if (selected) {
+                        perm[idx++] = i + 1;
+                    }
                 }
                 selectedIndices.clear(position);
              }
         } else if (shift < 0) {
             for (int iter = 0; iter < Math.abs(shift); iter++) {
-                for (int i = position; i < selectedIndices.size() ; i++) {
-                    selectedIndices.set(i, selectedIndices.get(i+1));
+                for (int i = position; i < selectedIndicesSize; i++) {
+                    boolean selected = selectedIndices.get(i + 1);
+                    selectedIndices.set(i, selected);
+                    
+                    if (selected) {
+                        perm[idx++] = i;
+                    }
                 }
             }
         }
@@ -237,8 +255,12 @@
             setSelectedIndex(getFocusedIndex() + shift);
         }
          
-        // TODO this isn't correct
-        selectedIndicesSeq.callObservers(new NonIterableChange.SimplePermutationChange<Integer>(0, getItemCount() - 1, new int[] { }, selectedIndicesSeq));
+        selectedIndicesSeq.callObservers(
+                new NonIterableChange.SimplePermutationChange<Integer>(
+                        0, 
+                        selectedIndicesCardinality, 
+                        perm, 
+                        selectedIndicesSeq));
     }
 
     @Override public void clearAndSelect(int row) {