Changeset 2396 in josm for trunk/src


Ignore:
Timestamp:
2009-11-07T07:26:15+01:00 (12 years ago)
Author:
Gubaer
Message:

Made nodes, ways, and relations in DataSet private. Plugin updates to be checked in shortly.
Also added setter/getter for DataSet version.

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

Legend:

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

    r2390 r2396  
    229229        String lbl = "";
    230230        switch(primitiveType) {
    231             case NODE: lbl =  tr("Synchronize node {0} only", id); break;
    232             case WAY: lbl =  tr("Synchronize way {0} only", id); break;
    233             case RELATION: lbl =  tr("Synchronize relation {0} only", id); break;
     231        case NODE: lbl =  tr("Synchronize node {0} only", id); break;
     232        case WAY: lbl =  tr("Synchronize way {0} only", id); break;
     233        case RELATION: lbl =  tr("Synchronize relation {0} only", id); break;
    234234        }
    235235        ButtonSpec[] spec = new ButtonSpec[] {
     
    275275        );
    276276        switch(ret) {
    277             case 0: synchronizePrimitive(primitiveType, id); break;
    278             case 1: synchronizeDataSet(); break;
    279             default: return;
     277        case 0: synchronizePrimitive(primitiveType, id); break;
     278        case 1: synchronizeDataSet(); break;
     279        default: return;
    280280        }
    281281    }
     
    635635                    try {
    636636                        getProgressMonitor().subTask(tr("Uploading {0} objects ...", toUpload.size()));
    637                         writer.uploadOsm(layer.data.version, toUpload, changeset, getProgressMonitor().createSubTaskMonitor(1, false));
     637                        writer.uploadOsm(layer.data.getVersion(), toUpload, changeset, getProgressMonitor().createSubTaskMonitor(1, false));
    638638                        processedPrimitives.addAll(writer.getProcessedPrimitives());
    639639                        // if we get here we've successfully uploaded the data. Exit the loop.
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2388 r2396  
    5252     * The API version that created this data set, if any.
    5353     */
    54     public String version;
     54    private String version;
     55
     56    /**
     57     * Replies the API version this dataset was created from. May be null.
     58     *
     59     * @return the API version this dataset was created from. May be null.
     60     */
     61    public String getVersion() {
     62        return version;
     63    }
     64
     65    /**
     66     * Sets the API version this dataset was created from.
     67     *
     68     * @param version the API version, i.e. "0.5" or "0.6"
     69     */
     70    public void setVersion(String version) {
     71        this.version = version;
     72    }
    5573
    5674    /**
    5775     * All nodes goes here, even when included in other data (ways etc). This enables the instant
    5876     * conversion of the whole DataSet by iterating over this data structure.
    59      * @deprecated Use getNodes() for read-only operations, addPrimitive() and removePrimitive() for modifications
    60      */
    61     @Deprecated
    62     public QuadBuckets<Node> nodes = new QuadBuckets<Node>();
    63 
     77     */
     78    private QuadBuckets<Node> nodes = new QuadBuckets<Node>();
     79
     80    /**
     81     * Replies an unmodifiable collection of nodes in this dataset
     82     *
     83     * @return an unmodifiable collection of nodes in this dataset
     84     */
    6485    public Collection<Node> getNodes() {
    6586        return Collections.unmodifiableCollection(nodes);
     
    7495     *
    7596     * The way nodes are stored only in the way list.
    76      * @deprecated Use getWays() for read-only operations, addPrimitive() and removePrimitive() for modifications
    77      */
    78     @Deprecated
    79     public QuadBuckets<Way> ways = new QuadBuckets<Way>();
    80 
     97     */
     98    private QuadBuckets<Way> ways = new QuadBuckets<Way>();
     99
     100    /**
     101     * Replies an unmodifiable collection of ways in this dataset
     102     *
     103     * @return an unmodifiable collection of ways in this dataset
     104     */
    81105    public Collection<Way> getWays() {
    82106        return Collections.unmodifiableCollection(ways);
     
    89113    /**
    90114     * All relations/relationships
    91      * @deprecated Use getRelations() for read-only operations, addPrimitive() and removePrimitive() for modifications
    92      */
    93     @Deprecated
    94     public Collection<Relation> relations = new LinkedList<Relation>();
    95 
     115     */
     116    private Collection<Relation> relations = new LinkedList<Relation>();
     117
     118    /**
     119     * Replies an unmodifiable collection of relations in this dataset
     120     *
     121     * @return an unmodifiable collection of relations in this dataset
     122     */
    96123    public Collection<Relation> getRelations() {
    97124        return Collections.unmodifiableCollection(relations);
     
    703730        }
    704731    }
     732
     733    /**
     734     * Removes all primitives from the dataset and resets the currently selected primitives
     735     * to the empty collection. Also notifies selection change listeners if necessary.
     736     *
     737     */
     738    public void clear() {
     739        if (!selectedPrimitives.isEmpty()) {
     740            selectedPrimitives.clear();
     741            fireSelectionChanged();
     742        }
     743        nodes.clear();
     744        ways.clear();
     745        relations.clear();
     746    }
    705747}
  • trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java

    r2348 r2396  
    1010import org.openstreetmap.josm.data.APIDataSet;
    1111import org.openstreetmap.josm.data.osm.Changeset;
    12 import org.openstreetmap.josm.data.osm.DataSet;
    1312import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1413import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    121120                    ProgressMonitor m = monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
    122121                    if (isCancelled()) return;
    123                     writer.uploadOsm(layer.data.version, toUpload, changeset, m);
     122                    writer.uploadOsm(layer.data.getVersion(), toUpload, changeset, m);
    124123                    processedPrimitives.addAll(writer.getProcessedPrimitives());
    125124                    break;
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r2388 r2396  
    256256        tool += trn("{0} way", "{0} ways", ways, ways);
    257257
    258         if (data.version != null) {
    259             tool += ", " + tr("version {0}", data.version);
     258        if (data.getVersion() != null) {
     259            tool += ", " + tr("version {0}", data.getVersion());
    260260        }
    261261        File f = getAssociatedFile();
     
    292292
    293293        // copy the merged layer's API version, downgrade if required
    294         if (data.version == null) {
    295             data.version = from.version;
    296         } else if ("0.5".equals(data.version) ^ "0.5".equals(from.version)) {
     294        if (data.getVersion() == null) {
     295            data.setVersion(from.getVersion());
     296        } else if ("0.5".equals(data.getVersion()) ^ "0.5".equals(from.getVersion())) {
    297297            System.err.println(tr("Warning: mixing 0.6 and 0.5 data results in version 0.5"));
    298             data.version = "0.5";
     298            data.setVersion("0.5");
    299299        }
    300300
     
    522522        p.add(new JLabel(wayText, ImageProvider.get("data", "way"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0));
    523523        p.add(new JLabel(relationText, ImageProvider.get("data", "relation"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0));
    524         p.add(new JLabel(tr("API version: {0}", (data.version != null) ? data.version : tr("unset"))));
     524        p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset"))));
    525525
    526526        return p;
  • trunk/src/org/openstreetmap/josm/io/OsmExporter.java

    r2181 r2396  
    6666            Writer writer = new OutputStreamWriter(out, "UTF-8");
    6767
    68             OsmWriter w = new OsmWriter(new PrintWriter(writer), false, layer.data.version);
     68            OsmWriter w = new OsmWriter(new PrintWriter(writer), false, layer.data.getVersion());
    6969            w.header();
    7070            w.writeDataSources(layer.data);
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r2382 r2396  
    184184                // save generator attribute for later use when creating DataSource objects
    185185                generator = atts.getValue("generator");
    186                 ds.version = v;
     186                ds.setVersion(v);
    187187
    188188            } else if (qName.equals("bounds")) {
     
    348348                    throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.id), version));
    349349                }
    350                 if (ds.version.equals("0.6")){
     350                if (ds.getVersion().equals("0.6")){
    351351                    if (current.version <= 0 && current.id > 0) {
    352352                        throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.id), version));
     
    355355                        current.version = 0;
    356356                    }
    357                 } else if (ds.version.equals("0.5")) {
     357                } else if (ds.getVersion().equals("0.5")) {
    358358                    if (current.version <= 0 && current.id > 0) {
    359359                        System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.id, current.version, 1, "0.5"));
     
    365365                } else {
    366366                    // should not happen. API version has been checked before
    367                     throwException(tr("Unknown or unsupported API version. Got {0}.", ds.version));
     367                    throwException(tr("Unknown or unsupported API version. Got {0}.", ds.getVersion()));
    368368                }
    369369            } else {
    370370                // version expected for OSM primitives with an id assigned by the server (id > 0), since API 0.6
    371371                //
    372                 if (current.id > 0 && ds.version != null && ds.version.equals("0.6")) {
     372                if (current.id > 0 && ds.getVersion() != null && ds.getVersion().equals("0.6")) {
    373373                    throwException(tr("Missing attribute ''version'' on OSM primitive with ID {0}.", Long.toString(current.id)));
    374                 } else if (current.id > 0 && ds.version != null && ds.version.equals("0.5")) {
     374                } else if (current.id > 0 && ds.getVersion() != null && ds.getVersion().equals("0.5")) {
    375375                    // default version in 0.5 files for existing primitives
    376376                    System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.id, current.version, 1, "0.5"));
    377377                    current.version= 1;
    378                 } else if (current.id <= 0 && ds.version != null && ds.version.equals("0.5")) {
     378                } else if (current.id <= 0 && ds.getVersion() != null && ds.getVersion().equals("0.5")) {
    379379                    // default version in 0.5 files for new primitives
    380380                    System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.id, current.version, 0, "0.5"));
Note: See TracChangeset for help on using the changeset viewer.