Changeset 29353 in osm for applications/editors
- Timestamp:
- 2013-03-08T23:43:49+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/reverter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/build.xml
r29216 r29353 4 4 <property name="commit.message" value="Reverter: Update MultiOsmReader to support null data after redaction"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="5 680"/>6 <property name="plugin.main.version" value="5765"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/reverter/src/reverter/ChangesetIdQuery.java
r29348 r29353 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Color;6 5 import java.awt.GridBagLayout; 7 6 import java.awt.Insets; 8 7 import java.awt.event.KeyEvent; 9 import java.awt.event.KeyListener; 10 import java.text.NumberFormat; 11 import java.text.ParseException; 8 import java.awt.event.WindowEvent; 9 import java.awt.event.WindowListener; 10 import java.util.Collections; 11 import java.util.LinkedList; 12 import java.util.List; 12 13 13 14 import javax.swing.ButtonGroup; 14 15 import javax.swing.JCheckBox; 15 import javax.swing.JFormattedTextField;16 16 import javax.swing.JLabel; 17 17 import javax.swing.JPanel; 18 18 import javax.swing.JRadioButton; 19 import javax.swing.JTextField; 20 import javax.swing.KeyStroke; 19 21 import javax.swing.event.DocumentEvent; 20 22 import javax.swing.event.DocumentListener; 23 import javax.swing.plaf.basic.BasicComboBoxEditor; 21 24 22 25 import org.openstreetmap.josm.Main; 23 26 import org.openstreetmap.josm.data.osm.DataSet; 24 27 import org.openstreetmap.josm.gui.ExtendedDialog; 28 import org.openstreetmap.josm.gui.widgets.ChangesetIdTextField; 29 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 25 30 import org.openstreetmap.josm.tools.GBC; 26 31 … … 29 34 @SuppressWarnings("serial") 30 35 public 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(); 33 39 private final ButtonGroup bgRevertType = new ButtonGroup(); 34 40 private final JRadioButton rbFull = new JRadioButton(tr("Revert changeset fully")); … … 37 43 private final JCheckBox cbNewLayer = new JCheckBox(tr("Download as new layer")); 38 44 39 private final Color defaultForegroundColor = tcid.getForeground();40 41 45 public int getChangesetId() { 42 try { 43 return format.parse(tcid.getText()).intValue(); 44 } catch (ParseException e) { 45 return 0; 46 } 46 return tcid.getChangesetId(); 47 47 } 48 48 … … 66 66 super(Main.parent, tr("Revert changeset"), new String[] {tr("Revert"),tr("Cancel")}, true); 67 67 contentInsets = new Insets(10,10,10,5); 68 setButtonIcons(new String[] {"ok.png", "cancel.png" }); 69 JPanel panel = new JPanel(new GridBagLayout()); 68 70 69 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)); 72 84 73 85 bgRevertType.add(rbFull); … … 83 95 +"Unselect to download into the currently active data layer.</html>")); 84 96 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(); 85 107 86 108 final DataSet ds = Main.main.getCurrentDataSet(); … … 104 126 private void idChanged() { 105 127 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()); 109 129 } 110 130 } 111 131 }); 112 132 113 setContent(panel); 114 setupDialog(); 133 if (Main.pref.getBoolean("downloadchangeset.autopaste", true)) { 134 tcid.tryToPasteFromClipboard(); 135 } 115 136 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; 126 167 } 168 remindChangesetsHistory(cbId); 127 169 } 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) {} 129 178 } 130 179 } -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java
r29347 r29353 25 25 public void actionPerformed(ActionEvent arg0) { 26 26 final ChangesetIdQuery dlg = new ChangesetIdQuery(); 27 dlg.setVisible(true); 28 if (dlg.getValue() != 1) return; 27 if (dlg.showDialog().getValue() != 1) return; 29 28 final int changesetId = dlg.getChangesetId(); 30 29 final RevertType revertType = dlg.getRevertType();
Note:
See TracChangeset
for help on using the changeset viewer.