Ticket #18429: 18429.patch

File 18429.patch, 4.0 KB (added by taylor.smock, 4 years ago)

Add checkbox to automatically get source on every upload

  • src/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanel.java

     
    2121import javax.swing.BorderFactory;
    2222import javax.swing.JCheckBox;
    2323import javax.swing.JEditorPane;
     24import javax.swing.JLabel;
    2425import javax.swing.JPanel;
    2526import javax.swing.event.ChangeEvent;
    2627import javax.swing.event.ChangeListener;
     
    8182        hcbUploadComment.getEditorComponent().addFocusListener(commentModelListener);
    8283        pnl.add(hcbUploadComment, GBC.eol().fill(GBC.HORIZONTAL));
    8384
    84         JEditorPane sourceLabel = new JMultilineLabel("<html><b>" + tr("Specify the data source for the changes")
    85                 + "</b> (<a href=\"urn:changeset-source\">" + tr("obtain from current layers") + "</a>)<b>:</b>");
    86         sourceLabel.addHyperlinkListener(e -> {
     85        JEditorPane sourceLabel = new JMultilineLabel("<html><b>" + tr("Specify the data source for the changes") + ":</b>");
     86        pnl.add(sourceLabel, GBC.eol().insets(0, 8, 10, 0).fill(GBC.HORIZONTAL));
     87        JEditorPane obtainSourceOnce = new JMultilineLabel(
     88                "<html><a href=\"urn:changeset-source\">" + tr("just once") + "</a></html>");
     89        obtainSourceOnce.addHyperlinkListener(e -> {
    8790            if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
    88                 final String source = MainApplication.getMap().mapView.getLayerInformationForSourceTag();
    89                 hcbUploadSource.setText(Utils.shortenString(source, Changeset.MAX_CHANGESET_TAG_LENGTH));
    90                 changesetSourceModel.setComment(hcbUploadSource.getText()); // Fix #9965
     91                automaticallyAddSource();
    9192            }
    9293        });
    93         pnl.add(sourceLabel, GBC.eol().insets(0, 8, 10, 3).fill(GBC.HORIZONTAL));
     94        JCheckBox obtainSourceAutomatically = new JCheckBox(tr("Automatically obtain source from current layers"));
     95        obtainSourceAutomatically.setSelected(Config.getPref().getBoolean("upload.source.obtainautomatically", false));
     96        obtainSourceAutomatically.addActionListener(e -> {
     97            if (obtainSourceAutomatically.isSelected())
     98                automaticallyAddSource();
    9499
     100            obtainSourceOnce.setVisible(!obtainSourceAutomatically.isSelected());
     101        });
     102        JPanel obtainSource = new JPanel(new GridBagLayout());
     103        obtainSource.add(obtainSourceAutomatically, GBC.std().anchor(GBC.WEST));
     104        obtainSource.add(obtainSourceOnce, GBC.std().anchor(GBC.WEST));
     105        obtainSource.add(new JLabel(), GBC.eol().fill(GBC.HORIZONTAL));
     106        pnl.add(obtainSource, GBC.eol().insets(0, 0, 10, 3).fill(GBC.HORIZONTAL));
     107
    95108        hcbUploadSource.setToolTipText(tr("Enter a source"));
    96109        hcbUploadSource.setMaxTextLength(Changeset.MAX_CHANGESET_TAG_LENGTH);
    97110        populateHistoryComboBox(hcbUploadSource, SOURCE_HISTORY_KEY, getDefaultSources());
     
    99112        hcbUploadSource.getEditor().addActionListener(sourceModelListener);
    100113        hcbUploadSource.getEditorComponent().addFocusListener(sourceModelListener);
    101114        pnl.add(hcbUploadSource, GBC.eol().fill(GBC.HORIZONTAL));
     115        if (obtainSourceAutomatically.isSelected()) {
     116            automaticallyAddSource();
     117        }
    102118        return pnl;
    103119    }
    104120
    105121    /**
     122     * Add the source tags
     123     *
     124     * @param resetIfSame If {@code true} reset if the last source and this source
     125     *                    are the same
     126     */
     127    protected void automaticallyAddSource() {
     128        final String source = MainApplication.getMap().mapView.getLayerInformationForSourceTag();
     129        hcbUploadSource.setText(Utils.shortenString(source, Changeset.MAX_CHANGESET_TAG_LENGTH));
     130        changesetSourceModel.setComment(hcbUploadSource.getText()); // Fix #9965
     131    }
     132
     133    /**
    106134     * Refreshes contents of upload history combo boxes from preferences.
    107135     */
    108136    protected void refreshHistoryComboBoxes() {