diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
index 7b0037f..71648d1 100644
a
|
b
|
import org.openstreetmap.josm.data.osm.Relation;
|
42 | 42 | import org.openstreetmap.josm.data.osm.RelationMember; |
43 | 43 | import org.openstreetmap.josm.data.osm.Tag; |
44 | 44 | import org.openstreetmap.josm.gui.ExtendedDialog; |
45 | | import org.openstreetmap.josm.gui.MapView; |
46 | 45 | import org.openstreetmap.josm.gui.Notification; |
47 | 46 | import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; |
48 | | import org.openstreetmap.josm.gui.layer.Layer; |
| 47 | import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; |
| 48 | import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; |
49 | 49 | import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; |
50 | 50 | import org.openstreetmap.josm.gui.tagging.presets.items.Key; |
51 | 51 | import org.openstreetmap.josm.gui.tagging.presets.items.Label; |
… |
… |
import org.xml.sax.SAXException;
|
74 | 74 | * It is also able to construct dialogs out of preset definitions. |
75 | 75 | * @since 294 |
76 | 76 | */ |
77 | | public class TaggingPreset extends AbstractAction implements MapView.LayerChangeListener, Predicate<OsmPrimitive> { |
| 77 | public class TaggingPreset extends AbstractAction implements ActiveLayerChangeListener, Predicate<OsmPrimitive> { |
78 | 78 | |
79 | 79 | public static final int DIALOG_ANSWER_APPLY = 1; |
80 | 80 | public static final int DIALOG_ANSWER_NEW_RELATION = 2; |
… |
… |
public class TaggingPreset extends AbstractAction implements MapView.LayerChange
|
112 | 112 | * Use this as default item for "do not select anything". |
113 | 113 | */ |
114 | 114 | public TaggingPreset() { |
115 | | MapView.addLayerChangeListener(this); |
| 115 | Main.getLayerManager().addActiveLayerChangeListener(this); |
116 | 116 | updateEnabledState(); |
117 | 117 | } |
118 | 118 | |
… |
… |
public class TaggingPreset extends AbstractAction implements MapView.LayerChange
|
479 | 479 | return sel; |
480 | 480 | } |
481 | 481 | |
| 482 | /** |
| 483 | * Gets a list of tags that are set by this preset. |
| 484 | * @return The list of tags. |
| 485 | */ |
482 | 486 | public List<Tag> getChangedTags() { |
483 | 487 | List<Tag> result = new ArrayList<>(); |
484 | 488 | for (TaggingPresetItem i: data) { |
… |
… |
public class TaggingPreset extends AbstractAction implements MapView.LayerChange
|
487 | 491 | return result; |
488 | 492 | } |
489 | 493 | |
| 494 | /** |
| 495 | * Create a command to change the given list of tags. |
| 496 | * @param sel The primitives to change the tags for |
| 497 | * @param changedTags The tags to change |
| 498 | * @return A command that changes the tags. |
| 499 | */ |
490 | 500 | public static Command createCommand(Collection<OsmPrimitive> sel, List<Tag> changedTags) { |
491 | 501 | List<Command> cmds = new ArrayList<>(); |
492 | 502 | for (Tag tag: changedTags) { |
… |
… |
public class TaggingPreset extends AbstractAction implements MapView.LayerChange
|
513 | 523 | } |
514 | 524 | |
515 | 525 | @Override |
516 | | public void activeLayerChange(Layer oldLayer, Layer newLayer) { |
517 | | updateEnabledState(); |
518 | | } |
519 | | |
520 | | @Override |
521 | | public void layerAdded(Layer newLayer) { |
522 | | updateEnabledState(); |
523 | | } |
524 | | |
525 | | @Override |
526 | | public void layerRemoved(Layer oldLayer) { |
| 526 | public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { |
527 | 527 | updateEnabledState(); |
528 | 528 | } |
529 | 529 | |
… |
… |
public class TaggingPreset extends AbstractAction implements MapView.LayerChange
|
532 | 532 | return (types == null ? "" : types.toString()) + ' ' + name; |
533 | 533 | } |
534 | 534 | |
| 535 | /** |
| 536 | * Determines whether this preset matches the types. |
| 537 | * @param t The types that must match |
| 538 | * @return <code>true</code> if all types match. |
| 539 | */ |
535 | 540 | public boolean typeMatches(Collection<TaggingPresetType> t) { |
536 | 541 | return t == null || types == null || types.containsAll(t); |
537 | 542 | } |
… |
… |
public class TaggingPreset extends AbstractAction implements MapView.LayerChange
|
557 | 562 | * @return {@code true} if this preset matches the parameters. |
558 | 563 | */ |
559 | 564 | public boolean matches(Collection<TaggingPresetType> t, Map<String, String> tags, boolean onlyShowable) { |
560 | | if (onlyShowable && !isShowable()) |
561 | | return false; |
562 | | else if (!typeMatches(t)) |
| 565 | if ((onlyShowable && !isShowable()) || !typeMatches(t)) { |
563 | 566 | return false; |
564 | | else |
| 567 | } else { |
565 | 568 | return TaggingPresetItem.matches(data, tags); |
| 569 | } |
566 | 570 | } |
567 | 571 | |
568 | 572 | /** |
… |
… |
public class TaggingPreset extends AbstractAction implements MapView.LayerChange
|
589 | 593 | } |
590 | 594 | } |
591 | 595 | |
| 596 | /** |
| 597 | * Gets a string describing this preset that can be used for the toolbar |
| 598 | * @return A String that can be passed on to the toolbar |
| 599 | * @see ToolbarPreferences#addCustomButton(String, int, boolean) |
| 600 | */ |
592 | 601 | public String getToolbarString() { |
593 | 602 | ToolbarPreferences.ActionParser actionParser = new ToolbarPreferences.ActionParser(null); |
594 | 603 | return actionParser.saveAction(new ToolbarPreferences.ActionDefinition(this)); |