Changeset 16672 in josm for trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
- Timestamp:
- 2020-06-17T21:47:17+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r16468 r16672 17 17 import java.lang.Character.UnicodeBlock; 18 18 import java.util.ArrayList; 19 import java.util.Arrays;20 19 import java.util.Collection; 21 20 import java.util.Collections; … … 30 29 import javax.swing.AbstractAction; 31 30 import javax.swing.BorderFactory; 32 import javax.swing.Icon;33 31 import javax.swing.JButton; 34 32 import javax.swing.JOptionPane; … … 41 39 import org.openstreetmap.josm.data.osm.DataSet; 42 40 import org.openstreetmap.josm.data.osm.OsmPrimitive; 43 import org.openstreetmap.josm.gui.ExtendedDialog;44 41 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 45 42 import org.openstreetmap.josm.gui.MainApplication; … … 57 54 import org.openstreetmap.josm.spi.preferences.Setting; 58 55 import org.openstreetmap.josm.tools.GBC; 59 import org.openstreetmap.josm.tools.ImageOverlay;60 56 import org.openstreetmap.josm.tools.ImageProvider; 61 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;62 57 import org.openstreetmap.josm.tools.InputMapUtils; 63 58 import org.openstreetmap.josm.tools.Utils; … … 450 445 } 451 446 452 /**453 * Displays a warning message indicating that the upload comment is empty/short.454 * @return true if the user wants to revisit, false if they want to continue455 */456 protected boolean warnUploadComment() {457 return warnUploadTag(458 tr("Please revise upload comment"),459 tr("Your upload comment is <i>empty</i>, or <i>very short</i>.<br /><br />" +460 "This is technically allowed, but please consider that many users who are<br />" +461 "watching changes in their area depend on meaningful changeset comments<br />" +462 "to understand what is going on!<br /><br />" +463 "If you spend a minute now to explain your change, you will make life<br />" +464 "easier for many other mappers."),465 "upload_comment_is_empty_or_very_short"466 );467 }468 469 /**470 * Displays a warning message indicating that no changeset source is given.471 * @return true if the user wants to revisit, false if they want to continue472 */473 protected boolean warnUploadSource() {474 return warnUploadTag(475 tr("Please specify a changeset source"),476 tr("You did not specify a source for your changes.<br />" +477 "It is technically allowed, but this information helps<br />" +478 "other users to understand the origins of the data.<br /><br />" +479 "If you spend a minute now to explain your change, you will make life<br />" +480 "easier for many other mappers."),481 "upload_source_is_empty"482 );483 }484 485 /**486 * Displays a warning message indicating that the upload comment is rejected.487 * @param details details explaining why488 * @return {@code true}489 */490 protected boolean warnRejectedUploadComment(String details) {491 return warnRejectedUploadTag(492 tr("Please revise upload comment"),493 tr("Your upload comment is <i>rejected</i>.") + "<br />" + details494 );495 }496 497 /**498 * Displays a warning message indicating that the changeset source is rejected.499 * @param details details explaining why500 * @return {@code true}501 */502 protected boolean warnRejectedUploadSource(String details) {503 return warnRejectedUploadTag(504 tr("Please revise changeset source"),505 tr("Your changeset source is <i>rejected</i>.") + "<br />" + details506 );507 }508 509 /**510 * Warn about an upload tag with the possibility of resuming the upload.511 * @param title dialog title512 * @param message dialog message513 * @param togglePref preference entry to offer the user a "Do not show again" checkbox for the dialog514 * @return {@code true} if the user wants to revise the upload tag515 */516 protected boolean warnUploadTag(final String title, final String message, final String togglePref) {517 return warnUploadTag(title, message, togglePref, true);518 }519 520 /**521 * Warn about an upload tag without the possibility of resuming the upload.522 * @param title dialog title523 * @param message dialog message524 * @return {@code true}525 */526 protected boolean warnRejectedUploadTag(final String title, final String message) {527 return warnUploadTag(title, message, null, false);528 }529 530 private boolean warnUploadTag(final String title, final String message, final String togglePref, boolean allowContinue) {531 List<String> buttonTexts = new ArrayList<>(Arrays.asList(tr("Revise"), tr("Cancel")));532 List<Icon> buttonIcons = new ArrayList<>(Arrays.asList(533 new ImageProvider("ok").setMaxSize(ImageSizes.LARGEICON).get(),534 new ImageProvider("cancel").setMaxSize(ImageSizes.LARGEICON).get()));535 List<String> tooltips = new ArrayList<>(Arrays.asList(536 tr("Return to the previous dialog to enter a more descriptive comment"),537 tr("Cancel and return to the previous dialog")));538 if (allowContinue) {539 buttonTexts.add(tr("Continue as is"));540 buttonIcons.add(new ImageProvider("upload").setMaxSize(ImageSizes.LARGEICON).addOverlay(541 new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.5, 1.0, 1.0)).get());542 tooltips.add(tr("Ignore this hint and upload anyway"));543 }544 545 ExtendedDialog dlg = new ExtendedDialog((Component) dialog, title, buttonTexts.toArray(new String[] {})) {546 @Override547 public void setupDialog() {548 super.setupDialog();549 InputMapUtils.addCtrlEnterAction(getRootPane(), buttons.get(buttons.size() - 1).getAction());550 }551 };552 dlg.setContent("<html>" + message + "</html>");553 dlg.setButtonIcons(buttonIcons.toArray(new Icon[] {}));554 dlg.setToolTipTexts(tooltips.toArray(new String[] {}));555 dlg.setIcon(JOptionPane.WARNING_MESSAGE);556 if (allowContinue) {557 dlg.toggleEnable(togglePref);558 }559 dlg.setCancelButton(1, 2);560 return dlg.showDialog().getValue() != 3;561 }562 563 447 protected void warnIllegalChunkSize() { 564 448 HelpAwareOptionPane.showOptionDialog( … … 614 498 // force update of model in case dialog is closed before focus lost event, see #17452 615 499 dialog.forceUpdateActiveField(); 616 617 final List<String> def = Collections.emptyList();618 final String uploadComment = dialog.getUploadComment();619 final String uploadCommentRejection = validateUploadTag(620 uploadComment, "upload.comment", def, def, def);621 if ((isUploadCommentTooShort(uploadComment) && warnUploadComment()) ||622 (uploadCommentRejection != null && warnRejectedUploadComment(uploadCommentRejection))) {623 // abort for missing or rejected comment624 dialog.handleMissingComment();625 return;626 }627 final String uploadSource = dialog.getUploadSource();628 final String uploadSourceRejection = validateUploadTag(629 uploadSource, "upload.source", def, def, def);630 if ((Utils.isStripEmpty(uploadSource) && warnUploadSource()) ||631 (uploadSourceRejection != null && warnRejectedUploadSource(uploadSourceRejection))) {632 // abort for missing or rejected changeset source633 dialog.handleMissingSource();634 return;635 }636 500 637 501 /* test for empty tags in the changeset metadata and proceed only after user's confirmation.
Note:
See TracChangeset
for help on using the changeset viewer.