Changeset 10604 in josm for trunk/src/org/openstreetmap/josm/gui/tagging
- Timestamp:
- 2016-07-23T14:54:19+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/tagging
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java
r10217 r10604 8 8 import java.util.ArrayList; 9 9 import java.util.Collection; 10 import java.util.Collections; 10 11 import java.util.Comparator; 11 12 import java.util.EnumSet; … … 25 26 import org.openstreetmap.josm.data.osm.Tag; 26 27 import org.openstreetmap.josm.data.osm.TagCollection; 28 import org.openstreetmap.josm.data.osm.TagMap; 27 29 import org.openstreetmap.josm.data.osm.Tagged; 28 30 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType; … … 47 49 48 50 private transient OsmPrimitive primitive; 51 52 private EndEditListener endEditListener; 49 53 50 54 /** … … 167 171 */ 168 172 public void clear() { 173 commitPendingEdit(); 169 174 boolean wasEmpty = tags.isEmpty(); 170 175 tags.clear(); … … 183 188 */ 184 189 public void add(TagModel tag) { 190 commitPendingEdit(); 185 191 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 186 192 tags.add(tag); … … 189 195 } 190 196 197 /** 198 * Add a tag at the beginning of the table. 199 * 200 * @param tag The tag to add 201 * 202 * @throws IllegalArgumentException if tag is null 203 * 204 * @see #add(TagModel) 205 */ 191 206 public void prepend(TagModel tag) { 207 commitPendingEdit(); 192 208 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 193 209 tags.add(0, tag); … … 209 225 */ 210 226 public void add(String name, String value) { 227 commitPendingEdit(); 211 228 String key = (name == null) ? "" : name; 212 229 String val = (value == null) ? "" : value; … … 259 276 if (tags == null) 260 277 return; 278 commitPendingEdit(); 261 279 for (int tagIdx : tagIndices) { 262 280 TagModel tag = tags.get(tagIdx); … … 277 295 if (tags == null) 278 296 return; 297 commitPendingEdit(); 279 298 for (int tagIdx : tagIndices) { 280 299 TagModel tag = tags.get(tagIdx); … … 293 312 */ 294 313 public void delete(String name) { 314 commitPendingEdit(); 295 315 if (name == null) 296 316 return; … … 318 338 if (tags == null) 319 339 return; 340 commitPendingEdit(); 320 341 List<TagModel> toDelete = new ArrayList<>(); 321 342 for (int tagIdx : tagIndices) { … … 356 377 */ 357 378 public void initFromPrimitive(Tagged primitive) { 379 commitPendingEdit(); 358 380 this.tags.clear(); 359 381 for (String key : primitive.keySet()) { … … 361 383 this.tags.add(new TagModel(key, value)); 362 384 } 385 sort(); 363 386 TagModel tag = new TagModel(); 364 sort();365 387 tags.add(tag); 366 388 setDirty(false); … … 374 396 */ 375 397 public void initFromTags(Map<String, String> tags) { 398 commitPendingEdit(); 376 399 this.tags.clear(); 377 400 for (Entry<String, String> entry : tags.entrySet()) { … … 391 414 */ 392 415 public void initFromTags(TagCollection tags) { 416 commitPendingEdit(); 393 417 this.tags.clear(); 394 418 if (tags == null) { … … 424 448 */ 425 449 private Map<String, String> applyToTags(boolean keepEmpty) { 426 Map<String, String> result = new HashMap<>(); 450 // TagMap preserves the order of tags. 451 TagMap result = new TagMap(); 427 452 for (TagModel tag: this.tags) { 428 453 // tag still holds an unchanged list of different values for the same key. … … 433 458 434 459 // tag name holds an empty key. Don't apply it to the selection. 435 //436 460 if (!keepEmpty && (tag.getName().trim().isEmpty() || tag.getValue().trim().isEmpty())) { 437 461 continue; … … 539 563 */ 540 564 protected void sort() { 541 java.util.Collections.sort(565 Collections.sort( 542 566 tags, 543 567 new Comparator<TagModel>() { … … 591 615 */ 592 616 public void updateTags(List<Tag> tags) { 593 617 if (tags.isEmpty()) 594 618 return; 595 619 620 commitPendingEdit(); 596 621 Map<String, TagModel> modelTags = new HashMap<>(); 597 622 for (int i = 0; i < getRowCount(); i++) { … … 648 673 } 649 674 675 /** 676 * Sets the listener that is notified when an edit should be aborted. 677 * @param endEditListener The listener to be notified when editing should be aborted. 678 */ 679 public void setEndEditListener(EndEditListener endEditListener) { 680 this.endEditListener = endEditListener; 681 } 682 683 private void commitPendingEdit() { 684 if (endEditListener != null) { 685 endEditListener.endCellEditing(); 686 } 687 } 688 650 689 class SelectionStateMemento { 651 690 private final int rowMin; … … 674 713 } 675 714 } 715 716 /** 717 * A listener that is called whenever the cells may be updated from outside the editor and the editor should thus be commited. 718 * @since 10604 719 */ 720 @FunctionalInterface 721 public interface EndEditListener { 722 /** 723 * Requests to end the editing of any cells on this model 724 */ 725 void endCellEditing(); 726 } 676 727 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java
r10378 r10604 2 2 package org.openstreetmap.josm.gui.tagging; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 … … 13 12 import java.beans.PropertyChangeEvent; 14 13 import java.beans.PropertyChangeListener; 15 import java.util.ArrayList;16 14 import java.util.Collections; 17 15 import java.util.EventObject; 18 import java.util.List;19 import java.util.Map;20 16 import java.util.concurrent.CopyOnWriteArrayList; 21 17 … … 32 28 33 29 import org.openstreetmap.josm.Main; 34 import org.openstreetmap.josm.actions.CopyAction;35 import org.openstreetmap.josm.actions.PasteTagsAction;36 import org.openstreetmap.josm.data.osm.OsmPrimitive;37 import org.openstreetmap.josm.data.osm.PrimitiveData;38 30 import org.openstreetmap.josm.data.osm.Relation; 39 import org.openstreetmap.josm.data.osm.Tag; 31 import org.openstreetmap.josm.data.osm.TagMap; 32 import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler; 33 import org.openstreetmap.josm.gui.tagging.TagEditorModel.EndEditListener; 40 34 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 41 35 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 42 36 import org.openstreetmap.josm.gui.widgets.JosmTable; 43 37 import org.openstreetmap.josm.tools.ImageProvider; 44 import org.openstreetmap.josm.tools.TextTagParser;45 import org.openstreetmap.josm.tools.Utils;46 38 47 39 /** … … 49 41 * @since 1762 50 42 */ 51 public class TagTable extends JosmTable {43 public class TagTable extends JosmTable implements EndEditListener { 52 44 /** the table cell editor used by this table */ 53 45 private TagCellEditor editor; … … 211 203 } 212 204 213 if (isEditing()) { 214 CellEditor cEditor = getCellEditor(); 215 if (cEditor != null) { 216 cEditor.cancelCellEditing(); 217 } 218 } 205 endCellEditing(); 219 206 220 207 if (model.getRowCount() == 0) { … … 233 220 234 221 protected final void updateEnabledState() { 235 if (isEditing() && getSelectedColumnCount() == 1 && getSelectedRowCount() == 1) { 236 setEnabled(true); 237 } else if (!isEditing() && getSelectedColumnCount() == 1 && getSelectedRowCount() == 1) { 238 setEnabled(true); 239 } else if (getSelectedColumnCount() > 1 || getSelectedRowCount() > 1) { 222 if (getSelectedColumnCount() >= 1 && getSelectedRowCount() >= 1) { 240 223 setEnabled(true); 241 224 } else { … … 295 278 Relation relation = new Relation(); 296 279 model.applyToPrimitive(relation); 297 298 String buf = Utils.getClipboardContent(); 299 if (buf == null || buf.isEmpty() || buf.matches(CopyAction.CLIPBOARD_REGEXP)) { 300 List<PrimitiveData> directlyAdded = Main.pasteBuffer.getDirectlyAdded(); 301 if (directlyAdded == null || directlyAdded.isEmpty()) return; 302 PasteTagsAction.TagPaster tagPaster = new PasteTagsAction.TagPaster(directlyAdded, 303 Collections.<OsmPrimitive>singletonList(relation)); 304 model.updateTags(tagPaster.execute()); 305 } else { 306 // Paste tags from arbitrary text 307 Map<String, String> tags = TextTagParser.readTagsFromText(buf); 308 if (tags == null || tags.isEmpty()) { 309 TextTagParser.showBadBufferMessage(ht("/Action/PasteTags")); 310 } else if (TextTagParser.validateTags(tags)) { 311 List<Tag> newTags = new ArrayList<>(); 312 for (Map.Entry<String, String> entry: tags.entrySet()) { 313 String k = entry.getKey(); 314 String v = entry.getValue(); 315 newTags.add(new Tag(k, v)); 316 } 317 model.updateTags(newTags); 318 } 319 } 280 new OsmTransferHandler().pasteTags(Collections.singleton(relation)); 281 model.updateTags(new TagMap(relation.getKeys()).getTags()); 320 282 } 321 283 … … 415 377 model.getRowSelectionModel()); 416 378 this.model = model; 379 model.setEndEditListener(this); 417 380 init(maxCharacters); 418 381 } … … 488 451 */ 489 452 public void setTagCellEditor(TagCellEditor editor) { 490 if (isEditing()) { 491 this.editor.cancelCellEditing(); 492 } 453 endCellEditing(); 493 454 this.editor = editor; 494 455 getColumnModel().getColumn(0).setCellEditor(editor); … … 546 507 // delegate to the default implementation 547 508 return super.editCellAt(row, column, e); 509 } 510 511 @Override 512 public void endCellEditing() { 513 if (isEditing()) { 514 CellEditor cEditor = getCellEditor(); 515 if (cEditor != null) { 516 // First attempt to commit. If this does not work, cancel. 517 cEditor.stopCellEditing(); 518 cEditor.cancelCellEditing(); 519 } 520 } 548 521 } 549 522 -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java
r10308 r10604 24 24 25 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.gui. util.GuiHelper;26 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 27 27 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 28 import org.openstreetmap.josm.tools.Utils;29 28 30 29 /** … … 134 133 final JTextComponent editorComponent = comboBox.getEditorComponent(); 135 134 // save unix system selection (middle mouse paste) 136 Clipboard sysSel = GuiHelper.getSystemSelection();135 Clipboard sysSel = ClipboardUtils.getSystemSelection(); 137 136 if (sysSel != null) { 138 Transferable old = Utils.getTransferableContent(sysSel);137 Transferable old = ClipboardUtils.getClipboardContent(sysSel); 139 138 editorComponent.select(start, end); 140 139 if (old != null) { … … 201 200 } 202 201 // save unix system selection (middle mouse paste) 203 Clipboard sysSel = GuiHelper.getSystemSelection();202 Clipboard sysSel = ClipboardUtils.getSystemSelection(); 204 203 if (sysSel != null) { 205 Transferable old = Utils.getTransferableContent(sysSel);204 Transferable old = ClipboardUtils.getClipboardContent(sysSel); 206 205 editorComponent.selectAll(); 207 206 if (old != null) {
Note:
See TracChangeset
for help on using the changeset viewer.