Changeset 29353 in osm for applications/editors


Ignore:
Timestamp:
2013-03-08T23:43:49+01:00 (12 years ago)
Author:
donvip
Message:

[josm_reverter] fix #josm8494 - automatically paste changeset id from buffer + history

Location:
applications/editors/josm/plugins/reverter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/build.xml

    r29216 r29353  
    44    <property name="commit.message" value="Reverter: Update MultiOsmReader to support null data after redaction"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    6     <property name="plugin.main.version" value="5680"/>
     6    <property name="plugin.main.version" value="5765"/>
    77
    88    <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetIdQuery.java

    r29348 r29353  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import java.awt.Color;
    65import java.awt.GridBagLayout;
    76import java.awt.Insets;
    87import java.awt.event.KeyEvent;
    9 import java.awt.event.KeyListener;
    10 import java.text.NumberFormat;
    11 import java.text.ParseException;
     8import java.awt.event.WindowEvent;
     9import java.awt.event.WindowListener;
     10import java.util.Collections;
     11import java.util.LinkedList;
     12import java.util.List;
    1213
    1314import javax.swing.ButtonGroup;
    1415import javax.swing.JCheckBox;
    15 import javax.swing.JFormattedTextField;
    1616import javax.swing.JLabel;
    1717import javax.swing.JPanel;
    1818import javax.swing.JRadioButton;
     19import javax.swing.JTextField;
     20import javax.swing.KeyStroke;
    1921import javax.swing.event.DocumentEvent;
    2022import javax.swing.event.DocumentListener;
     23import javax.swing.plaf.basic.BasicComboBoxEditor;
    2124
    2225import org.openstreetmap.josm.Main;
    2326import org.openstreetmap.josm.data.osm.DataSet;
    2427import org.openstreetmap.josm.gui.ExtendedDialog;
     28import org.openstreetmap.josm.gui.widgets.ChangesetIdTextField;
     29import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
    2530import org.openstreetmap.josm.tools.GBC;
    2631
     
    2934@SuppressWarnings("serial")
    3035public class ChangesetIdQuery extends ExtendedDialog {
    31     private final NumberFormat format = NumberFormat.getIntegerInstance();
    32     private final JFormattedTextField tcid = new JFormattedTextField(format);
     36    private final JPanel panel = new JPanel(new GridBagLayout());
     37    private final ChangesetIdTextField tcid = new ChangesetIdTextField();
     38    private final HistoryComboBox cbId = new HistoryComboBox();
    3339    private final ButtonGroup bgRevertType = new ButtonGroup();
    3440    private final JRadioButton rbFull = new JRadioButton(tr("Revert changeset fully"));
     
    3743    private final JCheckBox cbNewLayer = new JCheckBox(tr("Download as new layer"));
    3844   
    39     private final Color defaultForegroundColor = tcid.getForeground();
    40 
    4145    public int getChangesetId() {
    42         try {
    43             return format.parse(tcid.getText()).intValue();
    44         } catch (ParseException e) {
    45             return 0;
    46         }
     46        return tcid.getChangesetId();
    4747    }
    4848   
     
    6666        super(Main.parent, tr("Revert changeset"), new String[] {tr("Revert"),tr("Cancel")}, true);
    6767        contentInsets = new Insets(10,10,10,5);
    68         setButtonIcons(new String[] {"ok.png", "cancel.png" });
    69         JPanel panel = new JPanel(new GridBagLayout());
     68       
    7069        panel.add(new JLabel(tr("Changeset id:")));
    71         panel.add(tcid, GBC.eol().fill(GBC.HORIZONTAL));
     70
     71        cbId.setEditor(new BasicComboBoxEditor() {
     72            @Override
     73            protected JTextField createEditorComponent() {
     74                return tcid;
     75            }
     76        });
     77        cbId.setToolTipText(tr("Enter the ID of the changeset that should be reverted"));
     78        restoreChangesetsHistory(cbId);
     79
     80        // forward the enter key stroke to the revert button
     81        tcid.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false));
     82       
     83        panel.add(cbId, GBC.eol().fill(GBC.HORIZONTAL));
    7284
    7385        bgRevertType.add(rbFull);
     
    8395                +"Unselect to download into the currently active data layer.</html>"));
    8496        panel.add(cbNewLayer, GBC.eol().fill(GBC.HORIZONTAL));
     97    }
     98
     99    @Override
     100    public void setupDialog() {
     101        setContent(panel, false);
     102        setButtonIcons(new String[] {"ok.png", "cancel.png" });
     103        setDefaultButton(1);
     104       
     105        addWindowListener(new InternalWindowListener());
     106        super.setupDialog();
    85107       
    86108        final DataSet ds = Main.main.getCurrentDataSet();
     
    104126            private void idChanged() {
    105127                if (tcid.hasFocus()) {
    106                     boolean idOK = getChangesetId() > 0;
    107                     tcid.setForeground(idOK ? defaultForegroundColor : Color.RED);
    108                     buttons.get(0).setEnabled(idOK);
     128                    buttons.get(0).setEnabled(tcid.readIds());
    109129                }
    110130            }
    111131        });
    112132       
    113         setContent(panel);
    114         setupDialog();
     133        if (Main.pref.getBoolean("downloadchangeset.autopaste", true)) {
     134            tcid.tryToPasteFromClipboard();
     135        }
    115136       
    116         // Initially disables the Revert button
    117         buttons.get(0).setEnabled(false);
    118                
    119         // When pressing Enter in the changeset id field, validate the dialog if the id is correct (i.e. Revert button enabled)
    120         tcid.addKeyListener(new KeyListener() {
    121             @Override public void keyPressed(KeyEvent e) {}
    122             @Override public void keyTyped(KeyEvent e) { }
    123             @Override public void keyReleased(KeyEvent e) {
    124                 if (e != null && e.getKeyCode() == KeyEvent.VK_ENTER && buttons.get(0).isEnabled()) {
    125                     buttons.get(0).doClick();
     137        // Initially sets the revert button consistent with text id field contents
     138        buttons.get(0).setEnabled(tcid.readIds());
     139    }
     140
     141    /**
     142     * Restore the current history from the preferences
     143     *
     144     * @param cbHistory
     145     */
     146    protected void restoreChangesetsHistory(HistoryComboBox cbHistory) {
     147        List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(getClass().getName() + ".changesetsHistory", new LinkedList<String>()));
     148        // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement()
     149        Collections.reverse(cmtHistory);
     150        cbHistory.setPossibleItems(cmtHistory);
     151    }
     152   
     153    /**
     154     * Remind the current history in the preferences
     155     * @param cbHistory
     156     */
     157    protected void remindChangesetsHistory(HistoryComboBox cbHistory) {
     158        cbHistory.addCurrentItemToHistory();
     159        Main.pref.putCollection(getClass().getName() + ".changesetsHistory", cbHistory.getHistory());
     160    }
     161   
     162    private class InternalWindowListener implements WindowListener {
     163        @Override public void windowClosed(WindowEvent e) {
     164            if (e != null && e.getComponent() == ChangesetIdQuery.this && getValue() == 1) {
     165                if (!tcid.readIds()) {
     166                    return;
    126167                }
     168                remindChangesetsHistory(cbId);
    127169            }
    128         });
     170        }
     171   
     172        @Override public void windowOpened(WindowEvent e) {}
     173        @Override public void windowClosing(WindowEvent e) {}
     174        @Override public void windowIconified(WindowEvent e) {}
     175        @Override public void windowDeiconified(WindowEvent e) {}
     176        @Override public void windowActivated(WindowEvent e) {}
     177        @Override public void windowDeactivated(WindowEvent e) {}
    129178    }
    130179}
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java

    r29347 r29353  
    2525    public void actionPerformed(ActionEvent arg0)  {
    2626        final ChangesetIdQuery dlg = new ChangesetIdQuery();
    27         dlg.setVisible(true);
    28         if (dlg.getValue() != 1) return;
     27        if (dlg.showDialog().getValue() != 1) return;
    2928        final int changesetId = dlg.getChangesetId();
    3029        final RevertType revertType = dlg.getRevertType();
Note: See TracChangeset for help on using the changeset viewer.