Changeset 2657 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs
- Timestamp:
- 2009-12-19T12:55:50+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/dialogs/properties
- Files:
-
- 2 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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.