Changeset 17238 in josm


Ignore:
Timestamp:
2020-10-19T00:54:46+02:00 (6 weeks ago)
Author:
Don-vip
Message:

see #17634 - enforce upload policy again (broken after #19381 changes)

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
4 edited

Legend:

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

    r16696 r17238  
    9393        hcbUploadComment.setToolTipText(tr("Enter an upload comment"));
    9494        hcbUploadComment.setMaxTextLength(Changeset.MAX_CHANGESET_TAG_LENGTH);
    95         populateHistoryComboBox(hcbUploadComment, HISTORY_KEY, new LinkedList<String>());
     95        populateHistoryComboBox(hcbUploadComment, HISTORY_KEY, new LinkedList<>());
    9696        CommentModelListener commentModelListener = new CommentModelListener(hcbUploadComment, changesetCommentModel);
    9797        hcbUploadComment.getEditor().addActionListener(commentModelListener);
     
    172172     */
    173173    protected void refreshHistoryComboBoxes() {
    174         populateHistoryComboBox(hcbUploadComment, HISTORY_KEY, new LinkedList<String>());
     174        populateHistoryComboBox(hcbUploadComment, HISTORY_KEY, new LinkedList<>());
    175175        populateHistoryComboBox(hcbUploadSource, SOURCE_HISTORY_KEY, getDefaultSources());
    176176    }
     
    195195    public static List<String> getDefaultSources() {
    196196        return Arrays.asList("knowledge", "survey", "Bing");
     197    }
     198
     199    /**
     200     * Returns the list of {@link UploadTextComponentValidator} defined by this panel.
     201     * @return the list of {@code UploadTextComponentValidator} defined by this panel.
     202     * @since 17238
     203     */
     204    protected List<UploadTextComponentValidator> getUploadTextValidators() {
     205        return Arrays.asList(areaValidator, uploadCommentValidator, uploadSourceValidator);
    197206    }
    198207
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r16673 r17238  
    233233        pnlBasicUploadSettings.setUploadTagDownFocusTraversalHandlers(e -> btnUpload.requestFocusInWindow());
    234234
     235        // Enable/disable the upload button if at least an upload validator rejects upload
     236        pnlBasicUploadSettings.getUploadTextValidators().forEach(v -> v.addChangeListener(e -> btnUpload.setEnabled(
     237                pnlBasicUploadSettings.getUploadTextValidators().stream().noneMatch(UploadTextComponentValidator::isUploadRejected))));
     238
    235239        setMinimumSize(new Dimension(600, 350));
    236240
  • trunk/src/org/openstreetmap/josm/gui/io/UploadTextComponentValidator.java

    r16697 r17238  
    2222abstract class UploadTextComponentValidator extends AbstractTextComponentValidator {
    2323    private final JLabel feedback;
     24    protected boolean uploadRejected;
    2425
    2526    UploadTextComponentValidator(JTextComponent tc, JLabel feedback) {
     
    6061
    6162    /**
     63     * Determines if the input validator considers the violation bad enough to reject upload.
     64     * @return {@code true} if the input validator considers the violation bad enough to reject upload
     65     * @since 17238
     66     */
     67    public final boolean isUploadRejected() {
     68        return uploadRejected;
     69    }
     70
     71    /**
    6272     * Validator for the changeset {@code comment} tag
    6373     */
     
    8595                String rejection = UploadDialog.UploadAction.validateUploadTag(uploadComment, "upload.comment",
    8696                        Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    87                 if (rejection != null) {
     97                uploadRejected = rejection != null;
     98                if (uploadRejected) {
    8899                    feedbackWarning(tr("Your upload comment is <i>rejected</i>.") + "<br />" + rejection);
    89100                } else {
     
    120131                final String rejection = UploadDialog.UploadAction.validateUploadTag(
    121132                        uploadSource, "upload.source", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    122                 if (rejection != null) {
     133                uploadRejected = rejection != null;
     134                if (uploadRejected) {
    123135                    feedbackWarning(tr("Your changeset source is <i>rejected</i>.") + "<br />" + rejection);
    124136                } else {
  • trunk/src/org/openstreetmap/josm/gui/widgets/AbstractTextComponentValidator.java

    r17078 r17238  
    2121
    2222import org.openstreetmap.josm.data.preferences.NamedColorProperty;
     23import org.openstreetmap.josm.gui.util.ChangeNotifier;
    2324import org.openstreetmap.josm.tools.CheckParameterUtil;
    2425
     
    3536 * @since 2688
    3637 */
    37 public abstract class AbstractTextComponentValidator implements ActionListener, FocusListener, DocumentListener, PropertyChangeListener {
     38public abstract class AbstractTextComponentValidator extends ChangeNotifier
     39    implements ActionListener, FocusListener, DocumentListener, PropertyChangeListener {
    3840
    3941    protected static final Color ERROR_COLOR = new NamedColorProperty(marktr("Input validation: error"), Color.RED).get();
     
    6365        if (hasChanged(msg, Status.INVALID)) {
    6466            // only provide feedback if the validity has changed. This avoids unnecessary UI updates.
    65             tc.setBorder(ERROR_BORDER);
    66             tc.setBackground(ERROR_BACKGROUND);
    67             tc.setToolTipText(msg);
    68             this.status = Status.INVALID;
    69             this.msg = msg;
     67            feedback(ERROR_BORDER, ERROR_BACKGROUND, msg, Status.INVALID, msg);
    7068        }
    7169    }
     
    7472        if (hasChanged(msg, Status.WARNING)) {
    7573            // only provide feedback if the validity has changed. This avoids unnecessary UI updates.
    76             tc.setBorder(WARNING_BORDER);
    77             tc.setBackground(WARNING_BACKGROUND);
    78             tc.setToolTipText(msg);
    79             this.status = Status.WARNING;
    80             this.msg = msg;
     74            feedback(WARNING_BORDER, WARNING_BACKGROUND, msg, Status.WARNING, msg);
    8175        }
    8276    }
     
    8983        if (hasChanged(msg, Status.VALID)) {
    9084            // only provide feedback if the validity has changed. This avoids unnecessary UI updates.
    91             tc.setBorder(msg == null ? UIManager.getBorder("TextField.border") : VALID_BORDER);
    92             tc.setBackground(UIManager.getColor("TextField.background"));
    93             tc.setToolTipText(msg == null ? "" : msg);
    94             this.status = Status.VALID;
    95             this.msg = msg;
     85            feedback(msg == null ? UIManager.getBorder("TextField.border") : VALID_BORDER,
     86                UIManager.getColor("TextField.background"),
     87                msg == null ? "" : msg,
     88                Status.VALID,
     89                msg);
    9690        }
    9791    }
     
    9993    private boolean hasChanged(String msg, Status status) {
    10094        return !(Objects.equals(status, this.status) && Objects.equals(msg, this.msg));
     95    }
     96
     97    private void feedback(Border border, Color background, String tooltip, Status status, String msg) {
     98        tc.setBorder(border);
     99        tc.setBackground(background);
     100        tc.setToolTipText(tooltip);
     101        this.status = status;
     102        this.msg = msg;
     103        fireStateChanged();
    101104    }
    102105
     
    171174    /* -------------------------------------------------------------------------------- */
    172175    @Override
    173     public void focusGained(FocusEvent arg0) {}
    174 
    175     @Override
    176     public void focusLost(FocusEvent arg0) {
     176    public void focusGained(FocusEvent e) {}
     177
     178    @Override
     179    public void focusLost(FocusEvent e) {
    177180        validate();
    178181    }
     
    182185    /* -------------------------------------------------------------------------------- */
    183186    @Override
    184     public void actionPerformed(ActionEvent arg0) {
     187    public void actionPerformed(ActionEvent e) {
    185188        validate();
    186189    }
     
    190193    /* -------------------------------------------------------------------------------- */
    191194    @Override
    192     public void changedUpdate(DocumentEvent arg0) {
    193         validate();
    194     }
    195 
    196     @Override
    197     public void insertUpdate(DocumentEvent arg0) {
    198         validate();
    199     }
    200 
    201     @Override
    202     public void removeUpdate(DocumentEvent arg0) {
     195    public void changedUpdate(DocumentEvent e) {
     196        validate();
     197    }
     198
     199    @Override
     200    public void insertUpdate(DocumentEvent e) {
     201        validate();
     202    }
     203
     204    @Override
     205    public void removeUpdate(DocumentEvent e) {
    203206        validate();
    204207    }
Note: See TracChangeset for help on using the changeset viewer.