| 48 | 50 | public PasteTagsAction() { |
| 49 | 51 | super(tr("Paste Tags"), "pastetags", |
| 50 | 52 | tr("Apply tags of contents of paste buffer to all selected items."), |
| 51 | 53 | Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), |
| 52 | 54 | KeyEvent.VK_V, Shortcut.CTRL_SHIFT), true); |
| 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); |
| 68 | | } |
| 69 | | |
| 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; |
| | 273 | } |
| | 274 | |
| | 275 | /** Paste tags from arbitrary text |
| | 276 | * @return true if action was successful |
| | 277 | */ |
| | 278 | public static boolean pasteTagsFromText(Collection<OsmPrimitive> selection, String text) { |
| | 279 | Map<String, String> tags = TextTagParser.readTagsFromText(text); |
| | 280 | List<Command> commands = new ArrayList<Command>(); |
| | 281 | if (tags==null || tags.isEmpty()) { |
| | 282 | return false; |
| | 283 | } else { |
| | 284 | if (!TextTagParser.validateTags(tags)) return false; |
| | 290 | } |
| | 291 | commitCommands(selection, commands); |
| | 292 | return !commands.isEmpty(); |
| | 293 | } |
| | 294 | |
| | 295 | |
| | 296 | /** Paste tags from JOSM buffer |
| | 297 | * @param selection objects |
| | 298 | * @param commands |
| | 299 | * @return |
| | 300 | */ |
| | 301 | public static boolean pasteTagsFromJOSMBuffer(Collection<OsmPrimitive> selection) { |
| | 302 | List<PrimitiveData> directlyAdded = Main.pasteBuffer.getDirectlyAdded(); |
| | 303 | if (directlyAdded==null || directlyAdded.isEmpty()) return false; |
| | 304 | |
| | 305 | PasteTagsAction.TagPaster tagPaster = new PasteTagsAction.TagPaster(directlyAdded, selection); |
| | 306 | List<Command> commands = new ArrayList<Command>(); |
| | 307 | for (Tag tag : tagPaster.execute()) { |
| | 308 | commands.add(new ChangePropertyCommand(selection, tag.getKey(), "".equals(tag.getValue()) ? null : tag.getValue())); |