Changeset 3746 in josm for trunk/src


Ignore:
Timestamp:
2010-12-27T17:45:32+01:00 (14 years ago)
Author:
Upliner
Message:

make possible for plugins to set changeset tags, addresses #5779

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

Legend:

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

    r3518 r3746  
    33
    44import java.awt.BorderLayout;
     5import java.util.HashMap;
    56import java.util.Map;
    67import java.util.Observable;
     
    2324    /** the model for the changeset comment */
    2425    private ChangesetCommentModel changesetCommentModel;
    25 
     26    /** tags that applied to uploaded changesets by default*/
     27    private Map<String, String> defaultTags = new HashMap<String, String>();
    2628
    2729    protected void build() {
     
    4951     * @return the default value for "created_by"
    5052     */
    51     protected String getDefaultCreatedBy() {
     53    public static String getDefaultCreatedBy() {
    5254        Object ua = System.getProperties().get("http.agent");
    5355        return(ua == null) ? "JOSM" : ua.toString();
     
    8284    }
    8385
    84     protected void initNewChangeset() {
     86    public void initFromChangeset(Changeset cs) {
    8587        String currentComment = getUploadComment();
    86         pnlTagEditor.getModel().clear();
    87         if (currentComment != null) {
    88             pnlTagEditor.getModel().add("comment", currentComment);
     88        Map<String,String> tags = getDefaultTags();
     89        if (cs != null) {
     90            tags.putAll(cs.getKeys());
    8991        }
    90         pnlTagEditor.getModel().add("created_by", getDefaultCreatedBy());
    91     }
    92 
    93     protected void initFromExistingChangeset(Changeset cs) {
    94         String currentComment = getUploadComment();
    95         Map<String,String> tags = cs.getKeys();
    9692        if (tags.get("comment") == null) {
    9793            tags.put("comment", currentComment);
    9894        }
    99         tags.put("created_by", getDefaultCreatedBy());
     95        String created_by = tags.get("created_by");
     96        if (created_by == null || "".equals(created_by)) {
     97            tags.put("created_by", getDefaultCreatedBy());
     98        } else if (!created_by.contains(getDefaultCreatedBy())) {
     99            tags.put("created_by", created_by + ";" + getDefaultCreatedBy());
     100        }
    100101        pnlTagEditor.getModel().initFromTags(tags);
    101     }
    102 
    103     public void initFromChangeset(Changeset cs) {
    104         if (cs == null) {
    105             initNewChangeset();
    106         } else {
    107             initFromExistingChangeset(cs);
    108         }
    109102    }
    110103
     
    116109    public Map<String,String> getTags() {
    117110        return pnlTagEditor.getModel().getTags();
     111    }
     112
     113    public Map<String,String> getDefaultTags() {
     114        Map<String,String> tags = new HashMap<String, String>();
     115        tags.putAll(defaultTags);
     116        return tags;
     117    }
     118
     119    public void setDefaultTags(Map<String, String> tags) {
     120        defaultTags.clear();
     121        defaultTags.putAll(tags);
    118122    }
    119123
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r3719 r3746  
    1717import java.util.Collections;
    1818import java.util.List;
     19import java.util.Map;
    1920import java.util.logging.Logger;
    2021
     
    297298    }
    298299
     300    public Map<String, String> getDefaultChangesetTags() {
     301        return pnlTagSettings.getDefaultTags();
     302    }
     303
     304    public void setDefaultChangesetTags(Map<String, String> tags) {
     305        pnlTagSettings.setDefaultTags(tags);
     306    }
     307
    299308    /**
    300309     * Replies the {@see UploadStrategySpecification} the user entered in the dialog.
     
    369378        protected boolean warnUploadComment() {
    370379            ExtendedDialog dlg = new ExtendedDialog(UploadDialog.this,
    371                 tr("Please revise upload comment"),
    372                 new String[] {tr("Revise"), tr("Cancel"), tr("Continue as is")});
     380                    tr("Please revise upload comment"),
     381                    new String[] {tr("Revise"), tr("Cancel"), tr("Continue as is")});
    373382            dlg.setContent("<html>" +
    374383                    tr("Your upload comment is <i>empty</i>, or <i>very short</i>.<br /><br />" +
    375                        "This is technically allowed, but please consider that many users who are<br />" +
    376                        "watching changes in their area depend on meaningful changeset comments<br />" +
    377                        "to understand what is going on!<br /><br />" +
    378                        "If you spend a minute now to explain your change, you will make life<br />" +
    379                        "easier for many other mappers.") +
    380                     "</html>");
     384                            "This is technically allowed, but please consider that many users who are<br />" +
     385                            "watching changes in their area depend on meaningful changeset comments<br />" +
     386                            "to understand what is going on!<br /><br />" +
     387                            "If you spend a minute now to explain your change, you will make life<br />" +
     388                    "easier for many other mappers.") +
     389            "</html>");
    381390            dlg.setButtonIcons(new Icon[] {
    382                 ImageProvider.get("ok"),
    383                 ImageProvider.get("cancel"),
    384                 ImageProvider.overlay(
    385                     ImageProvider.get("upload"),
    386                     new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(10 , 10, Image.SCALE_SMOOTH)),
    387                     ImageProvider.OverlayPosition.SOUTHEAST)});
     391                    ImageProvider.get("ok"),
     392                    ImageProvider.get("cancel"),
     393                    ImageProvider.overlay(
     394                            ImageProvider.get("upload"),
     395                            new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(10 , 10, Image.SCALE_SMOOTH)),
     396                            ImageProvider.OverlayPosition.SOUTHEAST)});
    388397            dlg.setToolTipTexts(new String[] {
    389                 tr("Return to the previous dialog to enter a more descriptive comment"),
    390                 tr("Cancel and return to the previous dialog"),
    391                 tr("Ignore this hint and upload anyway")});
     398                    tr("Return to the previous dialog to enter a more descriptive comment"),
     399                    tr("Cancel and return to the previous dialog"),
     400                    tr("Ignore this hint and upload anyway")});
    392401            dlg.setIcon(JOptionPane.WARNING_MESSAGE);
    393402            dlg.toggleEnable("upload_comment_is_empty_or_very_short");
Note: See TracChangeset for help on using the changeset viewer.