Changeset 8979 in josm for trunk/src/org
- Timestamp:
- 2015-11-02T21:19:19+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r8971 r8979 28 28 import org.openstreetmap.josm.data.osm.Relation; 29 29 import org.openstreetmap.josm.data.osm.RelationMember; 30 import org.openstreetmap.josm.data.osm.Tagged; 30 31 import org.openstreetmap.josm.data.osm.Way; 31 32 import org.openstreetmap.josm.gui.mappaint.Environment; … … 233 234 234 235 /** 235 * Base class for all search operators. 236 * Base class for all search criteria. If the criterion only depends on an object's tags, 237 * inherit from {@link org.openstreetmap.josm.actions.search.SearchCompiler.TaggedMatch}. 236 238 */ 237 239 public abstract static class Match implements Predicate<OsmPrimitive> { 238 240 241 /** 242 * Tests whether the primitive matches this criterion. 243 * @param osm the primitive to test 244 * @return true if the primitive matches this criterion 245 */ 239 246 public abstract boolean match(OsmPrimitive osm); 247 248 /** 249 * Tests whether the tagged object matches this criterion. 250 * @param tagged the tagged object to test 251 * @return true if the tagged object matches this criterion 252 */ 253 public boolean match(Tagged tagged) { 254 return false; 255 } 240 256 241 257 /** … … 271 287 } 272 288 289 public abstract static class TaggedMatch extends Match { 290 291 @Override 292 public abstract boolean match(Tagged tags); 293 294 @Override 295 public final boolean match(OsmPrimitive osm) { 296 return match((Tagged) osm); 297 } 298 } 299 273 300 /** 274 301 * A unary search operator which may take data parameters. … … 318 345 * Matches every OsmPrimitive. 319 346 */ 320 public static class Always extends Match {347 public static class Always extends TaggedMatch { 321 348 /** The unique instance/ */ 322 349 public static final Always INSTANCE = new Always(); 323 350 @Override 324 public boolean match( OsmPrimitiveosm) {351 public boolean match(Tagged osm) { 325 352 return true; 326 353 } … … 330 357 * Never matches any OsmPrimitive. 331 358 */ 332 public static class Never extends Match {333 @Override 334 public boolean match( OsmPrimitiveosm) {359 public static class Never extends TaggedMatch { 360 @Override 361 public boolean match(Tagged osm) { 335 362 return false; 336 363 } … … 351 378 352 379 @Override 380 public boolean match(Tagged osm) { 381 return !match.match(osm); 382 } 383 384 @Override 353 385 public String toString() { 354 386 return "!" + match; … … 363 395 * Matches if the value of the corresponding key is ''yes'', ''true'', ''1'' or ''on''. 364 396 */ 365 private static class BooleanMatch extends Match {397 private static class BooleanMatch extends TaggedMatch { 366 398 private final String key; 367 399 private final boolean defaultValue; … … 373 405 374 406 @Override 375 public boolean match( OsmPrimitiveosm) {407 public boolean match(Tagged osm) { 376 408 Boolean ret = OsmUtils.getOsmBoolean(osm.get(key)); 377 409 if (ret == null) … … 401 433 402 434 @Override 435 public boolean match(Tagged osm) { 436 return lhs.match(osm) && rhs.match(osm); 437 } 438 439 @Override 403 440 public String toString() { 404 441 return lhs + " && " + rhs; … … 420 457 421 458 @Override 459 public boolean match(Tagged osm) { 460 return lhs.match(osm) || rhs.match(osm); 461 } 462 463 @Override 422 464 public String toString() { 423 465 return lhs + " || " + rhs; … … 439 481 440 482 @Override 483 public boolean match(Tagged osm) { 484 return lhs.match(osm) ^ rhs.match(osm); 485 } 486 487 @Override 441 488 public String toString() { 442 489 return lhs + " ^ " + rhs; … … 516 563 * Matches objects with the given key-value pair. 517 564 */ 518 private static class KeyValue extends Match {565 private static class KeyValue extends TaggedMatch { 519 566 private final String key; 520 567 private final Pattern keyPattern; … … 559 606 560 607 @Override 561 public boolean match( OsmPrimitiveosm) {608 public boolean match(Tagged osm) { 562 609 563 610 if (keyPattern != null) { … … 589 636 String mv = null; 590 637 591 if ("timestamp".equals(key) ) {592 mv = DateUtils.fromTimestamp( osm.getRawTimestamp());638 if ("timestamp".equals(key) && osm instanceof OsmPrimitive) { 639 mv = DateUtils.fromTimestamp(((OsmPrimitive) osm).getRawTimestamp()); 593 640 } else { 594 641 mv = osm.get(key); … … 623 670 } 624 671 625 public static class ValueComparison extends Match {672 public static class ValueComparison extends TaggedMatch { 626 673 private final String key; 627 674 private final String referenceValue; … … 648 695 649 696 @Override 650 public boolean match( OsmPrimitiveosm) {697 public boolean match(Tagged osm) { 651 698 final String currentValue = osm.get(key); 652 699 final int compareResult; … … 676 723 * Matches objects with the exact given key-value pair. 677 724 */ 678 public static class ExactKeyValue extends Match {725 public static class ExactKeyValue extends TaggedMatch { 679 726 680 727 private enum Mode { … … 749 796 750 797 @Override 751 public boolean match( OsmPrimitiveosm) {798 public boolean match(Tagged osm) { 752 799 753 800 if (!osm.hasKeys()) … … 806 853 * Match a string in any tags (key or value), with optional regex and case insensitivity. 807 854 */ 808 private static class Any extends Match {855 private static class Any extends TaggedMatch { 809 856 private final String search; 810 857 private final Pattern searchRegex; … … 833 880 834 881 @Override 835 public boolean match( OsmPrimitiveosm) {836 if (!osm.hasKeys() && osm.getUser() == null)882 public boolean match(Tagged osm) { 883 if (!osm.hasKeys()) 837 884 return search.isEmpty(); 838 885 -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r8836 r8979 5 5 6 6 import java.awt.BorderLayout; 7 import java.awt.Color;8 7 import java.awt.Component; 9 8 import java.awt.event.ActionEvent; 10 9 import java.awt.event.KeyEvent; 11 10 import java.awt.event.MouseEvent; 11 import java.beans.PropertyChangeEvent; 12 import java.beans.PropertyChangeListener; 12 13 import java.util.ArrayList; 13 14 import java.util.Arrays; … … 29 30 import javax.swing.KeyStroke; 30 31 import javax.swing.ListSelectionModel; 31 import javax.swing.UIManager;32 import javax.swing.event.DocumentEvent;33 import javax.swing.event.DocumentListener;34 32 import javax.swing.event.ListSelectionEvent; 35 33 import javax.swing.event.ListSelectionListener; … … 70 68 import org.openstreetmap.josm.gui.util.GuiHelper; 71 69 import org.openstreetmap.josm.gui.util.HighlightHelper; 70 import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator; 72 71 import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField; 73 72 import org.openstreetmap.josm.gui.widgets.JosmTextField; … … 283 282 final JosmTextField f = new DisableShortcutsOnFocusGainedTextField(); 284 283 f.setToolTipText(tr("Relation list filter")); 285 f.getDocument().addDocumentListener(new DocumentListener() { 286 287 private void setFilter() { 288 try { 289 f.setBackground(UIManager.getColor("TextField.background")); 290 f.setToolTipText(tr("Relation list filter")); 291 model.setFilter(SearchCompiler.compile(filter.getText())); 292 } catch (SearchCompiler.ParseError ex) { 293 f.setBackground(new Color(255, 224, 224)); 294 f.setToolTipText(ex.getMessage()); 295 model.setFilter(new SearchCompiler.Always()); 296 } 297 } 298 284 final CompileSearchTextDecorator decorator = CompileSearchTextDecorator.decorate(f); 285 f.addPropertyChangeListener("filter", new PropertyChangeListener() { 299 286 @Override 300 public void insertUpdate(DocumentEvent e) { 301 setFilter(); 302 } 303 304 @Override 305 public void removeUpdate(DocumentEvent e) { 306 setFilter(); 307 } 308 309 @Override 310 public void changedUpdate(DocumentEvent e) { 311 setFilter(); 287 public void propertyChange(PropertyChangeEvent evt) { 288 model.setFilter(decorator.getMatch()); 312 289 } 313 290 });
Note:
See TracChangeset
for help on using the changeset viewer.