Ignore:
Timestamp:
2009-10-27T22:33:54+01:00 (15 years ago)
Author:
Gubaer
Message:

Improved bookmark tab in download dialog

File:
1 edited

Legend:

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

    r2327 r2334  
    6060     */
    6161    public static class Bookmark implements Comparable<Bookmark> {
    62         public String name;
    63         public double[] latlon = new double[4]; // minlat, minlon, maxlat, maxlon
     62        private String name;
     63        private Bounds area;
    6464       
    65         public Bookmark() {           
     65        public Bookmark() {   
     66            area = null;
     67            name = null;
    6668        }
    6769       
    68         public Bookmark(Bounds b) {
    69             if (b == null) {
    70                 latlon[0] = 0.0;
    71                 latlon[1] = 0.0;
    72                 latlon[2] = 0.0;
    73                 latlon[3] = 0.0;
    74             } else {
    75                 latlon[0] = b.getMin().lat();
    76                 latlon[1] = b.getMin().lon();
    77                 latlon[2] = b.getMax().lat();
    78                 latlon[3] = b.getMax().lon();
    79             }
     70        public Bookmark(Bounds area) {
     71            this.area = area;           
    8072        }
    8173       
     
    8880        }
    8981       
    90         public Bounds asBounds() {
    91             return new Bounds(latlon[0], latlon[1], latlon[2], latlon[3]);
     82        public Bounds getArea() {
     83            return area;
     84        }
     85
     86        public String getName() {
     87            return name;
     88        }
     89
     90        public void setName(String name) {
     91            this.name = name;
     92        }
     93
     94        public void setArea(Bounds area) {
     95            this.area = area;
    9296        }
    9397    }
     
    488492            // FIXME: legacy code using ',' sign, should be \u001e only
    489493            Matcher m = Pattern.compile("^(.+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)$").matcher(line);
    490             if(m.matches())
    491             {
    492                 Bookmark b = new Bookmark();
    493                 b.name = m.group(1);
    494                 for (int i = 0; i < b.latlon.length; ++i) {
    495                     b.latlon[i] = Double.parseDouble(m.group(i+2));
     494            if (!m.matches() || m.groupCount() != 5) {
     495                System.err.println(tr("Error: Unexpected line ''{0}'' in bookmark file ''{1}''",line, bookmarkFile.toString()));
     496                continue;
     497            }
     498            Bookmark b = new Bookmark();
     499            b.setName(m.group(1));
     500            double[] values= new double[4];
     501            for (int i = 0; i < 4; ++i) {
     502                try {
     503                    values[i] = Double.parseDouble(m.group(i+2));
     504                } catch(NumberFormatException e) {
     505                    System.err.println(tr("Error: Illegal double value ''{0}'' on line ''{1}'' in bookmark file ''{2}''",m.group(i+2),line, bookmarkFile.toString()));
     506                    continue;                   
    496507                }
    497                 bookmarks.add(b);
    498             }
     508            }
     509            b.setArea(new Bounds(values));
     510            bookmarks.add(b);
    499511        }
    500512        in.close();
     
    511523                new FileOutputStream(bookmarkFile), "utf-8"));
    512524        for (Bookmark b : bookmarks) {
    513             out.print(b.name+"\u001e");
    514             for (int i = 0; i < b.latlon.length; ++i) {
    515                 out.print(b.latlon[i]+(i<b.latlon.length-1?"\u001e":""));
    516             }
     525            out.print(b.getName()+ "\u001e");
     526            Bounds area = b.getArea();
     527            out.print(area.getMin().lat() +"\u001e");
     528            out.print(area.getMin().lon() +"\u001e");
     529            out.print(area.getMax().lat() +"\u001e");
     530            out.print(area.getMax().lon());
    517531            out.println();
    518532        }
Note: See TracChangeset for help on using the changeset viewer.