Changeset 1435 in josm for trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
- Timestamp:
- 2009-02-21T14:49:52+01:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r1425 r1435 272 272 new JMenuItem(new SaveAction(this)), 273 273 new JMenuItem(new SaveAsAction(this)), 274 // new JMenuItem(new UploadTraceAction()),275 274 color, 276 275 line, … … 633 632 for (WayPoint p : seg) { 634 633 v.visit(p.eastNorth); 635 }636 }637 }638 }639 640 public class UploadTraceAction extends AbstractAction {641 public UploadTraceAction() {642 super(tr("Upload this trace..."), ImageProvider.get("uploadtrace"));643 }644 public void actionPerformed(ActionEvent e) {645 JPanel msg = new JPanel(new GridBagLayout());646 msg.add(new JLabel(tr("<html>This functionality has been added only recently. Please<br>"+647 "use with care and check if it works as expected.</html>")), GBC.eop());648 ButtonGroup bg = new ButtonGroup();649 JRadioButton c1 = null;650 JRadioButton c2 = null;651 652 //TODO653 //check whether data comes from server654 //check whether data changed sind last save/open655 656 c1 = new JRadioButton(tr("Upload track filtered by JOSM"), true);657 c2 = new JRadioButton(tr("Upload raw file: "), false);658 c2.setEnabled(false);659 c1.setEnabled(false);660 bg.add(c1);661 bg.add(c2);662 663 msg.add(c1, GBC.eol());664 msg.add(c2, GBC.eop());665 666 667 JLabel description = new JLabel((String) data.attr.get("desc"));668 JTextField tags = new JTextField();669 tags.setText((String) data.attr.get("keywords"));670 msg.add(new JLabel(tr("Description:")), GBC.std());671 msg.add(description, GBC.eol().fill(GBC.HORIZONTAL));672 msg.add(new JLabel(tr("Tags (keywords in GPX):")), GBC.std());673 msg.add(tags, GBC.eol().fill(GBC.HORIZONTAL));674 JCheckBox c3 = new JCheckBox("public");675 msg.add(c3, GBC.eop());676 msg.add(new JLabel("Please ensure that you don't upload your traces twice."), GBC.eop());677 678 int answer = JOptionPane.showConfirmDialog(Main.parent, msg, tr("GPX-Upload"), JOptionPane.OK_CANCEL_OPTION);679 if (answer == JOptionPane.OK_OPTION)680 {681 try {682 String version = Main.pref.get("osm-server.version", "0.5");683 URL url = new URL(Main.pref.get("osm-server.url") + "/" + version + "/gpx/create");684 685 // create a boundary string686 String boundary = MultiPartFormOutputStream.createBoundary();687 URLConnection urlConn = MultiPartFormOutputStream.createConnection(url);688 urlConn.setRequestProperty("Accept", "*/*");689 urlConn.setRequestProperty("Content-Type", MultiPartFormOutputStream.getContentType(boundary));690 // set some other request headers...691 urlConn.setRequestProperty("Connection", "Keep-Alive");692 urlConn.setRequestProperty("Cache-Control", "no-cache");693 // no need to connect cuz getOutputStream() does it694 MultiPartFormOutputStream out = new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);695 out.writeField("description", description.getText());696 out.writeField("tags", tags.getText());697 out.writeField("public", (c3.getSelectedObjects() != null) ? "1" : "0");698 // upload a file699 // out.writeFile("gpx_file", "text/xml", associatedFile);700 // can also write bytes directly701 // out.writeFile("myFile", "text/plain", "C:\\test.txt",702 // "This is some file text.".getBytes("ASCII"));703 File tmp = File.createTempFile("josm", "tmp.gpx");704 FileOutputStream outs = new FileOutputStream(tmp);705 new GpxWriter(outs).write(data);706 outs.close();707 FileInputStream ins = new FileInputStream(tmp);708 new GpxWriter(System.out).write(data);709 out.writeFile("gpx_file", "text/xml", data.storageFile.getName(), ins);710 out.close();711 tmp.delete();712 // read response from server713 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));714 String line = "";715 while((line = in.readLine()) != null) {716 System.out.println(line);717 }718 in.close();719 720 //TODO check response721 /* int retCode = urlConn.getResponseCode();722 System.out.println("got return: " + retCode);723 String retMsg = urlConn.getResponseMessage();724 urlConn.disconnect();725 if (retCode != 200) {726 // Look for a detailed error message from the server727 if (urlConn.getHeaderField("Error") != null)728 retMsg += "\n" + urlConn.getHeaderField("Error");729 730 // Report our error731 ByteArrayOutputStream o = new ByteArrayOutputStream();732 System.out.println(new String(o.toByteArray(), "UTF-8").toString());733 throw new RuntimeException(retCode+" "+retMsg);734 }735 */736 } catch (UnknownHostException ex) {737 throw new RuntimeException(tr("Unknown host")+": "+ex.getMessage(), ex);738 } catch (Exception ex) {739 //if (cancel)740 // return; // assume cancel741 if (ex instanceof RuntimeException)742 throw (RuntimeException)ex;743 throw new RuntimeException(ex.getMessage(), ex);744 634 } 745 635 }
Note:
See TracChangeset
for help on using the changeset viewer.
