Changeset 9266 in josm for trunk/src


Ignore:
Timestamp:
2016-01-02T18:51:06+01:00 (9 years ago)
Author:
simon04
Message:

Refactoring: move getMatchingPresets to TaggingPresets and add some Javadoc

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java

    r9243 r9266  
    1717import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetLabel;
    1818import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
     19import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    1920import org.openstreetmap.josm.tools.GBC;
    2021
     
    4748        }
    4849
    49         for (final TaggingPreset t : TaggingPreset.getMatchingPresets(types, tags, true)) {
     50        for (final TaggingPreset t : TaggingPresets.getMatchingPresets(types, tags, true)) {
    5051            final JLabel lbl = new TaggingPresetLabel(t);
    5152            lbl.addMouseListener(new MouseAdapter() {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r9263 r9266  
    7474import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    7575import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
     76import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    7677import org.openstreetmap.josm.gui.util.GuiHelper;
    7778import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    739740                    Map<String, String> map = new HashMap<>();
    740741                    map.put(t.getKey(), t.getValue());
    741                     for (TaggingPreset tp : TaggingPreset.getMatchingPresets(null, map, false)) {
     742                    for (TaggingPreset tp : TaggingPresets.getMatchingPresets(null, map, false)) {
    742743                        icon = tp.getIcon();
    743744                        if (icon != null) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r9078 r9266  
    8686import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler;
    8787import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
     88import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    8889import org.openstreetmap.josm.io.OnlineResource;
    8990import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    763764        CheckParameterUtil.ensureParameterNotNull(orig, "orig");
    764765        try {
    765             final Collection<TaggingPreset> presets = TaggingPreset.getMatchingPresets(
     766            final Collection<TaggingPreset> presets = TaggingPresets.getMatchingPresets(
    766767                    EnumSet.of(TaggingPresetType.RELATION), orig.getKeys(), false);
    767768            Relation relation = new Relation(orig);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r9246 r9266  
    4242import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler;
    4343import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
     44import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    4445import org.openstreetmap.josm.gui.util.GuiHelper;
    4546import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTableModel;
     
    422423
    423424    private void addMembersAtIndex(List<? extends OsmPrimitive> primitives, int index) {
    424         final Collection<TaggingPreset> presets = TaggingPreset.getMatchingPresets(EnumSet.of(TaggingPresetType.RELATION),
     425        final Collection<TaggingPreset> presets = TaggingPresets.getMatchingPresets(EnumSet.of(TaggingPresetType.RELATION),
    425426                presetHandler.getSelection().iterator().next().getKeys(), false);
    426427        if (primitives == null)
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java

    r8863 r9266  
    3030import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    3131import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
     32import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    3233import org.openstreetmap.josm.gui.tagging.presets.items.CheckGroup;
    3334import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem;
     
    335336    public void populateWithMemberRoles(AutoCompletionList list, Relation r) {
    336337        CheckParameterUtil.ensureParameterNotNull(list, "list");
    337         Collection<TaggingPreset> presets = r != null ? TaggingPreset.getMatchingPresets(null, r.getKeys(), false) : null;
     338        Collection<TaggingPreset> presets = r != null ? TaggingPresets.getMatchingPresets(null, r.getKeys(), false) : null;
    338339        if (r != null && presets != null && !presets.isEmpty()) {
    339340            for (TaggingPreset tp : presets) {
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r9231 r9266  
    296296    }
    297297
     298    /**
     299     * Determines whether a dialog can be shown for this preset, i.e., at least one tag can/must be set by the user.
     300     *
     301     * @return {@code true} if a dialog can be shown for this preset
     302     */
    298303    public boolean isShowable() {
    299304        for (TaggingPresetItem i : data) {
     
    503508    }
    504509
    505     @Override
     510    /**
     511     * Determines whether this preset matches the given primitive, i.e.,
     512     * whether the {@link #typeMatches(Collection) type matches} and the {@link TaggingPresetItem#matches(Map) tags match}.
     513     *
     514     * @param p the primitive
     515     * @return {@code true} if this preset matches the primitive
     516     */
     517     @Override
    506518    public boolean evaluate(OsmPrimitive p) {
    507519        return matches(EnumSet.of(TaggingPresetType.forPrimitive(p)), p.getKeys(), false);
    508520    }
    509521
     522    /**
     523     * Determines whether this preset matches the parameters.
     524     *
     525     * @param t the preset types to include, see {@link #typeMatches(Collection)}
     526     * @param tags the tags to perform matching on, see {@link TaggingPresetItem#matches(Map)}
     527     * @param onlyShowable whether the preset must be {@link #isShowable() showable}
     528     * @return {@code true} if this preset matches the parameters.
     529     */
    510530    public boolean matches(Collection<TaggingPresetType> t, Map<String, String> tags, boolean onlyShowable) {
    511531        if (onlyShowable && !isShowable())
     
    525545    }
    526546
    527     public static Collection<TaggingPreset> getMatchingPresets(final Collection<TaggingPresetType> t,
    528             final Map<String, String> tags, final boolean onlyShowable) {
    529         return Utils.filter(TaggingPresets.getTaggingPresets(), new Predicate<TaggingPreset>() {
    530             @Override
    531             public boolean evaluate(TaggingPreset object) {
    532                 return object.matches(t, tags, onlyShowable);
    533             }
    534         });
    535     }
    536 
    537547    /**
    538548     * Action that adds or removes the button on main toolbar
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java

    r9265 r9266  
    9696    }
    9797
     98    /**
     99     * Replies a new collection of all presets matching the parameters.
     100     *
     101     * @param t the preset types to include
     102     * @param tags the tags to perform matching on, see {@link TaggingPresetItem#matches(Map)}
     103     * @param onlyShowable whether only {@link TaggingPreset#isShowable() showable} presets should be returned
     104     * @return a new collection of all presets matching the parameters.
     105     * @see TaggingPreset#matches(Collection, Map, boolean)
     106     * @since 9266
     107     */
     108    public static Collection<TaggingPreset> getMatchingPresets(final Collection<TaggingPresetType> t,
     109                                                               final Map<String, String> tags, final boolean onlyShowable) {
     110        return Utils.filter(getTaggingPresets(), new Predicate<TaggingPreset>() {
     111            @Override
     112            public boolean evaluate(TaggingPreset object) {
     113                return object.matches(t, tags, onlyShowable);
     114            }
     115        });
     116    }
     117
     118    /**
     119     * Replies a new collection of all presets matching the given preset.
     120     *
     121     * @param primitive the primitive
     122     * @return a new collection of all presets matching the given preset.
     123     * @see TaggingPreset#evaluate(OsmPrimitive)
     124     * @since 9265
     125     */
    98126    public static Collection<TaggingPreset> getMatchingPresets(final OsmPrimitive primitive) {
    99127        return Utils.filter(getTaggingPresets(), new Predicate<TaggingPreset>() {
Note: See TracChangeset for help on using the changeset viewer.