1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.imagery;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.Collections;
|
---|
9 | import java.util.LinkedList;
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
14 | import org.openstreetmap.josm.gui.layer.ImageryLayer;
|
---|
15 |
|
---|
16 | public 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 | }
|
---|