Changeset 4286 in josm


Ignore:
Timestamp:
2011-08-07T18:05:48+02:00 (8 years ago)
Author:
jttt
Message:

Prefer last used preset in preset search dialog

Location:
trunk/src/org/openstreetmap/josm/gui/tagging
Files:
2 edited

Legend:

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

    r3720 r4286  
    2626            return;
    2727
    28         TaggingPresetSearchDialog dialog = new TaggingPresetSearchDialog(Main.parent);
     28        TaggingPresetSearchDialog dialog = TaggingPresetSearchDialog.getInstance();
    2929        dialog.showDialog();
    3030    }
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSearchDialog.java

    r4221 r4286  
    5454public class TaggingPresetSearchDialog extends ExtendedDialog {
    5555
    56     private int CLASSIFICATION_NAME_MATCH = 300;
    57     private int CLASSIFICATION_GROUP_MATCH = 200;
    58     private int CLASSIFICATION_TAGS_MATCH = 100;
    59 
    60     private final BooleanProperty SEARCH_IN_TAGS = new BooleanProperty("taggingpreset.dialog.search-in-tags", true);
    61     private final BooleanProperty ONLY_APPLICABLE  = new BooleanProperty("taggingpreset.dialog.only-applicable-to-selection", true);
     56    private static final int CLASSIFICATION_IN_FAVORITES = 300;
     57    private static final int CLASSIFICATION_NAME_MATCH = 300;
     58    private static final int CLASSIFICATION_GROUP_MATCH = 200;
     59    private static final int CLASSIFICATION_TAGS_MATCH = 100;
     60
     61    private static final BooleanProperty SEARCH_IN_TAGS = new BooleanProperty("taggingpreset.dialog.search-in-tags", true);
     62    private static final BooleanProperty ONLY_APPLICABLE  = new BooleanProperty("taggingpreset.dialog.only-applicable-to-selection", true);
    6263
    6364    private static class ResultListCellRenderer extends DefaultListCellRenderer {
     
    101102        public final TaggingPreset preset;
    102103        public int classification;
     104        public int favoriteIndex;
    103105        private final Collection<String> groups = new HashSet<String>();
    104106        private final Collection<String> names = new HashSet<String>();
     
    190192    }
    191193
     194    private static TaggingPresetSearchDialog instance;
     195    public static TaggingPresetSearchDialog getInstance() {
     196        if (instance == null) {
     197            instance = new TaggingPresetSearchDialog();
     198        }
     199        return instance;
     200    }
    192201
    193202    private JTextField edSearchText;
     
    199208    private ResultListModel lsResultModel = new ResultListModel();
    200209
    201     public TaggingPresetSearchDialog(Component parent) {
    202         super(parent, tr("Presets"), new String[] {tr("Select"), tr("Cancel")});
     210    private TaggingPresetSearchDialog() {
     211        super(Main.parent, tr("Presets"), new String[] {tr("Select"), tr("Cancel")});
    203212        getTypesInSelection();
    204213
     
    213222        build();
    214223        filterPresets("");
     224    }
     225
     226    @Override
     227    public ExtendedDialog showDialog() {
     228        super.showDialog();
     229        edSearchText.setText("");
     230        lsResult.getSelectionModel().clearSelection();
     231        return this;
    215232    }
    216233
     
    336353     */
    337354    private void filterPresets(String text) {
    338         //TODO Favorites
     355        //TODO Save favorites to file
    339356        text = text.toLowerCase();
    340357
     
    398415
    399416                if (presetClasification.classification > 0) {
     417                    presetClasification.classification += presetClasification.favoriteIndex;
    400418                    result.add(presetClasification);
    401419                }
     
    433451                selectPreset = 0;
    434452            }
    435             lsResultModel.getPresets().get(selectPreset).preset.actionPerformed(null);
     453            TaggingPreset preset = lsResultModel.getPresets().get(selectPreset).preset;
     454            for (PresetClasification pc: classifications) {
     455                if (pc.preset == preset) {
     456                    pc.favoriteIndex = CLASSIFICATION_IN_FAVORITES;
     457                } else if (pc.favoriteIndex > 0) {
     458                    pc.favoriteIndex--;
     459                }
     460            }
     461            preset.actionPerformed(null);
    436462        }
    437463
Note: See TracChangeset for help on using the changeset viewer.