Changeset 529 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2008-01-30T18:02:38+01:00 (16 years ago)
Author:
gebner
Message:

Part one of patch by Dave Hansen <dave@…>

  • Remove unused imports
  • Main.debug
  • Make attribute merging aware of TIGER-import attributes
  • Better upload progress information
  • Retry uploads
Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r518 r529  
    122122        public final MainMenu menu;
    123123
     124        /**
     125         * Print a debug message if debugging is on.
     126         */
     127        static public int debug_level = 1;
     128        static public final void debug(String msg) {
     129                if (debug_level <= 0)
     130                        return;
     131                System.out.println(msg);
     132        }
    124133
    125134        /**
  • trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java

    r469 r529  
    3838import org.openstreetmap.josm.data.osm.Way;
    3939import org.openstreetmap.josm.data.osm.Node;
     40import org.openstreetmap.josm.data.osm.TigerUtils;
    4041import org.openstreetmap.josm.tools.Pair;
    4142import org.openstreetmap.josm.tools.GBC;
     
    158159                JPanel p = new JPanel(new GridBagLayout());
    159160                for (Entry<String, Set<String>> e : props.entrySet()) {
    160                         if (e.getValue().size() > 1) {
     161                        if (TigerUtils.isTigerTag(e.getKey())) {
     162                                String combined = TigerUtils.combineTags(e.getKey(), e.getValue());
     163                                newWay.put(e.getKey(), combined);
     164                        } else if (e.getValue().size() > 1) {
    161165                                JComboBox c = new JComboBox(e.getValue().toArray());
    162166                                c.setEditable(true);
     
    219223
    220224                HashSet<Pair<Node,Node>> chunkSet = new HashSet<Pair<Node,Node>>();
    221                 for (Way w : ways) {
    222                         if (w.nodes.size() == 0) continue;
    223                         Node lastN = null;
    224                         for (Node n : w.nodes) {
    225                                 if (lastN == null) {
    226                                         lastN = n;
    227                                         continue;
    228                                 }
    229 
    230                                 Pair<Node,Node> np = new Pair<Node,Node>(lastN, n);
    231                                 if (ignoreDirection) {
    232                                         Pair.sort(np);
    233                                 }
    234                                 chunkSet.add(np);
    235 
    236                                 lastN = n;
    237                         }
    238                 }
     225                for (Way w : ways)
     226                        chunkSet.addAll(w.getNodePairs(ignoreDirection));
     227
    239228                LinkedList<Pair<Node,Node>> chunks = new LinkedList<Pair<Node,Node>>(chunkSet);
    240229
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r469 r529  
    3838import org.openstreetmap.josm.data.osm.Way;
    3939import org.openstreetmap.josm.data.osm.Node;
     40import org.openstreetmap.josm.data.osm.TigerUtils;
    4041import org.openstreetmap.josm.tools.Pair;
    4142import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
     
    170171                JPanel p = new JPanel(new GridBagLayout());
    171172                for (Entry<String, Set<String>> e : props.entrySet()) {
    172                         if (e.getValue().size() > 1) {
     173                        if (TigerUtils.isTigerTag(e.getKey())) {
     174                                String combined = TigerUtils.combineTags(e.getKey(), e.getValue());
     175                                newNode.put(e.getKey(), combined);
     176                        } else if (e.getValue().size() > 1) {
    173177                                JComboBox c = new JComboBox(e.getValue().toArray());
    174178                                c.setEditable(true);
  • trunk/src/org/openstreetmap/josm/actions/OpenAction.java

    r482 r529  
    1010import java.io.FileInputStream;
    1111import java.io.FileNotFoundException;
    12 import java.io.FileReader;
    1312import java.io.IOException;
    14 import java.util.Collection;
    15 import java.util.LinkedList;
    1613import java.util.zip.GZIPInputStream;
    1714
     
    2320import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2421import org.openstreetmap.josm.gui.layer.GpxLayer;
    25 import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
    2622import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
    2723import org.openstreetmap.josm.io.OsmReader;
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r485 r529  
    217217                        return;
    218218                }
     219                Main.debug("wayChunks.size(): " + wayChunks.size());
     220                Main.debug("way id: " + selectedWay.id);
    219221
    220222                // build a list of commands, and also a new selection list
     
    240242                        wayToAdd.nodes.addAll(chunkIt.next());
    241243                        commandList.add(new AddCommand(wayToAdd));
     244                        Main.debug("wayToAdd: " + wayToAdd);
    242245                        newSelection.add(wayToAdd);
    243246                }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r444 r529  
    55
    66import java.io.IOException;
    7 import java.util.Collection;
    87
    98import javax.swing.JCheckBox;
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r501 r529  
    88import java.awt.event.MouseEvent;
    99import java.util.ArrayList;
    10 import java.util.Arrays;
    1110import java.util.Collection;
    1211import java.util.Collections;
     
    1514import java.util.LinkedList;
    1615import java.util.List;
    17 import java.util.Map.Entry;
    1816
    1917import javax.swing.JOptionPane;
    2018
    2119import org.openstreetmap.josm.Main;
    22 import org.openstreetmap.josm.command.AddCommand;
    23 import org.openstreetmap.josm.command.ChangeCommand;
    24 import org.openstreetmap.josm.command.Command;
    25 import org.openstreetmap.josm.command.DeleteCommand;
    26 import org.openstreetmap.josm.command.SequenceCommand;
     20import org.openstreetmap.josm.command.*;
    2721import org.openstreetmap.josm.data.osm.Node;
    2822import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3226import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
    3327import org.openstreetmap.josm.gui.MapFrame;
    34 import org.openstreetmap.josm.tools.ImageProvider;
     28import org.openstreetmap.josm.tools.*;
    3529
    3630/**
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r298 r529  
    5959                        max = new LatLon(Math.max(ll.lat(), max.lat()), Math.max(ll.lon(), max.lon()));
    6060        }
     61        /**
     62         * Is the given point within this bounds?
     63         */
     64        public boolean contains(LatLon ll) {
     65                if (ll.lat() < min.lat() || ll.lon() < min.lon())
     66                        return false;
     67                if (ll.lat() > max.lat() || ll.lon() > max.lon())
     68                        return false;
     69                return true;
     70        }
    6171}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r498 r529  
    44import java.text.ParseException;
    55import java.text.SimpleDateFormat;
    6 import java.util.ArrayList;
    76import java.util.Arrays;
    87import java.util.Collection;
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r357 r529  
    77
    88import org.openstreetmap.josm.data.osm.visitor.Visitor;
     9import org.openstreetmap.josm.tools.Pair;
    910
    1011/**
     
    1920         */
    2021        public final List<Node> nodes = new ArrayList<Node>();
     22
     23        public void visitNodes(Visitor v) {
     24                for (Node n : this.nodes)
     25                        v.visit(n);
     26        }
     27
     28        public ArrayList<Pair<Node,Node>> getNodePairs(boolean sort) {
     29                ArrayList<Pair<Node,Node>> chunkSet = new ArrayList<Pair<Node,Node>>();
     30                Node lastN = null;
     31                for (Node n : this.nodes) {
     32            if (lastN == null) {
     33                    lastN = n;
     34                        continue;
     35                    }
     36                        Pair<Node,Node> np = new Pair<Node,Node>(lastN, n);
     37                if (sort) {
     38                        Pair.sort(np);
     39                }
     40                chunkSet.add(np);
     41                lastN = n;
     42                }
     43                return chunkSet;
     44        }
     45
    2146
    2247        @Override public void visit(Visitor visitor) {
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java

    r343 r529  
    3434         */
    3535        public void visit(Way w) {
    36                 for (Node n : w.nodes)
    37                         visit(n);
     36                w.visitNodes(this);
    3837        }
    3938
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r343 r529  
    2323
    2424        public void visit(Way w) {
    25                 for (Node n : w.nodes)
    26                         visit(n);
     25                w.visitNodes(this);
    2726        }
    2827
  • trunk/src/org/openstreetmap/josm/gui/ConflictResolver.java

    r343 r529  
    2323import javax.swing.JButton;
    2424import javax.swing.JLabel;
    25 import javax.swing.JOptionPane;
    2625import javax.swing.JPanel;
    2726import javax.swing.JScrollPane;
     
    3534import javax.swing.table.TableModel;
    3635
    37 import org.openstreetmap.josm.Main;
    3836import org.openstreetmap.josm.data.conflict.ConflictItem;
    3937import org.openstreetmap.josm.data.conflict.DeleteConflict;
  • trunk/src/org/openstreetmap/josm/gui/MainApplet.java

    r431 r529  
    128128                applet.setStub(new AppletStub() {
    129129                        public void appletResize(int w, int h) {
    130                                 frame.resize(w, h);
     130                                frame.setSize(w, h);
    131131                        }
    132132
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r497 r529  
    66import java.awt.event.ActionEvent;
    77import java.awt.event.ActionListener;
    8 import java.awt.event.InputEvent;
    9 import java.awt.event.KeyEvent;
    10 
    11 import javax.swing.Action;
     8
    129import javax.swing.JCheckBoxMenuItem;
    1310import javax.swing.JMenu;
     
    4643import org.openstreetmap.josm.actions.search.SearchAction;
    4744import org.openstreetmap.josm.data.DataSetChecker;
    48 import org.openstreetmap.josm.data.Preferences;
    4945
    5046/**
  • trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java

    r446 r529  
    55import static org.openstreetmap.josm.tools.I18n.trn;
    66
    7 import java.awt.CheckboxGroup;
    87import java.awt.Color;
    98import java.awt.Component;
     
    1413import java.awt.event.ActionListener;
    1514import java.io.BufferedReader;
    16 import java.io.ByteArrayOutputStream;
    1715import java.io.File;
    18 import java.io.FileInputStream;
    1916import java.io.InputStreamReader;
    20 import java.io.OutputStream;
    21 import java.net.HttpURLConnection;
    2217import java.net.URL;
    2318import java.net.URLConnection;
    2419import java.net.UnknownHostException;
    2520import java.util.Collection;
    26 import java.util.LinkedList;
    2721
    2822import javax.swing.AbstractAction;
     
    3226import javax.swing.JCheckBox;
    3327import javax.swing.JColorChooser;
    34 import javax.swing.JFileChooser;
    3528import javax.swing.JLabel;
    3629import javax.swing.JMenuItem;
     
    4033import javax.swing.JSeparator;
    4134import javax.swing.JTextField;
    42 import javax.swing.filechooser.FileFilter;
    4335
    4436import org.openstreetmap.josm.Main;
     
    5648import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    5749import org.openstreetmap.josm.io.MultiPartFormOutputStream;
    58 import org.openstreetmap.josm.io.OsmWriter;
    5950import org.openstreetmap.josm.tools.ColorHelper;
    6051import org.openstreetmap.josm.tools.DontShowAgainInfo;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r486 r529  
    1111import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1212import org.openstreetmap.josm.gui.MapFrame;
    13 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    1413import org.openstreetmap.josm.gui.layer.Layer;
    1514import org.openstreetmap.josm.gui.layer.OsmDataLayer;
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r343 r529  
    1313import java.net.URL;
    1414import java.net.UnknownHostException;
     15import java.net.SocketTimeoutException;
    1516import java.util.Collection;
    1617import java.util.LinkedList;
     
    5758         * does not want to send the data.
    5859         */
     60        private static final int MSECS_PER_SECOND = 1000;
     61        private static final int SECONDS_PER_MINUTE = 60;
     62        private static final int MSECS_PER_MINUTE = MSECS_PER_SECOND * SECONDS_PER_MINUTE;
     63
     64        long uploadStartTime;
     65        public String timeLeft(int progress, int list_size) {
     66                long now = System.currentTimeMillis();
     67                long elapsed = now - uploadStartTime;
     68                if (elapsed == 0)
     69                        elapsed = 1;
     70                float uploads_per_ms = (float)progress / elapsed;
     71                float uploads_left = list_size - progress;
     72                int ms_left = (int)(uploads_left / uploads_per_ms);
     73                int minutes_left = ms_left / MSECS_PER_MINUTE;
     74                int seconds_left = (ms_left / MSECS_PER_SECOND) % SECONDS_PER_MINUTE ;
     75                String time_left_str = Integer.toString(minutes_left) + ":";
     76                if (seconds_left < 10)
     77                        time_left_str += "0";
     78                time_left_str += Integer.toString(seconds_left);
     79                return time_left_str;
     80        }       
    5981        public void uploadOsm(Collection<OsmPrimitive> list) throws SAXException {
    6082                processed = new LinkedList<OsmPrimitive>();
     
    6688                NameVisitor v = new NameVisitor();
    6789                try {
     90                        uploadStartTime = System.currentTimeMillis();
    6891                        for (OsmPrimitive osm : list) {
    6992                                if (cancel)
    7093                                        return;
    7194                                osm.visit(v);
    72                                 Main.pleaseWaitDlg.currentAction.setText(tr("Upload {0} {1} ({2})...", tr(v.className), v.name, osm.id));
     95                                int progress = Main.pleaseWaitDlg.progress.getValue();
     96                                String time_left_str = timeLeft(progress, list.size());
     97                                Main.pleaseWaitDlg.currentAction.setText(tr("Upload {0} {1} (id: {2}) {3}% {4}/{5} ({6} left)...",
     98                                        tr(v.className), v.name, osm.id, 100.0*progress/list.size(), progress, list.size(), time_left_str));
    7399                                osm.visit(this);
    74100                                Main.pleaseWaitDlg.progress.setValue(Main.pleaseWaitDlg.progress.getValue()+1);
     101                                Main.pleaseWaitDlg.progress.setValue(progress+1);
    75102                        }
    76103                } catch (RuntimeException e) {
     
    150177         *              <code>false</code>, if only the id is encoded.
    151178         */
    152         private void sendRequest(String requestMethod, String urlSuffix,
    153                         OsmPrimitive osm, boolean addBody) {
     179        private void sendRequestRetry(String requestMethod, String urlSuffix,
     180                        OsmPrimitive osm, boolean addBody, int retries) {
    154181                try {
     182                        if (cancel)
     183                                return; // assume cancel
    155184                        String version = Main.pref.get("osm-server.version", "0.5");
    156185                        URL url = new URL(
     
    159188                                        "/" + urlSuffix +
    160189                                        "/" + (osm.id==0 ? "create" : osm.id));
    161                         System.out.println("upload to: "+url);
     190                        System.out.print("upload to: "+url+ "..." );
    162191                        activeConnection = (HttpURLConnection)url.openConnection();
    163192                        activeConnection.setConnectTimeout(15000);
     
    166195                                activeConnection.setDoOutput(true);
    167196                        activeConnection.connect();
    168 
     197                        System.out.println("connected");
    169198                        if (addBody) {
    170199                                OutputStream out = activeConnection.getOutputStream();
     
    181210                        if (retCode == 410 && requestMethod.equals("DELETE"))
    182211                                return; // everything fine.. was already deleted.
    183                         if (retCode != 200) {
    184                                 // Look for a detailed error message from the server
    185                                 if (activeConnection.getHeaderField("Error") != null)
    186                                         retMsg += "\n" + activeConnection.getHeaderField("Error");
    187 
    188                                 // Report our error
    189                                 ByteArrayOutputStream o = new ByteArrayOutputStream();
    190                                 OsmWriter.output(o, new OsmWriter.Single(osm, true));
    191                                 System.out.println(new String(o.toByteArray(), "UTF-8").toString());
    192                                 throw new RuntimeException(retCode+" "+retMsg);
     212                        if (retCode != 200 && retCode != 412) {
     213                                if (retries >= 0) {
     214                                        retries--;
     215                                        System.out.print("backing off for 10 seconds...");
     216                                        Thread.sleep(10000);
     217                                        System.out.println("retrying ("+retries+" left)");
     218                                        sendRequestRetry(requestMethod, urlSuffix, osm, addBody, retries);
     219                                } else {
     220                                        // Look for a detailed error message from the server
     221                                        if (activeConnection.getHeaderField("Error") != null)
     222                                                retMsg += "\n" + activeConnection.getHeaderField("Error");
     223
     224                                        // Report our error
     225                                        ByteArrayOutputStream o = new ByteArrayOutputStream();
     226                                        OsmWriter.output(o, new OsmWriter.Single(osm, true));
     227                                        System.out.println(new String(o.toByteArray(), "UTF-8").toString());
     228                                        throw new RuntimeException(retCode+" "+retMsg);
     229                                }
    193230                        }
    194231                } catch (UnknownHostException e) {
    195232                        throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e);
     233                } catch(SocketTimeoutException e) {
     234                        System.out.println(" timed out, retries left: " + retries);
     235                        if (cancel)
     236                                return; // assume cancel
     237                        if (retries-- > 0)
     238                                sendRequestRetry(requestMethod, urlSuffix, osm, addBody, retries);
     239                        else
     240                                throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
    196241                } catch (Exception e) {
    197242                        if (cancel)
     
    199244                        if (e instanceof RuntimeException)
    200245                                throw (RuntimeException)e;
    201                         throw new RuntimeException(e.getMessage(), e);
    202                 }
     246                        throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
     247                }
     248        }
     249        private void sendRequest(String requestMethod, String urlSuffix,
     250                        OsmPrimitive osm, boolean addBody) {
     251                sendRequestRetry(requestMethod, urlSuffix, osm, addBody, 10);
    203252        }
    204253}
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r431 r529  
    3939         * The icon cache
    4040         */
    41         private static Map<URL, Image> cache = new HashMap<URL, Image>();
     41        private static Map<String, Image> cache = new HashMap<String, Image>();
    4242
    4343        /**
     
    7575                        subdir += "/";
    7676                String ext = name.indexOf('.') != -1 ? "" : ".png";
     77                String full_name = subdir+name+ext;
    7778
    78                 URL path = getImageUrl(subdir+name+ext);
    79                 if (path == null)
    80                         return null;
    81                
    82                 Image img = cache.get(path);
     79                Image img = cache.get(full_name);
    8380                if (img == null) {
     81                        // getImageUrl() does a ton of "stat()" calls and gets expensive
     82                        // and redundant when you have a whole ton of objects.  So,
     83                        // index the cache by the name of the icon we're looking for
     84                        // and don't bother to create a URL unless we're actually
     85                        // creating the image.
     86                        URL path = getImageUrl(full_name);
     87                        if (path == null)
     88                                return null;
    8489                        img = Toolkit.getDefaultToolkit().createImage(path);
    85                         cache.put(path, img);
     90                        cache.put(full_name, img);
    8691                }
     92       
    8793                return new ImageIcon(img);
    8894        }
Note: See TracChangeset for help on using the changeset viewer.