Ticket #4439: 4439.patch

File 4439.patch, 32.9 KB (added by simon04, 10 months ago)
  • src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

     
    117117    private static final BooleanProperty PROP_FILL_DEFAULT = new BooleanProperty("taggingpreset.fill-default-for-tagged-primitives", false); 
    118118 
    119119    public static abstract class Item { 
     120 
    120121        protected void initAutoCompletionField(AutoCompletingTextField field, String key) { 
    121122            OsmDataLayer layer = Main.main.getEditLayer(); 
    122             if (layer == null) return; 
    123             AutoCompletionList list  = new AutoCompletionList(); 
     123            if (layer == null) { 
     124                return; 
     125            } 
     126            AutoCompletionList list = new AutoCompletionList(); 
    124127            Main.main.getEditLayer().data.getAutoCompletionManager().populateWithTagValues(list, key); 
    125128            field.setAutoCompletionList(list); 
    126129        } 
    127130 
    128131        abstract boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel); 
     132 
    129133        abstract void addCommands(List<Tag> changedTags); 
    130         boolean requestFocusInWindow() {return false;} 
     134 
     135        boolean requestFocusInWindow() { 
     136            return false; 
     137        } 
    131138    } 
    132139 
    133140    public static class Usage { 
     
    139146        } 
    140147 
    141148        public boolean unused() { 
    142             return values.size() == 0; 
     149            return values.isEmpty(); 
    143150        } 
    144151        public String getFirst() { 
    145152            return values.first(); 
     
    289296            return true; 
    290297        } 
    291298 
    292         @Override public void addCommands(List<Tag> changedTags) { 
     299        @Override 
     300        public void addCommands(List<Tag> changedTags) { 
    293301 
    294302            // return if unchanged 
    295             String v = (value instanceof JComboBox) ? 
    296                     ((JComboBox)value).getEditor().getItem().toString() : 
    297                         ((JTextField)value).getText(); 
     303            String v = (value instanceof JComboBox) 
     304                    ? ((JComboBox) value).getEditor().getItem().toString() 
     305                    : ((JTextField) value).getText(); 
     306            v = v.trim(); 
    298307 
    299                     if (!"false".equals(use_last_as_default)) { 
    300                         lastValue.put(key, v); 
    301                     } 
    302                     if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) return; 
     308            if (!"false".equals(use_last_as_default)) { 
     309                lastValue.put(key, v); 
     310            } 
     311            if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) { 
     312                return; 
     313            } 
    303314 
    304                     if (delete_if_empty && v.length() == 0) { 
    305                         v = null; 
    306                     } 
    307                     changedTags.add(new Tag(key, v)); 
     315            if (delete_if_empty && v.length() == 0) { 
     316                v = null; 
     317            } 
     318            changedTags.add(new Tag(key, v)); 
    308319        } 
    309         @Override boolean requestFocusInWindow() {return value.requestFocusInWindow();} 
     320 
     321        @Override 
     322        boolean requestFocusInWindow() { 
     323            return value.requestFocusInWindow(); 
     324        } 
    310325    } 
    311326 
    312327    public static class Check extends Item { 
     
    394409        @Override boolean requestFocusInWindow() {return check.requestFocusInWindow();} 
    395410    } 
    396411 
    397     public static class Combo extends Item { 
     412    public static abstract class ComboMultiSelect extends Item { 
    398413 
    399414        public String key; 
    400415        public String text; 
     
    407422        public String short_descriptions; 
    408423        public String locale_short_descriptions; 
    409424        public String default_; 
     425        public String delimiter = ";"; 
    410426        public boolean delete_if_empty = false; 
    411         public boolean editable = true; 
    412427        public String use_last_as_default = "false"; 
    413428        public boolean required = false; 
    414429 
    415         private List<String> short_description_list; 
    416         private JComboBox combo; 
    417         private Map<String, PresetListEntry> lhm; 
    418         private Usage usage; 
    419         private PresetListEntry originalValue; 
     430        protected List<String> short_description_list; 
     431        protected JComponent component; 
     432        protected Map<String, PresetListEntry> lhm; 
     433        protected Usage usage; 
     434        protected Object originalValue; 
    420435 
    421         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     436        protected abstract Object getSelectedItem(); 
     437        protected abstract void addToPanelAnchor(JPanel p, String def, String[] display_array); 
    422438 
     439        @Override 
     440        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     441 
    423442            // find out if our key is already used in the selection. 
    424443            usage = determineTextUsage(sel, key); 
    425444            String def = default_; 
    426445 
    427             String[] value_array = splitEscaped(',', values); 
     446            char delChar = ';'; 
     447            if (!delimiter.isEmpty()) { 
     448                delChar = delimiter.charAt(0); 
     449            } 
     450 
     451            String[] value_array = splitEscaped(delChar, values); 
    428452            String[] display_array; 
    429453            String[] short_descriptions_array = null; 
    430454 
    431             if(locale_display_values != null) { 
    432                 display_array = splitEscaped(',', locale_display_values); 
     455            if (locale_display_values != null) { 
     456                display_array = splitEscaped(delChar, locale_display_values); 
    433457            } else if (display_values != null) { 
    434                 display_array = splitEscaped(',', display_values); 
     458                display_array = splitEscaped(delChar, display_values); 
    435459            } else { 
    436460                display_array = value_array; 
    437461            } 
    438462 
    439463            if (locale_short_descriptions != null) { 
    440                 short_descriptions_array = splitEscaped(',', locale_short_descriptions); 
     464                short_descriptions_array = splitEscaped(delChar, locale_short_descriptions); 
    441465            } else if (short_descriptions != null) { 
    442                 short_descriptions_array = splitEscaped(',', short_descriptions); 
     466                short_descriptions_array = splitEscaped(delChar, short_descriptions); 
    443467            } else if (short_description_list != null) { 
    444468                short_descriptions_array = short_description_list.toArray(new String[0]); 
    445469            } 
     
    462486            if (!usage.hasUniqueValue() && !usage.unused()) { 
    463487                lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); 
    464488            } 
    465             for (int i=0; i<value_array.length; i++) { 
     489            for (int i = 0; i < value_array.length; i++) { 
    466490                PresetListEntry e = new PresetListEntry(value_array[i]); 
    467491                e.display_value = (locale_display_values == null) 
    468                 ? (values_context == null ? tr(fixPresetString(display_array[i])) 
     492                        ? (values_context == null ? tr(fixPresetString(display_array[i])) 
    469493                        : trc(values_context, fixPresetString(display_array[i]))) : display_array[i]; 
    470494                if (short_descriptions_array != null) { 
    471495                    e.short_description = locale_short_descriptions == null ? tr(fixPresetString(short_descriptions_array[i])) 
     
    473497                } 
    474498                lhm.put(value_array[i], e); 
    475499            } 
    476             if(!usage.unused()){ 
    477                 for (String s : usage.values) { 
    478                     if (!lhm.containsKey(s)) { 
    479                         lhm.put(s, new PresetListEntry(s)); 
    480                     } 
    481                 } 
    482             } 
    483             if (def != null && !lhm.containsKey(def)) { 
    484                 lhm.put(def, new PresetListEntry(def)); 
    485             } 
    486             lhm.put("", new PresetListEntry("")); 
    487500 
    488             combo = new JComboBox(lhm.values().toArray()); 
    489             combo.setRenderer(new PresetComboListCellRenderer()); 
    490             combo.setEditable(editable); 
    491             combo.setMaximumRowCount(13); 
    492             AutoCompletingTextField tf = new AutoCompletingTextField(); 
    493             initAutoCompletionField(tf, key); 
    494             tf.getAutoCompletionList().add(Arrays.asList(display_array), AutoCompletionItemPritority.IS_IN_STANDARD); 
    495             combo.setEditor(tf); 
    496  
    497             if (usage.hasUniqueValue()) { 
    498                 // all items have the same value (and there were no unset items) 
    499                 originalValue=lhm.get(usage.getFirst()); 
    500                 combo.setSelectedItem(originalValue); 
    501             } 
    502             else if (def != null && usage.unused()) { 
    503                 // default is set and all items were unset 
    504                 if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 
    505                     // selected osm primitives are untagged or filling default feature is enabled 
    506                     combo.setSelectedItem(def); 
    507                 } else { 
    508                     // selected osm primitives are tagged and filling default feature is disabled 
    509                     combo.setSelectedItem(""); 
    510                 } 
    511                 originalValue=lhm.get(DIFFERENT); 
    512             } 
    513             else if (usage.unused()) { 
    514                 // all items were unset (and so is default) 
    515                 originalValue=lhm.get(""); 
    516                 combo.setSelectedItem(originalValue); 
    517             } 
    518             else { 
    519                 originalValue=lhm.get(DIFFERENT); 
    520                 combo.setSelectedItem(originalValue); 
    521             } 
    522  
    523             if(locale_text == null) { 
    524                 if(text_context != null) { 
     501            if (locale_text == null) { 
     502                if (text_context != null) { 
    525503                    locale_text = trc(text_context, fixPresetString(text)); 
    526504                } else { 
    527505                    locale_text = tr(fixPresetString(text)); 
    528506                } 
    529507            } 
    530             p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 
    531             p.add(combo, GBC.eol().fill(GBC.HORIZONTAL)); 
    532             return true; 
    533         } 
     508            p.add(new JLabel(locale_text + ":"), GBC.std().insets(0, 0, 10, 0)); 
    534509 
     510            addToPanelAnchor(p, def, display_array); 
    535511 
    536         private static class PresetComboListCellRenderer implements ListCellRenderer { 
     512            return true; 
    537513 
    538             HtmlPanel lbl; 
    539             JComponent dummy = new JComponent() {}; 
     514        } 
    540515 
    541             public PresetComboListCellRenderer() { 
    542                 lbl = new HtmlPanel(); 
    543             } 
    544  
    545             public Component getListCellRendererComponent( 
    546                     JList list, 
    547                     Object value, 
    548                     int index, 
    549                     boolean isSelected, 
    550                     boolean cellHasFocus) 
    551             { 
    552                 if (isSelected) { 
    553                     lbl.setBackground(list.getSelectionBackground()); 
    554                     lbl.setForeground(list.getSelectionForeground()); 
    555                 } else { 
    556                     lbl.setBackground(list.getBackground()); 
    557                     lbl.setForeground(list.getForeground()); 
    558                 } 
    559  
    560                 PresetListEntry item = (PresetListEntry) value; 
    561                 String s = item.getListDisplay(); 
    562                 lbl.setText(s); 
    563                 // We do not want the editor to have the maximum height of all 
    564                 // entries. Return a dummy with bogus height. 
    565                 if (index == -1) { 
    566                     dummy.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10)); 
    567                     return dummy; 
    568                 } 
    569                 return lbl; 
    570             } 
     516        protected String getDisplayIfNull(String display) { 
     517            return display; 
    571518        } 
    572519 
    573         @Override public void addCommands(List<Tag> changedTags) { 
    574             Object obj = combo.getSelectedItem(); 
     520        @Override 
     521        public void addCommands(List<Tag> changedTags) { 
     522            Object obj = getSelectedItem(); 
    575523            String display = (obj == null) ? null : obj.toString(); 
    576524            String value = null; 
    577             if(display == null && combo.isEditable()) { 
    578                 display = combo.getEditor().getItem().toString(); 
     525            if (display == null) { 
     526                display = getDisplayIfNull(display); 
    579527            } 
    580528 
    581             if (display != null) 
    582             { 
     529            if (display != null) { 
    583530                for (String key : lhm.keySet()) { 
    584531                    String k = lhm.get(key).toString(); 
    585532                    if (k != null && k.equals(display)) { 
    586                         value=key; 
     533                        value = key; 
    587534                    } 
    588535                } 
    589                 if(value == null) { 
     536                if (value == null) { 
    590537                    value = display; 
    591538                } 
    592539            } else { 
    593540                value = ""; 
    594541            } 
     542            value = value.trim(); 
    595543 
    596544            // no change if same as before 
    597545            if (originalValue == null) { 
    598                 if (value.length() == 0) 
     546                if (value.length() == 0) { 
    599547                    return; 
    600             } else if (value.equals(originalValue.toString())) 
     548                } 
     549            } else if (value.equals(originalValue.toString())) { 
    601550                return; 
     551            } 
    602552 
    603553            if (delete_if_empty && value.length() == 0) { 
    604554                value = null; 
     
    616566            short_description_list.add(tr(s)); 
    617567        } 
    618568 
    619         @Override boolean requestFocusInWindow() {return combo.requestFocusInWindow();} 
     569        @Override 
     570        boolean requestFocusInWindow() { 
     571            return component.requestFocusInWindow(); 
     572        } 
     573 
     574        protected ListCellRenderer getListCellRenderer() { 
     575            return new ListCellRenderer() { 
     576 
     577                HtmlPanel lbl = new HtmlPanel(); 
     578                JComponent dummy = new JComponent() { 
     579                }; 
     580 
     581                public Component getListCellRendererComponent( 
     582                        JList list, 
     583                        Object value, 
     584                        int index, 
     585                        boolean isSelected, 
     586                        boolean cellHasFocus) { 
     587                    if (isSelected) { 
     588                        lbl.setBackground(list.getSelectionBackground()); 
     589                        lbl.setForeground(list.getSelectionForeground()); 
     590                    } else { 
     591                        lbl.setBackground(list.getBackground()); 
     592                        lbl.setForeground(list.getForeground()); 
     593                    } 
     594 
     595                    PresetListEntry item = (PresetListEntry) value; 
     596                    String s = item.getListDisplay(); 
     597                    lbl.setText(s); 
     598                    lbl.setEnabled(list.isEnabled()); 
     599                    // We do not want the editor to have the maximum height of all 
     600                    // entries. Return a dummy with bogus height. 
     601                    if (index == -1) { 
     602                        dummy.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10)); 
     603                        return dummy; 
     604                    } 
     605                    return lbl; 
     606                } 
     607            }; 
     608        } 
    620609    } 
    621610 
     611    public static class Combo extends ComboMultiSelect { 
     612 
     613        public boolean editable = true; 
     614        protected JComboBox combo; 
     615 
     616        public Combo() { 
     617            delimiter = ","; 
     618        } 
     619 
     620        @Override 
     621        protected void addToPanelAnchor(JPanel p, String def, String[] display_array) { 
     622            if (!usage.unused()) { 
     623                for (String s : usage.values) { 
     624                    if (!lhm.containsKey(s)) { 
     625                        lhm.put(s, new PresetListEntry(s)); 
     626                    } 
     627                } 
     628            } 
     629            if (def != null && !lhm.containsKey(def)) { 
     630                lhm.put(def, new PresetListEntry(def)); 
     631            } 
     632            lhm.put("", new PresetListEntry("")); 
     633 
     634            combo = new JComboBox(lhm.values().toArray()); 
     635            component = combo; 
     636            combo.setRenderer(getListCellRenderer()); 
     637            combo.setEditable(editable); 
     638            combo.setMaximumRowCount(13); 
     639            AutoCompletingTextField tf = new AutoCompletingTextField(); 
     640            initAutoCompletionField(tf, key); 
     641            tf.getAutoCompletionList().add(Arrays.asList(display_array), AutoCompletionItemPritority.IS_IN_STANDARD); 
     642            combo.setEditor(tf); 
     643 
     644            if (usage.hasUniqueValue()) { 
     645                // all items have the same value (and there were no unset items) 
     646                originalValue = lhm.get(usage.getFirst()); 
     647                combo.setSelectedItem(originalValue); 
     648            } else if (def != null && usage.unused()) { 
     649                // default is set and all items were unset 
     650                if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 
     651                    // selected osm primitives are untagged or filling default feature is enabled 
     652                    combo.setSelectedItem(def); 
     653                } else { 
     654                    // selected osm primitives are tagged and filling default feature is disabled 
     655                    combo.setSelectedItem(""); 
     656                } 
     657                originalValue = lhm.get(DIFFERENT); 
     658            } else if (usage.unused()) { 
     659                // all items were unset (and so is default) 
     660                originalValue = lhm.get(""); 
     661                combo.setSelectedItem(originalValue); 
     662            } else { 
     663                originalValue = lhm.get(DIFFERENT); 
     664                combo.setSelectedItem(originalValue); 
     665            } 
     666            p.add(combo, GBC.eol().fill(GBC.HORIZONTAL)); 
     667 
     668        } 
     669 
     670        @Override 
     671        protected Object getSelectedItem() { 
     672            return combo.getSelectedItem(); 
     673 
     674        } 
     675 
     676        @Override 
     677        protected String getDisplayIfNull(String display) { 
     678            if (combo.isEditable()) { 
     679                return combo.getEditor().getItem().toString(); 
     680            } else { 
     681                return display; 
     682            } 
     683 
     684        } 
     685    } 
     686 
    622687    /** 
    623      * Class that allows list values to be assigned and retrived as a comma-delimited 
     688     * Class that allows list values to be assigned and retrieved as a comma-delimited 
    624689     * string. 
    625690     */ 
    626691    public static class ConcatenatingJList extends JList { 
     
    664729        } 
    665730    } 
    666731 
    667     public static class MultiSelect extends Item { 
     732    public static class MultiSelect extends ComboMultiSelect { 
    668733 
    669         public String key; 
    670         public String text; 
    671         public String text_context; 
    672         public String locale_text; 
    673         public String values; 
    674         public String values_context; 
    675         public String display_values; 
    676         public String locale_display_values; 
    677         public String short_descriptions; 
    678         public String locale_short_descriptions; 
    679         public String default_; 
    680         public String delimiter = ";"; 
    681         public boolean delete_if_empty = false; 
    682         public String use_last_as_default = "false"; 
    683         public boolean required = false; 
    684734        public long rows = -1; 
     735        protected ConcatenatingJList list; 
    685736 
    686         private List<String> short_description_list; 
    687         private ConcatenatingJList list; 
    688         private Map<String, PresetListEntry> lhm; 
    689         private Usage usage; 
    690         private String originalValue; 
    691  
    692         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
    693  
    694             // find out if our key is already used in the selection. 
    695             usage = determineTextUsage(sel, key); 
    696             String def = default_; 
    697  
    698             char delChar = ';'; 
    699             if (delimiter.length() > 0) { 
    700                 delChar = delimiter.charAt(0); 
    701             } 
    702  
    703             String[] value_array = splitEscaped(delChar, values); 
    704             String[] display_array; 
    705             String[] short_descriptions_array = null; 
    706  
    707             if (locale_display_values != null) { 
    708                 display_array = splitEscaped(delChar, locale_display_values); 
    709             } else if (display_values != null) { 
    710                 display_array = splitEscaped(delChar, display_values); 
    711             } else { 
    712                 display_array = value_array; 
    713             } 
    714  
    715             if (locale_short_descriptions != null) { 
    716                 short_descriptions_array = splitEscaped(delChar, locale_short_descriptions); 
    717             } else if (short_descriptions != null) { 
    718                 short_descriptions_array = splitEscaped(delChar, short_descriptions); 
    719             } else if (short_description_list != null) { 
    720                 short_descriptions_array = short_description_list.toArray(new String[0]); 
    721             } 
    722  
    723             if (!"false".equals(use_last_as_default) && def == null && lastValue.containsKey(key)) { 
    724                 def = lastValue.get(key); 
    725             } 
    726  
    727             if (display_array.length != value_array.length) { 
    728                 System.err.println(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''display_values'' must be the same as in ''values''", key, text)); 
    729                 display_array = value_array; 
    730             } 
    731  
    732             if (short_descriptions_array != null && short_descriptions_array.length != value_array.length) { 
    733                 System.err.println(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''short_descriptions'' must be the same as in ''values''", key, text)); 
    734                 short_descriptions_array = null; 
    735             } 
    736  
    737             lhm = new LinkedHashMap<String, PresetListEntry>(); 
    738             if (!usage.hasUniqueValue() && !usage.unused()) { 
    739                 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); 
    740             } 
    741             for (int i=0; i<value_array.length; i++) { 
    742                 PresetListEntry e = new PresetListEntry(value_array[i]); 
    743                 e.display_value = (locale_display_values == null) 
    744                 ? (values_context == null ? tr(fixPresetString(display_array[i])) 
    745                         : trc(values_context, fixPresetString(display_array[i]))) : display_array[i]; 
    746                 if (short_descriptions_array != null) { 
    747                     e.short_description = locale_short_descriptions == null ? tr(fixPresetString(short_descriptions_array[i])) 
    748                             : short_descriptions_array[i]; 
    749                 } 
    750                 lhm.put(value_array[i], e); 
    751             } 
    752  
     737        @Override 
     738        protected void addToPanelAnchor(JPanel p, String def, String[] display_array) { 
    753739            list = new ConcatenatingJList(delimiter, lhm.values().toArray()); 
    754             PresetListCellRenderer renderer = new PresetListCellRenderer(); 
     740            component = list; 
     741            ListCellRenderer renderer = getListCellRenderer(); 
    755742            list.setCellRenderer(renderer); 
    756743 
    757744            if (usage.hasUniqueValue() && !usage.unused()) { 
    758                 originalValue=usage.getFirst(); 
     745                originalValue = usage.getFirst(); 
    759746                list.setSelectedItem(originalValue); 
    760             } 
    761             else if (def != null && !usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 
    762                 originalValue=DIFFERENT; 
     747            } else if (def != null && !usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 
     748                originalValue = DIFFERENT; 
    763749                list.setSelectedItem(def); 
    764             } 
    765             else if (usage.unused()) { 
    766                 originalValue=null; 
     750            } else if (usage.unused()) { 
     751                originalValue = null; 
    767752                list.setSelectedItem(originalValue); 
    768             } 
    769             else { 
    770                 originalValue=DIFFERENT; 
     753            } else { 
     754                originalValue = DIFFERENT; 
    771755                list.setSelectedItem(originalValue); 
    772756            } 
    773757 
    774             if (locale_text == null) { 
    775                 if(text_context != null) { 
    776                     locale_text = trc(text_context, fixPresetString(text)); 
    777                 } else { 
    778                     locale_text = tr(fixPresetString(text)); 
    779                 } 
    780             } 
    781             p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 
    782758            JScrollPane sp = new JScrollPane(list); 
    783759            // if a number of rows has been specified in the preset, 
    784760            // modify preferred height of scroll pane to match that row count. 
    785             if (rows != -1) 
    786             { 
     761            if (rows != -1) { 
    787762                double height = renderer.getListCellRendererComponent(list, 
    788763                        new PresetListEntry("x"), 0, false, false).getPreferredSize().getHeight() * rows; 
    789764                sp.setPreferredSize(new Dimension((int) sp.getPreferredSize().getWidth(), (int) height)); 
    790765            } 
    791766            p.add(sp, GBC.eol().fill(GBC.HORIZONTAL)); 
    792             return true; 
    793         } 
    794767 
    795         private static class PresetListCellRenderer implements ListCellRenderer { 
    796768 
    797             HtmlPanel lbl; 
    798             JComponent dummy = new JComponent() {}; 
    799  
    800             public PresetListCellRenderer() { 
    801                 lbl = new HtmlPanel(); 
    802             } 
    803  
    804             public Component getListCellRendererComponent( 
    805                     JList list, 
    806                     Object value, 
    807                     int index, 
    808                     boolean isSelected, 
    809                     boolean cellHasFocus) 
    810             { 
    811                 if (isSelected) { 
    812                     lbl.setBackground(list.getSelectionBackground()); 
    813                     lbl.setForeground(list.getSelectionForeground()); 
    814                 } else { 
    815                     lbl.setBackground(list.getBackground()); 
    816                     lbl.setForeground(list.getForeground()); 
    817                 } 
    818  
    819                 PresetListEntry item = (PresetListEntry) value; 
    820                 String s = item.getListDisplay(); 
    821                 lbl.setText(s); 
    822                 lbl.setEnabled(list.isEnabled()); 
    823                 // We do not want the editor to have the maximum height of all 
    824                 // entries. Return a dummy with bogus height. 
    825                 if (index == -1) { 
    826                     dummy.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10)); 
    827                     return dummy; 
    828                 } 
    829                 return lbl; 
    830             } 
    831769        } 
    832770 
    833         @Override public void addCommands(List<Tag> changedTags) { 
    834             Object obj = list.getSelectedItem(); 
    835             String display = (obj == null) ? null : obj.toString(); 
    836             String value = null; 
    837  
    838             if (display != null) 
    839             { 
    840                 for (String key : lhm.keySet()) { 
    841                     String k = lhm.get(key).toString(); 
    842                     if (k != null && k.equals(display)) { 
    843                         value=key; 
    844                     } 
    845                 } 
    846                 if (value == null) { 
    847                     value = display; 
    848                 } 
    849             } else { 
    850                 value = ""; 
    851             } 
    852  
    853             // no change if same as before 
    854             if (originalValue == null) { 
    855                 if (value.length() == 0) 
    856                     return; 
    857             } else if (value.equals(originalValue.toString())) 
    858                 return; 
    859  
    860             if (delete_if_empty && value.length() == 0) { 
    861                 value = null; 
    862             } 
    863             if (!"false".equals(use_last_as_default)) { 
    864                 lastValue.put(key, value); 
    865             } 
    866             changedTags.add(new Tag(key, value)); 
     771        @Override 
     772        protected Object getSelectedItem() { 
     773            return list.getSelectedItem(); 
    867774        } 
    868  
    869         public void setShort_description(String s) { 
    870             if (short_description_list == null) { 
    871                 short_description_list = new ArrayList<String>(); 
    872             } 
    873             short_description_list.add(tr(s)); 
    874         } 
    875  
    876         @Override boolean requestFocusInWindow() {return list.requestFocusInWindow();} 
    877775    } 
    878776 
    879777    /** 
     
    908806    } 
    909807 
    910808    public static class Label extends Item { 
     809 
    911810        public String text; 
    912811        public String text_context; 
    913812        public String locale_text; 
    914813 
    915         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
    916             if(locale_text == null) { 
    917                 if(text_context != null) { 
     814        @Override 
     815        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     816            if (locale_text == null) { 
     817                if (text_context != null) { 
    918818                    locale_text = trc(text_context, fixPresetString(text)); 
    919819                } else { 
    920820                    locale_text = tr(fixPresetString(text)); 
     
    923823            p.add(new JLabel(locale_text), GBC.eol()); 
    924824            return false; 
    925825        } 
    926         @Override public void addCommands(List<Tag> changedTags) {} 
     826 
     827        @Override 
     828        public void addCommands(List<Tag> changedTags) { 
     829        } 
    927830    } 
    928831 
    929832    public static class Link extends Item { 
     833 
    930834        public String href; 
    931835        public String text; 
    932836        public String text_context; 
    933837        public String locale_text; 
    934838        public String locale_href; 
    935839 
    936         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
    937             if(locale_text == null) { 
    938                 if(text == null) { 
     840        @Override 
     841        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     842            if (locale_text == null) { 
     843                if (text == null) { 
    939844                    locale_text = tr("More information about this feature"); 
    940                 } else if(text_context != null) { 
     845                } else if (text_context != null) { 
    941846                    locale_text = trc(text_context, fixPresetString(text)); 
    942847                } else { 
    943848                    locale_text = tr(fixPresetString(text)); 
     
    952857            } 
    953858            return false; 
    954859        } 
    955         @Override public void addCommands(List<Tag> changedTags) {} 
     860 
     861        @Override 
     862        public void addCommands(List<Tag> changedTags) { 
     863        } 
    956864    } 
    957865 
    958866    public static class Role { 
     
    1024932    } 
    1025933 
    1026934    public static class Roles extends Item { 
     935 
    1027936        public List<Role> roles = new LinkedList<Role>(); 
    1028         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     937 
     938        @Override 
     939        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
    1029940            p.add(new JLabel(" "), GBC.eol()); // space 
    1030             if(roles.size() > 0) 
    1031             { 
     941            if (roles.size() > 0) { 
    1032942                JPanel proles = new JPanel(new GridBagLayout()); 
    1033                 proles.add(new JLabel(tr("Available roles")), GBC.std().insets(0,0,10,0)); 
    1034                 proles.add(new JLabel(tr("role")), GBC.std().insets(0,0,10,0)); 
    1035                 proles.add(new JLabel(tr("count")), GBC.std().insets(0,0,10,0)); 
     943                proles.add(new JLabel(tr("Available roles")), GBC.std().insets(0, 0, 10, 0)); 
     944                proles.add(new JLabel(tr("role")), GBC.std().insets(0, 0, 10, 0)); 
     945                proles.add(new JLabel(tr("count")), GBC.std().insets(0, 0, 10, 0)); 
    1036946                proles.add(new JLabel(tr("elements")), GBC.eol()); 
    1037947                for (Role i : roles) { 
    1038948                    i.addToPanel(proles, sel); 
     
    1041951            } 
    1042952            return false; 
    1043953        } 
    1044         @Override public void addCommands(List<Tag> changedTags) {} 
     954 
     955        @Override 
     956        public void addCommands(List<Tag> changedTags) { 
     957        } 
    1045958    } 
    1046959 
    1047960    public static class Optional extends Item { 
     961 
    1048962        // TODO: Draw a box around optional stuff 
    1049         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     963        @Override 
     964        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
    1050965            p.add(new JLabel(" "), GBC.eol()); // space 
    1051966            p.add(new JLabel(tr("Optional Attributes:")), GBC.eol()); 
    1052967            p.add(new JLabel(" "), GBC.eol()); // space 
    1053968            return false; 
    1054969        } 
    1055         @Override public void addCommands(List<Tag> changedTags) {} 
     970 
     971        @Override 
     972        public void addCommands(List<Tag> changedTags) { 
     973        } 
    1056974    } 
    1057975 
    1058976    public static class Space extends Item { 
    1059         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     977 
     978        @Override 
     979        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
    1060980            p.add(new JLabel(" "), GBC.eol()); // space 
    1061981            return false; 
    1062982        } 
    1063         @Override public void addCommands(List<Tag> changedTags) {} 
     983 
     984        @Override 
     985        public void addCommands(List<Tag> changedTags) { 
     986        } 
    1064987    } 
    1065988 
    1066989    public static class Key extends Item { 
     990 
    1067991        public String key; 
    1068992        public String value; 
    1069993 
    1070         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { return false; } 
    1071         @Override public void addCommands(List<Tag> changedTags) { 
    1072             changedTags.add(new Tag(key, value != null && !value.equals("") ? value : null)); 
     994        @Override 
     995        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     996            return false; 
    1073997        } 
     998 
     999        @Override 
     1000        public void addCommands(List<Tag> changedTags) { 
     1001            changedTags.add(new Tag(key, value)); 
     1002        } 
    10741003    } 
    10751004 
    10761005    /**