Changeset 4454 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-09-23T12:11:43+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r4363 r4454 30 30 import java.util.HashSet; 31 31 import java.util.Iterator; 32 import java.util.LinkedList; 32 33 import java.util.List; 34 import java.util.Map.Entry; 33 35 import java.util.Map; 34 import java.util. Map.Entry;36 import java.util.Set; 35 37 import java.util.TreeMap; 38 import java.util.TreeSet; 36 39 import java.util.Vector; 37 import java.util.Set;38 40 39 41 import javax.swing.AbstractAction; … … 97 99 import org.openstreetmap.josm.tools.OpenBrowser; 98 100 import org.openstreetmap.josm.tools.Shortcut; 101 import org.openstreetmap.josm.tools.Utils; 99 102 100 103 /** … … 171 174 private DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 172 175 private HelpAction helpAction = new HelpAction(); 176 private CopyValueAction copyValueAction = new CopyValueAction(); 177 private CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction(); 178 private CopyAllKeyValueAction copyAllKeyValueAction = new CopyAllKeyValueAction(); 173 179 private AddAction addAction = new AddAction(); 174 180 private Shortcut addActionShortcut = Shortcut.registerShortcut("properties:add", tr("Add Properties"), KeyEvent.VK_B, … … 615 621 propertyTable.changeSelection(row, 0, false, false); 616 622 JPopupMenu menu = new JPopupMenu(); 623 menu.add(copyValueAction); 624 menu.add(copyKeyValueAction); 625 menu.add(copyAllKeyValueAction); 626 menu.addSeparator(); 617 627 menu.add(helpAction); 618 628 menu.show(propertyTable, p.x, p.y-3); … … 1292 1302 } 1293 1303 } 1304 1305 abstract class AbstractCopyAction extends AbstractAction { 1306 1307 protected abstract Collection<String> getString(OsmPrimitive p, String key); 1308 1309 @Override 1310 public void actionPerformed(ActionEvent ae) { 1311 if (propertyTable.getSelectedRowCount() != 1) { 1312 return; 1313 } 1314 String key = propertyData.getValueAt(propertyTable.getSelectedRow(), 0).toString(); 1315 Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 1316 if (sel.isEmpty()) { 1317 return; 1318 } 1319 Set<String> values = new TreeSet<String>(); 1320 for (OsmPrimitive p : sel) { 1321 Collection<String> s = getString(p,key); 1322 if (s != null) { 1323 values.addAll(s); 1324 } 1325 } 1326 Utils.copyToClipboard(Utils.join("\n", values)); 1327 } 1328 } 1329 1330 class CopyValueAction extends AbstractCopyAction { 1331 1332 public CopyValueAction() { 1333 putValue(NAME, tr("Copy Value")); 1334 putValue(SHORT_DESCRIPTION, tr("Copy the value of the selected tag to clipboard")); 1335 } 1336 1337 @Override 1338 protected Collection<String> getString(OsmPrimitive p, String key) { 1339 return Collections.singleton(p.get(key)); 1340 } 1341 } 1342 1343 class CopyKeyValueAction extends AbstractCopyAction { 1344 1345 public CopyKeyValueAction() { 1346 putValue(NAME, tr("Copy Key/Value")); 1347 putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the selected tag to clipboard")); 1348 } 1349 1350 @Override 1351 protected Collection<String> getString(OsmPrimitive p, String key) { 1352 String v = p.get(key); 1353 return v == null ? null : Collections.singleton(new Tag(key, v).toString()); 1354 } 1355 } 1356 1357 class CopyAllKeyValueAction extends AbstractCopyAction { 1358 1359 public CopyAllKeyValueAction() { 1360 putValue(NAME, tr("Copy all Keys/Values")); 1361 putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the all tags to clipboard")); 1362 } 1363 1364 @Override 1365 protected Collection<String> getString(OsmPrimitive p, String key) { 1366 List<String> r = new LinkedList<String>(); 1367 for (Entry<String, String> kv : p.getKeys().entrySet()) { 1368 r.add(new Tag(kv.getKey(), kv.getValue()).toString()); 1369 } 1370 return r; 1371 } 1372 } 1294 1373 }
Note:
See TracChangeset
for help on using the changeset viewer.