Ignore:
Timestamp:
2020-06-17T21:47:17+02:00 (4 years ago)
Author:
simon04
Message:

see #19381 - Upload dialog: make warnings less intrusive

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r16468 r16672  
    1717import java.lang.Character.UnicodeBlock;
    1818import java.util.ArrayList;
    19 import java.util.Arrays;
    2019import java.util.Collection;
    2120import java.util.Collections;
     
    3029import javax.swing.AbstractAction;
    3130import javax.swing.BorderFactory;
    32 import javax.swing.Icon;
    3331import javax.swing.JButton;
    3432import javax.swing.JOptionPane;
     
    4139import org.openstreetmap.josm.data.osm.DataSet;
    4240import org.openstreetmap.josm.data.osm.OsmPrimitive;
    43 import org.openstreetmap.josm.gui.ExtendedDialog;
    4441import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    4542import org.openstreetmap.josm.gui.MainApplication;
     
    5754import org.openstreetmap.josm.spi.preferences.Setting;
    5855import org.openstreetmap.josm.tools.GBC;
    59 import org.openstreetmap.josm.tools.ImageOverlay;
    6056import org.openstreetmap.josm.tools.ImageProvider;
    61 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
    6257import org.openstreetmap.josm.tools.InputMapUtils;
    6358import org.openstreetmap.josm.tools.Utils;
     
    450445        }
    451446
    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 continue
    455          */
    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 continue
    472          */
    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 why
    488          * @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 />" + details
    494             );
    495         }
    496 
    497         /**
    498          * Displays a warning message indicating that the changeset source is rejected.
    499          * @param details details explaining why
    500          * @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 />" + details
    506             );
    507         }
    508 
    509         /**
    510          * Warn about an upload tag with the possibility of resuming the upload.
    511          * @param title dialog title
    512          * @param message dialog message
    513          * @param togglePref preference entry to offer the user a "Do not show again" checkbox for the dialog
    514          * @return {@code true} if the user wants to revise the upload tag
    515          */
    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 title
    523          * @param message dialog message
    524          * @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                 @Override
    547                 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 
    563447        protected void warnIllegalChunkSize() {
    564448            HelpAwareOptionPane.showOptionDialog(
     
    614498            // force update of model in case dialog is closed before focus lost event, see #17452
    615499            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 comment
    624                 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 source
    633                 dialog.handleMissingSource();
    634                 return;
    635             }
    636500
    637501            /* 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.