Ignore:
Timestamp:
2017-12-17T15:37:11+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #15606 - export relation to GPX file or convert to a new GPX layer (patch by cmuelle8, modified)

File:
1 edited

Legend:

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

    r12846 r13210  
    1313import java.util.Collection;
    1414import java.util.Collections;
     15import java.util.EnumSet;
    1516import java.util.HashSet;
    1617import java.util.List;
     
    2930import javax.swing.KeyStroke;
    3031import javax.swing.ListSelectionModel;
     32import javax.swing.event.PopupMenuEvent;
     33import javax.swing.event.PopupMenuListener;
    3134
    3235import org.openstreetmap.josm.Main;
    3336import org.openstreetmap.josm.actions.ExpertToggleAction;
     37import org.openstreetmap.josm.actions.OsmPrimitiveAction;
    3438import org.openstreetmap.josm.actions.relation.AddSelectionToRelations;
    3539import org.openstreetmap.josm.actions.relation.DeleteRelationsAction;
     
    3842import org.openstreetmap.josm.actions.relation.DuplicateRelationAction;
    3943import org.openstreetmap.josm.actions.relation.EditRelationAction;
     44import org.openstreetmap.josm.actions.relation.ExportRelationToGpxAction;
     45import org.openstreetmap.josm.actions.relation.ExportRelationToGpxAction.Mode;
    4046import org.openstreetmap.josm.actions.relation.RecentRelationsAction;
    4147import org.openstreetmap.josm.actions.relation.SelectMembersAction;
     
    122128    private transient JMenuItem addSelectionToRelationMenuItem;
    123129
     130    /** export relation to GPX track action */
     131    private final ExportRelationToGpxAction exportRelationFromFirstAction =
     132            new ExportRelationToGpxAction(EnumSet.of(Mode.FROM_FIRST_MEMBER, Mode.TO_FILE));
     133    private final ExportRelationToGpxAction exportRelationFromLastAction =
     134            new ExportRelationToGpxAction(EnumSet.of(Mode.FROM_LAST_MEMBER, Mode.TO_FILE));
     135    private final ExportRelationToGpxAction exportRelationFromFirstToLayerAction =
     136            new ExportRelationToGpxAction(EnumSet.of(Mode.FROM_FIRST_MEMBER, Mode.TO_LAYER));
     137    private final ExportRelationToGpxAction exportRelationFromLastToLayerAction =
     138            new ExportRelationToGpxAction(EnumSet.of(Mode.FROM_LAST_MEMBER, Mode.TO_LAYER));
     139
    124140    private final transient HighlightHelper highlightHelper = new HighlightHelper();
    125141    private final boolean highlightEnabled = Config.getPref().getBoolean("draw.target-highlight", true);
     
    603619
    604620    private void setupPopupMenuHandler() {
     621        List<JMenuItem> checkDisabled = new ArrayList<>();
    605622
    606623        // -- select action
     
    612629        popupMenuHandler.addAction(addMembersToSelectionAction);
    613630
     631        // -- download members action
    614632        popupMenuHandler.addSeparator();
    615         // -- download members action
    616633        popupMenuHandler.addAction(downloadMembersAction);
    617 
    618         // -- download incomplete members action
    619634        popupMenuHandler.addAction(downloadSelectedIncompleteMembersAction);
     635
     636        // -- export relation to gpx action
     637        popupMenuHandler.addSeparator();
     638        checkDisabled.add(popupMenuHandler.addAction(exportRelationFromFirstAction));
     639        checkDisabled.add(popupMenuHandler.addAction(exportRelationFromLastAction));
     640        popupMenuHandler.addSeparator();
     641        checkDisabled.add(popupMenuHandler.addAction(exportRelationFromFirstToLayerAction));
     642        checkDisabled.add(popupMenuHandler.addAction(exportRelationFromLastToLayerAction));
    620643
    621644        popupMenuHandler.addSeparator();
     
    625648
    626649        addSelectionToRelationMenuItem = popupMenuHandler.addAction(addSelectionToRelations);
     650
     651        popupMenuHandler.addListener(new PopupMenuListener() {
     652            @Override
     653            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
     654                for (JMenuItem mi: checkDisabled) {
     655                    mi.setVisible(((OsmPrimitiveAction) mi.getAction()).isEnabled());
     656
     657                    Component sep = popupMenu.getComponent(
     658                            Math.max(0, popupMenu.getComponentIndex(mi)-1));
     659                    if (!(sep instanceof JMenuItem)) {
     660                        sep.setVisible(mi.isVisible());
     661                    }
     662                }
     663            }
     664
     665            @Override
     666            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
     667            }
     668
     669            @Override
     670            public void popupMenuCanceled(PopupMenuEvent e) {
     671            }
     672        });
    627673    }
    628674
Note: See TracChangeset for help on using the changeset viewer.