- Timestamp:
- 2013-02-21T15:05:09+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r5275 r5738 6 6 import static org.openstreetmap.josm.tools.I18n.trn; 7 7 8 import java.awt.GridBagLayout; 8 9 import java.awt.event.ActionEvent; 9 10 import java.awt.event.KeyEvent; … … 13 14 import java.util.List; 14 15 import java.util.Map; 16 import javax.swing.JLabel; 17 import javax.swing.JOptionPane; 18 import javax.swing.JPanel; 15 19 16 20 import org.openstreetmap.josm.Main; … … 21 25 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 22 26 import org.openstreetmap.josm.data.osm.PrimitiveData; 23 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy;24 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy.PasteBufferChangedListener;25 27 import org.openstreetmap.josm.data.osm.Tag; 26 28 import org.openstreetmap.josm.data.osm.TagCollection; 29 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 27 30 import org.openstreetmap.josm.gui.conflict.tags.PasteTagsConflictResolverDialog; 31 import org.openstreetmap.josm.gui.help.HelpUtil; 32 import org.openstreetmap.josm.tools.GBC; 28 33 import org.openstreetmap.josm.tools.Shortcut; 34 import org.openstreetmap.josm.tools.TextTagParser; 35 import org.openstreetmap.josm.tools.UrlLabel; 36 import org.openstreetmap.josm.tools.Utils; 29 37 30 38 /** … … 36 44 * @author David Earl 37 45 */ 38 public final class PasteTagsAction extends JosmAction implements PasteBufferChangedListener{46 public final class PasteTagsAction extends JosmAction { 39 47 40 48 public PasteTagsAction() { … … 43 51 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), 44 52 KeyEvent.VK_V, Shortcut.CTRL_SHIFT), true); 45 Main.pasteBuffer.addPasteBufferChangedListener(this);46 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); 47 68 } 48 69 … … 246 267 if (selection.isEmpty()) 247 268 return; 248 249 TagPaster tagPaster = new TagPaster(Main.pasteBuffer.getDirectlyAdded(), selection);269 270 String buf = Utils.getClipboardContent(); 250 271 251 272 List<Command> commands = new ArrayList<Command>(); 252 for (Tag tag: tagPaster.execute()) { 253 commands.add(new ChangePropertyCommand(selection, tag.getKey(), "".equals(tag.getValue())?null:tag.getValue())); 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 } 254 294 } 255 295 if (!commands.isEmpty()) { … … 262 302 )); 263 303 } 264 265 } 266 267 @Override public void pasteBufferChanged(PrimitiveDeepCopy newPasteBuffer) { 268 updateEnabledState(); 269 } 304 305 } 306 270 307 271 308 @Override 272 309 protected void updateEnabledState() { 273 if (getCurrentDataSet() == null || Main.pasteBuffer == null) {310 if (getCurrentDataSet() == null) { 274 311 setEnabled(false); 275 312 return; 276 313 } 277 setEnabled( 278 !getCurrentDataSet().getSelected().isEmpty() 279 && !TagCollection.unionOfAllPrimitives(Main.pasteBuffer.getDirectlyAdded()).isEmpty() 280 ); 314 // buffer listening slows down the program and is not very good for arbitrary text in buffer 315 setEnabled(!getCurrentDataSet().getSelected().isEmpty()); 281 316 } 282 317 283 318 @Override 284 319 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 285 setEnabled( 286 selection!= null && !selection.isEmpty() 287 && !TagCollection.unionOfAllPrimitives(Main.pasteBuffer.getDirectlyAdded()).isEmpty() 288 ); 320 setEnabled(selection!= null && !selection.isEmpty()); 289 321 } 290 322 }
Note:
See TracChangeset
for help on using the changeset viewer.