Changeset 16972 in josm
- Timestamp:
- 2020-08-29T20:24:10+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanel.java
r16453 r16972 5 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 6 7 import java.awt.Color;8 7 import java.awt.Component; 9 8 import java.awt.GridBagConstraints; … … 22 21 import java.util.Map.Entry; 23 22 24 import javax.swing.BorderFactory;25 23 import javax.swing.ButtonGroup; 26 24 import javax.swing.JLabel; 27 25 import javax.swing.JPanel; 28 26 import javax.swing.JRadioButton; 29 import javax.swing.UIManager; 30 import javax.swing.event.DocumentEvent; 31 import javax.swing.event.DocumentListener; 32 27 import javax.swing.text.JTextComponent; 28 29 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator; 33 30 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; 34 31 import org.openstreetmap.josm.gui.widgets.JosmTextField; … … 54 51 public static final String UPLOAD_STRATEGY_SPECIFICATION_PROP = 55 52 UploadStrategySelectionPanel.class.getName() + ".uploadStrategySpecification"; 56 57 private static final Color BG_COLOR_ERROR = new Color(255, 224, 224);58 53 59 54 private transient Map<UploadStrategy, JRadioButton> rbStrategy; … … 174 169 175 170 tfChunkSize.addFocusListener(new TextFieldFocusHandler()); 176 tfChunkSize.getDocument().addDocumentListener(new ChunkSizeInputVerifier());171 new ChunkSizeValidator(tfChunkSize); 177 172 178 173 StrategyChangeListener strategyChangeListener = new StrategyChangeListener(); … … 420 415 } 421 416 422 class ChunkSizeInputVerifier implements DocumentListener, PropertyChangeListener { 423 protected void setErrorFeedback(JosmTextField tf, String message) { 424 tf.setBorder(BorderFactory.createLineBorder(Color.RED, 1)); 425 tf.setToolTipText(message); 426 tf.setBackground(BG_COLOR_ERROR); 427 } 428 429 protected void clearErrorFeedback(JosmTextField tf, String message) { 430 tf.setBorder(UIManager.getBorder("TextField.border")); 431 tf.setToolTipText(message); 432 tf.setBackground(UIManager.getColor("TextField.background")); 433 } 434 435 protected void validateChunkSize() { 417 class ChunkSizeValidator extends AbstractTextComponentValidator { 418 ChunkSizeValidator(JTextComponent tc) { 419 super(tc); 420 } 421 422 @Override 423 public void validate() { 436 424 try { 437 425 int chunkSize = Integer.parseInt(tfChunkSize.getText().trim()); 438 426 int maxChunkSize = OsmApi.getOsmApi().getCapabilities().getMaxChangesetSize(); 439 427 if (chunkSize <= 0) { 440 setErrorFeedback(tfChunkSize,tr("Illegal chunk size <= 0. Please enter an integer > 1"));428 feedbackInvalid(tr("Illegal chunk size <= 0. Please enter an integer > 1")); 441 429 } else if (maxChunkSize > 0 && chunkSize > maxChunkSize) { 442 setErrorFeedback(tfChunkSize,tr("Chunk size {0} exceeds max. changeset size {1} for server ''{2}''",430 feedbackInvalid(tr("Chunk size {0} exceeds max. changeset size {1} for server ''{2}''", 443 431 chunkSize, maxChunkSize, OsmApi.getOsmApi().getBaseUrl())); 444 432 } else { 445 clearErrorFeedback(tfChunkSize, tr("Please enter an integer > 1"));433 feedbackValid(null); 446 434 } 447 435 448 436 if (maxChunkSize > 0 && chunkSize > maxChunkSize) { 449 setErrorFeedback(tfChunkSize,tr("Chunk size {0} exceeds max. changeset size {1} for server ''{2}''",437 feedbackInvalid(tr("Chunk size {0} exceeds max. changeset size {1} for server ''{2}''", 450 438 chunkSize, maxChunkSize, OsmApi.getOsmApi().getBaseUrl())); 451 439 } 452 440 } catch (NumberFormatException e) { 453 setErrorFeedback(tfChunkSize,tr("Value ''{0}'' is not a number. Please enter an integer > 1",441 feedbackInvalid(tr("Value ''{0}'' is not a number. Please enter an integer > 1", 454 442 tfChunkSize.getText().trim())); 455 443 } finally { … … 459 447 460 448 @Override 461 public void changedUpdate(DocumentEvent e) { 462 validateChunkSize(); 463 } 464 465 @Override 466 public void insertUpdate(DocumentEvent e) { 467 validateChunkSize(); 468 } 469 470 @Override 471 public void removeUpdate(DocumentEvent e) { 472 validateChunkSize(); 473 } 474 475 @Override 476 public void propertyChange(PropertyChangeEvent evt) { 477 if (evt.getSource() == tfChunkSize 478 && "enabled".equals(evt.getPropertyName()) 479 && (Boolean) evt.getNewValue() 480 ) { 481 validateChunkSize(); 482 } 449 public boolean isValid() { 450 throw new UnsupportedOperationException(); 483 451 } 484 452 }
Note:
See TracChangeset
for help on using the changeset viewer.