source: josm/trunk/src/org/openstreetmap/josm/gui/history/TagInfoTransferHandler.java@ 10670

Last change on this file since 10670 was 10637, checked in by Don-vip, 8 years ago

fix #13050 - cannot copy from the object history view (patch by michael2402, modified) - gsoc-core

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import java.awt.datatransfer.Clipboard;
5
6import javax.swing.JComponent;
7import javax.swing.JTable;
8import javax.swing.TransferHandler;
9import javax.swing.table.TableModel;
10
11import org.openstreetmap.josm.data.osm.TagMap;
12import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
13import org.openstreetmap.josm.gui.datatransfer.TagTransferable;
14import org.openstreetmap.josm.gui.datatransfer.data.TagTransferData;
15import org.openstreetmap.josm.gui.history.HistoryBrowserModel.TagTableModel;
16
17/**
18 * This transfer handler allows to select and copy tags from a table with the {@link TagTableColumnModel}.
19 * @author Michael Zangl
20 * @since 10637
21 */
22public class TagInfoTransferHandler extends TransferHandler {
23
24 @Override
25 public void exportToClipboard(JComponent comp, Clipboard clip, int action) throws IllegalStateException {
26 if (comp instanceof JTable) {
27 TableModel model = ((JTable) comp).getModel();
28 if (model instanceof TagTableModel) {
29 exportFromModel((JTable) comp, (TagTableModel) model);
30 }
31 }
32 }
33
34 private static void exportFromModel(JTable comp, TagTableModel model) {
35 int[] selected = comp.getSelectedRows();
36 TagMap tags = new TagMap();
37 for (int row : selected) {
38 String key = model.getKeyAt(row);
39 String value = model.getValue(key);
40 if (value != null) {
41 tags.put(key, value);
42 }
43 }
44 TagTransferData data = new TagTransferData(tags);
45 ClipboardUtils.copy(new TagTransferable(data));
46 }
47}
Note: See TracBrowser for help on using the repository browser.