Ignore:
Timestamp:
2006-11-24T15:52:34+01:00 (17 years ago)
Author:
imi
Message:
  • removed external tools (superseeded by plugins)
  • added align-in-line mode
  • added delete_if_empty-attribute to annotation presets
  • fixed exception when help is not available
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/annotation/AnnotationPreset.java

    r129 r167  
    4646
    4747        public static class Text implements Item {
    48                 String key;
    49                 String label;
    50                 JTextField value = new JTextField();
     48                private String key;
     49                private String label;
     50                private JTextField value = new JTextField();
     51                private boolean deleteIfEmpty;
    5152
    5253                public void addToPanel(JPanel p) {
     
    5455                        p.add(value, GBC.eol().fill(GBC.HORIZONTAL));
    5556                }
    56                 public Text(String key, String label, String value) {
     57                public Text(String key, String label, String value, boolean deleteIfEmpty) {
    5758                        this.key = key;
    5859                        this.label = label;
    5960                        this.value.setText(value == null ? "" : value);
    60                 }
    61                 public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) {
    62                         cmds.add(new ChangePropertyCommand(sel, key, value.getText()));
     61                        this.deleteIfEmpty = deleteIfEmpty;
     62                }
     63                public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) {
     64                        String v = value.getText();
     65                        if (deleteIfEmpty && v.length() == 0)
     66                                v = null;
     67                        cmds.add(new ChangePropertyCommand(sel, key, v));
    6368                }
    6469        }
    6570
    6671        public static class Check implements Item {
    67                 String key;
    68                 JCheckBox check = new JCheckBox();
     72                private String key;
     73                private JCheckBox check = new JCheckBox();
    6974
    7075                public void addToPanel(JPanel p) {
     
    8287
    8388        public static class Combo implements Item {
    84                 String key;
    85                 String label;
    86                 JComboBox combo;
     89                private String key;
     90                private String label;
     91                private JComboBox combo;
    8792                private final String[] values;
     93                private boolean deleteIfEmpty;
    8894
    8995                public void addToPanel(JPanel p) {
     
    9197                        p.add(combo, GBC.eol().fill(GBC.HORIZONTAL));
    9298                }
    93                 public Combo(String key, String label, String def, String[] values, String[] displayedValues, boolean editable) {
     99                public Combo(String key, String label, String def, String[] values, String[] displayedValues, boolean editable, boolean deleteIfEmpty) {
    94100                        this.key = key;
    95101                        this.label = label;
    96102                        this.values = values;
     103                        this.deleteIfEmpty = deleteIfEmpty;
    97104                        combo = new JComboBox(displayedValues);
    98105                        combo.setEditable(editable);
     
    102109                        String v = combo.getSelectedIndex() == -1 ? null : values[combo.getSelectedIndex()];
    103110                        String str = combo.isEditable()?combo.getEditor().getItem().toString() : v;
     111                        if (deleteIfEmpty && str != null && str.length() == 0)
     112                                str = null;
    104113                        cmds.add(new ChangePropertyCommand(sel, key, str));
    105114                }
     
    107116
    108117        public static class Label implements Item {
    109                 String text;
     118                private String text;
    110119
    111120                public void addToPanel(JPanel p) {
     
    119128
    120129        public static class Key implements Item {
    121                 String key;
    122                 String value;
     130                private String key;
     131                private String value;
    123132
    124133                public void addToPanel(JPanel p) {}
     
    162171                                }
    163172                        } else if (qname.equals("text"))
    164                                 current.add(new Text(a.getValue("key"), a.getValue("text"), a.getValue("default")));
     173                                current.add(new Text(a.getValue("key"), a.getValue("text"), a.getValue("default"), parseBoolean(a.getValue("delete_if_empty"))));
    165174                        else if (qname.equals("check")) {
    166175                                String s = a.getValue("default");
    167                                 boolean clear = s == null || s.equals("0") || s.startsWith("off") || s.startsWith("false") || s.startsWith("no");
     176                                boolean clear = parseBoolean(s);
    168177                                current.add(new Check(a.getValue("key"), a.getValue("text"), !clear));
    169178                        } else if (qname.equals("label"))
     
    173182                                String s = a.getValue("readonly");
    174183                                String dvstr = a.getValue("display_values");
    175                                 boolean editable = s == null  || s.equals("0") || s.startsWith("off") || s.startsWith("false") || s.startsWith("no");
     184                                boolean editable = parseBoolean(s);
    176185                                if (dvstr != null) {
    177186                                        if (editable && s != null)
     
    184193                                                        displayValues.length+" "+trn("element", "elements", displayValues.length),
    185194                                                        values.length+" "+trn("element", "elements", values.length)));
    186                                 current.add(new Combo(a.getValue("key"), a.getValue("text"), a.getValue("default"), values, displayValues, editable));
     195                                current.add(new Combo(a.getValue("key"), a.getValue("text"), a.getValue("default"), values, displayValues, editable, parseBoolean(a.getValue("delete_if_empty"))));
    187196                        } else if (qname.equals("key"))
    188197                                current.add(new Key(a.getValue("key"), a.getValue("value")));
     
    190199                                throw new SAXException(tr("Unknown annotation object {0} at line {1} column {2}", qname, getLineNumber(), getColumnNumber()));
    191200                }
     201
     202                private boolean parseBoolean(String s) {
     203                return s == null || s.equals("0") || s.startsWith("off") || s.startsWith("false") || s.startsWith("no");
     204        }
    192205
    193206                @Override public void endElement(String ns, String lname, String qname) {
Note: See TracChangeset for help on using the changeset viewer.