source: josm/trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java@ 17684

Last change on this file since 17684 was 17684, checked in by simon04, 3 years ago

fix #20678 - History Browser: reset coordinates of a node to previous versions (via popup menu)

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import java.awt.event.FocusEvent;
5import java.awt.event.FocusListener;
6import java.util.Collection;
7import java.util.Collections;
8import java.util.Map;
9import java.util.function.IntFunction;
10import java.util.function.Supplier;
11
12import javax.swing.JPopupMenu;
13import javax.swing.JTable;
14import javax.swing.ListSelectionModel;
15
16import org.openstreetmap.josm.actions.RestorePropertyAction;
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.data.osm.Tagged;
19import org.openstreetmap.josm.gui.dialogs.properties.CopyAllKeyValueAction;
20import org.openstreetmap.josm.gui.dialogs.properties.CopyKeyValueAction;
21import org.openstreetmap.josm.gui.dialogs.properties.CopyValueAction;
22import org.openstreetmap.josm.gui.dialogs.properties.HelpTagAction;
23import org.openstreetmap.josm.gui.dialogs.properties.TaginfoAction;
24import org.openstreetmap.josm.gui.util.TableHelper;
25import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
26
27/**
28 * TagInfoViewer is a UI component which displays the list of tags of two
29 * version of a {@link org.openstreetmap.josm.data.osm.OsmPrimitive} in a {@link org.openstreetmap.josm.data.osm.history.History}.
30 *
31 * <ul>
32 * <li>on the left, it displays the list of tags for the version at {@link PointInTimeType#REFERENCE_POINT_IN_TIME}</li>
33 * <li>on the right, it displays the list of tags for the version at {@link PointInTimeType#CURRENT_POINT_IN_TIME}</li>
34 * </ul>
35 * @since 1709
36 */
37public class TagInfoViewer extends HistoryViewerPanel {
38 private static final class RepaintOnFocusChange implements FocusListener {
39 @Override
40 public void focusLost(FocusEvent e) {
41 repaintSelected(e);
42 }
43
44 @Override
45 public void focusGained(FocusEvent e) {
46 repaintSelected(e);
47 }
48
49 private static void repaintSelected(FocusEvent e) {
50 // we would only need the selected rows, but this is easier:
51 e.getComponent().repaint();
52 }
53 }
54
55 /**
56 * Constructs a new {@code TagInfoViewer}.
57 * @param model The history browsing model
58 */
59 public TagInfoViewer(HistoryBrowserModel model) {
60 super(model);
61 }
62
63 @Override
64 protected JTable buildTable(PointInTimeType pointInTime) {
65 TagTableModel tagTableModel = model.getTagTableModel(pointInTime);
66 JTable table = new JTable(tagTableModel, new TagTableColumnModel());
67 TableHelper.setFont(table, getClass());
68 table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
69 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
70 table.getTableHeader().setReorderingAllowed(false);
71 table.setTransferHandler(new TagInfoTransferHandler());
72 table.addFocusListener(new RepaintOnFocusChange());
73 JPopupMenu tagMenu = new JPopupMenu();
74
75 IntFunction<String> tagKeyFn = x -> (String) table.getValueAt(x, 0);
76 IntFunction<String> tagValueFn = x -> tagTableModel.getValue(tagKeyFn.apply(x));
77 IntFunction<Map<String, Integer>> tagValuesFn = x -> {
78 String value = tagValueFn.apply(x);
79 return value != null ? Collections.singletonMap(value, 1) : Collections.emptyMap();
80 };
81 Supplier<Collection<? extends Tagged>> objectSp = () -> Collections.singletonList(model.getPointInTime(pointInTime));
82 Supplier<OsmPrimitive> primitiveSupplier = () -> getPrimitiveFromDataSet(pointInTime);
83
84 tagMenu.add(trackJosmAction(new CopyValueAction(table, tagKeyFn, objectSp)));
85 final CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction(table, tagKeyFn, objectSp);
86 tagMenu.add(trackJosmAction(copyKeyValueAction));
87 tagMenu.addPopupMenuListener(copyKeyValueAction);
88 tagMenu.add(trackJosmAction(new CopyAllKeyValueAction(table, tagKeyFn, objectSp)));
89 tagMenu.add(new RestorePropertyAction(tagKeyFn, tagValueFn, primitiveSupplier, table.getSelectionModel()));
90 tagMenu.addSeparator();
91 tagMenu.add(trackJosmAction(new HelpTagAction(table, tagKeyFn, tagValuesFn)));
92 TaginfoAction taginfoAction = new TaginfoAction(table, tagKeyFn, tagValuesFn, null, null);
93 tagMenu.add(trackJosmAction(taginfoAction.toTagHistoryAction()));
94 tagMenu.add(trackJosmAction(taginfoAction));
95
96 table.addMouseListener(new PopupMenuLauncher(tagMenu));
97 return table;
98 }
99}
Note: See TracBrowser for help on using the repository browser.