Ignore:
Timestamp:
2013-05-13T03:10:05+02:00 (11 years ago)
Author:
Don-vip
Message:
  • Improve PopupMenuLauncher to automatically select JTable/JList/JTree line under cursor
  • Simplify all popup menus with this new feature
  • Remove custom popup menus in BoundingBoxSelection and BoundingBoxSelection to use default text field popup menus recently introduced
  • Fix EDT violations in changeset window
  • Make Autoscale actions publicly available in MainMenu
  • Add a new "Zoom to problem" mode in AutoScaleAction
  • Make "Zoom to problem" menu item in validator dialog use this new feature
  • Update enabled state of "Zoom to Conflict" and "Zoom to problem" against selection of conflict/validator dialog
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    r5266 r5958  
    2929import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
    3030import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     31import org.openstreetmap.josm.gui.util.GuiHelper;
     32import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    3133import org.openstreetmap.josm.tools.ImageProvider;
    3234
     
    6668        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    6769        selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
    68         table.addMouseListener(new PopupMenuLauncher(table));
     70        table.addMouseListener(new InternalPopupMenuLauncher());
    6971        table.addMouseListener(new DoubleClickAdapter(table));
    7072        return table;
     
    7981        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    8082        selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
    81         table.addMouseListener(new PopupMenuLauncher(table));
     83        table.addMouseListener(new InternalPopupMenuLauncher());
    8284        table.addMouseListener(new DoubleClickAdapter(table));
    8385        return table;
     
    115117        selectionSynchronizer = new SelectionSynchronizer();
    116118
     119        popupMenu = new NodeListPopupMenu();
     120
    117121        // ---------------------------
    118122        gc.gridx = 0;
     
    135139        gc.anchor = GridBagConstraints.NORTHWEST;
    136140        add(embeddInScrollPane(buildCurrentNodeListTable()),gc);
    137 
    138         popupMenu = new NodeListPopupMenu();
    139141    }
    140142
     
    172174
    173175    static class NodeListPopupMenu extends JPopupMenu {
    174         private ZoomToNodeAction zoomToNodeAction;
    175         private ShowHistoryAction showHistoryAction;
     176        private final ZoomToNodeAction zoomToNodeAction;
     177        private final ShowHistoryAction showHistoryAction;
    176178
    177179        public NodeListPopupMenu() {
     
    262264            Runnable r = new Runnable() {
    263265                public void run() {
    264                     History h = HistoryDataSet.getInstance().getHistory(primitiveId);
     266                    final History h = HistoryDataSet.getInstance().getHistory(primitiveId);
    265267                    if (h == null)
    266268                        return;
    267                     HistoryBrowserDialogManager.getInstance().show(h);
     269                    GuiHelper.runInEDT(new Runnable() {
     270                        @Override public void run() {
     271                            HistoryBrowserDialogManager.getInstance().show(h);
     272                        }
     273                    });
    268274                }
    269275            };
     
    283289    }
    284290
    285     class PopupMenuLauncher extends MouseAdapter {
    286         private JTable table;
    287 
    288         public PopupMenuLauncher(JTable table) {
    289             this.table = table;
    290         }
    291 
    292         @Override
    293         public void mousePressed(MouseEvent e) {
    294             showPopup(e);
    295         }
    296 
    297         @Override
    298         public void mouseReleased(MouseEvent e) {
    299             showPopup(e);
    300         }
    301 
    302         private void showPopup(MouseEvent e) {
    303             if (!e.isPopupTrigger()) return;
    304             Point p = e.getPoint();
    305             int row = table.rowAtPoint(p);
    306 
    307             PrimitiveId pid = primitiveIdAtRow(table.getModel(), row);
    308             if (pid == null)
    309                 return;
    310             popupMenu.prepare(pid);
    311             popupMenu.show(e.getComponent(), e.getX(), e.getY());
     291    class InternalPopupMenuLauncher extends PopupMenuLauncher {
     292        public InternalPopupMenuLauncher() {
     293            super(popupMenu);
     294        }
     295
     296        @Override protected int checkTableSelection(JTable table, Point p) {
     297            int row = super.checkTableSelection(table, p);
     298            popupMenu.prepare(primitiveIdAtRow(table.getModel(), row));
     299            return row;
    312300        }
    313301    }
Note: See TracChangeset for help on using the changeset viewer.