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

Last change on this file since 3718 was 3715, checked in by Upliner, 13 years ago

Added imagery plugin to josm core. Imagery plugin is union of wmsplugin and slippymap plugins. It includes code by Tim Waters, Petr Dlouhý, Frederik Ramm and others. Also enables the remotecontol which was integrated in [3707].

File size: 2.5 KB
Line 
1package org.openstreetmap.josm.data.imagery;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.util.ArrayList;
6import java.util.Collection;
7import java.util.Collections;
8import java.util.LinkedList;
9import java.util.List;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.projection.Projection;
13import org.openstreetmap.josm.gui.layer.ImageryLayer;
14
15public 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}
Note: See TracBrowser for help on using the repository browser.