Changeset 6738 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-01-19T18:47:49+01:00 (11 years ago)
Author:
simon04
Message:

Add "Search for objects by preset" action

This allows to use presets for searching for objects.
SHIFT+F3 displays the preset dialog and after confirmation, the objects matching the preset are selected.

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r6597 r6738  
    114114import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
    115115import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction;
     116import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchPrimitiveDialog;
    116117import org.openstreetmap.josm.tools.ImageProvider;
    117118import org.openstreetmap.josm.tools.Shortcut;
     
    375376
    376377    public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
     378    public final TaggingPresetSearchPrimitiveDialog.Action presetSearchPrimitiveAction = new TaggingPresetSearchPrimitiveDialog.Action();
    377379    public final DialogsToggleAction dialogsToggleAction = new DialogsToggleAction();
    378380    public FullscreenToggleAction fullscreenToggleAction = null;
     
    640642        editMenu.addSeparator();
    641643        add(editMenu, search);
     644        add(editMenu, presetSearchPrimitiveAction);
    642645        editMenu.addSeparator();
    643646        add(editMenu, preferences);
     
    700703
    701704        add(presetsMenu, presetSearchAction);
     705        add(presetsMenu, presetSearchPrimitiveAction);
    702706        add(presetsMenu, PreferencesAction.forPreferenceSubTab(tr("Preset preferences"),
    703707                tr("Click to open the tagging presets tab in the preferences"), TaggingPresetPreference.class));
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r6572 r6738  
    6666 * @since 294
    6767 */
    68 public class TaggingPreset extends AbstractAction implements MapView.LayerChangeListener {
     68public class TaggingPreset extends AbstractAction implements MapView.LayerChangeListener, Predicate<OsmPrimitive> {
    6969
    7070    public static final int DIALOG_ANSWER_APPLY = 1;
     
    463463    }
    464464
     465    @Override
     466    public boolean evaluate(OsmPrimitive p) {
     467        return matches(EnumSet.of(TaggingPresetType.forPrimitive(p)), p.getKeys(), false);
     468    }
     469
    465470    public boolean matches(Collection<TaggingPresetType> t, Map<String, String> tags, boolean onlyShowable) {
    466471        if (onlyShowable && !isShowable())
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSearchDialog.java

    r6362 r6738  
    3434    private TaggingPresetSearchDialog() {
    3535        super(Main.parent, tr("Presets"), new String[] {tr("Select"), tr("Cancel")});
    36         selector = new TaggingPresetSelector();
     36        selector = new TaggingPresetSelector(true, true);
    3737        setContent(selector);
    3838        DataSet.addSelectionListener(selector);
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSelector.java

    r6425 r6738  
    201201     * Constructs a new {@code TaggingPresetSelector}.
    202202     */
    203     public TaggingPresetSelector() {
     203    public TaggingPresetSelector(boolean displayOnlyApplicable, boolean displaySearchInTags) {
    204204        super(new BorderLayout());
    205205        if (TaggingPresetPreference.taggingPresets!=null) {
     
    260260        pnChecks.setLayout(new BoxLayout(pnChecks, BoxLayout.Y_AXIS));
    261261
    262         ckOnlyApplicable = new JCheckBox();
    263         ckOnlyApplicable.setText(tr("Show only applicable to selection"));
    264         pnChecks.add(ckOnlyApplicable);
    265         ckOnlyApplicable.addItemListener(new ItemListener() {
    266             @Override
    267             public void itemStateChanged(ItemEvent e) {
    268                 filterPresets();
    269             }
    270         });
    271 
    272         ckSearchInTags = new JCheckBox();
    273         ckSearchInTags.setText(tr("Search in tags"));
    274         ckSearchInTags.setSelected(SEARCH_IN_TAGS.get());
    275         ckSearchInTags.addItemListener(new ItemListener() {
    276             @Override
    277             public void itemStateChanged(ItemEvent e) {
    278                 filterPresets();
    279             }
    280         });
    281         pnChecks.add(ckSearchInTags);
     262        if (displayOnlyApplicable) {
     263            ckOnlyApplicable = new JCheckBox();
     264            ckOnlyApplicable.setText(tr("Show only applicable to selection"));
     265            pnChecks.add(ckOnlyApplicable);
     266            ckOnlyApplicable.addItemListener(new ItemListener() {
     267                @Override
     268                public void itemStateChanged(ItemEvent e) {
     269                    filterPresets();
     270                }
     271            });
     272        }
     273
     274        if (displaySearchInTags) {
     275            ckSearchInTags = new JCheckBox();
     276            ckSearchInTags.setText(tr("Search in tags"));
     277            ckSearchInTags.setSelected(SEARCH_IN_TAGS.get());
     278            ckSearchInTags.addItemListener(new ItemListener() {
     279                @Override
     280                public void itemStateChanged(ItemEvent e) {
     281                    filterPresets();
     282                }
     283            });
     284            pnChecks.add(ckSearchInTags);
     285        }
    282286
    283287        add(pnChecks, BorderLayout.SOUTH);
     
    317321        }
    318322
    319         boolean onlyApplicable = ckOnlyApplicable.isSelected();
    320         boolean inTags = ckSearchInTags.isSelected();
     323        boolean onlyApplicable = ckOnlyApplicable != null && ckOnlyApplicable.isSelected();
     324        boolean inTags = ckSearchInTags != null && ckSearchInTags.isSelected();
    321325
    322326        List<PresetClassification> result = new ArrayList<PresetClassification>();
     
    402406
    403407    public void init() {
    404         ckOnlyApplicable.setEnabled(!getTypesInSelection().isEmpty());
    405         ckOnlyApplicable.setSelected(!getTypesInSelection().isEmpty() && ONLY_APPLICABLE.get());
     408        if (ckOnlyApplicable != null) {
     409            ckOnlyApplicable.setEnabled(!getTypesInSelection().isEmpty());
     410            ckOnlyApplicable.setSelected(!getTypesInSelection().isEmpty() && ONLY_APPLICABLE.get());
     411        }
    406412        edSearchText.setText("");
    407413        filterPresets();
     
    423429     */
    424430    public void savePreferences() {
    425         SEARCH_IN_TAGS.put(ckSearchInTags.isSelected());
    426         if (ckOnlyApplicable.isEnabled()) {
     431        if (ckSearchInTags != null) {
     432            SEARCH_IN_TAGS.put(ckSearchInTags.isSelected());
     433        }
     434        if (ckOnlyApplicable != null && ckOnlyApplicable.isEnabled()) {
    427435            ONLY_APPLICABLE.put(ckOnlyApplicable.isSelected());
    428436        }
Note: See TracChangeset for help on using the changeset viewer.