Ignore:
Timestamp:
2009-07-15T17:22:56+02:00 (16 years ago)
Author:
Gubaer
Message:

Relation Editor: complete rework
Relation Editor: had to temporarily remove code for "link information" and "sorting"
IO Subsystem: clean up in exception handling
some cosmetics

Location:
trunk/src/org/openstreetmap/josm/io
Files:
6 edited

Legend:

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

    r1772 r1790  
    6262    private HashSet<Long> relations;
    6363    private HashSet<Long> missingPrimitives;
    64     private HashSet<Long> skippedWayIds;
    6564    private DataSet outputDataSet;
    6665
     
    320319        try {
    321320            final OsmReader osm = OsmReader.parseDataSetOsm(in, Main.pleaseWaitDlg);
    322             skippedWayIds.addAll(osm.getSkippedWayIds());
    323321            merge(osm.getDs());
    324         } catch(IOException e) {
    325             throw new OsmTransferException(e);
    326         } catch(SAXException e) {
     322        } catch(Exception e) {
    327323            throw new OsmTransferException(e);
    328324        }
     
    346342        try {
    347343            final OsmReader osm = OsmReader.parseDataSetOsm(in,Main.pleaseWaitDlg);
    348             skippedWayIds.addAll(osm.getSkippedWayIds());
    349344            merge(osm.getDs());
    350         } catch(IOException e) {
    351             throw new OsmTransferException(e);
    352         } catch(SAXException e) {
     345        } catch(Exception e) {
    353346            throw new OsmTransferException(e);
    354347        }
     
    440433    @Override
    441434    public DataSet parseOsm() throws OsmTransferException {
    442         skippedWayIds = new HashSet<Long>();
    443435        missingPrimitives = new HashSet<Long>();
    444436
     
    450442
    451443    /**
    452      * replies the set of {@see Way}s which were present in the data fetched from the
    453      * server but which were not included in the JOSM dataset because they referred
    454      * to nodes not present in the dataset
    455      *
    456      * @return  the set of ids of skipped ways
    457      */
    458     public Set<Long> getSkippedWays() {
    459         return skippedWayIds;
    460     }
    461 
    462     /**
    463444     * replies the set of ids of all primitives for which a fetch request to the
    464445     * server was submitted but which are not available from the server (the server
  • trunk/src/org/openstreetmap/josm/io/OsmImporter.java

    r1772 r1790  
    5151        Main.main.addLayer(layer);
    5252        layer.fireDataChange();
    53         if (osm.getParseNotes().length() != 0) {
    54             /* display at most five lines */
    55             String notes = osm.getParseNotes();
    56             int j = 0;
    57             for (int i = 0; i < 5; i++) {
    58                 j = notes.indexOf('\n', j + 1);
    59             }
    60             j = j >= 0 ? j : notes.length();
    61             JOptionPane.showMessageDialog(Main.parent, notes.substring(0, j));
    62         }
    6353    }
    6454}
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r1772 r1790  
    1616import java.util.Set;
    1717import java.util.Map.Entry;
    18 
     18import java.util.logging.Logger;
     19
     20import javax.swing.SwingUtilities;
    1921import javax.xml.parsers.ParserConfigurationException;
    2022import javax.xml.parsers.SAXParserFactory;
    2123
    22 import org.openstreetmap.josm.Main;
    2324import org.openstreetmap.josm.data.Bounds;
    2425import org.openstreetmap.josm.data.coor.LatLon;
     
    5051 */
    5152public class OsmReader {
     53    static private final Logger logger = Logger.getLogger(OsmReader.class.getName());
    5254
    5355    /**
     
    5658    private DataSet ds = new DataSet();
    5759    public DataSet getDs() { return ds; }
    58 
    59     /**
    60      * Record warnings.  If there were any data inconsistencies, append
    61      * a newline-terminated string.
    62      */
    63     private String parseNotes = new String();
    64     private int parseNotesCount = 0;
    65     public String getParseNotes() {
    66         return parseNotes;
    67     }
    68 
    69     /** the list of ids of skipped {@see Way}s, i.e. ways which referred to nodes
    70      * not included in the parsed data
    71      */
    72     private Set<Long> skippedWayIds = new HashSet<Long>();
    7360
    7461    /**
     
    350337    protected void createWays() {
    351338        for (Entry<OsmPrimitiveData, Collection<Long>> e : ways.entrySet()) {
    352             Way w = new Way();
     339            Way w = new Way(e.getKey().id);
    353340            boolean failed = false;
    354341            for (long id : e.getValue()) {
    355342                Node n = findNode(id);
    356343                if (n == null) {
    357                     /* don't report ALL of them, just a few */
    358                     if (parseNotesCount++ < 6) {
    359                         parseNotes += tr("Skipping a way because it includes a node that doesn''t exist: {0}\n", id);
    360                     } else if (parseNotesCount == 6) {
    361                         parseNotes += "...\n";
    362                     }
    363344                    failed = true;
    364345                    break;
     
    367348            }
    368349            if (failed) {
    369                 skippedWayIds.add(e.getKey().id);
    370                 continue;
    371             }
    372             e.getKey().copyTo(w);
    373             adder.visit(w);
    374         }
    375 
     350                logger.warning(tr("marked way {0} incomplete because referred nodes are missing in the loaded data", e.getKey().id));
     351                e.getKey().copyTo(w);
     352                w.incomplete = true;
     353                w.nodes.clear();
     354            } else {
     355                e.getKey().copyTo(w);
     356                w.incomplete = false;
     357                adder.visit(w);
     358            }
     359        }
    376360    }
    377361
     
    475459    }
    476460
    477     public static OsmReader parseDataSetOsm(InputStream source,PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {
     461    public static OsmReader parseDataSetOsm(InputStream source, final PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {
    478462        OsmReader osm = new OsmReader();
    479463
     
    487471        }
    488472
    489         Main.pleaseWaitDlg.currentAction.setText(tr("Prepare OSM data..."));
    490         Main.pleaseWaitDlg.setIndeterminate(true);
     473        SwingUtilities.invokeLater(
     474                new Runnable() {
     475                    public void run() {
     476                        pleaseWaitDlg.currentAction.setText(tr("Prepare OSM data..."));
     477                        pleaseWaitDlg.setIndeterminate(true);
     478                    }
     479                }
     480        );
    491481
    492482        for (Node n : osm.nodes.values()) {
     
    508498            }
    509499
    510         Main.pleaseWaitDlg.setIndeterminate(false);
    511         Main.pleaseWaitDlg.progress.setValue(0);
     500        SwingUtilities.invokeLater(
     501                new Runnable() {
     502                    public void run() {
     503                        pleaseWaitDlg.setIndeterminate(false);
     504                        pleaseWaitDlg.progress.setValue(0);
     505                    }
     506                }
     507        );
    512508
    513509        return osm;
    514510    }
    515 
    516     /**
    517      * replies a set of ids of skipped {@see Way}s, i.e. ways which were included in the downloaded
    518      * data but which referred to nodes <strong>not</strong>  available in the downloaded data
    519      *
    520      * @return the set of ids
    521      */
    522     public Set<Long> getSkippedWayIds() {
    523         return skippedWayIds;
    524     }
    525511}
  • trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java

    r1670 r1790  
    7474            HistoryDataSet data = reader.parse(Main.pleaseWaitDlg);
    7575            return data;
    76         } catch (IOException e) {
    77             if (cancel)
    78                 return null;
    79             throw new OsmTransferException(e);
    80         } catch (SAXException e) {
    81             throw new OsmTransferException(e);
    8276        } catch(OsmTransferException e) {
    8377            throw e;
  • trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java

    r1772 r1790  
    2424    @Override
    2525    public DataSet parseOsm() throws OsmTransferException {
     26        InputStream in = null;
    2627        try {
    2728            Main.pleaseWaitDlg.progress.setValue(0);
    2829            Main.pleaseWaitDlg.currentAction.setText(tr("Contacting Server..."));
    2930
    30             final InputStream in = getInputStreamRaw(url, Main.pleaseWaitDlg);
     31            in = getInputStreamRaw(url, Main.pleaseWaitDlg);
    3132            if (in == null)
    3233                return null;
    3334            Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));
    34             final DataSet data = OsmReader.parseDataSet(in, Main.pleaseWaitDlg);
    35             in.close();
    36             activeConnection = null;
    37             return data;
    38         } catch (IOException e) {
    39             if (cancel)
    40                 return null;
    41             throw new OsmTransferException(e);
    42         } catch (SAXException e) {
    43             throw new OsmTransferException(e);
     35            return OsmReader.parseDataSet(in, Main.pleaseWaitDlg);
    4436        } catch(OsmTransferException e) {
    4537            throw e;
     
    4840                return null;
    4941            throw new OsmTransferException(e);
     42        } finally {
     43            try {
     44                if (in != null) {
     45                    in.close();
     46                }
     47                activeConnection = null;
     48            } catch(Exception e) {/* ignore it */}
    5049        }
    5150    }
  • trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java

    r1772 r1790  
    66import java.io.IOException;
    77import java.io.InputStream;
    8 
    9 import javax.swing.JOptionPane;
    108
    119import org.openstreetmap.josm.Main;
     
    5149            final DataSet data = osm.getDs();
    5250
    53             if (osm.getParseNotes().length() != 0) {
    54                 JOptionPane.showMessageDialog(Main.parent, osm.getParseNotes());
    55             }
    5651            in.close();
    5752            activeConnection = null;
Note: See TracChangeset for help on using the changeset viewer.