Changeset 14713 in josm


Ignore:
Timestamp:
2019-01-20T21:35:58+01:00 (9 months ago)
Author:
simon04
Message:

see #14462 - ChildRelationBrowser: add popup menu

File:
1 edited

Legend:

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

    r14277 r14713  
    99import java.awt.Dialog;
    1010import java.awt.FlowLayout;
     11import java.awt.Point;
    1112import java.awt.event.ActionEvent;
    12 import java.awt.event.MouseAdapter;
    1313import java.awt.event.MouseEvent;
    1414import java.io.IOException;
    1515import java.net.HttpURLConnection;
     16import java.util.Arrays;
    1617import java.util.HashSet;
    1718import java.util.Iterator;
     
    1920import java.util.Set;
    2021import java.util.Stack;
     22import java.util.stream.Collectors;
    2123
    2224import javax.swing.AbstractAction;
     
    2426import javax.swing.JOptionPane;
    2527import javax.swing.JPanel;
     28import javax.swing.JPopupMenu;
    2629import javax.swing.JScrollPane;
     30import javax.swing.JTree;
    2731import javax.swing.SwingUtilities;
    2832import javax.swing.event.TreeSelectionEvent;
     
    3337import org.openstreetmap.josm.data.osm.DataSetMerger;
    3438import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
     39import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3540import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3641import org.openstreetmap.josm.data.osm.Relation;
     
    3944import org.openstreetmap.josm.gui.MainApplication;
    4045import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     46import org.openstreetmap.josm.gui.PopupMenuHandler;
    4147import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4248import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    4349import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
     50import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    4451import org.openstreetmap.josm.io.OsmApi;
    4552import org.openstreetmap.josm.io.OsmApiException;
     
    8895        add(pane, BorderLayout.CENTER);
    8996
     97        final JPopupMenu popupMenu = new JPopupMenu();
     98        final PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu);
     99        RelationPopupMenus.setupHandler(popupMenuHandler);
     100
    90101        add(buildButtonPanel(), BorderLayout.SOUTH);
    91102        childTree.setToggleClickCount(0);
    92         childTree.addMouseListener(new MouseAdapter() {
     103        childTree.addMouseListener(new PopupMenuLauncher(popupMenu) {
    93104            @Override
    94105            public void mouseClicked(MouseEvent e) {
     
    103114                    }
    104115                }
     116            }
     117
     118            @Override
     119            protected TreePath checkTreeSelection(JTree tree, Point p) {
     120                final TreePath treeSelection = super.checkTreeSelection(tree, p);
     121                final TreePath[] selectionPaths = tree.getSelectionPaths();
     122                if (selectionPaths == null) {
     123                    return treeSelection;
     124                }
     125                final List<OsmPrimitive> relations = Arrays.stream(selectionPaths)
     126                        .map(TreePath::getLastPathComponent)
     127                        .map(OsmPrimitive.class::cast)
     128                        .collect(Collectors.toList());
     129                popupMenuHandler.setPrimitives(relations);
     130                return treeSelection;
    105131            }
    106132        });
Note: See TracChangeset for help on using the changeset viewer.