Changeset 4126 in josm for trunk/src/org
- Timestamp:
- 2011-06-07T19:05:14+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r3993 r4126 16 16 import java.awt.event.WindowEvent; 17 17 import java.io.File; 18 import java.lang.ref.WeakReference; 18 19 import java.net.URI; 19 20 import java.net.URISyntaxException; 20 21 import java.util.ArrayList; 21 22 import java.util.Collection; 23 import java.util.Iterator; 22 24 import java.util.List; 23 25 import java.util.Map; … … 56 58 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy; 57 59 import org.openstreetmap.josm.data.projection.Projection; 60 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; 58 61 import org.openstreetmap.josm.data.validation.OsmValidator; 59 62 import org.openstreetmap.josm.gui.GettingStarted; … … 73 76 import org.openstreetmap.josm.io.OsmApi; 74 77 import org.openstreetmap.josm.plugins.PluginHandler; 78 import org.openstreetmap.josm.tools.CheckParameterUtil; 75 79 import org.openstreetmap.josm.tools.I18n; 76 80 import org.openstreetmap.josm.tools.ImageProvider; … … 119 123 public static PrimitiveDeepCopy pasteBuffer = new PrimitiveDeepCopy(); 120 124 public static Layer pasteSource; 121 /** 122 * The projection method used. 123 */ 124 public static Projection proj; 125 125 126 /** 126 127 * The MapFrame. Use setMapFrame to set or clear it. … … 154 155 */ 155 156 static public int debug_level = 1; 156 static public finalvoid debug(String msg) {157 static public void debug(String msg) { 157 158 if (debug_level <= 0) 158 159 return; … … 213 214 platform.startupHook(); 214 215 215 // We try to establish an API connection early, so that any API 216 // We try to establish an API connection early, so that any API 216 217 // capabilities are already known to the editor instance. However 217 218 // if it goes wrong that's not critical at this stage. … … 768 769 System.err.println("Error: Could not recognize Java Version: "+version); 769 770 } 771 772 /* ----------------------------------------------------------------------------------------- */ 773 /* projection handling - Main is a registry for a single, global projection instance */ 774 /* */ 775 /* TODO: For historical reasons the registry is implemented by Main. An alternative approach */ 776 /* would be a singleton org.openstreetmap.josm.data.projection.ProjectionRegistry class. */ 777 /* ----------------------------------------------------------------------------------------- */ 778 /** 779 * The projection method used. 780 * @deprecated use {@link #getProjection()} and {@link #setProjection(Projection)} instead. 781 * For the time being still publicly available, but avoid/migrate write access to it. Use 782 * {@link #setProjection(Projection)} in order to trigger a projection change event. 783 */ 784 @Deprecated 785 public static Projection proj; 786 787 /** 788 * Replies the current projection. 789 * 790 * @return 791 */ 792 public static Projection getProjection() { 793 return proj; 794 } 795 796 /** 797 * Sets the current projection 798 * 799 * @param p the projection 800 */ 801 public static void setProjection(Projection p) { 802 CheckParameterUtil.ensureParameterNotNull(p); 803 Projection oldValue = proj; 804 proj = p; 805 fireProjectionChanged(oldValue, proj); 806 } 807 808 /* 809 * Keep WeakReferences to the listeners. This relieves clients from the burden of 810 * explicitly removing the listeners and allows us to transparently register every 811 * created dataset as projection change listener. 812 */ 813 private static final ArrayList<WeakReference<ProjectionChangeListener>> listeners = new ArrayList<WeakReference<ProjectionChangeListener>>(); 814 815 private static void fireProjectionChanged(Projection oldValue, Projection newValue) { 816 if (newValue == null ^ oldValue == null 817 || (newValue != null && oldValue != null && !newValue.getClass().getName().equals(oldValue.getClass().getName()))) { 818 819 synchronized(Main.class) { 820 Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator(); 821 while(it.hasNext()){ 822 WeakReference<ProjectionChangeListener> wr = it.next(); 823 if (wr.get() == null) { 824 it.remove(); 825 continue; 826 } 827 wr.get().projectionChanged(oldValue, newValue); 828 } 829 } 830 if (newValue != null) { 831 Bounds b = (Main.map != null && Main.map.mapView != null) ? Main.map.mapView.getRealBounds() : null; 832 if (b != null){ 833 Main.map.mapView.zoomTo(b); 834 } 835 } 836 /* TODO - remove layers with fixed projection */ 837 } 838 } 839 840 /** 841 * Register a projection change listener 842 * 843 * @param listener the listener. Ignored if null. 844 */ 845 public static void addProjectionChangeListener(ProjectionChangeListener listener) { 846 if (listener == null) return; 847 synchronized (Main.class) { 848 for (WeakReference<ProjectionChangeListener> wr : listeners) { 849 // already registered ? => abort 850 if (wr.get() == listener) return; 851 } 852 } 853 listeners.add(new WeakReference<ProjectionChangeListener>(listener)); 854 } 855 856 /** 857 * Removes a projection change listener 858 * 859 * @param listener the listener. Ignored if null. 860 */ 861 public static void removeProjectionChangeListener(ProjectionChangeListener listener) { 862 if (listener == null) return; 863 synchronized(Main.class){ 864 Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator(); 865 while(it.hasNext()){ 866 WeakReference<ProjectionChangeListener> wr = it.next(); 867 // remove the listener - and any other listener which god garbage 868 // collected in the meantime 869 if (wr.get() == null || wr.get() == listener) { 870 it.remove(); 871 } 872 } 873 } 874 } 770 875 } -
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r3083 r4126 153 153 double x = xc + r*Math.cos(a); 154 154 double y = yc + r*Math.sin(a); 155 Node n = new Node(Main. proj.eastNorth2latlon(new EastNorth(x,y)));155 Node n = new Node(Main.getProjection().eastNorth2latlon(new EastNorth(x,y))); 156 156 wayToAdd.add(n); 157 157 cmds.add(new AddCommand(n)); … … 245 245 double x = xc + r*Math.cos(a); 246 246 double y = yc + r*Math.sin(a); 247 Node n = new Node(Main. proj.eastNorth2latlon(new EastNorth(x,y)));247 Node n = new Node(Main.getProjection().eastNorth2latlon(new EastNorth(x,y))); 248 248 wayToAdd.add(n); 249 249 cmds.add(new AddCommand(n)); -
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r4001 r4126 162 162 pnl.add(new JMultilineLabel(tr("Use arrow keys or drag the imagery layer with mouse to adjust the imagery offset.\n" + 163 163 "You can also enter east and north offset in the {0} coordinates.\n" + 164 "If you want to save the offset as bookmark, enter the bookmark name below",Main. proj.toString())), GBC.eop());164 "If you want to save the offset as bookmark, enter the bookmark name below",Main.getProjection().toString())), GBC.eop()); 165 165 pnl.add(new JLabel(tr("Offset: ")),GBC.std()); 166 166 pnl.add(tOffset,GBC.eol().fill(GBC.HORIZONTAL).insets(0,0,0,5)); … … 211 211 public void updateOffsetIntl() { 212 212 // Support projections with very small numbers (e.g. 4326) 213 int precision = Main. proj.getDefaultZoomInPPD() >= 1.0 ? 2 : 7;213 int precision = Main.getProjection().getDefaultZoomInPPD() >= 1.0 ? 2 : 7; 214 214 // US locale to force decimal separator to be '.' 215 215 tOffset.setText(new java.util.Formatter(java.util.Locale.US).format( -
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r3757 r4126 117 117 if (!isEnabled()) 118 118 return; 119 if ("EPSG:4326".equals(Main. proj.toString())) {119 if ("EPSG:4326".equals(Main.getProjection().toString())) { 120 120 String msg = tr("<html>You are using the EPSG:4326 projection which might lead<br>" + 121 121 "to undesirable results when doing rectangular alignments.<br>" + -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r3939 r4126 255 255 256 256 // find out the movement distance, in metres 257 double distance = Main. proj.eastNorth2latlon(initialN1en).greatCircleDistance(Main.proj.eastNorth2latlon(newN1en));257 double distance = Main.getProjection().eastNorth2latlon(initialN1en).greatCircleDistance(Main.getProjection().eastNorth2latlon(newN1en)); 258 258 Main.map.statusLine.setDist(distance); 259 259 updateStatusLine(); … … 309 309 //move existing node 310 310 Node n1Old = selectedSegment.getFirstNode(); 311 cmds.add(new MoveCommand(n1Old, Main. proj.eastNorth2latlon(newN1en)));311 cmds.add(new MoveCommand(n1Old, Main.getProjection().eastNorth2latlon(newN1en))); 312 312 } else { 313 313 //introduce new node 314 Node n1New = new Node(Main. proj.eastNorth2latlon(newN1en));314 Node n1New = new Node(Main.getProjection().eastNorth2latlon(newN1en)); 315 315 wnew.addNode(insertionPoint, n1New); 316 316 insertionPoint ++; … … 326 326 //move existing node 327 327 Node n2Old = selectedSegment.getSecondNode(); 328 cmds.add(new MoveCommand(n2Old, Main. proj.eastNorth2latlon(newN2en)));328 cmds.add(new MoveCommand(n2Old, Main.getProjection().eastNorth2latlon(newN2en))); 329 329 } else { 330 330 //introduce new node 331 Node n2New = new Node(Main. proj.eastNorth2latlon(newN2en));331 Node n2New = new Node(Main.getProjection().eastNorth2latlon(newN2en)); 332 332 wnew.addNode(insertionPoint, n2New); 333 333 insertionPoint ++; -
trunk/src/org/openstreetmap/josm/command/MoveCommand.java
r3682 r4126 12 12 import javax.swing.JLabel; 13 13 14 import org.openstreetmap.josm.data.coor.CachedLatLon;15 14 import org.openstreetmap.josm.data.coor.EastNorth; 16 15 import org.openstreetmap.josm.data.coor.LatLon; … … 18 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 18 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 19 import org.openstreetmap.josm.data.projection.Projections; 20 20 import org.openstreetmap.josm.tools.ImageProvider; 21 21 … … 59 59 60 60 public MoveCommand(Node node, LatLon position) { 61 this(Collections.singleton((OsmPrimitive) node), node.getEastNorth().sub( new CachedLatLon(position).getEastNorth()));61 this(Collections.singleton((OsmPrimitive) node), node.getEastNorth().sub(Projections.project(position))); 62 62 } 63 63 -
trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java
r3253 r4126 5 5 import org.openstreetmap.josm.data.projection.Projection; 6 6 7 /** 8 * LatLon class that maintains a cache of projected EastNorth coordinates. 9 * 10 * This class is convenient to use, but has relatively high memory costs. 11 * It keeps a pointer to the last known projection in order to detect projection 12 * changes. 13 * 14 * Node and WayPoint have another, optimized, cache for projected coordinates. 15 */ 7 16 public class CachedLatLon extends LatLon { 8 17 private EastNorth eastNorth; … … 19 28 20 29 public CachedLatLon(EastNorth eastNorth) { 21 super(Main. proj.eastNorth2latlon(eastNorth));22 proj = Main. proj;30 super(Main.getProjection().eastNorth2latlon(eastNorth)); 31 proj = Main.getProjection(); 23 32 this.eastNorth = eastNorth; 24 33 } … … 30 39 31 40 public final void setEastNorth(EastNorth eastNorth) { 32 proj = Main. proj;41 proj = Main.getProjection(); 33 42 this.eastNorth = eastNorth; 34 43 LatLon l = proj.eastNorth2latlon(eastNorth); … … 36 45 } 37 46 47 /** 48 * Replies the projected east/north coordinates. 49 * 50 * @return the internally cached east/north coordinates. null, if the globally defined projection is null 51 */ 38 52 public final EastNorth getEastNorth() { 39 if(proj != Main. proj)53 if(proj != Main.getProjection()) 40 54 { 41 proj = Main. proj;55 proj = Main.getProjection(); 42 56 eastNorth = proj.latlon2eastNorth(this); 43 57 } -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r3656 r4126 106 106 case DEGREES_MINUTES_SECONDS: return dms(y) + ((y < 0) ? SOUTH : NORTH); 107 107 case NAUTICAL: return dm(y) + ((y < 0) ? SOUTH : NORTH); 108 case EAST_NORTH: return cDdFormatter.format(Main. proj.latlon2eastNorth(this).north());108 case EAST_NORTH: return cDdFormatter.format(Main.getProjection().latlon2eastNorth(this).north()); 109 109 default: return "ERR"; 110 110 } … … 122 122 case DEGREES_MINUTES_SECONDS: return dms(x) + ((x < 0) ? WEST : EAST); 123 123 case NAUTICAL: return dm(x) + ((x < 0) ? WEST : EAST); 124 case EAST_NORTH: return cDdFormatter.format(Main. proj.latlon2eastNorth(this).east());124 case EAST_NORTH: return cDdFormatter.format(Main.getProjection().latlon2eastNorth(this).east()); 125 125 default: return "ERR"; 126 126 } … … 142 142 */ 143 143 public boolean isOutSideWorld() { 144 Bounds b = Main. proj.getWorldBoundsLatLon();144 Bounds b = Main.getProjection().getWorldBoundsLatLon(); 145 145 return lat() < b.getMin().lat() || lat() > b.getMax().lat() || 146 146 lon() < b.getMin().lon() || lon() > b.getMax().lon(); -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r3321 r4126 7 7 import java.util.Date; 8 8 9 import org.openstreetmap.josm. data.coor.CachedLatLon;9 import org.openstreetmap.josm.Main; 10 10 import org.openstreetmap.josm.data.coor.EastNorth; 11 11 import org.openstreetmap.josm.data.coor.LatLon; 12 import org.openstreetmap.josm.data.projection.Projections; 12 13 import org.openstreetmap.josm.tools.PrimaryDateParser; 13 14 … … 26 27 27 28 public WayPoint(LatLon ll) { 28 coor = new CachedLatLon(ll); 29 lat = ll.lat(); 30 lon = ll.lon(); 29 31 } 30 32 31 private final CachedLatLon coor; 33 /* 34 * We "inline" lat/lon, rather than usinga LatLon internally => reduces memory overhead. Relevant 35 * because a lot of GPX waypoints are created when GPS tracks are downloaded from the OSM server. 36 */ 37 private double lat = 0; 38 private double lon = 0; 39 40 /* 41 * internal cache of projected coordinates 42 */ 43 private double east = Double.NaN; 44 private double north = Double.NaN; 45 46 /** 47 * Invalidate the internal cache of east/north coordinates. 48 */ 49 public void invalidateEastNorthCache() { 50 this.east = Double.NaN; 51 this.north = Double.NaN; 52 } 32 53 33 54 public final LatLon getCoor() { 34 return coor;55 return new LatLon(lat,lon); 35 56 } 36 57 58 /** 59 * <p>Replies the projected east/north coordinates.</p> 60 * 61 * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates. 62 * Internally caches the projected coordinates.</p> 63 * 64 * <p><strong>Caveat:</strong> doesn't listen to projection changes. Clients must 65 * {@link #reproject() trigger a reprojection} or {@link #invalidateEastNorthCache() invalidate the internal cache}.</p> 66 * 67 * @return the east north coordinates or {@code null} 68 * @see #invalidateEastNorthCache() 69 * 70 */ 37 71 public final EastNorth getEastNorth() { 38 return coor.getEastNorth(); 72 if (Double.isNaN(east) || Double.isNaN(north)) { 73 // projected coordinates haven't been calculated yet, 74 // so fill the cache of the projected waypoint coordinates 75 EastNorth en = Projections.project(new LatLon(lat, lon)); 76 this.east = en.east(); 77 this.north = en.north(); 78 } 79 return new EastNorth(east, north); 39 80 } 40 81 41 82 @Override 42 83 public String toString() { 43 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + coor.toString() + ", " + attr + ")";84 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + getCoor().toString() + ", " + attr + ")"; 44 85 } 45 86 … … 57 98 } 58 99 59 public int compareTo(WayPoint w) 60 { 100 public int compareTo(WayPoint w) { 61 101 return Double.compare(time, w.time); 62 102 } -
trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java
r3966 r4126 30 30 public boolean isUsable(ImageryLayer layer) { 31 31 if (proj == null) return false; 32 if (!Main. proj.toCode().equals(proj.toCode())) return false;32 if (!Main.getProjection().toCode().equals(proj.toCode())) return false; 33 33 return layer.getInfo().getName().equals(layerName); 34 34 } … … 122 122 LatLon center; 123 123 if (Main.map != null && Main.map.mapView != null) { 124 center = Main. proj.eastNorth2latlon(Main.map.mapView.getCenter());124 center = Main.getProjection().eastNorth2latlon(Main.map.mapView.getCenter()); 125 125 } else { 126 126 center = new LatLon(0,0); 127 127 } 128 128 OffsetBookmark nb = new OffsetBookmark( 129 Main. proj, layer.getInfo().getName(),129 Main.getProjection(), layer.getInfo().getName(), 130 130 name, layer.getDx(), layer.getDy(), center.lon(), center.lat()); 131 131 for (ListIterator<OffsetBookmark> it = allBookmarks.listIterator();it.hasNext();) { -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r4087 r4126 20 20 import java.util.concurrent.locks.ReentrantReadWriteLock; 21 21 22 import org.openstreetmap.josm.Main; 22 23 import org.openstreetmap.josm.data.Bounds; 23 24 import org.openstreetmap.josm.data.SelectionChangedListener; … … 34 35 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 35 36 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 37 import org.openstreetmap.josm.data.projection.Projection; 38 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; 36 39 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 37 40 import org.openstreetmap.josm.tools.FilteredCollection; 38 41 import org.openstreetmap.josm.tools.Predicate; 39 42 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 43 import org.openstreetmap.josm.tools.Utils; 40 44 41 45 /** … … 83 87 * @author imi 84 88 */ 85 public class DataSet implements Cloneable {89 public class DataSet implements Cloneable, ProjectionChangeListener { 86 90 87 91 /** … … 120 124 private final ReadWriteLock lock = new ReentrantReadWriteLock(); 121 125 private final Object selectionLock = new Object(); 126 127 public DataSet() { 128 /* 129 * Transparently register as projection change lister. No need to explicitly remove the 130 * the listener, projection change listeners are managed as WeakReferences. 131 */ 132 Main.addProjectionChangeListener(this); 133 } 122 134 123 135 public Lock getReadLock() { … … 975 987 } 976 988 989 /** 990 * Invalidates the internal cache of projected east/north coordinates. 991 * 992 * This method can be invoked after the globally configured projection method 993 * changed. In contrast to {@link DataSet#reproject()} it only invalidates the 994 * cache and doesn't reproject the coordinates. 995 */ 996 public void invalidateEastNorthCache() { 997 if (Main.getProjection() == null) return; // sanity check 998 try { 999 beginUpdate(); 1000 for (Node n: Utils.filteredCollection(allPrimitives, Node.class)) { 1001 n.invalidateEastNorthCache(); 1002 } 1003 } finally { 1004 endUpdate(); 1005 } 1006 } 1007 977 1008 public void cleanupDeletedPrimitives() { 978 1009 beginUpdate(); … … 1064 1095 return ret; 1065 1096 } 1097 1098 /* --------------------------------------------------------------------------------- */ 1099 /* interface ProjectionChangeListner */ 1100 /* --------------------------------------------------------------------------------- */ 1101 @Override 1102 public void projectionChanged(Projection oldValue, Projection newValue) { 1103 invalidateEastNorthCache(); 1104 } 1066 1105 } -
trunk/src/org/openstreetmap/josm/data/osm/INode.java
r4098 r4126 6 6 7 7 public interface INode extends IPrimitive { 8 8 9 9 LatLon getCoor(); 10 10 void setCoor(LatLon coor); 11 11 EastNorth getEastNorth(); 12 12 void setEastNorth(EastNorth eastNorth); 13 14 13 } -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r4100 r4126 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import org.openstreetmap.josm. data.coor.CachedLatLon;4 import org.openstreetmap.josm.Main; 5 5 import org.openstreetmap.josm.data.coor.EastNorth; 6 6 import org.openstreetmap.josm.data.coor.LatLon; 7 7 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 8 8 import org.openstreetmap.josm.data.osm.visitor.Visitor; 9 import org.openstreetmap.josm.data.projection.Projections; 9 10 10 11 /** … … 15 16 public final class Node extends OsmPrimitive implements INode { 16 17 17 private CachedLatLon coor; 18 /* 19 * We "inline" lat/lon rather than using a LatLon-object => reduces memory footprint 20 */ 21 static private final double COORDINATE_NOT_DEFINED = Double.NaN; 22 private double lat = COORDINATE_NOT_DEFINED; 23 private double lon = COORDINATE_NOT_DEFINED; 24 25 /* 26 * the cached projected coordinates 27 */ 28 private double east = Double.NaN; 29 private double north = Double.NaN; 30 31 private boolean isLatLonKnown() { 32 return lat != COORDINATE_NOT_DEFINED && lon != COORDINATE_NOT_DEFINED; 33 } 18 34 19 35 @Override … … 46 62 @Override 47 63 public final LatLon getCoor() { 48 return coor; 49 } 50 64 if (!isLatLonKnown()) return null; 65 return new LatLon(lat,lon); 66 } 67 68 /** 69 * <p>Replies the projected east/north coordinates.</p> 70 * 71 * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates. 72 * Internally caches the projected coordinates.</p> 73 * 74 * <p><strong>Caveat:</strong> doesn't listen to projection changes. Clients must 75 * {@link #invalidateEastNorthCache() invalidate the internal cache}.</p> 76 * 77 * <p>Replies {@code null} if this node doesn't know lat/lon-coordinates, i.e. because it is an incomplete node. 78 * 79 * @return the east north coordinates or {@code null} 80 * @see #invalidateEastNorthCache() 81 * 82 */ 51 83 @Override 52 84 public final EastNorth getEastNorth() { 53 return coor != null ? coor.getEastNorth() : null; 85 if (!isLatLonKnown()) return null; 86 87 if (getDataSet() == null) 88 // there is no dataset that listens for projection changes 89 // and invalidates the cache, so we don't use the cache at all 90 return Projections.project(new LatLon(lat, lon)); 91 92 if (Double.isNaN(east) || Double.isNaN(north)) { 93 // projected coordinates haven't been calculated yet, 94 // so fill the cache of the projected node coordinates 95 EastNorth en = Projections.project(new LatLon(lat, lon)); 96 this.east = en.east(); 97 this.north = en.north(); 98 } 99 return new EastNorth(east, north); 54 100 } 55 101 … … 58 104 */ 59 105 protected void setCoorInternal(LatLon coor, EastNorth eastNorth) { 60 if(this.coor == null) { 61 if (eastNorth == null) { 62 this.coor = new CachedLatLon(coor); 63 } else { 64 this.coor = new CachedLatLon(eastNorth); 65 } 66 } else { 67 if (eastNorth == null) { 68 this.coor.setCoor(coor); 69 } else { 70 this.coor.setEastNorth(eastNorth); 71 } 72 } 106 if (coor != null) { 107 this.lat = coor.lat(); 108 this.lon = coor.lon(); 109 invalidateEastNorthCache(); 110 } else if (eastNorth != null) { 111 LatLon ll = Projections.inverseProject(eastNorth); 112 this.lat = ll.lat(); 113 this.lon = ll.lon(); 114 this.east = eastNorth.east(); 115 this.north = eastNorth.north(); 116 } else 117 throw new IllegalArgumentException(); 73 118 } 74 119 … … 150 195 try { 151 196 super.cloneFrom(osm); 152 setCoor(((Node)osm). coor);197 setCoor(((Node)osm).getCoor()); 153 198 } finally { 154 199 writeUnlock(locked); … … 173 218 super.mergeFrom(other); 174 219 if (!other.isIncomplete()) { 175 setCoor( new LatLon(((Node)other).coor));220 setCoor(((Node)other).getCoor()); 176 221 } 177 222 } finally { … … 200 245 201 246 @Override public String toString() { 202 String coorDesc = coor == null?"":"lat="+coor.lat()+",lon="+coor.lon();247 String coorDesc = isLatLonKnown() ? "lat="+lat+",lon="+lon : ""; 203 248 return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " " + coorDesc+"}"; 204 249 } … … 211 256 return false; 212 257 Node n = (Node)other; 213 if (coor == null && n.coor == null) 258 LatLon coor = getCoor(); 259 LatLon otherCoor = n.getCoor(); 260 if (coor == null && otherCoor == null) 214 261 return true; 215 else if (coor != null && n.coor != null)216 return coor.equalsEpsilon( n.coor);262 else if (coor != null && otherCoor != null) 263 return coor.equalsEpsilon(otherCoor); 217 264 else 218 265 return false; … … 241 288 @Override 242 289 public void updatePosition() { 243 // TODO: replace CachedLatLon with simple doubles and update precalculated EastNorth value here244 290 } 245 291 … … 253 299 builder.append(toString()); 254 300 builder.append("\n"); 255 if ( coor == null) {301 if (isLatLonKnown()) { 256 302 builder.append("Coor is null\n"); 257 303 } else { 258 builder.append(String.format("EastNorth: %s\n", coor.getEastNorth()));259 builder.append( coor.getProjection());304 builder.append(String.format("EastNorth: %s\n", getEastNorth())); 305 builder.append(Main.getProjection()); 260 306 builder.append("\n"); 261 307 } … … 263 309 return builder.toString(); 264 310 } 311 312 /** 313 * Invoke to invalidate the internal cache of projected east/north coordinates. 314 * Coordinates are reprojected on demand when the {@link #getEastNorth()} is invoked 315 * next time. 316 */ 317 public void invalidateEastNorthCache() { 318 this.east = Double.NaN; 319 this.north = Double.NaN; 320 } 265 321 } -
trunk/src/org/openstreetmap/josm/data/osm/NodeData.java
r4100 r4126 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import org.openstreetmap.josm.data.coor.CachedLatLon;5 4 import org.openstreetmap.josm.data.coor.EastNorth; 6 5 import org.openstreetmap.josm.data.coor.LatLon; 7 6 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 7 import org.openstreetmap.josm.data.projection.Projections; 8 8 9 9 public class NodeData extends PrimitiveData implements INode { 10 10 11 private final CachedLatLon coor = new CachedLatLon(0, 0); 11 /* 12 * we "inline" lat/lon coordinates instead of using a LatLon => reduces memory footprint 13 */ 14 private double lat = Double.NaN; 15 private double lon = Double.NaN; 12 16 13 public NodeData() { 14 15 } 17 public NodeData() {} 16 18 17 19 public NodeData(NodeData data) { … … 20 22 } 21 23 24 private boolean isLatLonKnown() { 25 return lat != Double.NaN && lon != Double.NaN; 26 } 27 22 28 @Override 23 29 public LatLon getCoor() { 24 return coor;30 return isLatLonKnown() ? new LatLon(lat,lon) : null; 25 31 } 26 32 27 33 @Override 28 34 public void setCoor(LatLon coor) { 29 this.coor.setCoor(coor); 35 if (coor == null) { 36 this.lat = Double.NaN; 37 this.lon = Double.NaN; 38 } else { 39 this.lat = coor.lat(); 40 this.lon = coor.lon(); 41 } 30 42 } 31 43 32 44 @Override 33 45 public EastNorth getEastNorth() { 34 return this.coor.getEastNorth(); 46 /* 47 * No internal caching of projected coordinates needed. In contrast to getEastNorth() 48 * on Node, this method is rarely used. Caching would be overkill. 49 */ 50 return Projections.project(getCoor()); 35 51 } 36 52 37 53 @Override 38 54 public void setEastNorth(EastNorth eastNorth) { 39 this.coor.setEastNorth(eastNorth); 55 LatLon ll = Projections.inverseProject(eastNorth); 56 setCoor(ll); 40 57 } 41 58 … … 47 64 @Override 48 65 public String toString() { 49 return super.toString() + " NODE " + coor;66 return super.toString() + " NODE " + getCoor(); 50 67 } 51 68 … … 54 71 return OsmPrimitiveType.NODE; 55 72 } 56 57 @Override 73 74 @Override 58 75 public void visit(PrimitiveVisitor visitor) { 59 76 visitor.visit(this); … … 64 81 return formatter.format(this); 65 82 } 66 67 83 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r4065 r4126 113 113 if (bounds == null) 114 114 return; 115 LatLon minLatlon = Main. proj.eastNorth2latlon(bounds.getMin());116 LatLon maxLatlon = Main. proj.eastNorth2latlon(bounds.getMax());115 LatLon minLatlon = Main.getProjection().eastNorth2latlon(bounds.getMin()); 116 LatLon maxLatlon = Main.getProjection().eastNorth2latlon(bounds.getMax()); 117 117 bounds = new ProjectionBounds( 118 Main. proj.latlon2eastNorth(new LatLon(minLatlon.lat() - enlargeDegree, minLatlon.lon() - enlargeDegree)),119 Main. proj.latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree)));118 Main.getProjection().latlon2eastNorth(new LatLon(minLatlon.lat() - enlargeDegree, minLatlon.lon() - enlargeDegree)), 119 Main.getProjection().latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree))); 120 120 } 121 121 -
trunk/src/org/openstreetmap/josm/data/projection/Projections.java
r3874 r4126 2 2 package org.openstreetmap.josm.data.projection; 3 3 4 import java.util.ArrayList; 4 5 import java.util.Arrays; 5 import java.util.ArrayList; 6 7 import org.openstreetmap.josm.Main; 8 import org.openstreetmap.josm.data.coor.EastNorth; 9 import org.openstreetmap.josm.data.coor.LatLon; 6 10 7 11 /** … … 14 18 */ 15 19 private static ArrayList<Projection> allProjections = 16 new ArrayList<Projection>(Arrays.asList(new Projection[] {17 // global projections18 new Epsg4326(),19 new Mercator(),20 new UTM(),21 // regional - alphabetical order by country name22 new LambertEST(), // Still needs proper default zoom23 new Lambert(), // Still needs proper default zoom24 new LambertCC9Zones(), // Still needs proper default zoom25 new UTM_France_DOM(),26 new TransverseMercatorLV(),27 new Puwg(),28 new Epsg3008(), // SWEREF99 13 3029 new SwissGrid(),30 }));20 new ArrayList<Projection>(Arrays.asList(new Projection[] { 21 // global projections 22 new Epsg4326(), 23 new Mercator(), 24 new UTM(), 25 // regional - alphabetical order by country name 26 new LambertEST(), // Still needs proper default zoom 27 new Lambert(), // Still needs proper default zoom 28 new LambertCC9Zones(), // Still needs proper default zoom 29 new UTM_France_DOM(), 30 new TransverseMercatorLV(), 31 new Puwg(), 32 new Epsg3008(), // SWEREF99 13 30 33 new SwissGrid(), 34 })); 31 35 32 36 public static ArrayList<Projection> getProjections() { … … 43 47 allProjections.add(proj); 44 48 } 49 50 static public EastNorth project(LatLon ll) { 51 if (ll == null) return null; 52 return Main.getProjection().latlon2eastNorth(ll); 53 } 54 55 static public LatLon inverseProject(EastNorth en) { 56 if (en == null) return null; 57 return Main.getProjection().eastNorth2latlon(en); 58 } 45 59 } -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r4051 r4126 23 23 import org.openstreetmap.josm.Main; 24 24 import org.openstreetmap.josm.actions.ValidateAction; 25 import org.openstreetmap.josm.actions.upload.ValidateUploadHook;26 25 import org.openstreetmap.josm.data.projection.Epsg4326; 27 26 import org.openstreetmap.josm.data.projection.Lambert; … … 30 29 import org.openstreetmap.josm.data.validation.tests.CrossingWays; 31 30 import org.openstreetmap.josm.data.validation.tests.DuplicateNode; 31 import org.openstreetmap.josm.data.validation.tests.DuplicateRelation; 32 32 import org.openstreetmap.josm.data.validation.tests.DuplicateWay; 33 import org.openstreetmap.josm.data.validation.tests.DuplicateRelation;34 33 import org.openstreetmap.josm.data.validation.tests.DuplicatedWayNodes; 35 34 import org.openstreetmap.josm.data.validation.tests.MultipolygonTest; … … 48 47 import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays; 49 48 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 50 import org.openstreetmap.josm.gui.layer.ValidatorLayer;51 49 import org.openstreetmap.josm.gui.layer.Layer; 52 50 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 51 import org.openstreetmap.josm.gui.layer.ValidatorLayer; 53 52 import org.openstreetmap.josm.gui.preferences.ValidatorPreference; 54 53 … … 77 76 @SuppressWarnings("unchecked") 78 77 public static Class<Test>[] allAvailableTests = new Class[] { 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 78 DuplicateNode.class, // ID 1 .. 99 79 OverlappingWays.class, // ID 101 .. 199 80 UntaggedNode.class, // ID 201 .. 299 81 UntaggedWay.class, // ID 301 .. 399 82 SelfIntersectingWay.class, // ID 401 .. 499 83 DuplicatedWayNodes.class, // ID 501 .. 599 84 CrossingWays.class, // ID 601 .. 699 85 SimilarNamedWays.class, // ID 701 .. 799 86 NodesWithSameName.class, // ID 801 .. 899 87 Coastlines.class, // ID 901 .. 999 88 WronglyOrderedWays.class, // ID 1001 .. 1099 89 UnclosedWays.class, // ID 1101 .. 1199 90 TagChecker.class, // ID 1201 .. 1299 91 UnconnectedWays.class, // ID 1301 .. 1399 92 DuplicateWay.class, // ID 1401 .. 1499 93 NameMismatch.class, // ID 1501 .. 1599 94 MultipolygonTest.class, // ID 1601 .. 1699 95 RelationChecker.class, // ID 1701 .. 1799 96 TurnrestrictionTest.class, // ID 1801 .. 1899 97 DuplicateRelation.class, // ID 1901 .. 1999 99 98 }; 100 99 … … 242 241 */ 243 242 public void initializeGridDetail() { 244 if (Main. proj.toString().equals(new Epsg4326().toString())) {243 if (Main.getProjection().toString().equals(new Epsg4326().toString())) { 245 244 OsmValidator.griddetail = 10000; 246 } else if (Main. proj.toString().equals(new Mercator().toString())) {245 } else if (Main.getProjection().toString().equals(new Mercator().toString())) { 247 246 OsmValidator.griddetail = 0.01; 248 } else if (Main. proj.toString().equals(new Lambert().toString())) {247 } else if (Main.getProjection().toString().equals(new Lambert().toString())) { 249 248 OsmValidator.griddetail = 0.1; 250 249 } … … 265 264 JOptionPane.showMessageDialog(Main.parent, 266 265 tr("Error initializing test {0}:\n {1}", test.getClass() 267 .getSimpleName(), e),268 tr("Error"),269 JOptionPane.ERROR_MESSAGE);266 .getSimpleName(), e), 267 tr("Error"), 268 JOptionPane.ERROR_MESSAGE); 270 269 } 271 270 } -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r3896 r4126 118 118 * 119 119 * @param listener the listener. Ignored if null or already registered. 120 * @param initialFire Fire an edit-layer-changed-event right after adding 120 * @param initialFire Fire an edit-layer-changed-event right after adding 121 121 * the listener in case there is an edit layer present 122 122 */ … … 285 285 } 286 286 layer.addPropertyChangeListener(this); 287 Main.addProjectionChangeListener(layer); 287 288 AudioPlayer.reset(); 288 289 repaint(); … … 359 360 360 361 layers.remove(layer); 362 Main.removeProjectionChangeListener(layer); 361 363 fireLayerRemoved(layer); 362 364 layer.removePropertyChangeListener(this); -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r4079 r4126 39 39 import org.openstreetmap.josm.data.preferences.IntegerProperty; 40 40 import org.openstreetmap.josm.data.projection.Projection; 41 import org.openstreetmap.josm.data.projection.Projections; 41 42 import org.openstreetmap.josm.gui.help.Helpful; 42 43 import org.openstreetmap.josm.gui.preferences.ProjectionPreference; … … 96 97 * northing/easting space of the projection. 97 98 */ 98 private double scale = Main. proj.getDefaultZoomInPPD();99 private double scale = Main.getProjection().getDefaultZoomInPPD(); 99 100 /** 100 101 * Center n/e coordinate of the desired screen center. … … 111 112 112 113 private EastNorth calculateDefaultCenter() { 113 Bounds b = Main. proj.getWorldBoundsLatLon();114 Bounds b = Main.getProjection().getWorldBoundsLatLon(); 114 115 double lat = (b.getMax().lat() + b.getMin().lat())/2; 115 116 double lon = (b.getMax().lon() + b.getMin().lon())/2; 116 117 117 return Main. proj.latlon2eastNorth(new LatLon(lat, lon));118 return Main.getProjection().latlon2eastNorth(new LatLon(lat, lon)); 118 119 } 119 120 … … 209 210 EastNorth p2 = getEastNorth(r.x + r.width, r.y + r.height); 210 211 211 Bounds result = new Bounds(Main. proj.eastNorth2latlon(p1));212 Bounds result = new Bounds(Main.getProjection().eastNorth2latlon(p1)); 212 213 213 214 double eastMin = Math.min(p1.east(), p2.east()); … … 219 220 220 221 for (int i=0; i < 10; i++) { 221 result.extend(Main. proj.eastNorth2latlon(new EastNorth(eastMin + i * deltaEast, northMin)));222 result.extend(Main. proj.eastNorth2latlon(new EastNorth(eastMin + i * deltaEast, northMax)));223 result.extend(Main. proj.eastNorth2latlon(new EastNorth(eastMin, northMin + i * deltaNorth)));224 result.extend(Main. proj.eastNorth2latlon(new EastNorth(eastMax, northMin + i * deltaNorth)));222 result.extend(Main.getProjection().eastNorth2latlon(new EastNorth(eastMin + i * deltaEast, northMin))); 223 result.extend(Main.getProjection().eastNorth2latlon(new EastNorth(eastMin + i * deltaEast, northMax))); 224 result.extend(Main.getProjection().eastNorth2latlon(new EastNorth(eastMin, northMin + i * deltaNorth))); 225 result.extend(Main.getProjection().eastNorth2latlon(new EastNorth(eastMax, northMin + i * deltaNorth))); 225 226 } 226 227 … … 250 251 return getPoint2D(getProjection().latlon2eastNorth(latlon)); 251 252 } 253 252 254 public Point2D getPoint2D(Node n) { 253 255 return getPoint2D(n.getEastNorth()); … … 282 284 public void zoomTo(EastNorth newCenter, double newScale) { 283 285 Bounds b = getProjection().getWorldBoundsLatLon(); 284 CachedLatLon cl = new CachedLatLon(newCenter);286 LatLon cl = Projections.inverseProject(newCenter); 285 287 boolean changed = false; 286 288 double lat = cl.lat(); … … 291 293 else if(lon > b.getMax().lon()) {changed = true; lon = b.getMax().lon(); } 292 294 if(changed) { 293 newCenter = new CachedLatLon(lat, lon).getEastNorth();295 newCenter = Projections.project(new LatLon(lat,lon)); 294 296 } 295 297 int width = getWidth()/2; … … 350 352 351 353 public void zoomTo(LatLon newCenter) { 352 if(newCenter instanceof CachedLatLon) { 353 zoomTo(((CachedLatLon)newCenter).getEastNorth(), scale); 354 } else { 355 zoomTo(getProjection().latlon2eastNorth(newCenter), scale); 356 } 354 zoomTo(Projections.project(newCenter)); 357 355 } 358 356 359 357 public void smoothScrollTo(LatLon newCenter) { 360 if (newCenter instanceof CachedLatLon) { 361 smoothScrollTo(((CachedLatLon)newCenter).getEastNorth()); 362 } else { 363 smoothScrollTo(getProjection().latlon2eastNorth(newCenter)); 364 } 358 smoothScrollTo(Projections.project(newCenter)); 365 359 } 366 360 … … 441 435 442 436 public ZoomData(EastNorth center, double scale) { 443 this.center = new CachedLatLon(center);437 this.center = Projections.inverseProject(center); 444 438 this.scale = scale; 445 439 } … … 1145 1139 */ 1146 1140 public Projection getProjection() { 1147 return Main. proj;1141 return Main.getProjection(); 1148 1142 } 1149 1143 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r4043 r4126 52 52 import org.openstreetmap.josm.data.coor.LatLon; 53 53 import org.openstreetmap.josm.data.gpx.GpxData; 54 import org.openstreetmap.josm.data.gpx.GpxRoute; 54 55 import org.openstreetmap.josm.data.gpx.GpxTrack; 55 56 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; … … 59 60 import org.openstreetmap.josm.data.osm.Way; 60 61 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 62 import org.openstreetmap.josm.data.projection.Projection; 61 63 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 62 64 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 330 332 331 333 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 332 Main.pref.getBoolean("mappaint.gpx.use-antialiasing", false) ?333 RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);334 Main.pref.getBoolean("mappaint.gpx.use-antialiasing", false) ? 335 RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); 334 336 335 337 /**************************************************************** … … 1231 1233 if (bestEN == null) 1232 1234 return null; 1233 WayPoint best = new WayPoint(Main. proj.eastNorth2latlon(bestEN));1235 WayPoint best = new WayPoint(Main.getProjection().eastNorth2latlon(bestEN)); 1234 1236 best.time = bestTime; 1235 1237 return best; … … 1490 1492 importer.importDataHandleExceptions(files, NullProgressMonitor.INSTANCE); 1491 1493 } 1492 1494 } 1495 1496 @Override 1497 public void projectionChanged(Projection oldValue, Projection newValue) { 1498 if (newValue == null) return; 1499 if (data.waypoints != null) { 1500 for (WayPoint wp : data.waypoints){ 1501 wp.invalidateEastNorthCache(); 1502 } 1503 } 1504 if (data.tracks != null){ 1505 for (GpxTrack track: data.tracks) { 1506 for (GpxTrackSegment segment: track.getSegments()) { 1507 for (WayPoint wp: segment.getWayPoints()) { 1508 wp.invalidateEastNorthCache(); 1509 } 1510 } 1511 } 1512 } 1513 if (data.routes != null) { 1514 for (GpxRoute route: data.routes) { 1515 if (route.routePoints == null) { 1516 continue; 1517 } 1518 for (WayPoint wp: route.routePoints) { 1519 wp.invalidateEastNorthCache(); 1520 } 1521 } 1522 } 1493 1523 } 1494 1524 } -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r4065 r4126 83 83 84 84 public double getPPD(){ 85 if (Main.map == null || Main.map.mapView == null) return Main. proj.getDefaultZoomInPPD();85 if (Main.map == null || Main.map.mapView == null) return Main.getProjection().getDefaultZoomInPPD(); 86 86 ProjectionBounds bounds = Main.map.mapView.getProjectionBounds(); 87 87 return Main.map.mapView.getWidth() / (bounds.maxEast - bounds.minEast); -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r3705 r4126 23 23 import org.openstreetmap.josm.data.Bounds; 24 24 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 25 import org.openstreetmap.josm.data.projection.Projection; 26 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; 25 27 import org.openstreetmap.josm.gui.MapView; 26 28 import org.openstreetmap.josm.tools.Destroyable; … … 42 44 * @author imi 43 45 */ 44 abstract public class Layer implements Destroyable, MapViewPaintable {46 abstract public class Layer implements Destroyable, MapViewPaintable, ProjectionChangeListener { 45 47 46 48 public interface LayerAction { … … 362 364 } 363 365 } 366 367 /* --------------------------------------------------------------------------------- */ 368 /* interface ProjectionChangeListener */ 369 /* --------------------------------------------------------------------------------- */ 370 @Override 371 public void projectionChanged(Projection oldValue, Projection newValue) { 372 // default implementation does nothing - override in subclasses 373 } 364 374 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r4087 r4126 62 62 import org.openstreetmap.josm.data.osm.visitor.paint.MapRendererFactory; 63 63 import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; 64 import org.openstreetmap.josm.data.projection.Projection; 64 65 import org.openstreetmap.josm.data.validation.TestError; 65 66 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 80 81 */ 81 82 public class OsmDataLayer extends Layer implements Listener, SelectionChangedListener { 83 // static private final Logger logger = Logger.getLogger(OsmDataLayer.class.getName()); 84 82 85 static public final String REQUIRES_SAVE_TO_DISK_PROP = OsmDataLayer.class.getName() + ".requiresSaveToDisk"; 83 86 static public final String REQUIRES_UPLOAD_TO_SERVER_PROP = OsmDataLayer.class.getName() + ".requiresUploadToServer"; … … 658 661 } 659 662 } 660 661 663 } 662 664 … … 675 677 isChanged = true; 676 678 } 679 680 @Override 681 public void projectionChanged(Projection oldValue, Projection newValue) { 682 /* 683 * No reprojection required. The dataset itself is registered as projection 684 * change listener and already got notified. 685 */ 686 } 677 687 } -
trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
r3408 r4126 95 95 public GpsPoint(LatLon ll, String t) { 96 96 latlon = ll; 97 eastNorth = Main. proj.latlon2eastNorth(ll);97 eastNorth = Main.getProjection().latlon2eastNorth(ll); 98 98 time = t; 99 99 } -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r4017 r4126 871 871 872 872 private Point pixelPos(LatLon ll) { 873 return Main.map.mapView.getPoint(Main. proj.latlon2eastNorth(ll).add(getDx(), getDy()));873 return Main.map.mapView.getPoint(Main.getProjection().latlon2eastNorth(ll).add(getDx(), getDy())); 874 874 } 875 875 private Point pixelPos(Tile t) { … … 879 879 } 880 880 private LatLon getShiftedLatLon(EastNorth en) { 881 return Main. proj.eastNorth2latlon(en.add(-getDx(), -getDy()));881 return Main.getProjection().eastNorth2latlon(en.add(-getDx(), -getDy())); 882 882 } 883 883 private Coordinate getShiftedCoord(EastNorth en) { -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r3530 r4126 16 16 import javax.swing.Icon; 17 17 18 import org.openstreetmap.josm.data.coor.CachedLatLon;19 18 import org.openstreetmap.josm.data.coor.EastNorth; 20 19 import org.openstreetmap.josm.data.coor.LatLon; … … 23 22 import org.openstreetmap.josm.data.gpx.WayPoint; 24 23 import org.openstreetmap.josm.data.preferences.IntegerProperty; 24 import org.openstreetmap.josm.data.projection.Projections; 25 25 import org.openstreetmap.josm.gui.MapView; 26 26 import org.openstreetmap.josm.tools.ImageProvider; … … 70 70 may be adjusted later to sync with other data, so not final */ 71 71 72 private CachedLatLon coor;72 private LatLon coor; 73 73 74 74 public final void setCoor(LatLon coor) { 75 if(this.coor == null) { 76 this.coor = new CachedLatLon(coor); 77 } else { 78 this.coor.setCoor(coor); 79 } 75 this.coor = new LatLon(coor); 80 76 } 81 77 … … 85 81 86 82 public final void setEastNorth(EastNorth eastNorth) { 87 coor.setEastNorth(eastNorth);83 this.coor = Projections.inverseProject(eastNorth); 88 84 } 89 85 90 86 public final EastNorth getEastNorth() { 91 return coor.getEastNorth();87 return Projections.project(this.coor); 92 88 } 93 89 … … 264 260 */ 265 261 public String getText() { 266 if (this.text != null ) {262 if (this.text != null ) 267 263 return this.text; 268 } 269 else { 264 else 270 265 return getText(this.textMap); 271 }272 266 } 273 267 -
trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
r4028 r4126 734 734 @Override 735 735 public void actionPerformed(ActionEvent e) { 736 OffsetBookmark b = new OffsetBookmark(Main. proj,"","",0,0);736 OffsetBookmark b = new OffsetBookmark(Main.getProjection(),"","",0,0); 737 737 model.addRow(b); 738 738 } -
trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java
r3874 r4126 9 9 import java.util.ArrayList; 10 10 import java.util.Collection; 11 import java.util.concurrent.CopyOnWriteArrayList;12 11 13 12 import javax.swing.BorderFactory; … … 27 26 import org.openstreetmap.josm.data.projection.Mercator; 28 27 import org.openstreetmap.josm.data.projection.Projection; 28 import org.openstreetmap.josm.data.projection.ProjectionSubPrefs; 29 29 import org.openstreetmap.josm.data.projection.Projections; 30 import org.openstreetmap.josm.data.projection.ProjectionSubPrefs;31 30 import org.openstreetmap.josm.gui.NavigatableComponent; 32 31 import org.openstreetmap.josm.plugins.PluginHandler; … … 39 38 return new ProjectionPreference(); 40 39 } 41 }42 43 public interface ProjectionChangedListener {44 void projectionChanged();45 40 } 46 41 … … 65 60 } 66 61 67 //TODO This is not nice place for a listener code but probably only Dataset will want to listen for projection changes so it's acceptable68 private static CopyOnWriteArrayList<ProjectionChangedListener> listeners = new CopyOnWriteArrayList<ProjectionChangedListener>();69 70 public static void addProjectionChangedListener(ProjectionChangedListener listener) {71 listeners.addIfAbsent(listener);72 }73 74 public static void removeProjectionChangedListener(ProjectionChangedListener listener) {75 listeners.remove(listener);76 }77 78 private static void fireProjectionChanged() {79 for (ProjectionChangedListener listener: listeners) {80 listener.projectionChanged();81 }82 }83 84 85 62 /** 86 63 * Combobox with all projections available … … 161 138 gui.mapcontent.addTab(tr("Map Projection"), scrollpane); 162 139 163 updateMeta(Main. proj);140 updateMeta(Main.getProjection()); 164 141 } 165 142 … … 202 179 { 203 180 Bounds b = (Main.map != null && Main.map.mapView != null) ? Main.map.mapView.getRealBounds() : null; 204 Projection oldProj = Main.proj; 205 206 Projection p = null; 181 182 Projection proj = null; 207 183 for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) { 208 184 try { 209 p = (Projection) Class.forName(name, true, cl).newInstance();185 proj = (Projection) Class.forName(name, true, cl).newInstance(); 210 186 } catch (final Exception e) { 211 187 } 212 if (p != null) { 213 Main.proj = p; 214 break; 215 } 216 } 217 if (p == null) { 188 if (proj != null) { 189 break; 190 } 191 } 192 if (proj == null) { 218 193 JOptionPane.showMessageDialog( 219 194 Main.parent, … … 223 198 ); 224 199 coll = null; 225 Main.proj = new Mercator();226 name = Main. proj.getClass().getName();200 proj = new Mercator(); 201 name = Main.getProjection().getClass().getName(); 227 202 } 228 203 PROP_SUB_PROJECTION.put(coll); 229 204 PROP_PROJECTION_SUBPROJECTION.put(coll, name); 230 if(Main.proj instanceof ProjectionSubPrefs) { 231 ((ProjectionSubPrefs) Main.proj).setPreferences(coll); 232 } 233 fireProjectionChanged(); // This should be probably called from the if bellow, but hashCode condition doesn't look sure enough 234 if(b != null && (!Main.proj.getClass().getName().equals(oldProj.getClass().getName()) || Main.proj.hashCode() != oldProj.hashCode())) 205 if(proj instanceof ProjectionSubPrefs) { 206 ((ProjectionSubPrefs) proj).setPreferences(coll); 207 } 208 Projection oldProj = Main.getProjection(); 209 Main.setProjection(proj); 210 if(b != null && (!proj.getClass().getName().equals(oldProj.getClass().getName()) || proj.hashCode() != oldProj.hashCode())) 235 211 { 236 212 Main.map.mapView.zoomTo(b); -
trunk/src/org/openstreetmap/josm/io/imagery/Grabber.java
r4065 r4126 41 41 } 42 42 43 this.proj = Main. proj;43 this.proj = Main.getProjection(); 44 44 this.pixelPerDegree = request.getPixelPerDegree(); 45 45 this.request = request; -
trunk/src/org/openstreetmap/josm/io/imagery/HTMLGrabber.java
r4065 r4126 52 52 BufferedImage img = layer.normalizeImage(ImageIO.read(bais)); 53 53 bais.reset(); 54 layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main. proj, pixelPerDegree, b.minEast, b.minNorth);54 layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.getProjection(), pixelPerDegree, b.minEast, b.minNorth); 55 55 56 56 return img; -
trunk/src/org/openstreetmap/josm/io/imagery/OsmosnimkiOffsetServer.java
r3852 r4126 40 40 @Override 41 41 public EastNorth getOffset(ImageryInfo info, EastNorth en) { 42 LatLon ll = Main. proj.eastNorth2latlon(en);42 LatLon ll = Main.getProjection().eastNorth2latlon(en); 43 43 try { 44 44 URL url = new URL(this.url + "action=GetOffsetForPoint&lat=" + ll.lat() + "&lon=" + ll.lon() + "&id=" + URLEncoder.encode(info.getFullUrl(), "UTF-8")); … … 50 50 String sLon = s.substring(1,i); 51 51 String sLat = s.substring(i+1,s.length()-1); 52 return Main. proj.latlon2eastNorth(new LatLon(Double.valueOf(sLat),Double.valueOf(sLon))).sub(en);52 return Main.getProjection().latlon2eastNorth(new LatLon(Double.valueOf(sLat),Double.valueOf(sLon))).sub(en); 53 53 } catch (Exception e) { 54 54 e.printStackTrace(); -
trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
r4065 r4126 72 72 protected URL getURL(double w, double s,double e,double n, 73 73 int wi, int ht) throws MalformedURLException { 74 String myProj = Main. proj.toCode();75 if(Main. projinstanceof Mercator) // don't use mercator code directly74 String myProj = Main.getProjection().toCode(); 75 if(Main.getProjection() instanceof Mercator) // don't use mercator code directly 76 76 { 77 LatLon sw = Main. proj.eastNorth2latlon(new EastNorth(w, s));78 LatLon ne = Main. proj.eastNorth2latlon(new EastNorth(e, n));77 LatLon sw = Main.getProjection().eastNorth2latlon(new EastNorth(w, s)); 78 LatLon ne = Main.getProjection().eastNorth2latlon(new EastNorth(e, n)); 79 79 myProj = "EPSG:4326"; 80 80 s = sw.lat(); … … 114 114 static public String getProjection(String baseURL, Boolean warn) 115 115 { 116 String projname = Main. proj.toCode();117 if(Main. projinstanceof Mercator) {116 String projname = Main.getProjection().toCode(); 117 if(Main.getProjection() instanceof Mercator) { 118 118 projname = "EPSG:4326"; 119 119 } … … 146 146 @Override 147 147 public boolean loadFromCache(WMSRequest request) { 148 BufferedImage cached = layer.cache.getExactMatch(Main. proj, pixelPerDegree, b.minEast, b.minNorth);148 BufferedImage cached = layer.cache.getExactMatch(Main.getProjection(), pixelPerDegree, b.minEast, b.minNorth); 149 149 150 150 if (cached != null) { … … 152 152 return true; 153 153 } else if (request.isAllowPartialCacheMatch()) { 154 BufferedImage partialMatch = layer.cache.getPartialMatch(Main. proj, pixelPerDegree, b.minEast, b.minNorth);154 BufferedImage partialMatch = layer.cache.getPartialMatch(Main.getProjection(), pixelPerDegree, b.minEast, b.minNorth); 155 155 if (partialMatch != null) { 156 156 request.finish(State.PARTLY_IN_CACHE, partialMatch); … … 194 194 BufferedImage img = layer.normalizeImage(ImageIO.read(bais)); 195 195 bais.reset(); 196 layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main. proj, pixelPerDegree, b.minEast, b.minNorth);196 layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.getProjection(), pixelPerDegree, b.minEast, b.minNorth); 197 197 return img; 198 198 } -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r4085 r4126 112 112 } 113 113 114 Node newNode = new Node(Main. proj.eastNorth2latlon(intersection));114 Node newNode = new Node(Main.getProjection().eastNorth2latlon(intersection)); 115 115 Node intNode = newNode; 116 116 boolean insertInSeg1 = false; … … 458 458 return inside; 459 459 } 460 460 461 461 /** 462 462 * returns area of a closed way in square meters … … 478 478 return Math.abs(area/2); 479 479 } 480 480 481 481 protected static double calcX(Node p1){ 482 482 double lat1, lon1, lat2, lon2; … … 495 495 return 6367000 * c; 496 496 } 497 497 498 498 protected static double calcY(Node p1){ 499 499 double lat1, lon1, lat2, lon2;
Note:
See TracChangeset
for help on using the changeset viewer.