Changeset 5876 in josm for trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java
- Timestamp:
- 2013-04-17T20:14:32+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java
r5845 r5876 11 11 import java.awt.event.KeyEvent; 12 12 import java.awt.event.MouseEvent; 13 import java.io.UnsupportedEncodingException; 14 import java.net.URLDecoder; 13 15 import java.util.Collection; 14 16 import java.util.HashMap; 17 import java.util.HashSet; 18 import java.util.Map; 19 import java.util.Set; 15 20 import javax.swing.AbstractAction; 21 import javax.swing.JCheckBox; 16 22 17 23 import javax.swing.JPanel; 18 24 import javax.swing.JTable; 19 25 import javax.swing.KeyStroke; 20 import javax.swing.event.CellEditorListener;21 import javax.swing.event.ChangeEvent;22 26 import javax.swing.table.DefaultTableModel; 23 27 import javax.swing.table.TableCellEditor; … … 31 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; 32 36 import org.openstreetmap.josm.gui.ExtendedDialog; 37 import org.openstreetmap.josm.gui.util.GuiHelper; 33 38 import org.openstreetmap.josm.gui.util.TableHelper; 34 39 import org.openstreetmap.josm.tools.GBC; … … 46 51 47 52 53 /** initially given tags **/ 54 String[][] tags; 55 48 56 private final JTable propertyTable; 49 57 private Collection<? extends OsmPrimitive> sel; 50 58 int[] count; 51 59 60 String sender; 61 static Set<String> trustedSenders = new HashSet<String>(); 62 52 63 /** 53 64 * Class for displaying "delete from ... objects" in the table … … 110 121 } 111 122 112 public AddTagsDialog(String[][] tags ) {123 public AddTagsDialog(String[][] tags, String senderName) { 113 124 super(Main.parent, tr("Add tags to selected objects"), new String[] { tr("Add selected tags"), tr("Add all tags"), tr("Cancel")}, 114 125 false, 115 126 true); 116 127 setToolTipTexts(new String[]{tr("Add checked tags to selected objects"), tr("Shift+Enter: Add all tags to selected objects"), ""}); 117 128 129 this.sender = senderName; 130 118 131 DataSet.addSelectionListener(this); 119 132 … … 211 224 tablePanel.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); 212 225 tablePanel.add(propertyTable, GBC.eol().fill(GBC.BOTH)); 226 if (!trustedSenders.contains(sender)) { 227 final JCheckBox c = new JCheckBox(); 228 c.setAction(new AbstractAction(tr("Accept all tags from {0} for this session", sender) ) { 229 @Override public void actionPerformed(ActionEvent e) { 230 if (c.isSelected()) 231 trustedSenders.add(sender); 232 else 233 trustedSenders.remove(sender); 234 } 235 } ); 236 tablePanel.add(c , GBC.eol().insets(20,10,0,0)); 237 } 213 238 setContent(tablePanel); 214 239 setDefaultButton(2); … … 251 276 } 252 277 } 278 } 279 if (buttonIndex == 2) { 280 trustedSenders.remove(sender); 253 281 } 254 282 setVisible(false); … … 260 288 findExistingTags(); 261 289 } 262 290 291 /* 292 * parse addtags parameters Example URL (part): 293 * addtags=wikipedia:de%3DResidenzschloss Dresden|name:en%3DDresden Castle 294 */ 295 public static void addTags(final Map<String, String> args, final String sender) { 296 if (args.containsKey("addtags")) { 297 GuiHelper.executeByMainWorkerInEDT(new Runnable() { 298 299 public void run() { 300 String[] tags = null; 301 try { 302 tags = URLDecoder.decode(args.get("addtags"), "UTF-8").split("\\|"); 303 } catch (UnsupportedEncodingException e) { 304 throw new RuntimeException(); 305 } 306 Set<String> tagSet = new HashSet<String>(); 307 for (String tag : tags) { 308 if (!tag.trim().isEmpty() && tag.contains("=")) { 309 tagSet.add(tag.trim()); 310 } 311 } 312 if (!tagSet.isEmpty()) { 313 String[][] keyValue = new String[tagSet.size()][2]; 314 int i = 0; 315 for (String tag : tagSet) { 316 // support a = b===c as "a"="b===c" 317 String [] pair = tag.split("\\s*=\\s*",2); 318 keyValue[i][0] = pair[0]; 319 keyValue[i][1] = pair.length<2 ? "": pair[1]; 320 i++; 321 } 322 addTagsIfNeeded(keyValue, sender); 323 } 324 } 325 326 327 }); 328 } 329 } 330 331 private static void addTagsIfNeeded(String[][] keyValue, String sender) { 332 if (trustedSenders.contains(sender)) { 333 if (Main.main.getCurrentDataSet() != null) { 334 Collection<OsmPrimitive> s = Main.main.getCurrentDataSet().getSelected(); 335 for (int j = 0; j < keyValue.length; j++) { 336 Main.main.undoRedo.add(new ChangePropertyCommand(s, keyValue[j][0], keyValue[j][1])); 337 } 338 } 339 } else { 340 new AddTagsDialog(keyValue, sender).showDialog(); 341 } 342 } 263 343 }
Note:
See TracChangeset
for help on using the changeset viewer.