Changeset 32528 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/DeprecateOffsetAction.java
- Timestamp:
- 2016-07-02T03:55:03+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/DeprecateOffsetAction.java
r29434 r32528 1 // License: WTFPL. For details, see LICENSE file. 1 2 package iodb; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 2 5 3 6 import java.awt.event.ActionEvent; 4 7 import java.io.UnsupportedEncodingException; 5 import java.net.*; 8 import java.net.URLEncoder; 9 6 10 import javax.swing.AbstractAction; 7 11 import javax.swing.JOptionPane; 12 8 13 import org.openstreetmap.josm.Main; 9 14 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 10 import static org.openstreetmap.josm.tools.I18n.tr;11 15 import org.openstreetmap.josm.tools.ImageProvider; 12 16 13 17 /** 14 18 * A context-dependent action to deprecate an offset. 15 * 19 * 16 20 * @author Zverik 17 21 * @license WTFPL … … 20 24 private ImageryOffsetBase offset; 21 25 private QuerySuccessListener listener; 22 26 23 27 /** 24 28 * Initialize an action with an offset object. 25 29 */ 26 public DeprecateOffsetAction( ImageryOffsetBase offset) {30 public DeprecateOffsetAction(ImageryOffsetBase offset) { 27 31 super(tr("Deprecate Offset")); 28 32 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); … … 37 41 * on a positive answer. 38 42 */ 43 @Override 39 44 public void actionPerformed(ActionEvent e) { 40 if (Main.map == null || Main.map.mapView == null || !Main.map.isVisible())45 if (Main.map == null || Main.map.mapView == null || !Main.map.isVisible()) 41 46 return; 42 47 43 48 String desc = offset instanceof ImageryOffset ? 44 49 tr("Are you sure this imagery offset is wrong?") : 45 tr("Are you sure this calibration geometry is aligned badly?"); 46 if(JOptionPane.showConfirmDialog(Main.parent,47 tr("Warning: deprecation is basically irreversible!")+ "\n" + desc, 48 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION ) {49 return; 50 } 51 deprecateOffset(offset, listener); 50 tr("Are you sure this calibration geometry is aligned badly?"); 51 if (JOptionPane.showConfirmDialog(Main.parent, 52 tr("Warning: deprecation is basically irreversible!")+ "\n" + desc, 53 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) { 54 return; 55 } 56 deprecateOffset(offset, listener); 52 57 } 53 58 … … 55 60 * Installs a listener to process successful deprecation event. 56 61 */ 57 public void setListener( QuerySuccessListener listener) {62 public void setListener(QuerySuccessListener listener) { 58 63 this.listener = listener; 59 64 } … … 61 66 /** 62 67 * Deprecate the given offset. 63 * @see #deprecateOffset(iodb.ImageryOffsetBase, iodb.QuerySuccessListener) 68 * @see #deprecateOffset(iodb.ImageryOffsetBase, iodb.QuerySuccessListener) 64 69 */ 65 public static void deprecateOffset( ImageryOffsetBase offset) {70 public static void deprecateOffset(ImageryOffsetBase offset) { 66 71 deprecateOffset(offset, null); 67 72 } … … 71 76 * and executes {@link SimpleOffsetQueryTask} with a query to deprecate the offset. 72 77 */ 73 public static void deprecateOffset( ImageryOffsetBase offset, QuerySuccessListener listener) {78 public static void deprecateOffset(ImageryOffsetBase offset, QuerySuccessListener listener) { 74 79 String userName = JosmUserIdentityManager.getInstance().getUserName(); 75 if( userName == null ) { 76 JOptionPane.showMessageDialog(Main.parent, tr("To store imagery offsets you must be a registered OSM user."), ImageryOffsetTools.DIALOG_TITLE, JOptionPane.ERROR_MESSAGE); 80 if (userName == null) { 81 JOptionPane.showMessageDialog(Main.parent, tr("To store imagery offsets you must be a registered OSM user."), 82 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.ERROR_MESSAGE); 77 83 return; 78 84 } … … 80 86 String message = offset instanceof ImageryOffset 81 87 ? tr("Please enter the reason why you mark this imagery offset as deprecated") 82 : tr("Please enter the reason why you mark this calibration geometry as deprecated"); 83 String reason = StoreImageryOffsetAction.queryDescription(message + ":"); 84 if(reason == null)85 return; 86 87 try { 88 String query = "deprecate?id=" + offset.getId() 89 + "&author=" + URLEncoder.encode(userName, "UTF8") 90 + "&reason=" + URLEncoder.encode(reason, "UTF8"); 91 SimpleOffsetQueryTask depTask = new SimpleOffsetQueryTask(query, tr("Notifying the server of the deprecation...")); 92 if(listener != null)93 depTask.setListener(listener); 94 Main.worker.submit(depTask); 95 } catch (UnsupportedEncodingException ex) {96 // WTF97 } 88 : tr("Please enter the reason why you mark this calibration geometry as deprecated"); 89 String reason = StoreImageryOffsetAction.queryDescription(message + ":"); 90 if (reason == null) 91 return; 92 93 try { 94 String query = "deprecate?id=" + offset.getId() 95 + "&author=" + URLEncoder.encode(userName, "UTF8") 96 + "&reason=" + URLEncoder.encode(reason, "UTF8"); 97 SimpleOffsetQueryTask depTask = new SimpleOffsetQueryTask(query, tr("Notifying the server of the deprecation...")); 98 if (listener != null) 99 depTask.setListener(listener); 100 Main.worker.submit(depTask); 101 } catch (UnsupportedEncodingException ex) { 102 Main.error(ex); 103 } 98 104 } 99 105 }
Note:
See TracChangeset
for help on using the changeset viewer.
