Ignore:
Timestamp:
2018-03-13T00:28:24+01:00 (15 months ago)
Author:
Don-vip
Message:

fix #16085 - add contextual menu in tag table of history dialog with following entries, similarly to properties dialog:

  • Copy Value
  • Copy selected Key(s)/Value(s)
  • Copy all Keys/Values
  • Go to OSM wiki for tag help
  • Go to Taginfo
File:
1 edited

Legend:

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

    r10637 r13521  
    44import java.awt.event.FocusEvent;
    55import java.awt.event.FocusListener;
     6import java.util.Arrays;
     7import java.util.Collection;
     8import java.util.HashMap;
     9import java.util.Map;
     10import java.util.function.Function;
     11import java.util.function.Supplier;
    612
     13import javax.swing.JPopupMenu;
    714import javax.swing.JTable;
    815import javax.swing.ListSelectionModel;
     16
     17import org.openstreetmap.josm.data.osm.Tagged;
     18import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
     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.HelpAction;
     23import org.openstreetmap.josm.gui.dialogs.properties.TaginfoAction;
     24import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    925
    1026/**
     
    1632 *   <li>on the right, it displays the list of tags for the version at {@link PointInTimeType#CURRENT_POINT_IN_TIME}</li>
    1733 * </ul>
    18  *
     34 * @since 1709
    1935 */
    2036public class TagInfoViewer extends HistoryViewerPanel {
     
    4662    @Override
    4763    protected JTable buildReferenceTable() {
    48         JTable table = new JTable(
    49                 model.getTagTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME),
    50                 new TagTableColumnModel()
    51         );
    52         table.setName("table.referencetagtable");
    53         setUpDataTransfer(table);
    54         return table;
     64        return buildTable(PointInTimeType.REFERENCE_POINT_IN_TIME, "table.referencetagtable", model::getReferencePointInTime);
    5565    }
    5666
    5767    @Override
    5868    protected JTable buildCurrentTable() {
    59         JTable table = new JTable(
    60                 model.getTagTableModel(PointInTimeType.CURRENT_POINT_IN_TIME),
    61                 new TagTableColumnModel()
    62         );
    63         table.setName("table.currenttagtable");
    64         setUpDataTransfer(table);
    65         return table;
     69        return buildTable(PointInTimeType.CURRENT_POINT_IN_TIME, "table.currenttagtable", model::getCurrentPointInTime);
    6670    }
    6771
    68     private void setUpDataTransfer(JTable table) {
     72    private JTable buildTable(PointInTimeType pointInTime, String name, Supplier<HistoryOsmPrimitive> histoSp) {
     73        TagTableModel tagTableModel = model.getTagTableModel(pointInTime);
     74        JTable table = new JTable(tagTableModel, new TagTableColumnModel());
     75        table.setName(name);
    6976        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    7077        selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
    7178        table.setTransferHandler(new TagInfoTransferHandler());
    7279        table.addFocusListener(new RepaintOnFocusChange());
     80        JPopupMenu tagMenu = new JPopupMenu();
     81
     82        Function<Integer, String> tagKeyFn = x -> (String) table.getValueAt(x, 0);
     83        Function<Integer, Map<String, Integer>> tagValuesFn = x -> {
     84            Map<String, Integer> map = new HashMap<>();
     85            String key = tagTableModel.getValue((String) table.getValueAt(x, 0));
     86            if (key != null) {
     87                map.put(key, 1);
     88            }
     89            return map;
     90        };
     91        Supplier<Collection<? extends Tagged>> objectSp = () -> Arrays.asList(histoSp.get());
     92
     93        tagMenu.add(new CopyValueAction(table, tagKeyFn, objectSp));
     94        tagMenu.add(new CopyKeyValueAction(table, tagKeyFn, objectSp));
     95        tagMenu.add(new CopyAllKeyValueAction(table, tagKeyFn, objectSp));
     96        tagMenu.addSeparator();
     97        tagMenu.add(new HelpAction(table, tagKeyFn, tagValuesFn, null, null));
     98        tagMenu.add(new TaginfoAction(table, tagKeyFn, tagValuesFn, null, null));
     99
     100        table.addMouseListener(new PopupMenuLauncher(tagMenu));
     101        return table;
    73102    }
    74103}
Note: See TracChangeset for help on using the changeset viewer.