Ignore:
Timestamp:
15.06.2009 20:22:46 (3 years ago)
Author:
Gubaer
Message:

fixed: bug in OsmApi.getOsmApi()
cleanup: exception handling in interfacing with OSM API
new: new action for updating individual elements with the their current state on the server (including new menu item in the file menu)
new: improved user feedback in case of conflicts
new: handles 410 Gone conflicts when uploading a changeset
new: undoable command for "purging" a primitive from the current dataset (necessary if the primitive is already deleted on the server and the user wants to remove it from its local dataset)
new: undoable command for "undeleting" an already deleted primitive on the server (kind of "cloning")
new: after a full upload, checks whether there are primitives in the local dataset which might be deleted on the server.
new: data structures for history data
new: history download support in io package

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r1646 r1670  
    5151import org.openstreetmap.josm.data.osm.Node; 
    5252import org.openstreetmap.josm.data.osm.OsmPrimitive; 
     53import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 
    5354import org.openstreetmap.josm.data.osm.Relation; 
    5455import org.openstreetmap.josm.data.osm.Way; 
     
    7778        public final int[] normal = new int[3]; 
    7879        public final int[] deleted = new int[3]; 
    79         public final String[] names = {"node", "way", "relation"}; 
     80        public final String[] names = { 
     81                OsmPrimitiveType.NODE.getAPIName(), 
     82                OsmPrimitiveType.WAY.getAPIName(), 
     83                OsmPrimitiveType.RELATION.getAPIName() 
     84        }; 
    8085 
    8186        private void inc(final OsmPrimitive osm, final int i) { 
    8287            normal[i]++; 
    83             if (osm.deleted) 
     88            if (osm.deleted) { 
    8489                deleted[i]++; 
     90            } 
    8591        } 
    8692 
     
    201207 
    202208        SimplePaintVisitor painter; 
    203         if (Main.pref.getBoolean("draw.wireframe")) 
     209        if (Main.pref.getBoolean("draw.wireframe")) { 
    204210            painter = new SimplePaintVisitor(); 
    205         else 
     211        } else { 
    206212            painter = new MapPaintVisitor(); 
     213        } 
    207214        painter.setGraphics(g); 
    208215        painter.setNavigatableComponent(mv); 
     
    216223        tool += undeletedSize(data.nodes)+" "+trn("node", "nodes", undeletedSize(data.nodes))+", "; 
    217224        tool += undeletedSize(data.ways)+" "+trn("way", "ways", undeletedSize(data.ways)); 
    218         if (data.version != null) tool += ", " + tr("version {0}", data.version); 
     225        if (data.version != null) { 
     226            tool += ", " + tr("version {0}", data.version); 
     227        } 
    219228        File f = getAssociatedFile(); 
    220         if (f != null) 
     229        if (f != null) { 
    221230            tool = "<html>"+tool+"<br>"+f.getPath()+"</html>"; 
     231        } 
    222232        return tool; 
    223233    } 
    224234 
    225235    @Override public void mergeFrom(final Layer from) { 
    226         final MergeVisitor visitor = new MergeVisitor(data,((OsmDataLayer)from).data); 
    227         for (final OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives()) { 
    228 //            i++; 
    229 //            if(i%100 == 0) { 
    230 //                double perc = (((double)i) / ((double)max) * 100.0); 
    231 //                System.out.format(" " + (int)perc + "%%"); 
    232 //            } 
     236        mergeFrom(((OsmDataLayer)from).data); 
     237    } 
     238 
     239    /** 
     240     * merges the primitives in dataset <code>from</code> into the dataset of 
     241     * this layer 
     242     *  
     243     * @param from  the source data set 
     244     */ 
     245    public void mergeFrom(final DataSet from) { 
     246        final MergeVisitor visitor = new MergeVisitor(data,from); 
     247        for (final OsmPrimitive osm : from.allPrimitives()) { 
    233248            osm.visit(visitor); 
    234249        } 
    235250        visitor.fixReferences(); 
    236 //        System.out.println(""); 
    237251 
    238252        Area a = data.getDataSourceArea(); 
    239          
    240         // copy the merged layer's data source info;  
     253 
     254        // copy the merged layer's data source info; 
    241255        // only add source rectangles if they are not contained in the 
    242256        // layer already. 
    243         for (DataSource src : ((OsmDataLayer)from).data.dataSources) { 
    244             if (a == null || !a.contains(src.bounds.asRect())) 
     257        for (DataSource src : from.dataSources) { 
     258            if (a == null || !a.contains(src.bounds.asRect())) { 
    245259                data.dataSources.add(src); 
    246         } 
    247          
     260            } 
     261        } 
     262 
    248263        // copy the merged layer's API version, downgrade if required 
    249264        if (data.version == null) { 
    250             data.version = ((OsmDataLayer)from).data.version; 
     265            data.version = from.version; 
    251266        } else { 
    252             if ("0.5".equals(data.version) ^ "0.5".equals(((OsmDataLayer)from).data.version)) { 
    253                 System.err.println("Warning: mixing 0.6 and 0.5 data results in version 0.5"); 
     267            if ("0.5".equals(data.version) ^ "0.5".equals(from.version)) { 
     268                System.err.println(tr("Warning: mixing 0.6 and 0.5 data results in version 0.5")); 
    254269                data.version = "0.5"; 
    255270            } 
     
    263278        final ConflictDialog dlg = Main.map.conflictDialog; 
    264279        dlg.add(visitor.conflicts); 
    265         JOptionPane.showMessageDialog(Main.parent,tr("There were conflicts during import.")); 
    266         if (!dlg.isVisible()) 
     280        JOptionPane.showMessageDialog(Main.parent,tr("There were {0} conflicts during import.", visitor.conflicts.size())); 
     281        if (!dlg.isVisible()) { 
    267282            dlg.action.actionPerformed(new ActionEvent(this, 0, "")); 
     283        } 
    268284    } 
    269285 
     
    274290    @Override public void visitBoundingBox(final BoundingXYVisitor v) { 
    275291        for (final Node n : data.nodes) 
    276             if (!n.deleted && !n.incomplete) 
     292            if (!n.deleted && !n.incomplete) { 
    277293                v.visit(n); 
     294            } 
    278295    } 
    279296 
     
    299316        if (processed != null) { 
    300317            final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed); 
    301             for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();) 
     318            for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();) { 
    302319                cleanIterator(it, processedSet); 
    303             for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();) 
     320            } 
     321            for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();) { 
    304322                cleanIterator(it, processedSet); 
    305             for (final Iterator<Relation> it = data.relations.iterator(); it.hasNext();) 
     323            } 
     324            for (final Iterator<Relation> it = data.relations.iterator(); it.hasNext();) { 
    306325                cleanIterator(it, processedSet); 
     326            } 
    307327        } 
    308328 
     
    330350            return; 
    331351        osm.modified = false; 
    332         if (osm.deleted) 
     352        if (osm.deleted) { 
    333353            it.remove(); 
     354        } 
    334355    } 
    335356 
     
    342363            return; 
    343364        this.modified = modified; 
    344         for (final ModifiedChangedListener l : listenerModified) 
     365        for (final ModifiedChangedListener l : listenerModified) { 
    345366            l.modifiedChanged(modified, this); 
     367        } 
    346368    } 
    347369 
     
    352374        int size = 0; 
    353375        for (final OsmPrimitive osm : list) 
    354             if (!osm.deleted) 
     376            if (!osm.deleted) { 
    355377                size++; 
     378            } 
    356379        return size; 
    357380    } 
     
    359382    @Override public Object getInfoComponent() { 
    360383        final DataCountVisitor counter = new DataCountVisitor(); 
    361         for (final OsmPrimitive osm : data.allPrimitives()) 
     384        for (final OsmPrimitive osm : data.allPrimitives()) { 
    362385            osm.visit(counter); 
     386        } 
    363387        final JPanel p = new JPanel(new GridBagLayout()); 
    364388        p.add(new JLabel(tr("{0} consists of:", name)), GBC.eol()); 
    365389        for (int i = 0; i < counter.normal.length; ++i) { 
    366390            String s = counter.normal[i]+" "+trn(counter.names[i],counter.names[i]+"s",counter.normal[i]); 
    367             if (counter.deleted[i] > 0) 
     391            if (counter.deleted[i] > 0) { 
    368392                s += tr(" ({0} deleted.)",counter.deleted[i]); 
     393            } 
    369394            p.add(new JLabel(s, ImageProvider.get("data", counter.names[i]), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 
    370395        } 
     
    375400 
    376401    @Override public Component[] getMenuEntries() { 
    377         if (Main.applet) { 
     402        if (Main.applet) 
    378403            return new Component[]{ 
    379                     new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 
    380                     new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 
    381                     new JSeparator(), 
    382                     new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 
    383                     new JSeparator(), 
    384                     new JMenuItem(new LayerListPopup.InfoAction(this))}; 
    385         } 
     404                new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 
     405                new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 
     406                new JSeparator(), 
     407                new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 
     408                new JSeparator(), 
     409                new JMenuItem(new LayerListPopup.InfoAction(this))}; 
    386410        return new Component[]{ 
    387411                new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 
     
    409433        HashSet<Node> doneNodes = new HashSet<Node>(); 
    410434        for (Way w : data.ways) { 
    411             if (w.incomplete || w.deleted) continue; 
     435            if (w.incomplete || w.deleted) { 
     436                continue; 
     437            } 
    412438            GpxTrack trk = new GpxTrack(); 
    413439            gpxData.tracks.add(trk); 
    414440 
    415             if (w.get("name") != null) 
     441            if (w.get("name") != null) { 
    416442                trk.attr.put("name", w.get("name")); 
     443            } 
    417444 
    418445            ArrayList<WayPoint> trkseg = null; 
     
    429456                    doneNodes.add(n); 
    430457                } 
    431                 WayPoint wpt = new WayPoint(n.getCoor());                 
     458                WayPoint wpt = new WayPoint(n.getCoor()); 
    432459                if (!n.isTimestampEmpty()) 
    433460                { 
     
    442469        // records them? 
    443470        for (Node n : data.nodes) { 
    444             if (n.incomplete || n.deleted || doneNodes.contains(n)) continue; 
     471            if (n.incomplete || n.deleted || doneNodes.contains(n)) { 
     472                continue; 
     473            } 
    445474            WayPoint wpt = new WayPoint(n.getCoor()); 
    446475            if (!n.isTimestampEmpty()) { 
Note: See TracChangeset for help on using the changeset viewer.