Changeset 29347 in osm for applications


Ignore:
Timestamp:
2013-03-06T23:11:53+01:00 (12 years ago)
Author:
donvip
Message:

[josm_reverter] fix EDT violations + various UI improvements in query dialog

Location:
applications/editors/josm/plugins/reverter/src/reverter
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetIdQuery.java

    r29296 r29347  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.awt.Color;
    56import java.awt.GridBagLayout;
    67import java.awt.Insets;
     8import java.awt.event.KeyEvent;
     9import java.awt.event.KeyListener;
    710import java.text.NumberFormat;
    8 import java.text.ParseException;
    911
    1012import javax.swing.ButtonGroup;
     
    1416import javax.swing.JPanel;
    1517import javax.swing.JRadioButton;
     18import javax.swing.event.DocumentEvent;
     19import javax.swing.event.DocumentListener;
    1620
    1721import org.openstreetmap.josm.Main;
     22import org.openstreetmap.josm.data.osm.DataSet;
    1823import org.openstreetmap.josm.gui.ExtendedDialog;
    1924import org.openstreetmap.josm.tools.GBC;
     25
    2026import reverter.ChangesetReverter.RevertType;
    2127
    2228@SuppressWarnings("serial")
    2329public class ChangesetIdQuery extends ExtendedDialog {
    24     private final JFormattedTextField tcid = new JFormattedTextField(NumberFormat.getInstance());
     30    private final JFormattedTextField tcid = new JFormattedTextField(NumberFormat.getIntegerInstance());
    2531    private final ButtonGroup bgRevertType = new ButtonGroup();
    2632    private final JRadioButton rbFull = new JRadioButton(tr("Revert changeset fully"));
     
    2834    private final JRadioButton rbSelectionUndelete = new JRadioButton(tr("Revert selection and restore deleted objects"));
    2935    private final JCheckBox cbNewLayer = new JCheckBox(tr("Download as new layer"));
     36   
     37    private final Color defaultForegroundColor = tcid.getForeground();
    3038
    3139    public int getChangesetId() {
    3240        try {
    33             return NumberFormat.getInstance().parse(tcid.getText()).intValue();
    34         } catch (ParseException e) {
     41            return Integer.parseInt(tcid.getText());
     42        } catch (NumberFormatException e) {
    3543            return 0;
    3644        }
     
    7381                +"Unselect to download into the currently active data layer.</html>"));
    7482        panel.add(cbNewLayer, GBC.eol().fill(GBC.HORIZONTAL));
    75 
     83       
     84        final DataSet ds = Main.main.getCurrentDataSet();
     85       
     86        // Disables "Download in new layer" choice if there is no current data set (i.e no data layer)
     87        if (ds == null) {
     88            cbNewLayer.setSelected(true);
     89            cbNewLayer.setEnabled(false);
     90        }
     91        // Disables selection-related choices of there is no current selected objects
     92        if (ds == null || ds.getAllSelected().isEmpty()) {
     93            rbSelection.setEnabled(false);
     94            rbSelectionUndelete.setEnabled(false);
     95        }
     96       
     97        // Enables/disables the Revert button when a changeset id is correctly set or not
     98        tcid.getDocument().addDocumentListener(new DocumentListener() {
     99            @Override public void removeUpdate(DocumentEvent e) { idChanged(); }
     100            @Override public void insertUpdate(DocumentEvent e) { idChanged(); }
     101            @Override public void changedUpdate(DocumentEvent e) { idChanged(); }
     102            private void idChanged() {
     103                boolean idOK = getChangesetId() > 0;
     104                tcid.setForeground(idOK ? defaultForegroundColor : Color.RED);
     105                buttons.get(0).setEnabled(idOK);
     106            }
     107        });
     108       
    76109        setContent(panel);
    77110        setupDialog();
     111       
     112        // Initially disables the Revert button
     113        buttons.get(0).setEnabled(false);
     114       
     115        // When pressing Enter in the changeset id field, validate the dialog if the id is correct (i.e. Revert button enabled)
     116        tcid.addKeyListener(new KeyListener() {
     117            @Override public void keyPressed(KeyEvent e) {}
     118            @Override public void keyTyped(KeyEvent e) { }
     119            @Override public void keyReleased(KeyEvent e) {
     120                if (e != null && e.getKeyCode() == KeyEvent.VK_ENTER && buttons.get(0).isEnabled()) {
     121                    buttons.get(0).doClick();
     122                }
     123            }
     124        });
    78125    }
    79126}
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java

    r29296 r29347  
    3131import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3232import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     33import org.openstreetmap.josm.gui.util.GuiHelper;
    3334import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
    3435import org.openstreetmap.josm.io.OsmTransferException;
     
    5556    public final Changeset changeset;
    5657    public final RevertType revertType;
    57 
     58   
    5859    private final OsmDataLayer layer; // data layer associated with reverter
    5960    private final DataSet ds; // DataSet associated with reverter
     
    139140            monitor.finishTask();
    140141            if (newLayer) {
    141                 Main.main.addLayer(layer);
     142                GuiHelper.runInEDT(new Runnable() {
     143                    @Override
     144                    public void run() {
     145                        Main.main.addLayer(layer);
     146                    }
     147                });
    142148            }
    143149        }
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java

    r29296 r29347  
    2323    }
    2424
    25     @Override
    26     protected void updateEnabledState() {
    27         setEnabled(getCurrentDataSet() != null);
    28     }
    29 
    3025    public void actionPerformed(ActionEvent arg0)  {
    31         if (getCurrentDataSet() == null)
    32             return;
    3326        final ChangesetIdQuery dlg = new ChangesetIdQuery();
    3427        dlg.setVisible(true);
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetTask.java

    r29296 r29347  
    1212import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
    1313import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     14import org.openstreetmap.josm.gui.util.GuiHelper;
    1415import org.openstreetmap.josm.io.OsmTransferException;
    1516
     
    8485        if (!checkAndDownloadMissing()) return;
    8586        List<Command> cmds = rev.getCommands();
    86         Command cmd = new RevertChangesetCommand(tr(revertType == RevertType.FULL ? "Revert changeset #{0}" :
     87        final Command cmd = new RevertChangesetCommand(tr(revertType == RevertType.FULL ? "Revert changeset #{0}" :
    8788                "Partially revert changeset #{0}",changesetId),cmds);
    88         Main.main.undoRedo.add(cmd);
     89        GuiHelper.runInEDT(new Runnable() {
     90            @Override
     91            public void run() {
     92                Main.main.undoRedo.add(cmd);
     93            }
     94        });
    8995    }
    9096
Note: See TracChangeset for help on using the changeset viewer.