Changeset 34938 in osm for applications/editors/josm/plugins
- Timestamp:
- 2019-03-24T16:35:33+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/ChangesetIdsTextField.java
r32905 r34938 1 1 // License: GPL. For details, see LICENSE file. 2 2 package reverter; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.util.Collection; … … 10 12 11 13 import org.openstreetmap.josm.gui.widgets.AbstractIdTextField; 12 import org.openstreetmap.josm.gui.widgets. ChangesetIdTextField;14 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator; 13 15 16 /** 17 * A text field designed to enter one or more OSM changeset IDs. 18 */ 14 19 public class ChangesetIdsTextField extends AbstractIdTextField<ChangesetIdsTextField.OsmIdsValidator> { 15 20 21 /** 22 * Constructs a new {@link ChangesetIdsTextField} 23 */ 16 24 public ChangesetIdsTextField() { 17 25 super(OsmIdsValidator.class); 18 26 } 19 27 28 /** 29 * Reads the changeset ids. 30 * @return true if a list of valid changeset id has been successfully read, false otherwise 31 */ 20 32 @Override 21 33 public boolean readIds() { 22 return validator.readChangesetId ();34 return validator.readChangesetIds(); 23 35 } 24 36 37 /** 38 * @return sorted changeset IDs (highest ID first) 39 */ 25 40 public Collection<Integer> getIdsInReverseOrder() { 26 41 return validator.ids; 27 42 } 28 43 29 public static class OsmIdsValidator extends ChangesetIdTextField.ChangesetIdValidator {44 public static class OsmIdsValidator extends AbstractTextComponentValidator { 30 45 31 46 private Collection<Integer> ids = new TreeSet<>(Collections.reverseOrder()); 32 47 48 /** 49 * Constructs a new {@link OsmIdsValidator} 50 */ 33 51 public OsmIdsValidator(JTextComponent tc) { 34 52 super(tc); … … 36 54 37 55 @Override 38 public boolean readChangesetId() { 56 public void validate() { 57 String help = tr("Please enter one or more integer values > 0 or full changeset URLs."); 58 if (!isValid()) { 59 feedbackInvalid(tr("The current value is not a a list of valid changeset IDs. {0}", help)); 60 } else { 61 feedbackValid(help); 62 } 63 } 64 65 /** 66 * Read list of changeset IDs or changeset URLs. 67 * @return true if list is valid 68 */ 69 public boolean readChangesetIds() { 39 70 ids.clear(); 40 71 String value = getComponent().getText(); 41 72 try { 42 final StringTokenizer tokenizer = new StringTokenizer(value, ", .+/\t\n");73 final StringTokenizer tokenizer = new StringTokenizer(value, ",+ \t\n"); 43 74 while (tokenizer.hasMoreTokens()) { 44 ids.add(Integer.parseInt(tokenizer.nextToken().trim())); 75 String token = tokenizer.nextToken().trim(); 76 if (token.matches("http.*/changeset/[0-9]+")) { 77 // full URL given, extract id 78 token = token.substring(token.lastIndexOf('/') + 1); 79 } 80 ids.add(Integer.parseInt(token)); 45 81 } 46 82 return true; … … 50 86 } 51 87 } 88 89 @Override 90 public boolean isValid() { 91 return readChangesetIds(); 92 } 52 93 } 53 94 }
Note:
See TracChangeset
for help on using the changeset viewer.