Changeset 167 in josm for src/org/openstreetmap/josm/gui/annotation/AnnotationPreset.java
- Timestamp:
- 2006-11-24T15:52:34+01:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/annotation/AnnotationPreset.java
r129 r167 46 46 47 47 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; 51 52 52 53 public void addToPanel(JPanel p) { … … 54 55 p.add(value, GBC.eol().fill(GBC.HORIZONTAL)); 55 56 } 56 public Text(String key, String label, String value ) {57 public Text(String key, String label, String value, boolean deleteIfEmpty) { 57 58 this.key = key; 58 59 this.label = label; 59 60 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)); 63 68 } 64 69 } 65 70 66 71 public static class Check implements Item { 67 String key;68 JCheckBox check = new JCheckBox();72 private String key; 73 private JCheckBox check = new JCheckBox(); 69 74 70 75 public void addToPanel(JPanel p) { … … 82 87 83 88 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; 87 92 private final String[] values; 93 private boolean deleteIfEmpty; 88 94 89 95 public void addToPanel(JPanel p) { … … 91 97 p.add(combo, GBC.eol().fill(GBC.HORIZONTAL)); 92 98 } 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) { 94 100 this.key = key; 95 101 this.label = label; 96 102 this.values = values; 103 this.deleteIfEmpty = deleteIfEmpty; 97 104 combo = new JComboBox(displayedValues); 98 105 combo.setEditable(editable); … … 102 109 String v = combo.getSelectedIndex() == -1 ? null : values[combo.getSelectedIndex()]; 103 110 String str = combo.isEditable()?combo.getEditor().getItem().toString() : v; 111 if (deleteIfEmpty && str != null && str.length() == 0) 112 str = null; 104 113 cmds.add(new ChangePropertyCommand(sel, key, str)); 105 114 } … … 107 116 108 117 public static class Label implements Item { 109 String text;118 private String text; 110 119 111 120 public void addToPanel(JPanel p) { … … 119 128 120 129 public static class Key implements Item { 121 String key;122 String value;130 private String key; 131 private String value; 123 132 124 133 public void addToPanel(JPanel p) {} … … 162 171 } 163 172 } 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")))); 165 174 else if (qname.equals("check")) { 166 175 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); 168 177 current.add(new Check(a.getValue("key"), a.getValue("text"), !clear)); 169 178 } else if (qname.equals("label")) … … 173 182 String s = a.getValue("readonly"); 174 183 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); 176 185 if (dvstr != null) { 177 186 if (editable && s != null) … … 184 193 displayValues.length+" "+trn("element", "elements", displayValues.length), 185 194 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")))); 187 196 } else if (qname.equals("key")) 188 197 current.add(new Key(a.getValue("key"), a.getValue("value"))); … … 190 199 throw new SAXException(tr("Unknown annotation object {0} at line {1} column {2}", qname, getLineNumber(), getColumnNumber())); 191 200 } 201 202 private boolean parseBoolean(String s) { 203 return s == null || s.equals("0") || s.startsWith("off") || s.startsWith("false") || s.startsWith("no"); 204 } 192 205 193 206 @Override public void endElement(String ns, String lname, String qname) {
Note:
See TracChangeset
for help on using the changeset viewer.