Changeset 2716 in josm for trunk


Ignore:
Timestamp:
2009-12-31T00:25:21+01:00 (10 years ago)
Author:
mjulius
Message:

fixes #4247 - in relation editor sort only selected members if there are members selected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r2711 r2716  
    688688    }
    689689
    690     /**
    691      * Sort the relation members by the way they are linked.
    692      */
    693     void sort() {
    694         RelationNodeMap map = new RelationNodeMap(members);
    695 
     690    /*
     691     * Sort a collection of relation members by the way they are linked.
     692     *
     693     * @param relationMembers collection of relation members
     694     * @return sorted collection of relation members
     695     */
     696    private ArrayList<RelationMember> sortMembers(ArrayList<RelationMember> relationMembers) {
     697        RelationNodeMap map = new RelationNodeMap(relationMembers);
    696698        // List of groups of linked members
    697699        //
     
    722724                group.addFirst(next);
    723725            }
    724 
    725726        }
    726727
     
    732733        for (LinkedList<Integer> tmpGroup : allGroups) {
    733734            for (Integer p : tmpGroup) {
    734                 newMembers.add(members.get(p));
     735                newMembers.add(relationMembers.get(p));
     736            }
     737        }
     738        return newMembers;
     739    }
     740
     741    /**
     742     * Sort the relation members by the way they are linked.
     743     */
     744    void sort() {
     745        ArrayList<RelationMember> selectedMembers = new ArrayList<RelationMember>(getSelectedMembers());
     746        ArrayList<RelationMember> sortedMembers = null;
     747        ArrayList<RelationMember> newMembers;
     748        if (selectedMembers.isEmpty()) {
     749            newMembers = sortMembers(members);
     750        } else {
     751            sortedMembers = sortMembers(selectedMembers);
     752            List<Integer> selectedIndices = getSelectedIndices();
     753            newMembers = new ArrayList<RelationMember>();
     754            boolean inserted = false;
     755            for (int i=0; i < members.size(); i++) {
     756                if (selectedIndices.contains(i)) {
     757                    if (!inserted) {
     758                        newMembers.addAll(sortedMembers);
     759                        inserted = true;
     760                    }
     761                } else {
     762                    newMembers.add(members.get(i));
     763                }
    735764            }
    736765        }
     
    741770        members.addAll(newMembers);
    742771        fireTableDataChanged();
     772        setSelectedMembers(sortedMembers);
    743773    }
    744774
Note: See TracChangeset for help on using the changeset viewer.