- Timestamp:
- 2020-05-17T23:26:27+02:00 (5 years ago)
- 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 6 6 import java.awt.Point; 7 7 import java.awt.event.ActionEvent; 8 import java.awt.event.MouseAdapter;9 import java.awt.event.MouseEvent;10 8 11 9 import javax.swing.AbstractAction; … … 23 21 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 24 22 import org.openstreetmap.josm.data.osm.history.History; 25 import org.openstreetmap.josm.data.osm.history.HistoryDataSet;26 23 import org.openstreetmap.josm.gui.MainApplication; 27 import org.openstreetmap.josm.gui.util.GuiHelper;28 24 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 29 25 import org.openstreetmap.josm.tools.ImageProvider; … … 58 54 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel()); 59 55 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 })); 61 60 return table; 62 61 } … … 127 126 } 128 127 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 @Override142 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 170 128 private static PrimitiveId primitiveIdAtRow(DiffTableModel model, int row) { 171 129 Long id = (Long) model.getValueAt(row, 0).value; … … 186 144 } 187 145 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 @Override198 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 }211 146 } -
trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java
r16456 r16459 8 8 import javax.swing.JTable; 9 9 import javax.swing.ListSelectionModel; 10 11 import org.openstreetmap.josm.data.osm.RelationMemberData; 10 12 11 13 /** … … 34 36 table.scrollRectToVisible(rect); 35 37 }); 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 })); 36 42 return table; 37 43 }
Note:
See TracChangeset
for help on using the changeset viewer.