Changeset 3133 in josm for trunk/src


Ignore:
Timestamp:
2010-03-14T12:38:09+01:00 (10 years ago)
Author:
Gubaer
Message:

fixed #4371: Changeset comment reverts to previous when switching options

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

Legend:

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

    r3083 r3133  
    1212import java.awt.event.KeyEvent;
    1313import java.awt.event.KeyListener;
    14 import java.beans.PropertyChangeEvent;
    15 import java.beans.PropertyChangeListener;
    1614import java.util.Collections;
    1715import java.util.LinkedList;
    1816import java.util.List;
     17import java.util.Observable;
     18import java.util.Observer;
    1919
    2020import javax.swing.Action;
     
    2525import org.openstreetmap.josm.Main;
    2626import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
     27import org.openstreetmap.josm.tools.CheckParameterUtil;
    2728import org.openstreetmap.josm.tools.GBC;
    2829
     
    3233 *
    3334 */
    34 public class BasicUploadSettingsPanel extends JPanel implements PropertyChangeListener{
    35     static public final String UPLOAD_COMMENT_PROP = BasicUploadSettingsPanel.class.getName() + ".uploadComment";
     35public class BasicUploadSettingsPanel extends JPanel {
    3636    public static final String HISTORY_KEY = "upload.comment.history";
    3737
     
    4040    /** the panel with a summary of the upload parameters */
    4141    private UploadParameterSummaryPanel pnlUploadParameterSummary;
     42    /** the changset comment model */
     43    private ChangesetCommentModel changesetCommentModel;
    4244
    4345    protected JPanel buildUploadCommentPanel() {
     
    5658                new ActionListener() {
    5759                    public void actionPerformed(ActionEvent e) {
    58                         firePropertyChange(UPLOAD_COMMENT_PROP, null, hcbUploadComment.getText());
     60                        changesetCommentModel.setComment(hcbUploadComment.getText());
    5961                    }
    6062                }
     
    6466                    @Override
    6567                    public void focusLost(FocusEvent e) {
    66                         firePropertyChange(UPLOAD_COMMENT_PROP, null, hcbUploadComment.getText());
     68                        changesetCommentModel.setComment(hcbUploadComment.getText());
    6769                    }
    6870                }
     
    7981    }
    8082
    81     public BasicUploadSettingsPanel() {
     83    /**
     84     * Creates the panel
     85     *
     86     * @param changesetCommentModel the model for the changeset comment. Must not be null
     87     * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null
     88     */
     89    public BasicUploadSettingsPanel(ChangesetCommentModel changesetCommentModel) {
     90        CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel");
     91        this.changesetCommentModel = changesetCommentModel;
     92        changesetCommentModel.addObserver(new ChangesetCommentObserver());
    8293        build();
    8394    }
     
    120131    }
    121132
    122     /**
    123      * Replies the current upload comment
    124      *
    125      * @return
    126      */
    127     public String getUploadComment() {
    128         return hcbUploadComment.getText();
    129     }
    130 
    131     /**
    132      * Sets the current upload comment
    133      *
    134      * @return
    135      */
    136     public void setUploadComment(String uploadComment) {
    137         if (uploadComment == null) {
    138             uploadComment = "";
    139         }
    140         if (!uploadComment.equals(hcbUploadComment.getText())) {
    141             hcbUploadComment.setText(uploadComment);
    142         }
    143     }
    144 
    145     public void initEditingOfUploadComment(String comment) {
    146         setUploadComment(comment);
     133    public void initEditingOfUploadComment() {
    147134        hcbUploadComment.getEditor().selectAll();
    148135        hcbUploadComment.requestFocusInWindow();
     
    153140    }
    154141
    155     /* -------------------------------------------------------------------------- */
    156     /* Interface PropertyChangeListener                                           */
    157     /* -------------------------------------------------------------------------- */
    158     public void propertyChange(PropertyChangeEvent evt) {
    159         if (evt.getPropertyName().equals(TagSettingsPanel.UPLOAD_COMMENT_PROP)) {
    160             String comment = (String)evt.getNewValue();
    161             if (comment == null) {
    162                 comment = "";
     142    /**
     143     * Observes the changeset comment model and keeps the comment input field
     144     * in sync with the current changeset comment
     145     */
     146    class ChangesetCommentObserver implements Observer {
     147        public void update(Observable o, Object arg) {
     148            if (!(o instanceof ChangesetCommentModel)) return;
     149            String newComment = (String)arg;
     150            if (!hcbUploadComment.getText().equals(newComment)) {
     151                hcbUploadComment.setText(newComment);
    163152            }
    164             if (comment.equals(hcbUploadComment.getText()))
    165                 // nothing to change - return
    166                 return;
    167             hcbUploadComment.setText(comment);
    168153        }
    169154    }
  • trunk/src/org/openstreetmap/josm/gui/io/ChangesetManagementPanel.java

    r3110 r3133  
    2828import org.openstreetmap.josm.data.osm.ChangesetCache;
    2929import org.openstreetmap.josm.gui.JMultilineLabel;
     30import org.openstreetmap.josm.tools.CheckParameterUtil;
    3031import org.openstreetmap.josm.tools.ImageProvider;
    3132
     
    4647 * </ul>
    4748 */
    48 public class ChangesetManagementPanel extends JPanel implements ListDataListener {
     49public class ChangesetManagementPanel extends JPanel implements ListDataListener{
    4950    public final static String SELECTED_CHANGESET_PROP = ChangesetManagementPanel.class.getName() + ".selectedChangeset";
    5051    public final static String CLOSE_CHANGESET_AFTER_UPLOAD = ChangesetManagementPanel.class.getName() + ".closeChangesetAfterUpload";
     
    5859    private JCheckBox cbCloseAfterUpload;
    5960    private OpenChangesetComboBoxModel model;
     61    private ChangesetCommentModel changesetCommentModel;
    6062
    6163    /**
     
    159161    }
    160162
    161     public ChangesetManagementPanel() {
     163    /**
     164     * Creates a new panel
     165     *
     166     * @param changesetCommentModel the changeset comment model. Must not be null.
     167     * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null
     168     */
     169    public ChangesetManagementPanel(ChangesetCommentModel changesetCommentModel) {
     170        CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel");
     171        this.changesetCommentModel = changesetCommentModel;
    162172        build();
    163173        refreshGUI();
     
    174184    }
    175185
     186    /**
     187     * Sets the changeset to be used in the next upload
     188     *
     189     * @param cs the changeset
     190     */
    176191    public void setSelectedChangesetForNextUpload(Changeset cs) {
    177192        int idx  = model.getIndexOf(cs);
     
    204219    }
    205220
    206     /**
    207      * Replies the default value for "created_by"
    208      *
    209      * @return the default value for "created_by"
    210      */
    211     protected String getDefaultCreatedBy() {
    212         Object ua = System.getProperties().get("http.agent");
    213         return(ua == null) ? "JOSM" : ua.toString();
    214     }
    215 
    216221    /* ---------------------------------------------------------------------------- */
    217222    /* Interface ListDataListener                                                   */
     
    230235
    231236    /**
    232      * Listens to changes in the selected changeset and accordingly fires property
     237     * Listens to changes in the selected changeset and fires property
    233238     * change events.
    234239     *
     
    237242        public void itemStateChanged(ItemEvent e) {
    238243            Changeset cs = (Changeset)cbOpenChangesets.getSelectedItem();
     244            if (cs == null) return;
    239245            if (rbExisting.isSelected()) {
     246                // create a clone of the selected changeset and make sure
     247                // we keep the current changeset comment (see #4371)
     248                cs = new Changeset(cs);
     249                cs.put("comment", changesetCommentModel.getComment());
    240250                firePropertyChange(SELECTED_CHANGESET_PROP, null, cs);
    241                 if (cs == null) {
    242                     rbUseNew.setSelected(true);
    243                 }
    244251            }
    245252        }
     
    283290                }
    284291                Changeset cs = (Changeset)cbOpenChangesets.getSelectedItem();
     292                if (cs == null) return;
     293                // create a clone of the selected changeset and make sure
     294                // we keep the current changeset comment (see #4371)
     295                cs = new Changeset(cs);
     296                cs.put("comment", changesetCommentModel.getComment());
    285297                firePropertyChange(SELECTED_CHANGESET_PROP, null, cs);
    286298            }
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r3083 r3133  
    33
    44import java.awt.BorderLayout;
    5 import java.beans.PropertyChangeEvent;
    6 import java.beans.PropertyChangeListener;
    75import java.util.Map;
     6import java.util.Observable;
     7import java.util.Observer;
    88
    99import javax.swing.JPanel;
     
    1515import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
    1616import org.openstreetmap.josm.gui.tagging.TagModel;
     17import org.openstreetmap.josm.tools.CheckParameterUtil;
    1718
    18 public class TagSettingsPanel extends JPanel implements PropertyChangeListener, TableModelListener {
    19     static public final String UPLOAD_COMMENT_PROP = TagSettingsPanel.class.getName() + ".uploadComment";
     19public class TagSettingsPanel extends JPanel implements TableModelListener {
    2020
    2121    /** checkbox for selecting whether an atomic upload is to be used  */
    2222    private TagEditorPanel pnlTagEditor;
     23    /** the model for the changeset comment */
     24    private ChangesetCommentModel changesetCommentModel;
     25
    2326
    2427    protected void build() {
     
    2730    }
    2831
    29     public TagSettingsPanel() {
     32    /**
     33     * Creates a new panel
     34     *
     35     * @param changesetCommentModel the changeset comment model. Must not be null.
     36     * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null
     37     */
     38    public TagSettingsPanel(ChangesetCommentModel changesetCommentModel) throws IllegalArgumentException{
     39        CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel");
     40        this.changesetCommentModel = changesetCommentModel;
     41        this.changesetCommentModel.addObserver(new ChangesetCommentObserver());
    3042        build();
    3143        pnlTagEditor.getModel().addTableModelListener(this);
     
    4254    }
    4355
    44     public void setUploadComment(String comment) {
     56    protected void setUploadComment(String comment) {
    4557        if (comment == null) {
    4658            comment = "";
     
    111123
    112124    /* -------------------------------------------------------------------------- */
    113     /* Interface PropertyChangeListener                                           */
    114     /* -------------------------------------------------------------------------- */
    115     public void propertyChange(PropertyChangeEvent evt) {
    116         if (evt.getPropertyName().equals(ChangesetManagementPanel.SELECTED_CHANGESET_PROP)) {
    117             Changeset cs = (Changeset)evt.getNewValue();
    118             initFromChangeset(cs);
    119         } else if (evt.getPropertyName().equals(BasicUploadSettingsPanel.UPLOAD_COMMENT_PROP)) {
    120             String comment = (String)evt.getNewValue();
    121             setUploadComment(comment);
    122         }
    123     }
    124 
    125     /* -------------------------------------------------------------------------- */
    126125    /* Interface TableChangeListener                                              */
    127126    /* -------------------------------------------------------------------------- */
    128127    public void tableChanged(TableModelEvent e) {
    129128        String uploadComment = getUploadComment();
    130         firePropertyChange(UPLOAD_COMMENT_PROP, null, uploadComment);
     129        changesetCommentModel.setComment(uploadComment);
     130    }
     131
     132    /**
     133     * Observes the changeset comment model and keeps the tag editor in sync
     134     * with the current changeset comment
     135     *
     136     */
     137    class ChangesetCommentObserver implements Observer {
     138        public void update(Observable o, Object arg) {
     139            if (!(o instanceof ChangesetCommentModel)) return;
     140            String newValue = (String)arg;
     141            String oldValue = getUploadComment();
     142            if (oldValue == null) {
     143                oldValue = "";
     144            }
     145            if (!oldValue.equals(newValue)) {
     146                setUploadComment((String)arg);
     147            }
     148        }
    131149    }
    132150}
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r3083 r3133  
    8080    /** the upload button */
    8181    private JButton btnUpload;
    82 
    8382    private boolean canceled = false;
     83
     84    /** the changeset comment model keeping the state of the changeset comment */
     85    private ChangesetCommentModel changesetCommentModel;
    8486
    8587    /**
     
    113115        tpConfigPanels.add(new JPanel());
    114116
    115         tpConfigPanels.setComponentAt(0, pnlBasicUploadSettings = new BasicUploadSettingsPanel());
     117        changesetCommentModel = new ChangesetCommentModel();
     118
     119        tpConfigPanels.setComponentAt(0, pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel));
    116120        tpConfigPanels.setTitleAt(0, tr("Settings"));
    117121        tpConfigPanels.setToolTipTextAt(0, tr("Decide how to upload the data and which changeset to use"));
    118122
    119         tpConfigPanels.setComponentAt(1,pnlTagSettings = new TagSettingsPanel());
     123        tpConfigPanels.setComponentAt(1,pnlTagSettings = new TagSettingsPanel(changesetCommentModel));
    120124        tpConfigPanels.setTitleAt(1, tr("Tags of new changeset"));
    121125        tpConfigPanels.setToolTipTextAt(1, tr("Apply tags to the changeset data is uploaded to"));
    122126
    123         tpConfigPanels.setComponentAt(2,pnlChangesetManagement = new ChangesetManagementPanel());
     127        tpConfigPanels.setComponentAt(2,pnlChangesetManagement = new ChangesetManagementPanel(changesetCommentModel));
    124128        tpConfigPanels.setTitleAt(2, tr("Changesets"));
    125129        tpConfigPanels.setToolTipTextAt(2, tr("Manage open changesets and select a changeset to upload to"));
     
    175179        addWindowListener(new WindowEventHandler());
    176180
    177         // synchronized input of upload comments
    178         //
    179         //UploadCommentSynchronizer synchronizer = new UploadCommentSynchronizer();
    180         //pnlTagSettings.getModeaddTableModelListener(synchronizer);
    181         pnlTagSettings.addPropertyChangeListener(pnlBasicUploadSettings);
    182         pnlBasicUploadSettings.addPropertyChangeListener(pnlTagSettings);
    183181
    184182        // make sure the the configuration panels listen to each other
     
    188186                pnlBasicUploadSettings.getUploadParameterSummaryPanel()
    189187        );
    190         pnlChangesetManagement.addPropertyChangeListener(pnlTagSettings);
    191188        pnlChangesetManagement.addPropertyChangeListener(this);
    192189        pnlUploadedObjects.addPropertyChangeListener(
     
    197194                pnlBasicUploadSettings.getUploadParameterSummaryPanel()
    198195        );
     196
    199197
    200198        // users can click on either of two links in the upload parameter
     
    268266        pnlBasicUploadSettings.startUserInput();
    269267        pnlTagSettings.startUserInput();
    270         pnlTagSettings.setUploadComment(getUploadComment());
    271268        pnlTagSettings.initFromChangeset(pnlChangesetManagement.getSelectedChangeset());
    272269        pnlUploadStrategySelectionPanel.initFromPreferences();
     
    312309     */
    313310    protected String getUploadComment() {
    314         return pnlBasicUploadSettings.getUploadComment();
     311        return changesetCommentModel.getComment();
    315312    }
    316313
     
    385382                warnIllegalUploadComment();
    386383                tpConfigPanels.setSelectedIndex(0);
    387                 pnlBasicUploadSettings.initEditingOfUploadComment(getUploadComment());
     384                pnlBasicUploadSettings.initEditingOfUploadComment();
    388385                return;
    389386            }
     
    437434        public void windowActivated(WindowEvent arg0) {
    438435            if (tpConfigPanels.getSelectedIndex() == 0) {
    439                 pnlBasicUploadSettings.initEditingOfUploadComment(getUploadComment());
     436                pnlBasicUploadSettings.initEditingOfUploadComment();
    440437            }
    441438        }
Note: See TracChangeset for help on using the changeset viewer.