source: josm/trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java@ 3719

Last change on this file since 3719 was 3719, checked in by bastiK, 13 years ago

added missing license information

File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.ArrayList;
7import java.util.Collection;
8import java.util.Collections;
9import java.util.LinkedList;
10import java.util.List;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.projection.Projection;
14import org.openstreetmap.josm.gui.layer.ImageryLayer;
15
16public class OffsetBookmark {
17 public static List<OffsetBookmark> allBookmarks = new ArrayList<OffsetBookmark>();
18
19 public Projection proj;
20 public String layerName;
21 public String name;
22 public double dx, dy;
23
24 public boolean isUsable(ImageryLayer layer) {
25 return Main.proj.getClass() == proj.getClass() &&
26 layer.getInfo().getName().equals(layerName);
27 }
28 public OffsetBookmark(Projection proj, String layerName, String name, double dx, double dy) {
29 this.proj = proj;
30 this.layerName = layerName;
31 this.name = name;
32 this.dx = dx;
33 this.dy = dy;
34 }
35
36 public OffsetBookmark(Collection<String> list) {
37 ArrayList<String> array = new ArrayList<String>(list);
38 String projectionName = array.get(0);
39 for (Projection proj : Projection.allProjections) {
40 if (proj.getCacheDirectoryName().equals(projectionName)) {
41 this.proj = proj;
42 break;
43 }
44 }
45 if (this.proj == null)
46 throw new IllegalStateException(tr("Projection ''{0}'' not found", projectionName));
47 this.layerName = array.get(1);
48 this.name = array.get(2);
49 this.dx = Double.valueOf(array.get(3));
50 this.dy = Double.valueOf(array.get(4));
51 }
52
53 public ArrayList<String> getInfoArray() {
54 ArrayList<String> res = new ArrayList<String>(5);
55 res.add(proj.getCacheDirectoryName()); // we should use non-localized projection name
56 res.add(layerName);
57 res.add(name);
58 res.add(String.valueOf(dx));
59 res.add(String.valueOf(dy));
60 return res;
61 }
62
63 public static void loadBookmarks() {
64 for(Collection<String> c : Main.pref.getArray("imagery.offsets",
65 Collections.<Collection<String>>emptySet())) {
66 allBookmarks.add(new OffsetBookmark(c));
67 }
68 }
69
70 public static void saveBookmarks() {
71 LinkedList<Collection<String>> coll = new LinkedList<Collection<String>>();
72 for (OffsetBookmark b : allBookmarks) {
73 coll.add(b.getInfoArray());
74 }
75 Main.pref.putArray("imagery.offsets", coll);
76 }
77
78}
Note: See TracBrowser for help on using the repository browser.