Changeset 16459 in josm


Ignore:
Timestamp:
2020-05-17T23:26:27+02:00 (3 weeks ago)
Author:
simon04
Message:

fix #19254 - History browser: double click relation member table to open history of member

Location:
trunk/src/org/openstreetmap/josm/gui/history
Files:
1 added
2 edited

Legend:

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

    r16456 r16459  
    66import java.awt.Point;
    77import java.awt.event.ActionEvent;
    8 import java.awt.event.MouseAdapter;
    9 import java.awt.event.MouseEvent;
    108
    119import javax.swing.AbstractAction;
     
    2321import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
    2422import org.openstreetmap.josm.data.osm.history.History;
    25 import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
    2623import org.openstreetmap.josm.gui.MainApplication;
    27 import org.openstreetmap.josm.gui.util.GuiHelper;
    2824import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    2925import org.openstreetmap.josm.tools.ImageProvider;
     
    5854        selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
    5955        table.addMouseListener(new InternalPopupMenuLauncher());
    60         table.addMouseListener(new DoubleClickAdapter(table));
     56        table.addMouseListener(new ShowHistoryAction.DoubleClickAdapter(e -> {
     57            int row = table.rowAtPoint(e.getPoint());
     58            return row <= 0 ? null : primitiveIdAtRow(tableModel, row);
     59        }));
    6160        return table;
    6261    }
     
    127126    }
    128127
    129     static class ShowHistoryAction extends AbstractAction {
    130         private transient PrimitiveId primitiveId;
    131 
    132         /**
    133          * Constructs a new {@code ShowHistoryAction}.
    134          */
    135         ShowHistoryAction() {
    136             putValue(NAME, tr("Show history"));
    137             putValue(SHORT_DESCRIPTION, tr("Open a history browser with the history of this node"));
    138             new ImageProvider("dialogs", "history").getResource().attachImageIcon(this, true);
    139         }
    140 
    141         @Override
    142         public void actionPerformed(ActionEvent e) {
    143             if (isEnabled()) {
    144                 run();
    145             }
    146         }
    147 
    148         public void setPrimitiveId(PrimitiveId pid) {
    149             this.primitiveId = pid;
    150             updateEnabledState();
    151         }
    152 
    153         public void run() {
    154             if (HistoryDataSet.getInstance().getHistory(primitiveId) == null) {
    155                 MainApplication.worker.submit(new HistoryLoadTask().add(primitiveId));
    156             }
    157             MainApplication.worker.submit(() -> {
    158                 final History h = HistoryDataSet.getInstance().getHistory(primitiveId);
    159                 if (h == null)
    160                     return;
    161                 GuiHelper.runInEDT(() -> HistoryBrowserDialogManager.getInstance().show(h));
    162             });
    163         }
    164 
    165         public void updateEnabledState() {
    166             setEnabled(primitiveId != null && !primitiveId.isNew());
    167         }
    168     }
    169 
    170128    private static PrimitiveId primitiveIdAtRow(DiffTableModel model, int row) {
    171129        Long id = (Long) model.getValueAt(row, 0).value;
     
    186144    }
    187145
    188     static class DoubleClickAdapter extends MouseAdapter {
    189         private final JTable table;
    190         private final ShowHistoryAction showHistoryAction;
    191 
    192         DoubleClickAdapter(JTable table) {
    193             this.table = table;
    194             showHistoryAction = new ShowHistoryAction();
    195         }
    196 
    197         @Override
    198         public void mouseClicked(MouseEvent e) {
    199             if (e.getClickCount() < 2)
    200                 return;
    201             int row = table.rowAtPoint(e.getPoint());
    202             if (row <= 0)
    203                 return;
    204             PrimitiveId pid = primitiveIdAtRow((DiffTableModel) table.getModel(), row);
    205             if (pid == null || pid.isNew())
    206                 return;
    207             showHistoryAction.setPrimitiveId(pid);
    208             showHistoryAction.run();
    209         }
    210     }
    211146}
  • trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java

    r16456 r16459  
    88import javax.swing.JTable;
    99import javax.swing.ListSelectionModel;
     10
     11import org.openstreetmap.josm.data.osm.RelationMemberData;
    1012
    1113/**
     
    3436            table.scrollRectToVisible(rect);
    3537        });
     38        table.addMouseListener(new ShowHistoryAction.DoubleClickAdapter(e -> {
     39            int row = table.rowAtPoint(e.getPoint());
     40            return row <= 0 ? null : (RelationMemberData) tableModel.getValueAt(row, 0).value;
     41        }));
    3642        return table;
    3743    }
Note: See TracChangeset for help on using the changeset viewer.