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