Ticket #13250: memberTable_performance.patch

File memberTable_performance.patch, 4.6 KB (added by GerdP, 4 years ago)

performance patch for relation editor

  • src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

     
    33
    44import java.util.ArrayList;
    55import java.util.Arrays;
     6import java.util.BitSet;
    67import java.util.Collection;
    78import java.util.Collections;
    89import java.util.EnumSet;
     
    266267        fireTableDataChanged();
    267268        getSelectionModel().setValueIsAdjusting(true);
    268269        getSelectionModel().clearSelection();
     270        BitSet selected = new BitSet();
    269271        for (int row : selectedRows) {
    270272            row--;
    271             getSelectionModel().addSelectionInterval(row, row);
     273            selected.set(row);
    272274        }
     275        addToSelectedMembers(selected);
    273276        getSelectionModel().setValueIsAdjusting(false);
    274277        fireMakeMemberVisible(selectedRows[0] - 1);
    275278    }
     
    289292        getSelectionModel();
    290293        getSelectionModel().setValueIsAdjusting(true);
    291294        getSelectionModel().clearSelection();
     295        BitSet selected = new BitSet();
    292296        for (int row : selectedRows) {
    293297            row++;
    294             getSelectionModel().addSelectionInterval(row, row);
     298            selected.set(row);
    295299        }
     300        addToSelectedMembers(selected);
    296301        getSelectionModel().setValueIsAdjusting(false);
    297302        fireMakeMemberVisible(selectedRows[0] + 1);
    298303    }
     
    529534            members.add(row, newMember);
    530535        }
    531536        fireTableDataChanged();
     537        BitSet selected = new BitSet();
    532538        for (int row : idx) {
    533             getSelectionModel().addSelectionInterval(row, row);
     539//            getSelectionModel().addSelectionInterval(row, row);
     540            selected.set(row);
    534541        }
     542        addToSelectedMembers(selected);
    535543    }
    536544
    537545    /**
     
    615623        //
    616624        getSelectionModel().setValueIsAdjusting(true);
    617625        getSelectionModel().clearSelection();
     626        BitSet selected = new BitSet();
    618627        for (int row : selectedIndices) {
    619             getSelectionModel().addSelectionInterval(row, row);
     628            selected.set(row);
    620629        }
     630        addToSelectedMembers(selected);
    621631        getSelectionModel().setValueIsAdjusting(false);
    622632        // make the first selected member visible
    623633        //
     
    627637    }
    628638
    629639    /**
    630      * Replies true if the index-th relation members referrs
     640     * Add one or more members indices to the selection.
     641     * Detect groups of consecutive indices.
     642     * Only one costly call of addSelectionInterval is performed for each group
     643
     644     * @param selectedIndices
     645     * @return number of groups
     646     */
     647    private int addToSelectedMembers(BitSet selectedIndices){
     648        if (selectedIndices == null || selectedIndices.isEmpty()) {
     649            return 0;
     650        }
     651        // select the members
     652        //
     653        int start = selectedIndices.nextSetBit(0);
     654        int end;
     655        int steps = 0;
     656        int last = selectedIndices.length();
     657        while (start >= 0){
     658            end = selectedIndices.nextClearBit(start);
     659            steps++;
     660            getSelectionModel().addSelectionInterval(start,end-1);
     661            start = selectedIndices.nextSetBit(end);
     662            if (start < 0 || end == last)
     663                break;
     664        }
     665        return steps;
     666    }
     667    /**
     668     * Replies true if the index-th relation members refers
    631669     * to an editable relation, i.e. a relation which is not
    632670     * incomplete.
    633671     *
    634672     * @param index the index
    635      * @return true, if the index-th relation members referrs
     673     * @return true, if the index-th relation members refers
    636674     * to an editable relation, i.e. a relation which is not
    637675     * incomplete
    638676     */
     
    693731        if (primitives == null) return;
    694732        getSelectionModel().setValueIsAdjusting(true);
    695733        getSelectionModel().clearSelection();
     734        BitSet selected = new BitSet();
    696735        for (int i = 0; i < members.size(); i++) {
    697736            RelationMember m = members.get(i);
    698737            if (primitives.contains(m.getMember())) {
    699                 this.getSelectionModel().addSelectionInterval(i, i);
     738//                this.getSelectionModel().addSelectionInterval(i, i);
     739                selected.set(i);
    700740            }
    701741        }
     742        addToSelectedMembers(selected);
    702743        getSelectionModel().setValueIsAdjusting(false);
    703744        if (!getSelectedIndices().isEmpty()) {
    704745            fireMakeMemberVisible(getSelectedIndices().get(0));