Changeset 2158 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-09-19T10:37:43+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3541: Upload-Dialog: Pressing 'enter' in comment-field should upload changes
fixed #3491: uploading form should preselect more intelligent

File:
1 edited

Legend:

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

    r2148 r2158  
    66
    77import java.awt.BorderLayout;
    8 import java.awt.Component;
    98import java.awt.Dimension;
    109import java.awt.FlowLayout;
     
    1514import java.awt.event.ItemEvent;
    1615import java.awt.event.ItemListener;
     16import java.awt.event.KeyEvent;
    1717import java.awt.event.WindowAdapter;
    1818import java.awt.event.WindowEvent;
    19 import java.text.SimpleDateFormat;
    2019import java.util.ArrayList;
    2120import java.util.Collection;
     
    2928import javax.swing.ButtonGroup;
    3029import javax.swing.DefaultComboBoxModel;
    31 import javax.swing.ImageIcon;
     30import javax.swing.InputMap;
    3231import javax.swing.JButton;
    3332import javax.swing.JCheckBox;
    3433import javax.swing.JComboBox;
     34import javax.swing.JComponent;
    3535import javax.swing.JDialog;
    3636import javax.swing.JLabel;
     
    4141import javax.swing.JScrollPane;
    4242import javax.swing.JTabbedPane;
    43 import javax.swing.ListCellRenderer;
    44 import javax.swing.UIManager;
     43import javax.swing.KeyStroke;
    4544import javax.swing.event.ChangeEvent;
    4645import javax.swing.event.ChangeListener;
     
    106105    /** the tabbed pane used below of the list of primitives  */
    107106    private JTabbedPane southTabbedPane;
     107    /** the upload button */
     108    private JButton btnUpload;
    108109
    109110    private ChangesetSelectionPanel pnlChangesetSelection;
     
    124125    }
    125126
    126 
     127    /**
     128     * builds the content panel for the upload dialog
     129     *
     130     * @return the content panel
     131     */
    127132    protected JPanel buildContentPanel() {
    128133        JPanel pnl = new JPanel();
     
    160165    }
    161166
     167    /**
     168     * builds the panel with the OK and CANCEL buttons
     169     *
     170     * @return
     171     */
    162172    protected JPanel buildActionPanel() {
    163173        JPanel pnl = new JPanel();
     
    166176
    167177        // -- upload button
    168         pnl.add(new SideButton(new UploadAction()));
     178        UploadAction uploadAction = new UploadAction();
     179        pnl.add(btnUpload = new SideButton(uploadAction));
     180        btnUpload.setFocusable(true);
     181        InputMap inputMap = btnUpload.getInputMap();
     182        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "doUpload");
     183        btnUpload.getActionMap().put("doUpload", uploadAction);
    169184
    170185        // -- cancel button
    171         pnl.add(new SideButton(new CancelAction()));
    172 
     186        CancelAction cancelAction = new CancelAction();
     187        pnl.add(new SideButton(cancelAction));
     188        getRootPane().registerKeyboardAction(
     189                cancelAction,
     190                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0),
     191                JComponent.WHEN_IN_FOCUSED_WINDOW
     192        );
    173193        return pnl;
    174194    }
     
    178198     */
    179199    protected void build() {
     200        setTitle(tr("Upload"));
    180201        getContentPane().setLayout(new BorderLayout());
    181202        getContentPane().add(buildContentPanel(), BorderLayout.CENTER);
     
    312333    }
    313334
     335    /**
     336     * Replies true if the changeset is to be closed after the
     337     * next upload
     338     *
     339     * @return true if the changeset is to be closed after the
     340     * next upload; false, otherwise
     341     */
    314342    public boolean isDoCloseAfterUpload() {
    315343        return pnlChangesetSelection.isCloseAfterUpload();
     
    326354    }
    327355
     356    /**
     357     * Replies the current value for the upload comment
     358     *
     359     * @return the current value for the upload comment
     360     */
    328361    protected String getUploadComment() {
    329362        switch(southTabbedPane.getSelectedIndex()) {
    330         case 0:
    331             return pnlChangesetSelection.getUploadComment();
    332         case 1:
    333             TagModel tm = tagEditorPanel.getModel().get("comment");
    334             return tm == null? "" : tm.getValue();
     363            case 0:
     364                return pnlChangesetSelection.getUploadComment();
     365            case 1:
     366                TagModel tm = tagEditorPanel.getModel().get("comment");
     367                return tm == null? "" : tm.getValue();
    335368        }
    336369        return "";
    337370    }
    338371
     372    /**
     373     * Replies true, if the dialog was canceled
     374     *
     375     * @return true, if the dialog was canceled
     376     */
    339377    public boolean isCanceled() {
    340378        return canceled;
    341379    }
    342380
     381    /**
     382     * Sets whether the dialog was canceld
     383     *
     384     * @param canceled true, if the dialog is canceled
     385     */
    343386    protected void setCanceled(boolean canceled) {
    344387        this.canceled = canceled;
     
    589632                    }
    590633            );
     634            cmt.getEditor().addActionListener(
     635                    new ActionListener() {
     636                        public void actionPerformed(ActionEvent e) {
     637                            btnUpload.requestFocusInWindow();
     638                        }
     639                    }
     640            );
    591641            pnl.add(cmt, GBC.eol().fill(GBC.HORIZONTAL));
    592642            return pnl;
     
    702752        }
    703753
     754        public void prepareDialogForNextUpload(Changeset cs) {
     755            if (cs == null || cs.getId() == 0) {
     756                rbUseNew.setSelected(true);
     757                cbCloseAfterUpload.setSelected(true);
     758            } if (cs.getId() == 0) {
     759                rbUseNew.setSelected(true);
     760                cbCloseAfterUpload.setSelected(true);
     761            } else if (cs.isOpen()) {
     762                rbExisting.setSelected(true);
     763                cbCloseAfterUpload.setSelected(false);
     764            } else {
     765                rbUseNew.setSelected(true);
     766                cbCloseAfterUpload.setSelected(true);
     767            }
     768        }
     769
    704770        /**
    705771         * Replies the current upload comment
     
    762828                tagEditorPanel.getModel().add("created_by", getDefaultCreatedBy());
    763829                tagEditorPanel.getModel().appendNewTag();
    764                 rbUseNew.setSelected(true);
    765830            } else if (cs.getId() == 0) {
    766831                if (cs.get("created_by") == null) {
     
    769834                tagEditorPanel.getModel().initFromPrimitive(cs);
    770835                tagEditorPanel.getModel().appendNewTag();
    771                 rbUseNew.setSelected(true);
    772836            } else if (cs.getId() > 0 && cs.isOpen()){
    773837                if (cs.get("created_by") == null) {
     
    790854                }
    791855            }
     856            prepareDialogForNextUpload(cs);
    792857        }
    793858
Note: See TracChangeset for help on using the changeset viewer.