Changeset 25546 in osm for applications


Ignore:
Timestamp:
2011-03-08T19:25:36+01:00 (13 years ago)
Author:
joshdoe
Message:

pdfimport: Save and restore projection preferences to/from placement sidecar file

With the recent addition of a projection preference dialog, it makes sense to save and restore the preferences on a per PDF basis.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pdfimport/src/pdfimport/FilePlacement.java

    r25349 r25546  
    55import java.awt.geom.AffineTransform;
    66import java.awt.geom.Point2D;
     7import java.util.Arrays;
     8import java.util.Collection;
    79import java.util.Properties;
    810
     
    1113import org.openstreetmap.josm.data.coor.LatLon;
    1214import org.openstreetmap.josm.data.projection.Projection;
     15import org.openstreetmap.josm.data.projection.ProjectionSubPrefs;
    1316import org.openstreetmap.josm.data.projection.Projections;
     17import org.openstreetmap.josm.tools.Utils;
    1418
    1519public class FilePlacement {
     
    4246        }
    4347
     48        private String fromCollection(Collection<String> val) {
     49                if (val != null && !val.isEmpty())
     50                    return Utils.join("\u001e", val);
     51                return null;
     52        }
     53
     54        private Collection<String> toCollection(String s) {
     55                if (s != null && s.length() != 0) {
     56                        return Arrays.asList(s.split("\u001e", -1));
     57                }
     58                return null;
     59        }
     60
    4461        public Properties toProperties() {
    4562                Properties p = new Properties();
    4663                if (projection != null) {
    4764                        p.setProperty("Projection", projection.getClass().getCanonicalName());
     65
     66                        if (projection instanceof ProjectionSubPrefs) {
     67                                ProjectionSubPrefs projPrefs = (ProjectionSubPrefs) projection;
     68                                String code = projection.toCode();
     69                                String prefs = fromCollection(projPrefs.getPreferencesFromCode(code));
     70                                if (prefs != null) {
     71                                    p.setProperty("ProjectionPrefs", prefs);
     72                                }
     73                        }
    4874                }
    4975
     
    7096                                        projection = proj;
    7197                                        break;
     98                                }
     99                        }
     100                        if (projection instanceof ProjectionSubPrefs) {
     101                                ProjectionSubPrefs projPrefs = (ProjectionSubPrefs) projection;
     102
     103                                String s;
     104                                s = p.getProperty("ProjectionPrefs", null);
     105                                Collection<String> prefs = toCollection(s);
     106                                if (prefs != null) {
     107                                    projPrefs.setPreferences(prefs);
    72108                                }
    73109                        }
Note: See TracChangeset for help on using the changeset viewer.