Changeset 8505 in josm


Ignore:
Timestamp:
2015-06-19T23:18:44+02:00 (9 years ago)
Author:
simon04
Message:

fix #11559 - Relation editor: add button to sort the selected relation members and all members below (for experts only)

Location:
trunk
Files:
1 added
2 edited

Legend:

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

    r8444 r8505  
    3333import javax.swing.BorderFactory;
    3434import javax.swing.InputMap;
     35import javax.swing.JButton;
    3536import javax.swing.JComponent;
    3637import javax.swing.JLabel;
     
    5657import org.openstreetmap.josm.Main;
    5758import org.openstreetmap.josm.actions.CopyAction;
     59import org.openstreetmap.josm.actions.ExpertToggleAction;
    5860import org.openstreetmap.josm.actions.JosmAction;
    5961import org.openstreetmap.josm.command.AddCommand;
     
    114116     */
    115117    private JMenuItem windowMenuItem;
     118    /**
     119     * Button for performing the {@link org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.SortBelowAction}.
     120     */
     121    private JButton sortBelowButton;
    116122
    117123    /**
     
    508514        memberTableModel.addTableModelListener(sortAction);
    509515        tb.add(sortAction);
     516        final SortBelowAction sortBelowAction = new SortBelowAction();
     517        memberTableModel.addTableModelListener(sortBelowAction);
     518        memberTableModel.getSelectionModel().addListSelectionListener(sortBelowAction);
     519        sortBelowButton = tb.add(sortBelowAction);
    510520
    511521        // -- reverse action
     
    603613        super.setVisible(visible);
    604614        if (visible) {
     615            sortBelowButton.setVisible(ExpertToggleAction.isExpert());
    605616            RelationDialogManager.getRelationDialogManager().positionOnScreen(this);
    606617            if(windowMenuItem == null) {
     
    10591070    }
    10601071
     1072    class SortBelowAction extends AbstractAction implements TableModelListener, ListSelectionListener {
     1073        public SortBelowAction() {
     1074            putValue(SMALL_ICON, ImageProvider.get("dialogs", "sort_below"));
     1075            putValue(NAME, tr("Sort below"));
     1076            putValue(SHORT_DESCRIPTION, tr("Sort the selected relation members and all members below"));
     1077            updateEnabledState();
     1078        }
     1079
     1080        @Override
     1081        public void actionPerformed(ActionEvent e) {
     1082            memberTableModel.sortBelow();
     1083        }
     1084
     1085        protected void updateEnabledState() {
     1086            setEnabled(memberTableModel.getRowCount() > 0 && !memberTableModel.getSelectionModel().isSelectionEmpty());
     1087        }
     1088
     1089        @Override
     1090        public void tableChanged(TableModelEvent e) {
     1091            updateEnabledState();
     1092        }
     1093
     1094        @Override
     1095        public void valueChanged(ListSelectionEvent e) {
     1096            updateEnabledState();
     1097        }
     1098    }
     1099
    10611100    class ReverseAction extends AbstractAction implements TableModelListener {
    10621101        public ReverseAction() {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r8413 r8505  
    718718    }
    719719
     720    /**
     721     * Sort the selected relation members and all members below by the way they are linked.
     722     */
     723    void sortBelow() {
     724        final List<RelationMember> subList = members.subList(getSelectionModel().getMinSelectionIndex(), members.size());
     725        final List<RelationMember> sorted = relationSorter.sortMembers(subList);
     726        subList.clear();
     727        subList.addAll(sorted);
     728        fireTableDataChanged();
     729        setSelectedMembers(sorted);
     730    }
     731
    720732    WayConnectionType getWayConnection(int i) {
    721733        if (connectionType == null) {
Note: See TracChangeset for help on using the changeset viewer.