- Timestamp:
- 2017-05-07T17:34:41+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java
r11651 r12084 7 7 import java.util.Collection; 8 8 import java.util.Collections; 9 import java.util.LinkedList;10 9 import java.util.List; 11 10 import java.util.ListIterator; 12 11 13 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.Preferences.pref; 14 import org.openstreetmap.josm.data.coor.EastNorth; 14 15 import org.openstreetmap.josm.data.coor.LatLon; 15 16 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; … … 19 20 private static final List<OffsetBookmark> allBookmarks = new ArrayList<>(); 20 21 21 publicString projectionCode;22 publicStringlayerName;23 publicString name;24 publicdouble dx, dy;25 publicdouble centerX, centerY;22 @pref private String projection_code; 23 @pref private String imagery_name; 24 @pref private String name; 25 @pref private double dx, dy; 26 @pref private double center_lon, center_lat; 26 27 27 28 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; 29 if (projection_code == null) return false; 30 if (!Main.getProjection().toCode().equals(projection_code)) return false; 31 return layer.getInfo().getName().equals(imagery_name); 32 } 33 34 /** 35 * Construct new empty OffsetBookmark. 36 * 37 * Only used for preferences handling. 38 */ 39 public OffsetBookmark() { 40 // do nothing 41 } 42 43 public OffsetBookmark(String projectionCode, String imageryName, String name, double dx, double dy) { 44 this(projectionCode, imageryName, name, dx, dy, 0, 0); 45 } 46 47 public OffsetBookmark(String projectionCode, String imageryName, String name, double dx, double dy, double centerLon, double centerLat) { 48 this.projection_code = projectionCode; 49 this.imagery_name = imageryName; 40 50 this.name = name; 41 51 this.dx = dx; 42 52 this.dy = dy; 43 this.center X= centerX;44 this.center Y= centerY;53 this.center_lon = centerLon; 54 this.center_lat = centerLat; 45 55 } 46 56 47 57 public OffsetBookmark(Collection<String> list) { 48 58 List<String> array = new ArrayList<>(list); 49 this.projection Code = array.get(0);50 this. layerName = array.get(1);59 this.projection_code = array.get(0); 60 this.imagery_name = array.get(1); 51 61 this.name = array.get(2); 52 62 this.dx = Double.parseDouble(array.get(3)); 53 63 this.dy = Double.parseDouble(array.get(4)); 54 64 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); 65 this.center_lon = Double.parseDouble(array.get(5)); 66 this.center_lat = Double.parseDouble(array.get(6)); 67 } 68 if (projection_code == null) { 69 Main.error(tr("Projection ''{0}'' is not found, bookmark ''{1}'' is not usable", projection_code, name)); 70 } 71 } 72 73 public String getProjectionCode() { 74 return projection_code; 75 } 76 77 public String getName() { 78 return name; 79 } 80 81 public String getImageryName() { 82 return imagery_name; 83 } 84 85 public EastNorth getOffset() { 86 return new EastNorth(dx, dy); 87 } 88 89 public LatLon getCenter() { 90 return new LatLon(center_lat, center_lon); 91 } 92 93 public void setProjectionCode(String projectionCode) { 94 this.projection_code = projectionCode; 95 } 96 97 public void setName(String name) { 98 this.name = name; 99 } 100 101 public void setImageryName(String imageryName) { 102 this.imagery_name = imageryName; 103 } 104 105 public void setOffset(EastNorth offset) { 106 this.dx = offset.east(); 107 this.dy = offset.north(); 108 } 109 110 public static void loadBookmarks() { 111 List<OffsetBookmark> bookmarks = Main.pref.getListOfStructs("imagery.offsetbookmarks", null, OffsetBookmark.class); 112 if (bookmarks == null) { 113 loadBookmarksOld(); 114 saveBookmarks(); 67 115 } 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() { 116 allBookmarks.addAll(bookmarks); 117 } 118 } 119 120 // migration code - remove Nov. 2017 121 private static void loadBookmarksOld() { 82 122 for (Collection<String> c : Main.pref.getArray("imagery.offsets", 83 123 Collections.<Collection<String>>emptySet())) { … … 87 127 88 128 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); 129 Main.pref.putListOfStructs("imagery.offsetbookmarks", allBookmarks, OffsetBookmark.class); 94 130 } 95 131 -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r11960 r12084 54 54 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource; 55 55 import org.openstreetmap.josm.Main; 56 import org.openstreetmap.josm.data.coor.EastNorth; 56 57 import org.openstreetmap.josm.data.imagery.ImageryInfo; 57 58 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds; … … 783 784 784 785 private static boolean confirmEulaAcceptance(PreferenceTabbedPane gui, String eulaUrl) { 785 URL url = null;786 URL url; 786 787 try { 787 788 url = new URL(eulaUrl.replaceAll("\\{lang\\}", LanguageInfo.getWikiLanguagePrefix())); 788 JosmEditorPane htmlPane = null;789 JosmEditorPane htmlPane; 789 790 try { 790 791 htmlPane = new JosmEditorPane(url); … … 904 905 switch (column) { 905 906 case 0: 906 if (info. projectionCode == null) return "";907 return info. projectionCode;907 if (info.getProjectionCode() == null) return ""; 908 return info.getProjectionCode(); 908 909 case 1: 909 return info. layerName;910 return info.getImageryName(); 910 911 case 2: 911 return info. name;912 return info.getName(); 912 913 case 3: 913 return info. dx;914 return info.getOffset().east(); 914 915 case 4: 915 return info. dy;916 return info.getOffset().north(); 916 917 default: 917 918 throw new ArrayIndexOutOfBoundsException(); … … 924 925 switch (column) { 925 926 case 1: 926 info. layerName =o.toString();927 info.setImageryName(o.toString()); 927 928 break; 928 929 case 2: 929 info. name =o.toString();930 info.setName(o.toString()); 930 931 break; 931 932 case 3: 932 info.dx = Double.parseDouble((String) o); 933 double dx = Double.parseDouble((String) o); 934 info.setOffset(new EastNorth(dx, info.getOffset().north())); 933 935 break; 934 936 case 4: 935 info.dy = Double.parseDouble((String) o); 937 double dy = Double.parseDouble((String) o); 938 info.setOffset(new EastNorth(info.getOffset().east(), dy)); 936 939 break; 937 940 default:
Note:
See TracChangeset
for help on using the changeset viewer.