Changeset 2483 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-11-19T17:28:41+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
r2403 r2483 56 56 57 57 58 protected void registerBoundingBoxBuilder() { 59 BoundingBoxBuilder bboxbuilder = new BoundingBoxBuilder(); 60 for (int i = 0;i < latlon.length; i++) { 61 latlon[i].addFocusListener(bboxbuilder); 62 latlon[i].addActionListener(bboxbuilder); 63 } 64 } 65 58 66 protected void buildDownloadAreaInputFields() { 59 67 latlon = new JTextField[4]; … … 78 86 latlon[3].addFocusListener(lonChecker); 79 87 latlon[3].addActionListener(lonChecker); 88 89 registerBoundingBoxBuilder(); 80 90 } 81 91 … … 175 185 latlon[2].setText(Double.toString(area.getMax().lat())); 176 186 latlon[3].setText(Double.toString(area.getMax().lon())); 177 for (JTextField f: latlon) {178 f.setCaretPosition(0);187 for (JTextField tf: latlon) { 188 resetErrorMessage(tf); 179 189 } 180 190 } … … 185 195 } 186 196 197 private Border errorBorder = BorderFactory.createLineBorder(Color.RED, 1); 198 199 protected void setErrorMessage(JTextField tf, String msg) { 200 tf.setBorder(errorBorder); 201 tf.setToolTipText(msg); 202 } 203 204 protected void resetErrorMessage(JTextField tf) { 205 tf.setBorder(UIManager.getBorder("TextField.border")); 206 tf.setToolTipText(""); 207 } 208 187 209 188 210 class LatValueChecker extends FocusAdapter implements ActionListener{ 189 211 private JTextField tfLatValue; 190 212 191 private Border errorBorder = BorderFactory.createLineBorder(Color.RED, 1);192 protected void setErrorMessage(String msg) {193 if (msg != null) {194 tfLatValue.setBorder(errorBorder);195 tfLatValue.setToolTipText(msg);196 } else {197 tfLatValue.setBorder(UIManager.getBorder("TextField.border"));198 tfLatValue.setToolTipText("");199 }200 }201 202 213 public LatValueChecker(JTextField tfLatValue) { 203 214 this.tfLatValue = tfLatValue; … … 209 220 value = Double.parseDouble(tfLatValue.getText()); 210 221 } catch(NumberFormatException ex) { 211 setErrorMessage(t r("The string ''{0}'' isn''t a valid double value.", tfLatValue.getText()));222 setErrorMessage(tfLatValue,tr("The string ''{0}'' isn''t a valid double value.", tfLatValue.getText())); 212 223 return; 213 224 } 214 225 if (!LatLon.isValidLat(value)) { 215 setErrorMessage(t r("Value for latitude in range [-90,90] required.", tfLatValue.getText()));226 setErrorMessage(tfLatValue,tr("Value for latitude in range [-90,90] required.", tfLatValue.getText())); 216 227 return; 217 228 } 218 setErrorMessage(null);229 resetErrorMessage(tfLatValue); 219 230 } 220 231 … … 231 242 class LonValueChecker extends FocusAdapter implements ActionListener { 232 243 private JTextField tfLonValue; 233 private Border errorBorder = BorderFactory.createLineBorder(Color.RED, 1);234 protected void setErrorMessage(String msg) {235 if (msg != null) {236 tfLonValue.setBorder(errorBorder);237 tfLonValue.setToolTipText(msg);238 } else {239 tfLonValue.setBorder(UIManager.getBorder("TextField.border"));240 tfLonValue.setToolTipText("");241 }242 }243 244 244 245 public LonValueChecker(JTextField tfLonValue) { … … 251 252 value = Double.parseDouble(tfLonValue.getText()); 252 253 } catch(NumberFormatException ex) { 253 setErrorMessage(t r("The string ''{0}'' isn''t a valid double value.", tfLonValue.getText()));254 setErrorMessage(tfLonValue,tr("The string ''{0}'' isn''t a valid double value.", tfLonValue.getText())); 254 255 return; 255 256 } 256 257 if (!LatLon.isValidLon(value)) { 257 setErrorMessage(t r("Value for longitude in range [-180,180] required.", tfLonValue.getText()));258 setErrorMessage(tfLonValue,tr("Value for longitude in range [-180,180] required.", tfLonValue.getText())); 258 259 return; 259 260 } 260 setErrorMessage(null);261 resetErrorMessage(tfLonValue); 261 262 } 262 263 … … 336 337 } 337 338 } 339 340 class BoundingBoxBuilder extends FocusAdapter implements ActionListener { 341 protected Bounds build() { 342 double minlon, minlat, maxlon,maxlat; 343 try { 344 minlon = Double.parseDouble(latlon[0].getText().trim()); 345 minlat = Double.parseDouble(latlon[1].getText().trim()); 346 maxlon = Double.parseDouble(latlon[2].getText().trim()); 347 maxlat = Double.parseDouble(latlon[3].getText().trim()); 348 } catch(NumberFormatException e) { 349 return null; 350 } 351 if (!LatLon.isValidLon(minlon) || !LatLon.isValidLon(maxlon) 352 || !LatLon.isValidLat(minlat) || ! LatLon.isValidLat(maxlat)) 353 return null; 354 if (minlon > maxlon) 355 return null; 356 if (minlat > maxlat) 357 return null; 358 return new Bounds(minlon,minlat,maxlon,maxlat); 359 } 360 361 protected void refreshBounds() { 362 Bounds b = build(); 363 parent.boundingBoxChanged(b, BoundingBoxSelection.this); 364 } 365 366 @Override 367 public void focusLost(FocusEvent e) { 368 refreshBounds(); 369 } 370 371 public void actionPerformed(ActionEvent e) { 372 refreshBounds(); 373 } 374 } 338 375 }
Note:
See TracChangeset
for help on using the changeset viewer.