Changeset 402 in josm


Ignore:
Timestamp:
19.10.2007 01:04:24 (5 years ago)
Author:
framm
Message:
  • started adding support for uploading GPX files, not complete yet, disabled
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/.classpath

    r401 r402  
    22<classpath> 
    33        <classpathentry kind="src" path="src"/> 
    4         <classpathentry excluding="build/|dist/|src/|test/" including="images/" kind="src" path=""/> 
     4        <classpathentry excluding="build/|dist/|src/|test/" including="images/|presets/" kind="src" path=""/> 
    55        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 
    66        <classpathentry kind="lib" path="lib/metadata-extractor-2.3.1-nosun.jar"/> 
    7         <classpathentry kind="lib" path="lib/gettext-commons-0.9.jar" /> 
     7        <classpathentry kind="lib" path="lib/gettext-commons-0.9.jar"/> 
    88        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> 
    9         <classpathentry kind="lib" path="lib/jfcunit.jar" /> 
     9        <classpathentry kind="lib" path="lib/jfcunit.jar"/> 
    1010        <classpathentry kind="output" path="bin"/> 
    1111</classpath> 
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r390 r402  
    5454        private Point mousePos; 
    5555        private SelectionManager selectionManager; 
    56  
    57         /** 
    58          * Create a new MoveAction 
    59          * @param mapFrame The MapFrame, this action belongs to. 
     56         
     57        /** 
     58         * The time which needs to pass between click and release before something 
     59         * counts as a move 
     60         */ 
     61        private int initialMoveDelay = 100; 
     62 
     63        /** 
     64         * Create a new SelectAction 
     65         * @param mapFrame The MapFrame this action belongs to. 
    6066         */ 
    6167        public SelectAction(MapFrame mapFrame) { 
     
    6470                        getCursor("normal", "selection", Cursor.DEFAULT_CURSOR)); 
    6571                putValue("help", "Action/Move/Move"); 
    66                 selectionManager = new SelectionManager(this, false, mapFrame.mapView); 
     72                selectionManager = new SelectionManager(this, false, mapFrame.mapView);          
     73                try { initialMoveDelay = Integer.parseInt(Main.pref.get("edit.initial-move-delay","100")); } catch (NumberFormatException x) {}; 
     74 
     75 
    6776        } 
    6877 
     
    114123                 
    115124                // do not count anything as a move if it lasts less than 100 milliseconds. 
    116                 if ((mode == Mode.move) && (System.currentTimeMillis() - mouseDownTime < 100)) return; 
     125                if ((mode == Mode.move) && (System.currentTimeMillis() - mouseDownTime < initialMoveDelay)) return; 
    117126 
    118127                if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) 
  • trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java

    r343 r402  
    55import static org.openstreetmap.josm.tools.I18n.trn; 
    66 
     7import java.awt.CheckboxGroup; 
    78import java.awt.Color; 
    89import java.awt.Component; 
     
    1213import java.awt.event.ActionEvent; 
    1314import java.awt.event.ActionListener; 
     15import java.io.BufferedReader; 
     16import java.io.ByteArrayOutputStream; 
    1417import java.io.File; 
     18import java.io.FileInputStream; 
     19import java.io.InputStreamReader; 
     20import java.io.OutputStream; 
     21import java.net.HttpURLConnection; 
     22import java.net.URL; 
     23import java.net.URLConnection; 
     24import java.net.UnknownHostException; 
    1525import java.util.Collection; 
    1626import java.util.LinkedList; 
     
    2030import javax.swing.ButtonGroup; 
    2131import javax.swing.Icon; 
     32import javax.swing.JCheckBox; 
    2233import javax.swing.JColorChooser; 
    2334import javax.swing.JFileChooser; 
     
    2839import javax.swing.JRadioButton; 
    2940import javax.swing.JSeparator; 
     41import javax.swing.JTextField; 
    3042import javax.swing.filechooser.FileFilter; 
    3143 
     
    4355import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 
    4456import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 
     57import org.openstreetmap.josm.io.MultiPartFormOutputStream; 
     58import org.openstreetmap.josm.io.OsmWriter; 
    4559import org.openstreetmap.josm.tools.ColorHelper; 
    4660import org.openstreetmap.josm.tools.DontShowAgainInfo; 
     
    7993                        Main.main.addLayer(new OsmDataLayer(ds, tr("Converted from: {0}", RawGpsLayer.this.name), null)); 
    8094                        Main.main.removeLayer(RawGpsLayer.this); 
     95                } 
     96        } 
     97         
     98        public class UploadTraceAction extends AbstractAction { 
     99                public UploadTraceAction() { 
     100                        super(tr("Upload this trace..."), ImageProvider.get("uploadtrace")); 
     101                } 
     102                public void actionPerformed(ActionEvent e) { 
     103                        JPanel msg = new JPanel(new GridBagLayout()); 
     104                        msg.add(new JLabel(tr("<html>This functionality has been added only recently. Please<br>"+ 
     105                                                      "use with care and check if it works as expected.</html>")), GBC.eop()); 
     106                        ButtonGroup bg = new ButtonGroup(); 
     107                        JRadioButton c1 = null; 
     108                        JRadioButton c2 = null; 
     109                         
     110                        if (associatedFile != null) { 
     111                                c1 = new JRadioButton(tr("Upload track filtered by JOSM"), false); 
     112                                c2 = new JRadioButton(tr("Upload raw file: {0}", associatedFile.getName()), true); 
     113                        } 
     114                        else 
     115                        { 
     116                                c1 = new JRadioButton(tr("Upload track filtered by JOSM"), true); 
     117                                c2 = new JRadioButton(tr("Upload raw file: "), false); 
     118                                c2.setEnabled(false); 
     119                        } 
     120                        c1.setEnabled(false); 
     121                        bg.add(c1); 
     122                        bg.add(c2); 
     123 
     124                        msg.add(c1, GBC.eol()); 
     125                        msg.add(c2, GBC.eop()); 
     126 
     127                         
     128                        JTextField description = new JTextField(); 
     129                        JTextField tags = new JTextField(); 
     130                        msg.add(new JLabel(tr("Description:")), GBC.std()); 
     131                        msg.add(description, GBC.eol().fill(GBC.HORIZONTAL)); 
     132                        msg.add(new JLabel(tr("Tags:")), GBC.std()); 
     133                        msg.add(tags, GBC.eol().fill(GBC.HORIZONTAL)); 
     134                        JCheckBox c3 = new JCheckBox("public"); 
     135                        msg.add(c3, GBC.eop()); 
     136                        msg.add(new JLabel("Please ensure that you don't upload your traces twice."), GBC.eop()); 
     137                         
     138                        int answer = JOptionPane.showConfirmDialog(Main.parent, msg, tr("GPX-Upload"), JOptionPane.OK_CANCEL_OPTION); 
     139                        if (answer == JOptionPane.OK_OPTION) 
     140                        { 
     141                                try { 
     142                                        String version = Main.pref.get("osm-server.version", "0.5"); 
     143                                        URL url = new URL(Main.pref.get("osm-server.url") + 
     144                                                        "/" + version + "/gpx/create"); 
     145 
     146                                        // create a boundary string 
     147                                        String boundary = MultiPartFormOutputStream.createBoundary(); 
     148                                        URLConnection urlConn = MultiPartFormOutputStream.createConnection(url); 
     149                                        urlConn.setRequestProperty("Accept", "*/*"); 
     150                                        urlConn.setRequestProperty("Content-Type",  
     151                                                MultiPartFormOutputStream.getContentType(boundary)); 
     152                                        // set some other request headers... 
     153                                        urlConn.setRequestProperty("Connection", "Keep-Alive"); 
     154                                        urlConn.setRequestProperty("Cache-Control", "no-cache"); 
     155                                        // no need to connect cuz getOutputStream() does it 
     156                                        MultiPartFormOutputStream out =  
     157                                                new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary); 
     158                                        out.writeField("description", description.getText()); 
     159                                        out.writeField("tags", tags.getText()); 
     160                                        out.writeField("public", (c3.getSelectedObjects() != null) ? "1" : "0"); 
     161                                        // upload a file 
     162                                        out.writeFile("gpx_file", "text/xml", associatedFile); 
     163                                        // can also write bytes directly 
     164                                        // out.writeFile("myFile", "text/plain", "C:\\test.txt",  
     165                                        // "This is some file text.".getBytes("ASCII")); 
     166                                        out.close(); 
     167                                        // read response from server 
     168                                        BufferedReader in = new BufferedReader( 
     169                                                new InputStreamReader(urlConn.getInputStream())); 
     170                                        String line = ""; 
     171                                        while((line = in.readLine()) != null) { 
     172                                                 System.out.println(line); 
     173                                        } 
     174                                        in.close(); 
     175                                         
     176                                        /* 
     177                                        int retCode = activeConnection.getResponseCode(); 
     178                                        System.out.println("got return: "+retCode); 
     179                                        String retMsg = activeConnection.getResponseMessage(); 
     180                                        activeConnection.disconnect(); 
     181                                        if (retCode != 200) { 
     182                                                // Look for a detailed error message from the server 
     183                                                if (activeConnection.getHeaderField("Error") != null) 
     184                                                        retMsg += "\n" + activeConnection.getHeaderField("Error"); 
     185 
     186                                                // Report our error 
     187                                                ByteArrayOutputStream o = new ByteArrayOutputStream(); 
     188                                                System.out.println(new String(o.toByteArray(), "UTF-8").toString()); 
     189                                                throw new RuntimeException(retCode+" "+retMsg); 
     190                                        } 
     191                                        */ 
     192                                } catch (UnknownHostException ex) { 
     193                                        throw new RuntimeException(tr("Unknown host")+": "+ex.getMessage(), ex); 
     194                                } catch (Exception ex) { 
     195                                        //if (cancel) 
     196                                        //      return; // assume cancel 
     197                                        if (ex instanceof RuntimeException) 
     198                                                throw (RuntimeException)ex; 
     199                                        throw new RuntimeException(ex.getMessage(), ex); 
     200                                }        
     201                        } 
    81202                } 
    82203        } 
     
    278399                                line, 
    279400                                new JMenuItem(new ConvertToDataLayerAction()), 
     401                                //new JMenuItem(new UploadTraceAction()), 
    280402                                new JSeparator(), 
    281403                                new JMenuItem(new RenameLayerAction(associatedFile, this)), 
     
    291413                                tagimage, 
    292414                                new JMenuItem(new ConvertToDataLayerAction()), 
     415                                //new JMenuItem(new UploadTraceAction()), 
    293416                                new JSeparator(), 
    294417                                new JMenuItem(new RenameLayerAction(associatedFile, this)), 
Note: See TracChangeset for help on using the changeset viewer.