Changeset 6795 in josm for trunk/src/org


Ignore:
Timestamp:
2014-01-31T21:42:40+01:00 (10 years ago)
Author:
simon04
Message:

Refactor tagging presets in order to get rid of static variable presetInitiallyMatches - see #8413

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

Legend:

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

    r6772 r6795  
    1111import java.awt.Insets;
    1212import java.awt.event.ActionEvent;
    13 import java.awt.event.MouseEvent;
    1413import java.util.ArrayList;
    1514import java.util.Collection;
     
    4140import org.openstreetmap.josm.gui.ExtendedDialog;
    4241import org.openstreetmap.josm.gui.MapView;
    43 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel;
    4442import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    4543import org.openstreetmap.josm.gui.layer.Layer;
     
    220218        }
    221219
     220        boolean presetInitiallyMatches = !selected.isEmpty() && Utils.forAll(selected, this);
    222221        JPanel items = new JPanel(new GridBagLayout());
    223222        for (TaggingPresetItem i : data){
     
    227226                presetLink.add(i);
    228227            } else {
    229                 if(i.addToPanel(items, selected)) {
     228                if(i.addToPanel(items, selected, presetInitiallyMatches)) {
    230229                    p.hasElements = true;
    231230                }
     
    240239        if (!presetLink.isEmpty()) {
    241240            p.add(new JLabel(tr("Edit also …")), GBC.eol().insets(0, 8, 0, 0));
    242         }
    243         for(TaggingPresetItem link : presetLink) {
    244             link.addToPanel(p, selected);
     241            for(TaggingPresetItem link : presetLink) {
     242                link.addToPanel(p, selected, presetInitiallyMatches);
     243            }
    245244        }
    246245
    247246        // add Link
    248247        for(TaggingPresetItem link : l) {
    249             link.addToPanel(p, selected);
     248            link.addToPanel(p, selected, presetInitiallyMatches);
    250249        }
    251250
     
    275274    }
    276275
    277     static boolean presetInitiallyMatches = false;
    278 
    279276    @Override
    280277    public void actionPerformed(ActionEvent e) {
     
    283280
    284281        Collection<OsmPrimitive> sel = createSelection(Main.main.getCurrentDataSet().getSelected());
    285         presetInitiallyMatches = !sel.isEmpty() && Utils.forAll(sel, this);
    286282        int answer = showDialog(sel, supportsRelation());
    287283
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItem.java

    r6336 r6795  
    3535     * Called by {@link TaggingPreset#createPanel} during tagging preset panel creation.
    3636     * All components defining this tagging preset item must be added to given panel.
     37     *
    3738     * @param p The panel where components must be added
    3839     * @param sel The related selected OSM primitives
     40     * @param presetInitiallyMatches Whether this {@link TaggingPreset} already matched before applying,
     41     *                               i.e. whether the map feature already existed on the primitive.
    3942     * @return {@code true} if this item adds semantic tagging elements, {@code false} otherwise.
    4043     */
    41     abstract boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel);
     44    abstract boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches);
    4245
    4346    /**
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    r6792 r6795  
    352352
    353353        @Override
    354         public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     354        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    355355            initializeLocaleText(null);
    356356            p.add(new JLabel(locale_text), GBC.eol());
     
    372372
    373373        @Override
    374         public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     374        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    375375            initializeLocaleText(tr("More information about this feature"));
    376376            String url = locale_href;
     
    397397
    398398        @Override
    399         boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     399        boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    400400            final String presetName = preset_name;
    401401            final TaggingPreset t = Utils.filter(TaggingPresetPreference.taggingPresets, new Predicate<TaggingPreset>() {
     
    427427
    428428        @Override
    429         public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     429        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    430430            p.add(new JLabel(" "), GBC.eol()); // space
    431431            if (!roles.isEmpty()) {
     
    452452        // TODO: Draw a box around optional stuff
    453453        @Override
    454         public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     454        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    455455            initializeLocaleText(tr("Optional Attributes:"));
    456456            p.add(new JLabel(" "), GBC.eol()); // space
     
    464464
    465465        @Override
    466         public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     466        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    467467            p.add(new JLabel(" "), GBC.eol()); // space
    468468            return false;
     
    486486
    487487        @Override
    488         public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     488        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    489489            p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 5));
    490490            return false;
     
    540540
    541541        @Override
    542         public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     542        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    543543            return false;
    544544        }
     
    578578        private JComponent value;
    579579
    580         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     580        @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    581581
    582582            // find out if our key is already used in the selection.
     
    597597                else if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) {
    598598                    // selected osm primitives are untagged or filling default values feature is enabled
    599                     if (!"false".equals(use_last_as_default) && lastValue.containsKey(key) && !TaggingPreset.presetInitiallyMatches) {
     599                    if (!"false".equals(use_last_as_default) && lastValue.containsKey(key) && !presetInitiallyMatches) {
    600600                        textField.setText(lastValue.get(key));
    601601                    } else {
     
    760760
    761761        @Override
    762         boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     762        boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    763763            Integer cols = Integer.valueOf(columns);
    764764            int rows = (int) Math.ceil(checks.size()/cols.doubleValue());
     
    766766
    767767            for (Check check : checks) {
    768                 check.addToPanel(panel, sel);
     768                check.addToPanel(panel, sel, presetInitiallyMatches);
    769769            }
    770770
     
    797797        private boolean def;
    798798
    799         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     799        @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    800800
    801801            // find out if our key is already used in the selection.
     
    912912
    913913        protected abstract Object getSelectedItem();
    914         protected abstract void addToPanelAnchor(JPanel p, String def);
     914        protected abstract void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches);
    915915
    916916        protected char getDelChar() {
     
    935935
    936936        @Override
    937         public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     937        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    938938
    939939            initListEntries();
     
    946946
    947947            p.add(new JLabel(tr("{0}:", locale_text)), GBC.std().insets(0, 0, 10, 0));
    948             addToPanelAnchor(p, default_);
     948            addToPanelAnchor(p, default_, presetInitiallyMatches);
    949949
    950950            return true;
     
    11811181
    11821182        @Override
    1183         protected void addToPanelAnchor(JPanel p, String def) {
     1183        protected void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches) {
    11841184            if (!usage.unused()) {
    11851185                for (String s : usage.values) {
     
    12271227                // all items were unset (and so is default)
    12281228                originalValue = lhm.get("");
    1229                 if ("force".equals(use_last_as_default) && lastValue.containsKey(key) && !TaggingPreset.presetInitiallyMatches) {
     1229                if ("force".equals(use_last_as_default) && lastValue.containsKey(key) && !presetInitiallyMatches) {
    12301230                    combo.setSelectedItem(lhm.get(lastValue.get(key)));
    12311231                } else {
     
    12601260
    12611261        @Override
    1262         protected void addToPanelAnchor(JPanel p, String def) {
     1262        protected void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches) {
    12631263            list = new ConcatenatingJList(delimiter, lhm.values().toArray());
    12641264            component = list;
Note: See TracChangeset for help on using the changeset viewer.