Changeset 29380 in osm for applications/editors/josm
- Timestamp:
- 2013-03-21T07:28:34+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db/src/iodb
- Files:
-
- 1 added
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/DeprecateOffsetAction.java
r29377 r29380 1 1 package iodb; 2 2 3 import iodb.QuerySuccessListener; 3 4 import java.awt.event.ActionEvent; 4 5 import java.io.UnsupportedEncodingException; … … 18 19 public class DeprecateOffsetAction extends AbstractAction { 19 20 private ImageryOffsetBase offset; 21 private QuerySuccessListener listener; 20 22 21 23 public DeprecateOffsetAction( ImageryOffsetBase offset ) { … … 37 39 return; 38 40 } 39 deprecateOffset(offset); 41 deprecateOffset(offset, listener); 42 } 43 44 public void setListener( QuerySuccessListener listener ) { 45 this.listener = listener; 40 46 } 41 47 42 48 public static void deprecateOffset( ImageryOffsetBase offset ) { 49 deprecateOffset(offset, null); 50 } 51 52 public static void deprecateOffset( ImageryOffsetBase offset, QuerySuccessListener listener ) { 43 53 String userName = JosmUserIdentityManager.getInstance().getUserName(); 44 54 if( userName == null ) { … … 58 68 + "&reason=" + URLEncoder.encode(reason, "UTF8"); 59 69 SimpleOffsetQueryTask depTask = new SimpleOffsetQueryTask(query, tr("Notifying the server of the deprecation...")); 70 if( listener != null ) 71 depTask.setListener(listener); 60 72 Main.worker.submit(depTask); 61 73 } catch( UnsupportedEncodingException ex ) { -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/GetImageryOffsetAction.java
r29377 r29380 61 61 return; 62 62 } 63 final ImageryOffsetBase offset = new OffsetDialog(offsets).showDialog(); 64 if( offset != null ) { 65 if( offset instanceof ImageryOffset ) { 66 ImageryOffsetTools.applyLayerOffset(layer, (ImageryOffset)offset); 67 Main.map.repaint(); 68 } else if( offset instanceof CalibrationObject ) { 69 CalibrationLayer clayer = new CalibrationLayer((CalibrationObject)offset); 70 Main.map.mapView.addLayer(clayer); 71 clayer.panToCenter(); 72 if( !Main.pref.getBoolean("iodb.calibration.message", false) ) { 73 JOptionPane.showMessageDialog(Main.parent, 74 tr("A layer has been added with a calibration geometry. Hide data layers,\n" 75 + "find the corresponding feature on the imagery layer and move it accordingly."), 76 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE); 77 Main.pref.put("iodb.calibration.message", true); 78 } 79 } 80 } 63 OffsetDialog offsetDialog = new OffsetDialog(offsets); 64 if( offsetDialog.showDialog() != null ) 65 offsetDialog.applyOffset(); 81 66 } 82 67 … … 92 77 int radius = Main.pref.getInteger("iodb.radius", -1); 93 78 if( radius > 0 ) 94 query = query + " ?radius=" + radius;79 query = query + "&radius=" + radius; 95 80 setQuery(query); 96 81 } catch( UnsupportedEncodingException e ) { -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetTools.java
r29379 r29380 1 1 package iodb; 2 2 3 import java.text.MessageFormat; 3 4 import java.util.*; 4 5 import org.openstreetmap.josm.Main; … … 177 178 LatLon correctedCenterLL = proj.eastNorth2latlon(pos.add(dx, dy)); 178 179 double length = correctedCenterLL.greatCircleDistance(offset.getImageryPos()); 179 double direction = length < 1e- 3? 0.0 : correctedCenterLL.heading(offset.getImageryPos());180 double direction = length < 1e-2 ? 0.0 : correctedCenterLL.heading(offset.getImageryPos()); 180 181 // todo: north vs south. Meanwhile, let's fix this dirty: 181 182 direction = Math.PI - direction; … … 186 187 187 188 public static String formatDistance( double d ) { 188 if( d < 0.0095 ) return tr("{0,number,0} mm", d * 1000); 189 if( d < 0.095 ) return tr("{0,number,0.0} cm", d * 100); 190 if( d < 0.95) return tr("{0,number,0} cm", d * 100); 191 if( d < 9.5 ) return tr("{0,number,0.0} m", d); 192 if( d < 950 ) return tr("{0,number,0} m", d); 193 if( d < 9500 ) return tr("{0,number,0.0} km", d / 1000); 194 return tr("{0,number,0} km", d / 1000); 189 if( d < 0.0095 ) return formatDistance(d * 1000, tr("mm"), false); 190 if( d < 0.095 ) return formatDistance(d * 100, tr("cm"), true ); 191 if( d < 0.95 ) return formatDistance(d * 100, tr("cm"), false); 192 if( d < 9.5 ) return formatDistance(d, tr("m"), true ); 193 if( d < 950 ) return formatDistance(d, tr("m"), false ); 194 if( d < 9500 ) return formatDistance(d / 1000, tr("km"), true); 195 return formatDistance(d / 1000, tr("km"), false); 196 } 197 198 private static String formatDistance( double d, String si, boolean floating ) { 199 return MessageFormat.format(floating ? "{0,number,0.0} {1}" : "{0,number,0} {1}", d, si); 195 200 } 196 201 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29379 r29380 11 11 import javax.swing.border.EmptyBorder; 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.tools.GBC; 13 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 14 import org.openstreetmap.josm.gui.NavigatableComponent; 15 import org.openstreetmap.josm.gui.layer.ImageryLayer; 14 16 import static org.openstreetmap.josm.tools.I18n.tr; 17 import org.openstreetmap.josm.tools.ImageProvider; 18 import org.openstreetmap.josm.tools.OpenBrowser; 15 19 16 20 /** … … 19 23 * @author zverik 20 24 */ 21 public class OffsetDialog extends JDialog implements ActionListener {25 public class OffsetDialog extends JDialog implements ActionListener, NavigatableComponent.ZoomChangeListener { 22 26 protected static final String PREF_CALIBRATION = "iodb.show.calibration"; 23 27 protected static final String PREF_DEPRECATED = "iodb.show.deprecated"; 24 28 private static final int MAX_OFFSETS = Main.main.pref.getInteger("iodb.max.offsets", 5); 29 private static final boolean MODAL = false; // modal does not work for executing actions 25 30 26 31 private List<ImageryOffsetBase> offsets; … … 29 34 30 35 public OffsetDialog( List<ImageryOffsetBase> offsets ) { 31 super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, ModalityType.DOCUMENT_MODAL); 36 super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, 37 MODAL ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS); 32 38 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 33 //setResizable(false);39 setResizable(false); 34 40 this.offsets = offsets; 41 NavigatableComponent.addZoomChangeListener(this); 35 42 36 43 // make this dialog close on "escape" … … 61 68 checkBoxPanel.add(calibrationBox); 62 69 checkBoxPanel.add(deprecatedBox); 63 JButton cancelButton = new JButton( "Cancel");70 JButton cancelButton = new JButton(tr("Cancel"), ImageProvider.get("cancel")); 64 71 cancelButton.addActionListener(this); 65 cancelButton.setAlignmentX(CENTER_ALIGNMENT); 72 JButton helpButton = new JButton(new HelpAction()); 73 JPanel cancelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); 74 cancelPanel.add(cancelButton); 75 cancelPanel.add(helpButton); 66 76 67 77 Box dialog = new Box(BoxLayout.Y_AXIS); 68 78 dialog.add(buttonPanel); 69 79 dialog.add(checkBoxPanel); 70 dialog.add(cancel Button);80 dialog.add(cancelPanel); 71 81 72 82 dialog.setBorder(new CompoundBorder(dialog.getBorder(), new EmptyBorder(5, 5, 5, 5))); … … 87 97 JPopupMenu popupMenu = new JPopupMenu(); 88 98 popupMenu.add(new OffsetInfoAction(offset)); 89 if( !offset.isDeprecated() ) 90 popupMenu.add(new DeprecateOffsetAction(offset)); 99 if( !offset.isDeprecated() ) { 100 DeprecateOffsetAction action = new DeprecateOffsetAction(offset); 101 action.setListener(new DeprecateOffsetListener(offset)); 102 popupMenu.add(action); 103 } 91 104 button.setComponentPopupMenu(popupMenu); 92 105 buttonPanel.add(button); … … 110 123 return filteredOffsets; 111 124 } 125 126 public void zoomChanged() { 127 for( Component c : buttonPanel.getComponents() ) { 128 if( c instanceof OffsetDialogButton ) { 129 ((OffsetDialogButton)c).updateLocation(); 130 } 131 } 132 } 112 133 113 134 public ImageryOffsetBase showDialog() { … … 118 139 } 119 140 141 public void applyOffset() { 142 if( selectedOffset instanceof ImageryOffset ) { 143 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 144 ImageryOffsetTools.applyLayerOffset(layer, (ImageryOffset)selectedOffset); 145 Main.map.repaint(); 146 if( !Main.pref.getBoolean("iodb.offset.message", false) ) { 147 JOptionPane.showMessageDialog(Main.parent, 148 tr("The topmost imagery layer has been shifted to presumably match\n" 149 + "OSM data in the area. Please check that the offset is still valid\n" 150 + "by downloading GPS tracks and comparing them and OSM data to the imagery."), 151 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE); 152 Main.pref.put("iodb.offset.message", true); 153 } 154 } else if( selectedOffset instanceof CalibrationObject ) { 155 CalibrationLayer clayer = new CalibrationLayer((CalibrationObject)selectedOffset); 156 Main.map.mapView.addLayer(clayer); 157 clayer.panToCenter(); 158 if( !Main.pref.getBoolean("iodb.calibration.message", false) ) { 159 JOptionPane.showMessageDialog(Main.parent, 160 tr("A layer has been added with a calibration geometry. Hide data layers,\n" 161 + "find the corresponding feature on the imagery layer and move it accordingly."), 162 ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE); 163 Main.pref.put("iodb.calibration.message", true); 164 } 165 } 166 } 167 120 168 public void actionPerformed( ActionEvent e ) { 121 169 if( e.getSource() instanceof OffsetDialogButton ) { … … 123 171 } else 124 172 selectedOffset = null; 173 NavigatableComponent.removeZoomChangeListener(this); 125 174 setVisible(false); 175 if( !MODAL && selectedOffset != null ) 176 applyOffset(); 177 } 178 179 private class DeprecateOffsetListener implements QuerySuccessListener { 180 ImageryOffsetBase offset; 181 182 public DeprecateOffsetListener( ImageryOffsetBase offset ) { 183 this.offset = offset; 184 } 185 186 public void queryPassed() { 187 offset.setDeprecated(new Date(), JosmUserIdentityManager.getInstance().getUserName(), ""); 188 updateButtonPanel(); 189 } 190 } 191 192 class HelpAction extends AbstractAction { 193 194 public HelpAction() { 195 super(tr("Help")); 196 putValue(SMALL_ICON, ImageProvider.get("help")); 197 } 198 199 public void actionPerformed( ActionEvent e ) { 200 String base = "http://wiki.openstreetmap.org/wiki/"; 201 String page = "Imagery_Offset_Database"; 202 String lang = "RU:"; // todo: determine it 203 OpenBrowser.displayUrl(base + lang + page); 204 } 126 205 } 127 206 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
r29379 r29380 24 24 public OffsetDialogButton( ImageryOffsetBase offset ) { 25 25 super(); 26 this.offset = offset; 26 27 setMinimumSize(new Dimension(500, 10)); 27 28 setMaximumSize(new Dimension(500, 150)); 28 setText("<html>" 29 + Math.round(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) + " m: " 30 + offset.getDescription() + "</html>"); 29 setRelevantText(); 31 30 setIcon(new OffsetIcon(offset)); 32 this.offset = offset;33 31 34 32 offsetLength = offset instanceof ImageryOffset ? getLengthAndDirection((ImageryOffset)offset)[0] : 0.0; 35 33 // todo: layout, info, map distance and direction 34 } 35 36 /** 37 * Update text on the button. This method is to be deleted by release. 38 */ 39 public void setRelevantText() { 40 setText("<html>" 41 + ImageryOffsetTools.formatDistance(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) 42 + ": " + offset.getDescription() + "</html>"); 36 43 } 37 44 … … 46 53 size.height = 70; 47 54 return size; 55 } 56 57 /** 58 * Update arrow for the offset location. 59 */ 60 public void updateLocation() { 61 // map was moved, update arrow. 62 setRelevantText(); 48 63 } 49 64 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetInfoAction.java
r29379 r29380 36 36 if( offset instanceof ImageryOffset ) { 37 37 double[] ld = ImageryOffsetTools.getLengthAndDirection((ImageryOffset)offset); 38 sb.append(ld[0] < 1e- 3? tr("An imagery offset of 0 mm") : tr("An imagery offset of {0} to {1}",38 sb.append(ld[0] < 1e-2 ? tr("An imagery offset of 0 mm") : tr("An imagery offset of {0} to {1}", 39 39 ImageryOffsetTools.formatDistance(ld[0]), explainDirection(ld[1]))).append('\n'); 40 40 sb.append("Imagery ID: ").append(((ImageryOffset)offset).getImagery()).append('\n'); … … 44 44 45 45 double dist = ImageryOffsetTools.getMapCenter().greatCircleDistance(offset.getPosition()); 46 double heading = dist < 1 ? 0.0 : ImageryOffsetTools.getMapCenter().heading(offset.getPosition());47 sb.append(dist < 10 ? tr("Determined right here") : tr("Determined at a point {0} to the {1}",46 double heading = dist < 10 ? 0.0 : ImageryOffsetTools.getMapCenter().heading(offset.getPosition()); 47 sb.append(dist < 50 ? tr("Determined right here") : tr("Determined at a point {0} to the {1}", 48 48 ImageryOffsetTools.formatDistance(dist), explainDirection(heading))); 49 49 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/SimpleOffsetQueryTask.java
r29372 r29380 22 22 private String title; 23 23 protected boolean cancelled; 24 private QuerySuccessListener listener; 24 25 25 26 public SimpleOffsetQueryTask( String query, String title ) { … … 32 33 public void setQuery( String query ) { 33 34 this.query = query; 35 } 36 37 public void setListener( QuerySuccessListener listener ) { 38 this.listener = listener; 39 } 40 41 public void removeListener() { 42 this.listener = null; 34 43 } 35 44 … … 50 59 try { 51 60 URL url = new URL(ImageryOffsetTools.getServerURL() + query); 52 System.out.println("url=" + url); 61 System.out.println("url=" + url); // todo: remove in release 53 62 HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 54 63 connection.connect(); … … 79 88 if( errorMessage != null ) { 80 89 JOptionPane.showMessageDialog(Main.parent, errorMessage, tr("Imagery Offset"), JOptionPane.ERROR_MESSAGE); 90 } else if( listener != null ) { 91 listener.queryPassed(); 81 92 } 82 93 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/StoreImageryOffsetAction.java
r29377 r29380 132 132 if( ImageryOffsetTools.getTopImageryLayer() == null ) 133 133 state = false; 134 if( getCurrentDataSet() == null ) 135 state = false; 134 136 setEnabled(state); 135 137 }
Note:
See TracChangeset
for help on using the changeset viewer.