Changeset 32528 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetInfoAction.java
- Timestamp:
- 2016-07-02T03:55:03+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetInfoAction.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; … … 5 8 import java.net.URLEncoder; 6 9 import java.text.SimpleDateFormat; 10 7 11 import javax.swing.AbstractAction; 8 12 import javax.swing.JOptionPane; 13 9 14 import org.openstreetmap.josm.Main; 10 import static org.openstreetmap.josm.tools.I18n.tr;11 15 import org.openstreetmap.josm.tools.ImageProvider; 12 16 13 17 /** 14 18 * Display an information box for an offset. 15 * 19 * 16 20 * @author Zverik 17 21 * @license WTFPL … … 21 25 22 26 ImageryOffsetBase offset; 23 27 24 28 /** 25 29 * Initializes the action with an offset object. 26 30 * Calls {@link #getInformationObject(iodb.ImageryOffsetBase)}. 27 31 */ 28 public OffsetInfoAction( ImageryOffsetBase offset) {32 public OffsetInfoAction(ImageryOffsetBase offset) { 29 33 super(tr("Offset Information")); 30 34 putValue(SMALL_ICON, ImageProvider.get("info")); … … 37 41 * to report the given offset. 38 42 */ 43 @Override 39 44 public void actionPerformed(ActionEvent e) { 40 45 Object info = offset == null ? null : getInformationObject(offset); 41 if (offset.isFlagged())46 if (offset.isFlagged()) 42 47 JOptionPane.showMessageDialog(Main.parent, info, ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE); 43 48 else { 44 49 int result = JOptionPane.showOptionDialog(Main.parent, info, ImageryOffsetTools.DIALOG_TITLE, 45 50 JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, 46 new String[] { "OK", tr("Report this offset")}, null);47 if (result == 1) {51 new String[] {"OK", tr("Report this offset")}, null); 52 if (result == 1) { 48 53 // ask for a reason 49 54 Object reason = JOptionPane.showInputDialog(Main.parent, 50 55 tr("You are to notify moderators of this offset. Why?"), 51 56 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE); 52 if (reason != null && reason.toString().length() > 0) {57 if (reason != null && reason.toString().length() > 0) { 53 58 try { 54 59 String query = "report?id=" + offset.getId() 55 + "&reason=" + URLEncoder.encode(reason.toString(), "UTF8");60 + "&reason=" + URLEncoder.encode(reason.toString(), "UTF8"); 56 61 SimpleOffsetQueryTask reportTask = 57 62 new SimpleOffsetQueryTask(query, tr("Reporting the offset...")); 58 63 Main.worker.submit(reportTask); 59 } catch (UnsupportedEncodingException ex) {60 // WTF64 } catch (UnsupportedEncodingException ex) { 65 Main.error(ex); 61 66 } 62 67 } … … 68 73 * Constructs a string with all information about the given offset. 69 74 */ 70 public static Object getInformationObject( ImageryOffsetBase offset) {75 public static Object getInformationObject(ImageryOffsetBase offset) { 71 76 StringBuilder sb = new StringBuilder(); 72 if (offset instanceof ImageryOffset) {73 double odist = ((ImageryOffset)offset).getImageryPos().greatCircleDistance(offset.getPosition()); 74 if (odist < 1e-2) odist = 0.0;77 if (offset instanceof ImageryOffset) { 78 double odist = ((ImageryOffset) offset).getImageryPos().greatCircleDistance(offset.getPosition()); 79 if (odist < 1e-2) odist = 0.0; 75 80 sb.append(tr("An imagery offset of {0}", ImageryOffsetTools.formatDistance(odist))).append('\n'); 76 sb.append(tr("Imagery ID")).append(": ").append(((ImageryOffset)offset).getImagery()).append('\n'); 81 sb.append(tr("Imagery ID")).append(": ").append(((ImageryOffset) offset).getImagery()).append('\n'); 77 82 } else { 78 sb.append(tr("A calibration geometry of {0} nodes", ((CalibrationObject)offset).getGeometry().length)).append('\n'); 83 sb.append(tr("A calibration geometry of {0} nodes", ((CalibrationObject) offset).getGeometry().length)).append('\n'); 79 84 } 80 85 81 86 double dist = ImageryOffsetTools.getMapCenter().greatCircleDistance(offset.getPosition()); 82 87 sb.append(dist < 50 ? tr("Determined right here") : tr("Determined {0} away", 83 88 ImageryOffsetTools.formatDistance(dist))); 84 89 85 90 sb.append("\n\n"); 86 91 sb.append(tr("Created by {0} on {1}", offset.getAuthor(), 87 92 DATE_FORMAT.format(offset.getDate()))).append('\n'); 88 93 sb.append(tr("Description")).append(": ").append(offset.getDescription()); 89 90 if (offset.isDeprecated()) {94 95 if (offset.isDeprecated()) { 91 96 sb.append("\n\n"); 92 sb.append(tr("Deprecated by {0} on {1}",offset.getAbandonAuthor(), 97 sb.append(tr("Deprecated by {0} on {1}", offset.getAbandonAuthor(), 93 98 DATE_FORMAT.format(offset.getAbandonDate()))).append('\n'); 94 99 sb.append(tr("Reason")).append(": ").append(offset.getAbandonReason()); 95 100 } 96 101 97 if (offset.isFlagged()) {102 if (offset.isFlagged()) { 98 103 sb.append("\n\n").append(tr("This entry has been reported.")); 99 104 }
Note:
See TracChangeset
for help on using the changeset viewer.
