Changeset 1307 in josm
- Timestamp:
- 2009-01-20T09:38:04+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r1286 r1307 50 50 import org.openstreetmap.josm.gui.PleaseWaitDialog; 51 51 import org.openstreetmap.josm.gui.SplashScreen; 52 import org.openstreetmap.josm.gui.download.BoundingBoxSelection;53 52 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 54 53 import org.openstreetmap.josm.gui.layer.Layer; … … 61 60 import org.openstreetmap.josm.plugins.PluginProxy; 62 61 import org.openstreetmap.josm.tools.ImageProvider; 62 import org.openstreetmap.josm.tools.OsmUrlToBounds; 63 63 import org.openstreetmap.josm.tools.PlatformHook; 64 64 import org.openstreetmap.josm.tools.PlatformHookUnixoid; … … 494 494 private static void downloadFromParamString(final boolean rawGps, String s) { 495 495 if (s.startsWith("http:")) { 496 final Bounds b = BoundingBoxSelection.osmurl2bounds(s);496 final Bounds b = OsmUrlToBounds.parse(s); 497 497 if (b == null) 498 498 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed URL: \"{0}\"", s)); -
trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
r1285 r1307 24 24 import org.openstreetmap.josm.data.coor.LatLon; 25 25 import org.openstreetmap.josm.tools.GBC; 26 import org.openstreetmap.josm.tools.OsmUrlToBounds; 27 26 28 /** 27 29 * Bounding box selector. … … 41 43 final JTextArea osmUrl = new JTextArea(); 42 44 final JTextArea showUrl = new JTextArea(); 43 String noteUrl = tr("You can paste an URL here to download the area.");44 45 45 46 public void addGui(final DownloadDialog gui) { 46 47 47 48 JPanel dlg = new JPanel(new GridBagLayout()); 48 osmUrl.setText(noteUrl);49 49 50 50 final FocusListener dialogUpdater = new FocusAdapter() { … … 80 80 public void removeUpdate(DocumentEvent e) { dowork(); } 81 81 private void dowork() { 82 Bounds b = osmurl2bounds(osmUrl.getText());82 Bounds b = OsmUrlToBounds.parse(osmUrl.getText()); 83 83 if (b != null) { 84 84 gui.minlon = b.min.lon(); … … 119 119 dlg.add(latlon[3], GBC.eol()); 120 120 121 dlg.add(new JLabel(tr("URL from www.openstreetmap.org ")), GBC.eol().insets(10,20,5,0));121 dlg.add(new JLabel(tr("URL from www.openstreetmap.org (you can paste an URL here to download the area)")), GBC.eol().insets(10,20,5,0)); 122 122 dlg.add(osmUrl, GBC.eop().insets(10,0,5,0).fill()); 123 123 dlg.add(showUrl, GBC.eop().insets(10,0,5,5)); … … 173 173 showUrl.setText("http://www.openstreetmap.org/?lat="+lat+"&lon="+lon+"&zoom="+zoom); 174 174 } 175 176 public static Bounds osmurl2bounds(String url) {177 int i = url.indexOf('?');178 if (i == -1)179 return null;180 String[] args = url.substring(i+1).split("&");181 HashMap<String, String> map = new HashMap<String, String>();182 for (String arg : args) {183 int eq = arg.indexOf('=');184 if (eq != -1) {185 map.put(arg.substring(0, eq), arg.substring(eq + 1));186 }187 }188 189 Bounds b = null;190 try {191 if (map.containsKey("bbox")) {192 String bbox[] = map.get("bbox").split(",");193 b = new Bounds(194 new LatLon(Double.parseDouble(bbox[1]), Double.parseDouble(bbox[0])),195 new LatLon(Double.parseDouble(bbox[3]), Double.parseDouble(bbox[2])));196 197 } else {198 double size = 180.0 / Math.pow(2, Integer.parseInt(map.get("zoom")));199 b = new Bounds(200 new LatLon(parseDouble(map, "lat") - size/2, parseDouble(map, "lon") - size),201 new LatLon(parseDouble(map, "lat") + size/2, parseDouble(map, "lon") + size));202 }203 } catch (NumberFormatException x) {204 } catch (NullPointerException x) {205 }206 return b;207 }208 209 private static double parseDouble(HashMap<String, String> map, String key) {210 if (map.containsKey(key))211 return Double.parseDouble(map.get(key));212 return Double.parseDouble(map.get("m"+key));213 }214 175 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r1245 r1307 5 5 6 6 import java.awt.Color; 7 import java.awt.datatransfer.DataFlavor; 8 import java.awt.datatransfer.Transferable; 9 import java.awt.event.ActionEvent; 10 import java.awt.event.InputEvent; 11 import java.awt.event.KeyEvent; 7 12 import java.awt.Font; 8 13 import java.awt.GridBagLayout; 14 import java.awt.Toolkit; 9 15 import java.util.ArrayList; 10 16 import java.util.List; 11 17 18 import javax.swing.AbstractAction; 12 19 import javax.swing.JCheckBox; 13 20 import javax.swing.JLabel; … … 15 22 import javax.swing.JPanel; 16 23 import javax.swing.JTabbedPane; 24 import javax.swing.KeyStroke; 17 25 18 26 import org.openstreetmap.josm.Main; … … 20 28 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 21 29 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 30 import org.openstreetmap.josm.data.Bounds; 22 31 import org.openstreetmap.josm.gui.MapView; 23 32 import org.openstreetmap.josm.plugins.PluginProxy; 24 33 import org.openstreetmap.josm.tools.GBC; 34 import org.openstreetmap.josm.tools.OsmUrlToBounds; 25 35 26 36 /** … … 146 156 sizeCheck.setFont(labelFont.deriveFont(Font.PLAIN, labelFont.getSize())); 147 157 add(sizeCheck, GBC.eop().insets(0,5,5,10)); 148 } 158 159 getInputMap(WHEN_IN_FOCUSED_WINDOW).put( 160 KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), "checkClipboardContents"); 161 162 getActionMap().put("checkClipboardContents", new AbstractAction() { 163 public void actionPerformed(ActionEvent e) { 164 checkClipboardContents(); 165 } 166 }); 167 } 168 169 private void checkClipboardContents() { 170 String result = ""; 171 Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); 172 173 if(contents == null || !contents.isDataFlavorSupported(DataFlavor.stringFlavor)) 174 return; 175 176 try { 177 result = (String)contents.getTransferData(DataFlavor.stringFlavor); 178 } 179 catch(Exception ex) { 180 return; 181 } 182 183 Bounds b = OsmUrlToBounds.parse(result); 184 if (b != null) { 185 minlon = b.min.lon(); 186 minlat = b.min.lat(); 187 maxlon = b.max.lon(); 188 maxlat = b.max.lat(); 189 boundingBoxChanged(null); 190 } 191 } 149 192 150 193 private void updateSizeCheck() {
Note:
See TracChangeset
for help on using the changeset viewer.