Changeset 5071 in josm
- Timestamp:
- 2012-03-11T15:02:31+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSearchDialog.java
r4968 r5071 36 36 37 37 import org.openstreetmap.josm.Main; 38 import org.openstreetmap.josm.data.SelectionChangedListener; 39 import org.openstreetmap.josm.data.osm.DataSet; 38 40 import org.openstreetmap.josm.data.osm.Node; 39 41 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 52 54 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Text; 53 55 54 public class TaggingPresetSearchDialog extends ExtendedDialog { 56 public class TaggingPresetSearchDialog extends ExtendedDialog implements SelectionChangedListener { 55 57 56 58 private static final int CLASSIFICATION_IN_FAVORITES = 300; … … 205 207 private JCheckBox ckSearchInTags; 206 208 private final EnumSet<PresetType> typesInSelection = EnumSet.noneOf(PresetType.class); 209 private boolean typesInSelectionDirty = true; 207 210 private final List<PresetClasification> classifications = new ArrayList<PresetClasification>(); 208 211 private ResultListModel lsResultModel = new ResultListModel(); … … 210 213 private TaggingPresetSearchDialog() { 211 214 super(Main.parent, tr("Presets"), new String[] {tr("Select"), tr("Cancel")}); 212 getTypesInSelection();215 DataSet.addSelectionListener(this); 213 216 214 217 for (TaggingPreset preset: TaggingPresetPreference.taggingPresets) { … … 221 224 222 225 build(); 223 filterPresets(""); 226 filterPresets(); 227 } 228 229 @Override 230 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 231 typesInSelectionDirty = true; 224 232 } 225 233 226 234 @Override 227 235 public ExtendedDialog showDialog() { 236 237 ckOnlyApplicable.setEnabled(!getTypesInSelection().isEmpty()); 238 ckOnlyApplicable.setSelected(!getTypesInSelection().isEmpty() && ONLY_APPLICABLE.get()); 239 edSearchText.setText(""); 240 filterPresets(); 241 228 242 super.showDialog(); 229 edSearchText.setText("");230 243 lsResult.getSelectionModel().clearSelection(); 231 244 return this; … … 241 254 @Override 242 255 public void removeUpdate(DocumentEvent e) { 243 filterPresets( edSearchText.getText());256 filterPresets(); 244 257 } 245 258 246 259 @Override 247 260 public void insertUpdate(DocumentEvent e) { 248 filterPresets( edSearchText.getText());261 filterPresets(); 249 262 250 263 } … … 252 265 @Override 253 266 public void changedUpdate(DocumentEvent e) { 254 filterPresets( edSearchText.getText());267 filterPresets(); 255 268 256 269 } … … 302 315 ckOnlyApplicable.setText(tr("Show only applicable to selection")); 303 316 pnChecks.add(ckOnlyApplicable); 304 305 if (typesInSelection.isEmpty()) { 306 ckOnlyApplicable.setSelected(false); 307 ckOnlyApplicable.setEnabled(false); 308 } else { 309 ckOnlyApplicable.setSelected(ONLY_APPLICABLE.get()); 310 ckOnlyApplicable.addItemListener(new ItemListener() { 311 @Override 312 public void itemStateChanged(ItemEvent e) { 313 filterPresets(edSearchText.getText()); 314 } 315 }); 316 } 317 ckOnlyApplicable.addItemListener(new ItemListener() { 318 @Override 319 public void itemStateChanged(ItemEvent e) { 320 filterPresets(); 321 } 322 }); 317 323 318 324 ckSearchInTags = new JCheckBox(); … … 322 328 @Override 323 329 public void itemStateChanged(ItemEvent e) { 324 filterPresets( edSearchText.getText());330 filterPresets(); 325 331 } 326 332 }); … … 352 358 * @param text 353 359 */ 354 private void filterPresets( String text) {360 private void filterPresets() { 355 361 //TODO Save favorites to file 356 text = text.toLowerCase();362 String text = edSearchText.getText().toLowerCase(); 357 363 358 364 String[] groupWords; … … 379 385 boolean found = false; 380 386 for (PresetType type: preset.types) { 381 if ( typesInSelection.contains(type)) {387 if (getTypesInSelection().contains(type)) { 382 388 found = true; 383 389 break; … … 427 433 } 428 434 429 430 private void getTypesInSelection() { 431 for (OsmPrimitive primitive: Main.main.getCurrentDataSet().getSelected()) { 432 if (primitive instanceof Node) { 433 typesInSelection.add(PresetType.NODE); 434 } else if (primitive instanceof Way) { 435 typesInSelection.add(PresetType.WAY); 436 if (((Way)primitive).isClosed()) { 437 typesInSelection.add(PresetType.CLOSEDWAY); 438 } 439 } else if (primitive instanceof Relation) { 440 typesInSelection.add(PresetType.RELATION); 441 } 442 } 435 private EnumSet<PresetType> getTypesInSelection() { 436 if (typesInSelectionDirty) { 437 synchronized (typesInSelection) { 438 typesInSelectionDirty = false; 439 typesInSelection.clear(); 440 for (OsmPrimitive primitive : Main.main.getCurrentDataSet().getSelected()) { 441 if (primitive instanceof Node) { 442 typesInSelection.add(PresetType.NODE); 443 } else if (primitive instanceof Way) { 444 typesInSelection.add(PresetType.WAY); 445 if (((Way) primitive).isClosed()) { 446 typesInSelection.add(PresetType.CLOSEDWAY); 447 } 448 } else if (primitive instanceof Relation) { 449 typesInSelection.add(PresetType.RELATION); 450 } 451 } 452 } 453 } 454 return typesInSelection; 443 455 } 444 456
Note:
See TracChangeset
for help on using the changeset viewer.