Changeset 29347 in osm for applications
- Timestamp:
- 2013-03-06T23:11:53+01:00 (11 years ago)
- 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 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Color; 5 6 import java.awt.GridBagLayout; 6 7 import java.awt.Insets; 8 import java.awt.event.KeyEvent; 9 import java.awt.event.KeyListener; 7 10 import java.text.NumberFormat; 8 import java.text.ParseException;9 11 10 12 import javax.swing.ButtonGroup; … … 14 16 import javax.swing.JPanel; 15 17 import javax.swing.JRadioButton; 18 import javax.swing.event.DocumentEvent; 19 import javax.swing.event.DocumentListener; 16 20 17 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.data.osm.DataSet; 18 23 import org.openstreetmap.josm.gui.ExtendedDialog; 19 24 import org.openstreetmap.josm.tools.GBC; 25 20 26 import reverter.ChangesetReverter.RevertType; 21 27 22 28 @SuppressWarnings("serial") 23 29 public class ChangesetIdQuery extends ExtendedDialog { 24 private final JFormattedTextField tcid = new JFormattedTextField(NumberFormat.getIn stance());30 private final JFormattedTextField tcid = new JFormattedTextField(NumberFormat.getIntegerInstance()); 25 31 private final ButtonGroup bgRevertType = new ButtonGroup(); 26 32 private final JRadioButton rbFull = new JRadioButton(tr("Revert changeset fully")); … … 28 34 private final JRadioButton rbSelectionUndelete = new JRadioButton(tr("Revert selection and restore deleted objects")); 29 35 private final JCheckBox cbNewLayer = new JCheckBox(tr("Download as new layer")); 36 37 private final Color defaultForegroundColor = tcid.getForeground(); 30 38 31 39 public int getChangesetId() { 32 40 try { 33 return NumberFormat.getInstance().parse(tcid.getText()).intValue();34 } catch ( ParseException e) {41 return Integer.parseInt(tcid.getText()); 42 } catch (NumberFormatException e) { 35 43 return 0; 36 44 } … … 73 81 +"Unselect to download into the currently active data layer.</html>")); 74 82 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 76 109 setContent(panel); 77 110 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 }); 78 125 } 79 126 } -
applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java
r29296 r29347 31 31 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 32 32 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 33 import org.openstreetmap.josm.gui.util.GuiHelper; 33 34 import org.openstreetmap.josm.io.MultiFetchServerObjectReader; 34 35 import org.openstreetmap.josm.io.OsmTransferException; … … 55 56 public final Changeset changeset; 56 57 public final RevertType revertType; 57 58 58 59 private final OsmDataLayer layer; // data layer associated with reverter 59 60 private final DataSet ds; // DataSet associated with reverter … … 139 140 monitor.finishTask(); 140 141 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 }); 142 148 } 143 149 } -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java
r29296 r29347 23 23 } 24 24 25 @Override26 protected void updateEnabledState() {27 setEnabled(getCurrentDataSet() != null);28 }29 30 25 public void actionPerformed(ActionEvent arg0) { 31 if (getCurrentDataSet() == null)32 return;33 26 final ChangesetIdQuery dlg = new ChangesetIdQuery(); 34 27 dlg.setVisible(true); -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetTask.java
r29296 r29347 12 12 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 13 13 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 14 import org.openstreetmap.josm.gui.util.GuiHelper; 14 15 import org.openstreetmap.josm.io.OsmTransferException; 15 16 … … 84 85 if (!checkAndDownloadMissing()) return; 85 86 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}" : 87 88 "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 }); 89 95 } 90 96
Note:
See TracChangeset
for help on using the changeset viewer.