source: josm/trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java@ 16473

Last change on this file since 16473 was 16473, checked in by GerdP, 4 years ago

fix #19260: Show menu on right-click in History of relation members
Common code for NodeListViewer and RelationMemberListViewer was moved to HistoryViewerPanel

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Point;
7
8import javax.swing.JTable;
9import javax.swing.ListSelectionModel;
10
11import org.openstreetmap.josm.data.osm.OsmPrimitive;
12import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
13import org.openstreetmap.josm.data.osm.PrimitiveId;
14import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
15import org.openstreetmap.josm.data.osm.history.History;
16import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
17
18/**
19 * NodeListViewer is a UI component which displays the node list of two
20 * version of a {@link OsmPrimitive} in a {@link History}.
21 *
22 * <ul>
23 * <li>on the left, it displays the node list for the version at {@link PointInTimeType#REFERENCE_POINT_IN_TIME}</li>
24 * <li>on the right, it displays the node list for the version at {@link PointInTimeType#CURRENT_POINT_IN_TIME}</li>
25 * </ul>
26 * @since 1709
27 */
28public class NodeListViewer extends HistoryViewerPanel {
29
30 /**
31 * Constructs a new {@code NodeListViewer}.
32 * @param model history browser model
33 */
34 public NodeListViewer(HistoryBrowserModel model) {
35 super(model);
36 }
37
38 @Override
39 protected JTable buildTable(PointInTimeType pointInTimeType) {
40 final DiffTableModel tableModel = model.getNodeListTableModel(pointInTimeType);
41 final NodeListTableColumnModel columnModel = new NodeListTableColumnModel();
42 final JTable table = new JTable(tableModel, columnModel);
43 tableModel.addTableModelListener(new ReversedChangeListener(table, columnModel, tr("The nodes of this way are in reverse order")));
44 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
45 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
46 table.addMouseListener(new InternalPopupMenuLauncher());
47 table.addMouseListener(new ShowHistoryAction.DoubleClickAdapter(e -> {
48 int row = table.rowAtPoint(e.getPoint());
49 return primitiveIdAtRow(tableModel, row);
50 }));
51 return table;
52 }
53
54 private static PrimitiveId primitiveIdAtRow(DiffTableModel model, int row) {
55 if (row < 0)
56 return null;
57 Long id = (Long) model.getValueAt(row, 0).value;
58 return id == null ? null : new SimplePrimitiveId(id, OsmPrimitiveType.NODE);
59 }
60
61 static class InternalPopupMenuLauncher extends PopupMenuLauncher {
62 InternalPopupMenuLauncher() {
63 super(new ListPopupMenu(tr("Zoom to node"), tr("Zoom to this node in the current data layer")));
64 }
65
66 @Override
67 protected int checkTableSelection(JTable table, Point p) {
68 int row = super.checkTableSelection(table, p);
69 ((ListPopupMenu) menu).prepare(primitiveIdAtRow((DiffTableModel) table.getModel(), row));
70 return row;
71 }
72 }
73
74}
Note: See TracBrowser for help on using the repository browser.