Changeset 34 in josm
- Timestamp:
- 2005-12-22T23:54:50+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/DownloadAction.java
r33 r34 61 61 dlg.add(new JLabel("Bounding box"), GBC.eol()); 62 62 63 dlg.add(new JLabel("min lon"), GBC.std().insets(10,0,5,0)); 64 dlg.add(latlon[0], GBC.std()); 63 65 dlg.add(new JLabel("min lat"), GBC.std().insets(10,0,5,0)); 64 dlg.add(latlon[0], GBC.std()); 66 dlg.add(latlon[1], GBC.eol()); 67 dlg.add(new JLabel("max lon"), GBC.std().insets(10,0,5,0)); 68 dlg.add(latlon[2], GBC.std()); 65 69 dlg.add(new JLabel("max lat"), GBC.std().insets(10,0,5,0)); 66 dlg.add(latlon[1], GBC.eol());67 dlg.add(new JLabel("min lon"), GBC.std().insets(10,0,5,0));68 dlg.add(latlon[2], GBC.std());69 dlg.add(new JLabel("max lon"), GBC.std().insets(10,0,5,0));70 70 dlg.add(latlon[3], GBC.eop()); 71 71 … … 144 144 return; 145 145 } 146 OsmServerReader osmReader = new OsmServerReader(Main.pref.osmDataServer, 147 b.latlon[0], b.latlon[1], b.latlon[2], b.latlon[3]); 146 OsmServerReader osmReader = new OsmServerReader(b.latlon[0], b.latlon[1], b.latlon[2], b.latlon[3]); 148 147 try { 149 148 String name = latlon[0].getText()+" "+latlon[1].getText()+" x "+ -
src/org/openstreetmap/josm/actions/UploadAction.java
r33 r34 15 15 import javax.swing.KeyStroke; 16 16 17 import org.jdom.JDOMException; 17 18 import org.openstreetmap.josm.Main; 18 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 20 import org.openstreetmap.josm.gui.GBC; 20 21 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 22 import org.openstreetmap.josm.io.OsmServerWriter; 21 23 22 24 /** … … 61 63 return; 62 64 63 JOptionPane.showMessageDialog(Main.main, "not implemented yet."); 65 OsmServerWriter server = new OsmServerWriter(); 66 try { 67 Collection<OsmPrimitive> all = new LinkedList<OsmPrimitive>(); 68 all.addAll(add); 69 all.addAll(update); 70 all.addAll(delete); 71 server.uploadOsm(all); 72 } catch (JDOMException x) { 73 x.printStackTrace(); 74 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 75 } 64 76 } 65 77 -
src/org/openstreetmap/josm/command/MoveCommand.java
r32 r34 6 6 import java.util.List; 7 7 8 import org.openstreetmap.josm.Main; 8 9 import org.openstreetmap.josm.data.osm.Node; 9 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 38 39 class OldState 39 40 { 40 double x,y ;41 double x,y,lat,lon; 41 42 boolean modified; 42 43 } … … 57 58 os.x = n.coor.x; 58 59 os.y = n.coor.y; 60 os.lat = n.coor.lat; 61 os.lon = n.coor.lon; 59 62 os.modified = n.modified; 60 63 oldState.add(os); … … 85 88 n.coor.x += x; 86 89 n.coor.y += y; 90 Main.pref.getProjection().xy2latlon(n.coor); 87 91 } 88 92 this.x += x; … … 94 98 n.coor.x += x; 95 99 n.coor.y += y; 100 Main.pref.getProjection().xy2latlon(n.coor); 96 101 n.modified = true; 97 102 } … … 104 109 n.coor.x = os.x; 105 110 n.coor.y = os.y; 111 n.coor.lat = os.lat; 112 n.coor.lon = os.lon; 106 113 n.modified = os.modified; 107 114 } -
src/org/openstreetmap/josm/io/OsmServerReader.java
r31 r34 10 10 11 11 import org.jdom.JDOMException; 12 import org.openstreetmap.josm.Main; 12 13 import org.openstreetmap.josm.data.GeoPoint; 13 14 import org.openstreetmap.josm.data.osm.DataSet; … … 21 22 22 23 /** 23 * The url stringof the desired map data.24 * The boundings of the desired map data. 24 25 */ 25 private String urlStr;26 26 private final double lat1; 27 27 private final double lon1; … … 32 32 * Construct the reader and store the information for attaching 33 33 */ 34 public OsmServerReader(String server, 35 double lat1, double lon1, double lat2, double lon2) { 34 public OsmServerReader(double lat1, double lon1, double lat2, double lon2) { 36 35 this.lon2 = lon2; 37 36 this.lat2 = lat2; 38 37 this.lon1 = lon1; 39 38 this.lat1 = lat1; 40 urlStr = server.endsWith("/") ? server : server+"/";41 39 } 42 40 … … 49 47 */ 50 48 public Collection<Collection<GeoPoint>> parseRawGps() throws IOException, JDOMException { 51 String url = urlStr+"trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=";49 String url = Main.pref.osmDataServer+"/trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page="; 52 50 Collection<Collection<GeoPoint>> data = new LinkedList<Collection<GeoPoint>>(); 53 51 Collection<GeoPoint> list = new LinkedList<GeoPoint>(); … … 80 78 */ 81 79 public DataSet parseOsm() throws JDOMException, IOException { 82 Reader r = getReader( urlStr+"map?bbox="+lon1+","+lat1+","+lon2+","+lat2);80 Reader r = getReader(Main.pref.osmDataServer+"/map?bbox="+lon1+","+lat1+","+lon2+","+lat2); 83 81 if (r == null) 84 82 return null; … … 95 93 private Reader getReader(String urlStr) throws IOException { 96 94 initAuthentication(); 95 System.out.println(urlStr); 97 96 URL url = new URL(urlStr); 98 97 HttpURLConnection con = (HttpURLConnection)url.openConnection(); -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r33 r34 1 1 package org.openstreetmap.josm.io; 2 2 3 import java.io.BufferedReader; 3 4 import java.io.IOException; 5 import java.io.InputStream; 6 import java.io.InputStreamReader; 7 import java.io.OutputStream; 8 import java.net.HttpURLConnection; 9 import java.net.URL; 10 import java.util.Collection; 4 11 12 import org.jdom.Document; 13 import org.jdom.Element; 5 14 import org.jdom.JDOMException; 6 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.jdom.output.Format; 16 import org.jdom.output.XMLOutputter; 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.osm.Key; 19 import org.openstreetmap.josm.data.osm.LineSegment; 20 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.Track; 23 import org.openstreetmap.josm.data.osm.visitor.OsmXmlVisitor; 24 import org.openstreetmap.josm.data.osm.visitor.Visitor; 7 25 8 26 /** … … 15 33 * - All remaining objects with modified flag set are updated. 16 34 * 35 * This class implements visitor and will perform the correct upload action 36 * on the visited element. 37 * 17 38 * @author imi 18 39 */ 19 public class OsmServerWriter extends OsmConnection {40 public class OsmServerWriter extends OsmConnection implements Visitor { 20 41 21 22 42 /** 23 43 * Send the dataset to the server. Ask the user first and does nothing if 24 44 * he does not want to send the data. 25 45 */ 26 public void uploadOsm( DataSet dataSet) throws IOException,JDOMException {46 public void uploadOsm(Collection<OsmPrimitive> list) throws JDOMException { 27 47 initAuthentication(); 48 49 try { 50 // for (OsmPrimitive osm : list) 51 // osm.visit(this); 52 } catch (RuntimeException e) { 53 throw new JDOMException("An error occoured: ", e); 54 } 55 } 56 57 /** 58 * Upload a single node. 59 */ 60 @SuppressWarnings("unchecked") 61 public void visit(Node n) { 62 if (n.id == 0) { 63 sendRequest("PUT", "newnode", n); 64 } else if (Main.main.ds.deleted.contains(n)) { 65 sendRequest("DELETE", "node/"+n.id, n); 66 } else { 67 sendRequest("PUT", "node/"+n.id, n); 68 } 69 } 70 71 public void visit(LineSegment ls) { 72 } 73 74 public void visit(Track t) { 75 } 76 77 public void visit(Key k) { 78 } 79 80 /** 81 * Read an long from the input stream and return it. 82 */ 83 private long readId(InputStream inputStream) throws IOException { 84 BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); 85 String s = in.readLine(); 86 if (s == null) 87 return 0; 88 try { 89 return Long.parseLong(s); 90 } catch (NumberFormatException e) { 91 return 0; 92 } 93 } 94 95 @SuppressWarnings("unchecked") 96 private void sendRequest(String requestMethod, String urlSuffix, OsmPrimitive osm) { 97 try { 98 URL url = new URL(Main.pref.osmDataServer + "/" + urlSuffix); 99 HttpURLConnection con = (HttpURLConnection)url.openConnection(); 100 con.setConnectTimeout(20000); 101 con.setRequestMethod(requestMethod); 102 con.setDoOutput(true); 103 con.connect(); 104 105 OsmXmlVisitor visitor = new OsmXmlVisitor(false); 106 osm.visit(visitor); 107 Element root = new Element("osm"); 108 root.setAttribute("version", "0.2"); 109 root.getChildren().add(visitor.element); 110 XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); 111 OutputStream out = con.getOutputStream(); 112 Document doc = new Document(root); 113 xmlOut.output(doc, out); 114 xmlOut.output(doc, System.out); 115 out.close(); 116 117 int retCode = con.getResponseCode(); 118 System.out.println(retCode+" "+con.getResponseMessage()); 119 if (retCode == 200 && osm.id == 0) 120 osm.id = readId(con.getInputStream()); 121 con.disconnect(); 122 } catch (Exception e) { 123 throw new RuntimeException(e.getMessage(), e); 124 } 28 125 } 29 126 }
Note:
See TracChangeset
for help on using the changeset viewer.