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

Last change on this file since 11114 was 10742, checked in by Don-vip, 8 years ago

sonar - squid:CallToDeprecatedMethod - remove calls to deprecated methods

  • Property svn:eol-style set to native
File size: 4.3 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;
11import java.util.ListIterator;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.coor.LatLon;
15import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
16import org.openstreetmap.josm.gui.layer.ImageryLayer;
17
18public class OffsetBookmark {
19 public static final List<OffsetBookmark> allBookmarks = new ArrayList<>();
20
21 public String projectionCode;
22 public String layerName;
23 public String name;
24 public double dx, dy;
25 public double centerX, centerY;
26
27 public boolean isUsable(ImageryLayer layer) {
28 if (projectionCode == null) return false;
29 if (!Main.getProjection().toCode().equals(projectionCode)) return false;
30 return layer.getInfo().getName().equals(layerName);
31 }
32
33 public OffsetBookmark(String projectionCode, String layerName, String name, double dx, double dy) {
34 this(projectionCode, layerName, name, dx, dy, 0, 0);
35 }
36
37 public OffsetBookmark(String projectionCode, String layerName, String name, double dx, double dy, double centerX, double centerY) {
38 this.projectionCode = projectionCode;
39 this.layerName = layerName;
40 this.name = name;
41 this.dx = dx;
42 this.dy = dy;
43 this.centerX = centerX;
44 this.centerY = centerY;
45 }
46
47 public OffsetBookmark(Collection<String> list) {
48 List<String> array = new ArrayList<>(list);
49 this.projectionCode = array.get(0);
50 this.layerName = array.get(1);
51 this.name = array.get(2);
52 this.dx = Double.parseDouble(array.get(3));
53 this.dy = Double.parseDouble(array.get(4));
54 if (array.size() >= 7) {
55 this.centerX = Double.parseDouble(array.get(5));
56 this.centerY = Double.parseDouble(array.get(6));
57 }
58 if (projectionCode == null) {
59 Main.error(tr("Projection ''{0}'' is not found, bookmark ''{1}'' is not usable", projectionCode, name));
60 }
61 }
62
63 public List<String> getInfoArray() {
64 List<String> res = new ArrayList<>(7);
65 if (projectionCode != null) {
66 res.add(projectionCode);
67 } else {
68 res.add("");
69 }
70 res.add(layerName);
71 res.add(name);
72 res.add(String.valueOf(dx));
73 res.add(String.valueOf(dy));
74 if (centerX != 0 || centerY != 0) {
75 res.add(String.valueOf(centerX));
76 res.add(String.valueOf(centerY));
77 }
78 return res;
79 }
80
81 public static void loadBookmarks() {
82 for (Collection<String> c : Main.pref.getArray("imagery.offsets",
83 Collections.<Collection<String>>emptySet())) {
84 allBookmarks.add(new OffsetBookmark(c));
85 }
86 }
87
88 public static void saveBookmarks() {
89 List<Collection<String>> coll = new LinkedList<>();
90 for (OffsetBookmark b : allBookmarks) {
91 coll.add(b.getInfoArray());
92 }
93 Main.pref.putArray("imagery.offsets", coll);
94 }
95
96 public static OffsetBookmark getBookmarkByName(ImageryLayer layer, String name) {
97 for (OffsetBookmark b : allBookmarks) {
98 if (b.isUsable(layer) && name.equals(b.name))
99 return b;
100 }
101 return null;
102 }
103
104 public static void bookmarkOffset(String name, AbstractTileSourceLayer layer) {
105 LatLon center;
106 if (Main.isDisplayingMapView()) {
107 center = Main.getProjection().eastNorth2latlon(Main.map.mapView.getCenter());
108 } else {
109 center = LatLon.ZERO;
110 }
111 OffsetBookmark nb = new OffsetBookmark(
112 Main.getProjection().toCode(), layer.getInfo().getName(),
113 name, layer.getDisplaySettings().getDx(), layer.getDisplaySettings().getDy(), center.lon(), center.lat());
114 for (ListIterator<OffsetBookmark> it = allBookmarks.listIterator(); it.hasNext();) {
115 OffsetBookmark b = it.next();
116 if (b.isUsable(layer) && name.equals(b.name)) {
117 it.set(nb);
118 saveBookmarks();
119 return;
120 }
121 }
122 allBookmarks.add(nb);
123 saveBookmarks();
124 }
125}
Note: See TracBrowser for help on using the repository browser.