Changeset 5809 in josm for trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
- Timestamp:
- 2013-03-29T12:16:54+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r5738 r5809 6 6 import static org.openstreetmap.josm.tools.I18n.trn; 7 7 8 import java.awt.GridBagLayout;9 8 import java.awt.event.ActionEvent; 10 9 import java.awt.event.KeyEvent; … … 14 13 import java.util.List; 15 14 import java.util.Map; 16 import javax.swing.JLabel;17 import javax.swing.JOptionPane;18 import javax.swing.JPanel;19 15 20 16 import org.openstreetmap.josm.Main; … … 27 23 import org.openstreetmap.josm.data.osm.Tag; 28 24 import org.openstreetmap.josm.data.osm.TagCollection; 29 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;30 25 import org.openstreetmap.josm.gui.conflict.tags.PasteTagsConflictResolverDialog; 31 26 import org.openstreetmap.josm.gui.help.HelpUtil; 32 import org.openstreetmap.josm.tools.GBC;33 27 import org.openstreetmap.josm.tools.Shortcut; 34 28 import org.openstreetmap.josm.tools.TextTagParser; 35 import org.openstreetmap.josm.tools.UrlLabel;36 29 import org.openstreetmap.josm.tools.Utils; 37 30 … … 46 39 public final class PasteTagsAction extends JosmAction { 47 40 41 private static final String help = ht("/Action/PasteTags"); 42 private static final String helpUrl = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(help)); 43 48 44 public PasteTagsAction() { 49 45 super(tr("Paste Tags"), "pastetags", … … 51 47 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), 52 48 KeyEvent.VK_V, Shortcut.CTRL_SHIFT), true); 53 putValue("help", ht("/Action/PasteTags")); 54 } 55 56 private void showBadBufferMessage() { 57 String msg = tr("<html><p> Sorry, it is impossible to paste tags from buffer. It does not contain any JOSM object" 58 + " or suitable text. </p></html>"); 59 JPanel p = new JPanel(new GridBagLayout()); 60 p.add(new JLabel(msg),GBC.eop()); 61 p.add(new UrlLabel( 62 HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic((String)getValue("help")))), 63 GBC.eop()); 64 65 ConditionalOptionPaneUtil.showMessageDialog( 66 "paste_badbuffer", Main.parent, 67 p, tr("Warning"), JOptionPane.WARNING_MESSAGE); 49 putValue("help", help); 68 50 } 69 51 … … 269 251 270 252 String buf = Utils.getClipboardContent(); 271 253 if (buf == null || buf.isEmpty() || buf.matches("(\\d+,)*\\d+")) { 254 pasteTagsFromJOSMBuffer(selection); 255 } else { 256 // Paste tags from arbitrary text 257 pasteTagsFromText(selection, buf); 258 } 259 } 260 261 /** Paste tags from arbitrary text 262 * @return false if action was successful 263 */ 264 public static boolean pasteTagsFromText(Collection<OsmPrimitive> selection, String text) { 265 Map<String, String> tags = TextTagParser.readTagsFromText(text); 272 266 List<Command> commands = new ArrayList<Command>(); 273 if (buf==null) { 274 showBadBufferMessage(); 275 return; 276 } 277 if (buf.matches("(\\d+,)*\\d+")) { // Paste tags from JOSM buffer 278 PasteTagsAction.TagPaster tagPaster = new PasteTagsAction.TagPaster(Main.pasteBuffer.getDirectlyAdded(), selection); 279 for (Tag tag: tagPaster.execute()) { 280 commands.add(new ChangePropertyCommand(selection, tag.getKey(), "".equals(tag.getValue())?null:tag.getValue())); 281 } 282 } else { // Paste tags from arbitrary text 283 Map<String, String> tags = TextTagParser.readTagsFromText(buf); 284 if (tags==null || tags.isEmpty()) { 285 showBadBufferMessage(); 286 return; 287 } 288 if (!TextTagParser.validateTags(tags)) return; 289 String v; 290 for (String key: tags.keySet()) { 291 v = tags.get(key); 292 commands.add(new ChangePropertyCommand(selection, key, "".equals(v)?null:v)); 293 } 294 } 267 if (tags==null || tags.isEmpty()) { 268 TextTagParser.showBadBufferMessage(helpUrl); 269 return false; 270 }; 271 if (!TextTagParser.validateTags(tags)) return false; 272 String v; 273 for (String key: tags.keySet()) { 274 v = tags.get(key); 275 commands.add(new ChangePropertyCommand(selection, key, "".equals(v)?null:v)); 276 } 277 commitCommands(selection, commands); 278 return !commands.isEmpty(); 279 } 280 281 /** Paste tags from JOSM buffer 282 * @param selection objects 283 * @param commands 284 * @return 285 */ 286 public static boolean pasteTagsFromJOSMBuffer(Collection<OsmPrimitive> selection) { 287 List<PrimitiveData> directlyAdded = Main.pasteBuffer.getDirectlyAdded(); 288 if (directlyAdded==null || directlyAdded.isEmpty()) return false; 289 290 PasteTagsAction.TagPaster tagPaster = new PasteTagsAction.TagPaster(directlyAdded, selection); 291 List<Command> commands = new ArrayList<Command>(); 292 for (Tag tag : tagPaster.execute()) { 293 commands.add(new ChangePropertyCommand(selection, tag.getKey(), "".equals(tag.getValue()) ? null : tag.getValue())); 294 } 295 commitCommands(selection, commands); 296 return true; 297 } 298 299 /** 300 * Create and execute SequenceCommand with descriptive title 301 * @param commands 302 */ 303 private static void commitCommands(Collection<OsmPrimitive> selection, List<Command> commands) { 295 304 if (!commands.isEmpty()) { 296 305 String title1 = trn("Pasting {0} tag", "Pasting {0} tags", commands.size(), commands.size()); … … 302 311 )); 303 312 } 304 305 } 306 307 313 } 314 308 315 @Override 309 316 protected void updateEnabledState() {
Note:
See TracChangeset
for help on using the changeset viewer.