Changeset 6401 in josm


Ignore:
Timestamp:
2013-11-22T22:19:33+01:00 (10 years ago)
Author:
simon04
Message:

see #6381 - Ask for source tag in changeset/upload

Location:
trunk/src/org/openstreetmap/josm/gui/io
Files:
3 edited

Legend:

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

    r6084 r6401  
    3737    public static final String HISTORY_KEY = "upload.comment.history";
    3838    public static final String HISTORY_LAST_USED_KEY = "upload.comment.last-used";
     39    public static final String SOURCE_HISTORY_KEY = "upload.comment.source";
    3940
    4041    /** the history combo box for the upload comment */
    41     private HistoryComboBox hcbUploadComment;
     42    private final HistoryComboBox hcbUploadComment = new HistoryComboBox();
     43    private final HistoryComboBox hcbUploadSource = new HistoryComboBox();
    4244    /** the panel with a summary of the upload parameters */
    43     private UploadParameterSummaryPanel pnlUploadParameterSummary;
    44     /** the changset comment model */
    45     private ChangesetCommentModel changesetCommentModel;
     45    private final UploadParameterSummaryPanel pnlUploadParameterSummary = new UploadParameterSummaryPanel();
     46    /** the changeset comment model */
     47    private final ChangesetCommentModel changesetCommentModel;
     48    private final ChangesetCommentModel changesetSourceModel;
    4649
    4750    protected JPanel buildUploadCommentPanel() {
    4851        JPanel pnl = new JPanel();
    4952        pnl.setLayout(new GridBagLayout());
     53
    5054        pnl.add(new JLabel(tr("Provide a brief comment for the changes you are uploading:")), GBC.eol().insets(0, 5, 10, 3));
    51         hcbUploadComment = new HistoryComboBox();
    5255        hcbUploadComment.setToolTipText(tr("Enter an upload comment"));
    5356        hcbUploadComment.setMaxTextLength(Changeset.MAX_COMMENT_LENGTH);
    5457        List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(HISTORY_KEY, new LinkedList<String>()));
    55         // we have to reverse the history, because ComboBoxHistory will reverse it again
    56         // in addElement()
    57         //
    58         Collections.reverse(cmtHistory);
     58        Collections.reverse(cmtHistory); // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement()
    5959        hcbUploadComment.setPossibleItems(cmtHistory);
    60         hcbUploadComment.getEditor().addActionListener(
    61                 new ActionListener() {
    62                     @Override
    63                     public void actionPerformed(ActionEvent e) {
    64                         changesetCommentModel.setComment(hcbUploadComment.getText());
    65                     }
    66                 }
    67         );
    68         hcbUploadComment.getEditor().getEditorComponent().addFocusListener(
    69                 new FocusAdapter() {
    70                     @Override
    71                     public void focusLost(FocusEvent e) {
    72                         changesetCommentModel.setComment(hcbUploadComment.getText());
    73                     }
    74                 }
    75         );
     60        final CommentModelListener commentModelListener = new CommentModelListener(hcbUploadComment, changesetCommentModel);
     61        hcbUploadComment.getEditor().addActionListener(commentModelListener);
     62        hcbUploadComment.getEditor().getEditorComponent().addFocusListener(commentModelListener);
    7663        pnl.add(hcbUploadComment, GBC.eol().fill(GBC.HORIZONTAL));
     64
     65        pnl.add(new JLabel(tr("Specify the data source for the changes:")), GBC.eol().insets(0, 8, 10, 3));
     66        hcbUploadSource.setToolTipText(tr("Enter a source"));
     67        List<String> sourceHistory = new LinkedList<String>(Main.pref.getCollection(SOURCE_HISTORY_KEY, new LinkedList<String>()));
     68        Collections.reverse(sourceHistory); // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement()
     69        hcbUploadComment.setPossibleItems(sourceHistory);
     70        final CommentModelListener sourceModelListener = new CommentModelListener(hcbUploadSource, changesetSourceModel);
     71        hcbUploadSource.getEditor().addActionListener(sourceModelListener);
     72        hcbUploadSource.getEditor().getEditorComponent().addFocusListener(sourceModelListener);
     73        pnl.add(hcbUploadSource, GBC.eol().fill(GBC.HORIZONTAL));
    7774        return pnl;
    7875    }
     
    8279        setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
    8380        add(buildUploadCommentPanel(), BorderLayout.NORTH);
    84         add(pnlUploadParameterSummary = new UploadParameterSummaryPanel(), BorderLayout.CENTER);
     81        add(pnlUploadParameterSummary, BorderLayout.CENTER);
    8582    }
    8683
     
    8986     *
    9087     * @param changesetCommentModel the model for the changeset comment. Must not be null
     88     * @param changesetSourceModel the model for the changeset source. Must not be null.
    9189     * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null
    9290     */
    93     public BasicUploadSettingsPanel(ChangesetCommentModel changesetCommentModel) {
     91    public BasicUploadSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel) {
    9492        CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel");
     93        CheckParameterUtil.ensureParameterNotNull(changesetSourceModel, "changesetSourceModel");
    9594        this.changesetCommentModel = changesetCommentModel;
    96         changesetCommentModel.addObserver(new ChangesetCommentObserver());
     95        this.changesetSourceModel = changesetSourceModel;
     96        changesetCommentModel.addObserver(new ChangesetCommentObserver(hcbUploadComment));
     97        changesetSourceModel.addObserver(new ChangesetCommentObserver(hcbUploadSource));
    9798        build();
    9899    }
     
    125126        Main.pref.putCollection(HISTORY_KEY, hcbUploadComment.getHistory());
    126127        Main.pref.putInteger(HISTORY_LAST_USED_KEY, (int) (System.currentTimeMillis() / 1000));
     128        // store the history of sources
     129        hcbUploadSource.addCurrentItemToHistory();
     130        Main.pref.putCollection(SOURCE_HISTORY_KEY, hcbUploadSource.getHistory());
    127131    }
    128132
     
    151155
    152156    /**
     157     * Updates the changeset comment model upon changes in the input field.
     158     */
     159    class CommentModelListener extends FocusAdapter implements ActionListener {
     160
     161        final HistoryComboBox source;
     162        final ChangesetCommentModel destination;
     163
     164        CommentModelListener(HistoryComboBox source, ChangesetCommentModel destination) {
     165            this.source = source;
     166            this.destination = destination;
     167        }
     168
     169        @Override
     170        public void actionPerformed(ActionEvent e) {
     171            destination.setComment(source.getText());
     172        }
     173        @Override
     174        public void focusLost(FocusEvent e) {
     175            destination.setComment(source.getText());
     176        }
     177    }
     178
     179    /**
    153180     * Observes the changeset comment model and keeps the comment input field
    154181     * in sync with the current changeset comment
    155182     */
    156183    class ChangesetCommentObserver implements Observer {
     184
     185        private final HistoryComboBox destination;
     186
     187        ChangesetCommentObserver(HistoryComboBox destination) {
     188            this.destination = destination;
     189        }
     190
    157191        @Override
    158192        public void update(Observable o, Object arg) {
    159193            if (!(o instanceof ChangesetCommentModel)) return;
    160194            String newComment = (String)arg;
    161             if (!hcbUploadComment.getText().equals(newComment)) {
    162                 hcbUploadComment.setText(newComment);
     195            if (!destination.getText().equals(newComment)) {
     196                destination.setText(newComment);
    163197            }
    164198        }
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r6309 r6401  
    2222
    2323    /** checkbox for selecting whether an atomic upload is to be used  */
    24     private TagEditorPanel pnlTagEditor;
     24    private final TagEditorPanel pnlTagEditor = new TagEditorPanel(null);
    2525    /** the model for the changeset comment */
    26     private ChangesetCommentModel changesetCommentModel;
     26    private final ChangesetCommentModel changesetCommentModel;
     27    private final ChangesetCommentModel changesetSourceModel;
    2728    /** tags that applied to uploaded changesets by default*/
    28     private Map<String, String> defaultTags = new HashMap<String, String>();
     29    private final Map<String, String> defaultTags = new HashMap<String, String>();
    2930
    3031    protected void build() {
    3132        setLayout(new BorderLayout());
    32         add(pnlTagEditor = new TagEditorPanel(null), BorderLayout.CENTER);
     33        add(pnlTagEditor, BorderLayout.CENTER);
    3334    }
    3435
     
    3738     *
    3839     * @param changesetCommentModel the changeset comment model. Must not be null.
     40     * @param changesetSourceModel the changeset source model. Must not be null.
    3941     * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null
    4042     */
    41     public TagSettingsPanel(ChangesetCommentModel changesetCommentModel) throws IllegalArgumentException{
     43    public TagSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel) throws IllegalArgumentException{
    4244        CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel");
     45        CheckParameterUtil.ensureParameterNotNull(changesetSourceModel, "changesetSourceModel");
    4346        this.changesetCommentModel = changesetCommentModel;
    44         this.changesetCommentModel.addObserver(new ChangesetCommentObserver());
     47        this.changesetSourceModel = changesetSourceModel;
     48        this.changesetCommentModel.addObserver(new ChangesetCommentObserver("comment"));
     49        this.changesetSourceModel.addObserver(new ChangesetCommentObserver("source"));
    4550        build();
    4651        pnlTagEditor.getModel().addTableModelListener(this);
    4752    }
    4853
    49     protected void setUploadComment(String comment) {
    50         if (comment == null) {
    51             comment = "";
     54    protected void setProperty(String key, String value) {
     55        if (value == null) {
     56            value = "";
    5257        }
    53         comment  = comment.trim();
    54         String commentInTag = getUploadComment();
    55         if (comment.equals(commentInTag))
     58        value = value.trim();
     59        String commentInTag = getTagEditorValue(key);
     60        if (value.equals(commentInTag))
    5661            return;
    5762
    58         if (comment.isEmpty()) {
    59             pnlTagEditor.getModel().delete("comment");
     63        if (value.isEmpty()) {
     64            pnlTagEditor.getModel().delete(key);
    6065            return;
    6166        }
    62         TagModel tag = pnlTagEditor.getModel().get("comment");
     67        TagModel tag = pnlTagEditor.getModel().get(key);
    6368        if (tag == null) {
    64             tag = new TagModel("comment", comment);
     69            tag = new TagModel(key, value);
    6570            pnlTagEditor.getModel().add(tag);
    6671        } else {
    67             pnlTagEditor.getModel().updateTagValue(tag, comment);
     72            pnlTagEditor.getModel().updateTagValue(tag, value);
    6873        }
    6974    }
    7075
    71     protected String getUploadComment() {
    72         TagModel tag = pnlTagEditor.getModel().get("comment");
     76    protected String getTagEditorValue(String key) {
     77        TagModel tag = pnlTagEditor.getModel().get(key);
    7378        if (tag == null) return null;
    7479        return tag.getValue();
     
    7681
    7782    public void initFromChangeset(Changeset cs) {
    78         String currentComment = getUploadComment();
     83        String currentComment = getTagEditorValue("comment");
    7984        Map<String,String> tags = getDefaultTags();
    8085        if (cs != null) {
     
    8388        if (tags.get("comment") == null) {
    8489            tags.put("comment", currentComment);
     90        }
     91        if (tags.get("source") == null) {
     92            tags.put("source", "");
    8593        }
    8694        String agent = Version.getInstance().getAgentString(false);
     
    123131    @Override
    124132    public void tableChanged(TableModelEvent e) {
    125         String uploadComment = getUploadComment();
    126         changesetCommentModel.setComment(uploadComment);
     133        changesetCommentModel.setComment(getTagEditorValue("comment"));
     134        changesetSourceModel.setComment(getTagEditorValue("source"));
    127135    }
    128136
     
    133141     */
    134142    class ChangesetCommentObserver implements Observer {
     143
     144        private final String key;
     145
     146        ChangesetCommentObserver(String key) {
     147            this.key = key;
     148        }
     149
    135150        @Override
    136151        public void update(Observable o, Object arg) {
    137152            if (!(o instanceof ChangesetCommentModel)) return;
    138153            String newValue = (String)arg;
    139             String oldValue = getUploadComment();
     154            String oldValue = getTagEditorValue(key);
    140155            if (oldValue == null) {
    141156                oldValue = "";
    142157            }
    143158            if (!oldValue.equals(newValue)) {
    144                 setUploadComment((String)arg);
     159                setProperty(key, (String) arg);
    145160            }
    146161        }
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r6315 r6401  
    100100
    101101    /** the changeset comment model keeping the state of the changeset comment */
    102     private ChangesetCommentModel changesetCommentModel;
     102    private final ChangesetCommentModel changesetCommentModel = new ChangesetCommentModel();
     103    private final ChangesetCommentModel changesetSourceModel = new ChangesetCommentModel();
    103104
    104105    /**
     
    131132        };
    132133
    133         changesetCommentModel = new ChangesetCommentModel();
    134 
    135         tpConfigPanels.add(pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel));
     134        tpConfigPanels.add(pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel, changesetSourceModel));
    136135        tpConfigPanels.setTitleAt(0, tr("Settings"));
    137136        tpConfigPanels.setToolTipTextAt(0, tr("Decide how to upload the data and which changeset to use"));
    138137
    139         tpConfigPanels.add(pnlTagSettings = new TagSettingsPanel(changesetCommentModel));
     138        tpConfigPanels.add(pnlTagSettings = new TagSettingsPanel(changesetCommentModel, changesetSourceModel));
    140139        tpConfigPanels.setTitleAt(1, tr("Tags of new changeset"));
    141140        tpConfigPanels.setToolTipTextAt(1, tr("Apply tags to the changeset data is uploaded to"));
Note: See TracChangeset for help on using the changeset viewer.