- Timestamp:
- 2009-12-19T12:55:50+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r2656 r2657 849 849 } 850 850 851 void fireTagsChanged(OsmPrimitive prim ) {852 fireEvent(new TagsChangedEvent(this, prim ));851 void fireTagsChanged(OsmPrimitive prim, Map<String, String> originalKeys) { 852 fireEvent(new TagsChangedEvent(this, prim, originalKeys)); 853 853 } 854 854 -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r2656 r2657 717 717 */ 718 718 public void setKeys(Map<String, String> keys) { 719 Map<String, String> originalKeys = getKeys(); 719 720 if (keys == null) { 720 721 this.keys = null; 722 keysChangedImpl(originalKeys); 721 723 return; 722 724 } … … 728 730 } 729 731 this.keys = newKeys; 730 keysChangedImpl( );732 keysChangedImpl(originalKeys); 731 733 } 732 734 … … 741 743 */ 742 744 public final void put(String key, String value) { 745 Map<String, String> originalKeys = getKeys(); 743 746 if (key == null) 744 747 return; … … 747 750 } else if (keys == null || keys.length == 0){ 748 751 keys = new String[] {key, value}; 749 keysChangedImpl( );752 keysChangedImpl(originalKeys); 750 753 } else { 751 754 for (int i=0; i<keys.length;i+=2) { 752 755 if (keys[i].equals(key)) { 753 756 keys[i+1] = value; 754 keysChangedImpl( );757 keysChangedImpl(originalKeys); 755 758 return; 756 759 } … … 764 767 newKeys[keys.length + 1] = value; 765 768 keys = newKeys; 766 keysChangedImpl( );769 keysChangedImpl(originalKeys); 767 770 } 768 771 } … … 776 779 if (!hasKey(key)) 777 780 return; 781 Map<String, String> originalKeys = getKeys(); 778 782 if (keys.length == 2) { 779 783 keys = null; 780 keysChangedImpl( );784 keysChangedImpl(originalKeys); 781 785 return; 782 786 } … … 790 794 } 791 795 keys = newKeys; 792 keysChangedImpl( );796 keysChangedImpl(originalKeys); 793 797 } 794 798 … … 799 803 */ 800 804 public final void removeAll() { 801 keys = null; 802 keysChangedImpl(); 805 if (keys != null) { 806 Map<String, String> originalKeys = getKeys(); 807 keys = null; 808 keysChangedImpl(originalKeys); 809 } 803 810 } 804 811 … … 854 861 } 855 862 856 private void keysChangedImpl( ) {863 private void keysChangedImpl(Map<String, String> originalKeys) { 857 864 clearCached(); 858 865 updateHasDirectionKeys(); 859 866 updateTagged(); 860 867 if (dataSet != null) { 861 dataSet.fireTagsChanged(this );868 dataSet.fireTagsChanged(this, originalKeys); 862 869 } 863 870 } -
trunk/src/org/openstreetmap/josm/data/osm/event/TagsChangedEvent.java
r2645 r2657 4 4 import java.util.Collections; 5 5 import java.util.List; 6 import java.util.Map; 6 7 7 8 import org.openstreetmap.josm.data.osm.DataSet; … … 11 12 12 13 private final OsmPrimitive primitive; 14 private final Map<String, String> originalKeys; 13 15 14 public TagsChangedEvent(DataSet dataSet, OsmPrimitive primitive ) {16 public TagsChangedEvent(DataSet dataSet, OsmPrimitive primitive, Map<String, String> originalKeys) { 15 17 super(dataSet); 16 18 this.primitive = primitive; 19 this.originalKeys = originalKeys; 17 20 } 18 21 … … 36 39 } 37 40 41 public Map<String, String> getOriginalKeys() { 42 return originalKeys; 43 } 44 38 45 } -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r2655 r2657 37 37 import org.openstreetmap.josm.gui.dialogs.HistoryDialog; 38 38 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 39 import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;40 39 import org.openstreetmap.josm.gui.dialogs.RelationListDialog; 41 40 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; 42 41 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 43 42 import org.openstreetmap.josm.gui.dialogs.UserListDialog; 43 import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog; 44 44 import org.openstreetmap.josm.tools.Destroyable; 45 45 -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r2654 r2657 1 1 2 package org.openstreetmap.josm.gui.dialogs ;2 package org.openstreetmap.josm.gui.dialogs.properties; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; … … 20 20 import java.awt.event.MouseEvent; 21 21 import java.awt.event.MouseListener; 22 import java.util.ArrayList; 22 23 import java.util.Collection; 23 24 import java.util.Collections; … … 27 28 import java.util.Map; 28 29 import java.util.TreeMap; 29 import java.util.TreeSet;30 30 import java.util.Vector; 31 31 import java.util.Map.Entry; … … 63 63 import org.openstreetmap.josm.data.osm.RelationMember; 64 64 import org.openstreetmap.josm.data.osm.Way; 65 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 65 66 import org.openstreetmap.josm.gui.DefaultNameFormatter; 66 67 import org.openstreetmap.josm.gui.ExtendedDialog; … … 68 69 import org.openstreetmap.josm.gui.MapView; 69 70 import org.openstreetmap.josm.gui.SideButton; 70 import org.openstreetmap.josm.gui. MapView.LayerChangeListener;71 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 71 72 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 72 73 import org.openstreetmap.josm.gui.layer.Layer; … … 139 140 140 141 private final Map<String, Map<String, Integer>> valueCount = new TreeMap<String, Map<String, Integer>>(); 142 private final ListOfUsedTags listOfUsedTags = new ListOfUsedTags(); 143 144 @Override 145 public void showNotify() { 146 DatasetEventManager.getInstance().addDatasetListener(listOfUsedTags, false); 147 } 148 149 @Override 150 public void hideNotify() { 151 DatasetEventManager.getInstance().removeDatasetListener(listOfUsedTags); 152 } 153 141 154 /** 142 155 * Edit the value in the properties table row … … 158 171 panel.add(new JLabel(msg), BorderLayout.NORTH); 159 172 160 final TreeMap<String, TreeSet<String>> allData = createAutoCompletionInfo(true);161 162 173 JPanel p = new JPanel(new GridBagLayout()); 163 174 panel.add(p, BorderLayout.CENTER); 164 175 165 176 final AutoCompleteComboBox keys = new AutoCompleteComboBox(); 166 keys.setPossibleItems( allData.keySet());177 keys.setPossibleItems(listOfUsedTags.getUsedKeys()); 167 178 keys.setEditable(true); 168 179 keys.setSelectedItem(key); … … 194 205 }); 195 206 values.setEditable(true); 196 updateListData(key, allData, values);207 values.setPossibleItems(listOfUsedTags.getUsedValues(key)); 197 208 Map<String, Integer> m=(Map<String, Integer>)propertyData.getValueAt(row, 1); 198 209 final String selection= m.size()!=1?tr("<different>"):m.entrySet().iterator().next().getKey(); … … 202 213 p.add(Box.createHorizontalStrut(10), GBC.std()); 203 214 p.add(values, GBC.eol().fill(GBC.HORIZONTAL)); 204 addFocusAdapter(row, allData,keys, values);215 addFocusAdapter(row, keys, values); 205 216 206 217 final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION) { … … 288 299 289 300 /** 290 * @param key291 * @param allData292 * @param values293 */294 private void updateListData(String key, final TreeMap<String, TreeSet<String>> allData,295 final AutoCompleteComboBox values) {296 Collection<String> newItems;297 if (allData.containsKey(key)) {298 newItems = allData.get(key);299 } else {300 newItems = Collections.emptyList();301 }302 values.setPossibleItems(newItems);303 }304 305 /**306 301 * This simply fires up an relation editor for the relation shown; everything else 307 302 * is the editor's business. … … 330 325 "This will change up to {0} objects.", sel.size(),sel.size()) 331 326 +"<br><br>"+tr("Please select a key")), BorderLayout.NORTH); 332 final TreeMap<String, TreeSet<String>> allData = createAutoCompletionInfo(false);333 327 final AutoCompleteComboBox keys = new AutoCompleteComboBox(); 334 keys.setPossibleItems(allData.keySet()); 328 List<String> usedKeys = new ArrayList<String>(listOfUsedTags.getUsedKeys()); 329 for (int i = 0; i < propertyData.getRowCount(); ++i) { 330 usedKeys.remove(propertyData.getValueAt(i, 0)); 331 } 332 keys.setPossibleItems(usedKeys); 335 333 keys.setEditable(true); 336 334 … … 344 342 p2.add(values, BorderLayout.CENTER); 345 343 346 addFocusAdapter(-1, allData,keys, values);344 addFocusAdapter(-1, keys, values); 347 345 JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){ 348 346 @Override public void selectInitialValue() { … … 373 371 * @param values 374 372 */ 375 private void addFocusAdapter(final int row, final TreeMap<String, TreeSet<String>> allData, 376 final AutoCompleteComboBox keys, final AutoCompleteComboBox values) { 373 private void addFocusAdapter(final int row, final AutoCompleteComboBox keys, final AutoCompleteComboBox values) { 377 374 // get the combo box' editor component 378 375 JTextComponent editor = (JTextComponent)values.getEditor() … … 382 379 @Override public void focusGained(FocusEvent e) { 383 380 String key = keys.getEditor().getItem().toString(); 384 updateListData(key, allData, values);381 values.setPossibleItems(listOfUsedTags.getUsedValues(key)); 385 382 objKey=key; 386 383 } … … 388 385 } 389 386 private String objKey; 390 391 private TreeMap<String, TreeSet<String>> createAutoCompletionInfo(392 boolean edit) {393 final TreeMap<String, TreeSet<String>> allData = new TreeMap<String, TreeSet<String>>();394 for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedPrimitives()) {395 for (String key : osm.keySet()) {396 TreeSet<String> values = null;397 if (allData.containsKey(key)) {398 values = allData.get(key);399 } else {400 values = new TreeSet<String>();401 allData.put(key, values);402 }403 values.add(osm.get(key));404 }405 }406 if (!edit) {407 for (int i = 0; i < propertyData.getRowCount(); ++i) {408 allData.remove(propertyData.getValueAt(i, 0));409 }410 }411 return allData;412 }413 387 414 388 /**
Note:
See TracChangeset
for help on using the changeset viewer.