- Timestamp:
- 2009-10-27T18:49:09+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandler.java
r2327 r2332 114 114 Main.parent, 115 115 sb.toString(), 116 tr("Errors during Download"),116 tr("Errors during download"), 117 117 JOptionPane.ERROR_MESSAGE); 118 118 return; -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r2327 r2332 25 25 private static DecimalFormat cDdFormatter = new DecimalFormat("###0.0000"); 26 26 27 /** 28 * Replies true if lat is in the range [-90,90] 29 * 30 * @param lat the latitude 31 * @return true if lat is in the range [-90,90] 32 */ 33 public static boolean isValidLat(double lat) { 34 return lat >= -90d && lat <= 90d; 35 } 27 36 37 /** 38 * Replies true if lon is in the range [-180,180] 39 * 40 * @param lon the longitude 41 * @return true if lon is in the range [-180,180] 42 */ 43 public static boolean isValidLon(double lon) { 44 return lon >= -180d && lon <= 180d; 45 } 46 28 47 public static String dms(double pCoordinate) { 29 48 -
trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java
r2327 r2332 18 18 19 19 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.data.Bounds; 20 21 import org.openstreetmap.josm.data.Preferences; 21 22 import org.openstreetmap.josm.gui.BookmarkList; … … 100 101 } 101 102 102 public void boundingBoxChanged(DownloadDialog gui) { 103 tempBookmark = new Preferences.Bookmark(gui.getSelectedDownloadArea()); 103 104 public void setDownloadArea(Bounds area) { 105 if (area == null) return; 106 tempBookmark = new Preferences.Bookmark(area); 104 107 bookmarks.clearSelection(); 105 108 } 106 107 108 109 } -
trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
r2327 r2332 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Color; 6 7 import java.awt.Dimension; 7 8 import java.awt.GridBagLayout; 9 import java.awt.event.ActionEvent; 10 import java.awt.event.ActionListener; 8 11 import java.awt.event.FocusAdapter; 9 12 import java.awt.event.FocusEvent; 10 import java.awt.event.FocusListener; 11 13 14 import javax.swing.BorderFactory; 12 15 import javax.swing.JLabel; 16 import javax.swing.JOptionPane; 13 17 import javax.swing.JPanel; 14 18 import javax.swing.JTextArea; 15 19 import javax.swing.JTextField; 16 import javax.swing.SwingUtilities; 20 import javax.swing.UIManager; 21 import javax.swing.border.Border; 17 22 import javax.swing.event.DocumentEvent; 18 23 import javax.swing.event.DocumentListener; 19 24 import javax.swing.text.JTextComponent; 25 26 import org.openstreetmap.josm.Main; 20 27 import org.openstreetmap.josm.data.Bounds; 21 28 import org.openstreetmap.josm.data.coor.LatLon; … … 33 40 public class BoundingBoxSelection implements DownloadSelection { 34 41 35 private JTextField[] latlon = new JTextField[] { 36 new JTextField(11), 37 new JTextField(11), 38 new JTextField(11), 39 new JTextField(11) }; 42 private JTextField[] latlon = null; 40 43 final JTextArea osmUrl = new JTextArea(); 41 44 final JTextArea showUrl = new JTextArea(); 42 45 46 47 protected void buildDownloadAreaInputFields() { 48 latlon = new JTextField[4]; 49 for(int i=0; i< 4; i++) { 50 latlon[i] = new JTextField(11); 51 latlon[i].setMinimumSize(new Dimension(100,new JTextField().getMinimumSize().height)); 52 latlon[i].addFocusListener(new SelectAllOnFocusHandler(latlon[i])); 53 } 54 LatValueChecker latChecker = new LatValueChecker(latlon[0]); 55 latlon[0].addFocusListener(latChecker); 56 latlon[0].addActionListener(latChecker); 57 58 latChecker = new LatValueChecker(latlon[3]); 59 latlon[2].addFocusListener(latChecker); 60 latlon[2].addActionListener(latChecker); 61 62 LonValueChecker lonChecker = new LonValueChecker(latlon[1]); 63 latlon[1].addFocusListener(lonChecker); 64 latlon[1].addActionListener(lonChecker); 65 66 lonChecker = new LonValueChecker(latlon[3]); 67 latlon[3].addFocusListener(lonChecker); 68 latlon[3].addActionListener(lonChecker); 69 70 } 71 43 72 public void addGui(final DownloadDialog gui) { 44 73 buildDownloadAreaInputFields(); 45 74 JPanel dlg = new JPanel(new GridBagLayout()); 46 47 final FocusListener dialogUpdater = new FocusAdapter() {48 @Override public void focusLost(FocusEvent e) {49 SwingUtilities.invokeLater(new Runnable() {50 public void run() {51 try {52 double minlat = Double.parseDouble(latlon[0].getText());53 double minlon = Double.parseDouble(latlon[1].getText());54 double maxlat = Double.parseDouble(latlon[2].getText());55 double maxlon = Double.parseDouble(latlon[3].getText());56 Bounds b = new Bounds(minlat,minlon, maxlat,maxlon);57 if (gui.getSelectedDownloadArea() == null) return;58 if (gui.getSelectedDownloadArea() == null || !gui.getSelectedDownloadArea().equals(new Bounds(minlat,minlon, maxlat,maxlon))) {59 gui.boundingBoxChanged(b, BoundingBoxSelection.this);60 }61 } catch (NumberFormatException x) {62 // ignore63 }64 updateUrl(gui);65 }66 });67 }68 };69 70 for (JTextField f : latlon) {71 f.setMinimumSize(new Dimension(100,new JTextField().getMinimumSize().height));72 f.addFocusListener(dialogUpdater);73 }74 75 75 76 class osmUrlRefresher implements DocumentListener { … … 84 85 // windows look+feel but not for others. needs invokeLater to avoid strange 85 86 // side effects that will cancel out the newly made selection otherwise. 86 osmUrl.addFocusListener(new FocusAdapter() { 87 @Override public void focusGained(FocusEvent e) { 88 SwingUtilities.invokeLater(new Runnable() { 89 public void run() { 90 osmUrl.selectAll(); 91 } 92 }); 93 } 94 }); 87 osmUrl.addFocusListener(new SelectAllOnFocusHandler(osmUrl)); 95 88 osmUrl.setLineWrap(true); 96 89 osmUrl.setBorder(latlon[0].getBorder()); … … 110 103 showUrl.setEditable(false); 111 104 showUrl.setBackground(dlg.getBackground()); 112 showUrl.addFocusListener(new FocusAdapter(){ 113 @Override 114 public void focusGained(FocusEvent e) { 115 showUrl.selectAll(); 116 } 117 }); 105 showUrl.addFocusListener(new SelectAllOnFocusHandler(showUrl)); 118 106 119 107 gui.addDownloadAreaSelector(dlg, tr("Bounding Box")); 120 108 } 121 109 122 /** 123 * Called when bounding box is changed by one of the other download dialog tabs. 124 */ 125 public void boundingBoxChanged(DownloadDialog gui) { 126 updateBboxFields(gui); 127 updateUrl(gui); 110 111 public void setDownloadArea(Bounds area) { 112 updateBboxFields(area); 113 updateUrl(area); 114 } 115 116 public Bounds getDownloadArea() { 117 double[] values = new double[4]; 118 for (int i=0; i < 4; i++) { 119 try { 120 values[i] = Double.parseDouble(latlon[i].getText()); 121 } catch(NumberFormatException x) { 122 return null; 123 } 124 } 125 if (!LatLon.isValidLat(values[0]) || !LatLon.isValidLon(values[1])) 126 return null; 127 if (!LatLon.isValidLat(values[2]) || !LatLon.isValidLon(values[3])) 128 return null; 129 return new Bounds(values); 128 130 } 129 131 … … 132 134 if(b == null) return false; 133 135 gui.boundingBoxChanged(b,BoundingBoxSelection.this); 134 updateBboxFields( gui);135 updateUrl( gui);136 updateBboxFields(b); 137 updateUrl(b); 136 138 return true; 137 139 } 138 140 139 private void updateBboxFields(DownloadDialog gui) { 140 Bounds b = gui.getSelectedDownloadArea(); 141 if (b == null) return; 142 latlon[0].setText(Double.toString(b.getMin().lat())); 143 latlon[1].setText(Double.toString(b.getMin().lon())); 144 latlon[2].setText(Double.toString(b.getMax().lat())); 145 latlon[3].setText(Double.toString(b.getMax().lon())); 141 private void updateBboxFields(Bounds area) { 142 if (area == null) return; 143 latlon[0].setText(Double.toString(area.getMin().lat())); 144 latlon[1].setText(Double.toString(area.getMin().lon())); 145 latlon[2].setText(Double.toString(area.getMax().lat())); 146 latlon[3].setText(Double.toString(area.getMax().lon())); 146 147 for (JTextField f : latlon) { 147 148 f.setCaretPosition(0); … … 149 150 } 150 151 151 private void updateUrl(DownloadDialog gui) { 152 if (gui.getSelectedDownloadArea() == null) return; 153 showUrl.setText(OsmUrlToBounds.getURL(gui.getSelectedDownloadArea())); 152 private void updateUrl(Bounds area) { 153 if (area == null) return; 154 showUrl.setText(OsmUrlToBounds.getURL(area)); 155 } 156 157 158 class LatValueChecker extends FocusAdapter implements ActionListener{ 159 private JTextField tfLatValue; 160 161 private Border errorBorder = BorderFactory.createLineBorder(Color.RED, 1); 162 protected void setErrorMessage(String msg) { 163 if (msg != null) { 164 tfLatValue.setBorder(errorBorder); 165 tfLatValue.setToolTipText(msg); 166 } else { 167 tfLatValue.setBorder(UIManager.getBorder("TextField.border")); 168 tfLatValue.setToolTipText(""); 169 } 170 } 171 172 public LatValueChecker(JTextField tfLatValue) { 173 this.tfLatValue = tfLatValue; 174 } 175 176 protected void check() { 177 double value = 0; 178 try { 179 value = Double.parseDouble(tfLatValue.getText()); 180 } catch(NumberFormatException ex) { 181 setErrorMessage(tr("The string ''{0}'' isn''t a valid double value.", tfLatValue.getText())); 182 return; 183 } 184 if (!LatLon.isValidLat(value)) { 185 JOptionPane.showMessageDialog( 186 Main.parent, 187 tr("Value for latitude in range [-90,90] required.", tfLatValue.getText()), 188 tr("Error"), 189 JOptionPane.ERROR_MESSAGE 190 ); 191 setErrorMessage(tr("Value for latitude in range [-90,90] required.", tfLatValue.getText())); 192 return; 193 } 194 } 195 196 @Override 197 public void focusLost(FocusEvent e) { 198 check(); 199 } 200 201 public void actionPerformed(ActionEvent e) { 202 check(); 203 } 204 } 205 206 class LonValueChecker extends FocusAdapter implements ActionListener { 207 private JTextField tfLonValue; 208 private Border errorBorder = BorderFactory.createLineBorder(Color.RED, 1); 209 protected void setErrorMessage(String msg) { 210 if (msg != null) { 211 tfLonValue.setBorder(errorBorder); 212 tfLonValue.setToolTipText(msg); 213 } else { 214 tfLonValue.setBorder(UIManager.getBorder("TextField.border")); 215 tfLonValue.setToolTipText(""); 216 } 217 } 218 219 public LonValueChecker(JTextField tfLonValue) { 220 this.tfLonValue = tfLonValue; 221 } 222 223 protected void check() { 224 double value = 0; 225 try { 226 value = Double.parseDouble(tfLonValue.getText()); 227 } catch(NumberFormatException ex) { 228 setErrorMessage(tr("The string ''{0}'' isn''t a valid double value.", tfLonValue.getText())); 229 return; 230 } 231 if (!LatLon.isValidLon(value)) { 232 setErrorMessage(tr("Value for longitude in range [-180,180] required.", tfLonValue.getText())); 233 return; 234 } 235 } 236 237 @Override 238 public void focusLost(FocusEvent e) { 239 check(); 240 } 241 242 public void actionPerformed(ActionEvent e) { 243 check(); 244 } 245 } 246 247 class SelectAllOnFocusHandler extends FocusAdapter { 248 private JTextComponent tfTarget; 249 public SelectAllOnFocusHandler(JTextComponent tfTarget) { 250 this.tfTarget = tfTarget; 251 } 252 253 @Override 254 public void focusGained(FocusEvent e) { 255 tfTarget.selectAll(); 256 } 154 257 } 155 258 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r2331 r2332 195 195 for (DownloadSelection s : downloadSelections) { 196 196 if (s != eventSource) { 197 s. boundingBoxChanged(this);197 s.setDownloadArea(currentBounds); 198 198 } 199 199 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadSelection.java
r1169 r2332 2 2 package org.openstreetmap.josm.gui.download; 3 3 4 import org.openstreetmap.josm.data.Bounds; 4 5 5 public interface DownloadSelection { 6 7 public interface DownloadSelection { 8 6 9 /** 7 10 * Add the GUI elements to the dialog. … … 9 12 void addGui(DownloadDialog gui); 10 13 14 11 15 /** 12 * Update or clear display when a selection is made through another 13 * DownloadSelection object 16 * Sets the current download area. The area may be null to clear 17 * the current download area. 18 * 19 * @param are the current download area 14 20 */ 15 void boundingBoxChanged(DownloadDialog gui); 21 public void setDownloadArea(Bounds area); 22 } 16 23 17 } -
trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java
r2331 r2332 310 310 ) 311 311 ); 312 updatingSelf = true;313 312 gui.boundingBoxChanged(b,null); 314 updatingSelf = false;315 313 } 316 314 } … … 332 330 } 333 331 334 // if bounding box selected on other tab, de-select item 335 public void boundingBoxChanged(DownloadDialog gui) { 336 if (!updatingSelf) { 337 searchResultDisplay.clearSelection(); 338 } 332 public void setDownloadArea(Bounds area) { 333 searchResultDisplay.clearSelection(); 339 334 } 340 335 } -
trunk/src/org/openstreetmap/josm/gui/download/SlippyMapChooser.java
r2329 r2332 166 166 } 167 167 168 public void boundingBoxChanged(DownloadDialog gui) { 169 Bounds b = gui.getSelectedDownloadArea(); 170 if (b == null) 168 public void setDownloadArea(Bounds area) { 169 if (area == null) 171 170 return; 172 171 173 172 // test if a bounding box has been set set 174 if ( b.getMin().lat() == 0.0 &&b.getMin().lon() == 0.0 &&b.getMax().lat() == 0.0 &&b.getMax().lon() == 0.0)173 if (area.getMin().lat() == 0.0 && area.getMin().lon() == 0.0 && area.getMax().lat() == 0.0 && area.getMax().lon() == 0.0) 175 174 return; 176 175 177 int y1 = OsmMercator.LatToY( b.getMin().lat(), MAX_ZOOM);178 int y2 = OsmMercator.LatToY( b.getMax().lat(), MAX_ZOOM);179 int x1 = OsmMercator.LonToX( b.getMin().lon(), MAX_ZOOM);180 int x2 = OsmMercator.LonToX( b.getMax().lon(), MAX_ZOOM);176 int y1 = OsmMercator.LatToY(area.getMin().lat(), MAX_ZOOM); 177 int y2 = OsmMercator.LatToY(area.getMax().lat(), MAX_ZOOM); 178 int x1 = OsmMercator.LonToX(area.getMin().lon(), MAX_ZOOM); 179 int x2 = OsmMercator.LonToX(area.getMax().lon(), MAX_ZOOM); 181 180 182 181 iSelectionRectStart = new Point(Math.min(x1, x2), Math.min(y1, y2)); … … 184 183 185 184 // calc the screen coordinates for the new selection rectangle 186 MapMarkerDot xmin_ymin = new MapMarkerDot( b.getMin().lat(),b.getMin().lon());187 MapMarkerDot xmax_ymax = new MapMarkerDot( b.getMax().lat(),b.getMax().lon());185 MapMarkerDot xmin_ymin = new MapMarkerDot(area.getMin().lat(), area.getMin().lon()); 186 MapMarkerDot xmax_ymax = new MapMarkerDot(area.getMax().lat(), area.getMax().lon()); 188 187 189 188 Vector<MapMarker> marker = new Vector<MapMarker>(2); -
trunk/src/org/openstreetmap/josm/gui/download/TileSelection.java
r2327 r2332 87 87 } 88 88 89 /** 90 * Called when bounding box is changed by one of the other download dialog tabs. 91 */ 92 public void boundingBoxChanged(DownloadDialog gui) { 93 updateBboxFields(gui); 94 } 95 96 private void updateBboxFields(DownloadDialog gui) { 89 public void setDownloadArea(Bounds area) { 90 if (area == null) 91 return; 97 92 int z = ((Integer) tileZ.getValue()).intValue(); 98 Bounds b = gui.getSelectedDownloadArea(); 99 if (b == null) 100 return; 101 tileX0.setText(Integer.toString(lonToTileX(z, b.getMin().lon()))); 102 tileX1.setText(Integer.toString(lonToTileX(z, b.getMax().lon()-.00001))); 103 tileY0.setText(Integer.toString(latToTileY(z, b.getMax().lat()-.00001))); 104 tileY1.setText(Integer.toString(latToTileY(z, b.getMin().lat()))); 93 tileX0.setText(Integer.toString(lonToTileX(z, area.getMin().lon()))); 94 tileX1.setText(Integer.toString(lonToTileX(z, area.getMax().lon()-.00001))); 95 tileY0.setText(Integer.toString(latToTileY(z, area.getMax().lat()-.00001))); 96 tileY1.setText(Integer.toString(latToTileY(z, area.getMin().lat()))); 105 97 } 106 98
Note:
See TracChangeset
for help on using the changeset viewer.