- Timestamp:
- 2012-05-12T18:23:08+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 13 added
- 2 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r5226 r5234 816 816 CheckParameterUtil.ensureParameterNotNull(p); 817 817 Projection oldValue = proj; 818 Bounds b = (Main.map != null && Main.map.mapView != null) ? Main.map.mapView.getRealBounds() : null; 818 819 proj = p; 819 fireProjectionChanged(oldValue, proj); 820 fireProjectionChanged(oldValue, proj, b); 820 821 } 821 822 … … 827 828 private static final ArrayList<WeakReference<ProjectionChangeListener>> listeners = new ArrayList<WeakReference<ProjectionChangeListener>>(); 828 829 829 private static void fireProjectionChanged(Projection oldValue, Projection newValue) { 830 private static void fireProjectionChanged(Projection oldValue, Projection newValue, Bounds oldBounds) { 830 831 if (newValue == null ^ oldValue == null 831 832 || (newValue != null && oldValue != null && !Utils.equal(newValue.toCode(), oldValue.toCode()))) { … … 843 844 } 844 845 } 845 if (newValue != null) { 846 Bounds b = (Main.map != null && Main.map.mapView != null) ? Main.map.mapView.getRealBounds() : null; 847 if (b != null){ 848 Main.map.mapView.zoomTo(b); 849 } 846 if (newValue != null && oldBounds != null) { 847 Main.map.mapView.zoomTo(oldBounds); 850 848 } 851 849 /* TODO - remove layers with fixed projection */ -
trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java
r5228 r5234 40 40 * null means fall back mode (Mercator) 41 41 */ 42 protected String pref = null;42 protected String pref; 43 43 protected Bounds bounds; 44 44 … … 87 87 this.key = key; 88 88 this.hasValue = hasValue; 89 } 90 } 91 92 public CustomProjection() { 93 this.pref = null; 94 } 95 96 public CustomProjection(String pref) { 97 try { 98 this.pref = pref; 99 update(pref); 100 } catch (ProjectionConfigurationException ex) { 101 try { 102 update(null); 103 } catch (ProjectionConfigurationException ex1) { 104 throw new RuntimeException(); 105 } 89 106 } 90 107 } -
trunk/src/org/openstreetmap/josm/data/projection/GaussKrueger.java
r5226 r5234 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.GridBagLayout;7 import java.awt.event.ActionListener;8 import java.util.Collection;9 import java.util.Collections;10 11 import javax.swing.JComboBox;12 import javax.swing.JLabel;13 import javax.swing.JPanel;14 5 15 6 import org.openstreetmap.josm.data.Bounds; … … 19 10 import org.openstreetmap.josm.data.projection.proj.ProjParameters; 20 11 import org.openstreetmap.josm.data.projection.proj.TransverseMercator; 21 import org.openstreetmap.josm.tools.GBC;22 12 23 public class GaussKrueger extends AbstractProjection implements ProjectionSubPrefs{13 public class GaussKrueger extends AbstractProjection { 24 14 25 15 public static final int DEFAULT_ZONE = 2; 26 private int zone; 16 private final int zone; 27 17 28 18 private static Bounds[] bounds = { … … 33 23 }; 34 24 35 private static String[] zones = { "2", "3", "4", "5" };36 37 25 public GaussKrueger() { 38 26 this(DEFAULT_ZONE); … … 40 28 41 29 public GaussKrueger(int zone) { 42 updateParameters(zone); 43 } 44 45 private void updateParameters(int zone) { 30 if (zone < 2 || zone > 5) 31 throw new IllegalArgumentException(); 46 32 this.zone = zone; 47 33 ellps = Ellipsoid.Bessel1841; … … 63 49 @Override 64 50 public String toString() { 65 return tr("Gau\u00DF-Kr\u00FCger ");51 return tr("Gau\u00DF-Kr\u00FCger Zone {0}", zone); 66 52 } 67 53 … … 81 67 } 82 68 83 @Override84 public void setupPreferencePanel(JPanel p, ActionListener listener) {85 JComboBox prefcb = new JComboBox(zones);86 87 prefcb.setSelectedIndex(zone-2);88 p.setLayout(new GridBagLayout());89 p.add(new JLabel(tr("GK Zone")), GBC.std().insets(5,5,0,5));90 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));91 /* Note: we use component position 2 below to find this again */92 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));93 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));94 95 if (listener != null) {96 prefcb.addActionListener(listener);97 }98 }99 100 @Override101 public Collection<String> getPreferences(JPanel p) {102 Object prefcb = p.getComponent(2);103 if(!(prefcb instanceof JComboBox))104 return null;105 int zone = ((JComboBox)prefcb).getSelectedIndex();106 return Collections.singleton(Integer.toString(zone+2));107 }108 109 @Override110 public void setPreferences(Collection<String> args) {111 int zone = DEFAULT_ZONE;112 if (args != null) {113 try {114 for(String s : args)115 {116 zone = Integer.parseInt(s);117 if(zone < 2 || zone > 5) {118 zone = DEFAULT_ZONE;119 }120 break;121 }122 } catch(NumberFormatException e) {}123 }124 updateParameters(zone);125 }126 127 @Override128 public String[] allCodes() {129 String[] zones = new String[4];130 for (int zone = 2; zone <= 5; zone++) {131 zones[zone-2] = "EPSG:" + (31464 + zone);132 }133 return zones;134 }135 136 @Override137 public Collection<String> getPreferencesFromCode(String code)138 {139 //zone 2 = EPSG:31466 up to zone 5 = EPSG:31469140 for (int zone = 2; zone <= 5; zone++) {141 String epsg = "EPSG:" + (31464 + zone);142 if (epsg.equals(code))143 return Collections.singleton(String.valueOf(zone));144 }145 return null;146 }147 148 69 } -
trunk/src/org/openstreetmap/josm/data/projection/Lambert.java
r5230 r5234 30 30 * @author Pieren 31 31 */ 32 public class Lambert extends AbstractProjection implements ProjectionSubPrefs{32 public class Lambert extends AbstractProjection { 33 33 34 34 /** … … 92 92 93 93 public Lambert() { 94 updateParameters(DEFAULT_ZONE);94 this(DEFAULT_ZONE); 95 95 } 96 96 97 p rivate void updateParameters(final int layoutZone) {97 public Lambert(final int layoutZone) { 98 98 this.layoutZone = layoutZone; 99 99 ellps = Ellipsoid.clarkeIGN; … … 151 151 } 152 152 153 public static String[] lambert4zones = {154 tr("{0} ({1} to {2} degrees)", 1,"51.30","48.15"),155 tr("{0} ({1} to {2} degrees)", 2,"48.15","45.45"),156 tr("{0} ({1} to {2} degrees)", 3,"45.45","42.76"),157 tr("{0} (Corsica)", 4)158 };159 160 @Override161 public void setupPreferencePanel(JPanel p, ActionListener listener) {162 JComboBox prefcb = new JComboBox(lambert4zones);163 164 prefcb.setSelectedIndex(layoutZone);165 p.setLayout(new GridBagLayout());166 p.add(new JLabel(tr("Lambert CC Zone")), GBC.std().insets(5,5,0,5));167 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));168 /* Note: we use component position 2 below to find this again */169 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));170 p.add(new JLabel(ImageProvider.get("data/projection", "Departements_Lambert4Zones.png")), GBC.eol().fill(GBC.HORIZONTAL));171 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));172 173 if (listener != null) {174 prefcb.addActionListener(listener);175 }176 }177 178 @Override179 public Collection<String> getPreferences(JPanel p) {180 Object prefcb = p.getComponent(2);181 if(!(prefcb instanceof JComboBox))182 return null;183 layoutZone = ((JComboBox)prefcb).getSelectedIndex();184 return Collections.singleton(Integer.toString(layoutZone+1));185 }186 187 @Override188 public void setPreferences(Collection<String> args) {189 int layoutZone = DEFAULT_ZONE;190 if (args != null) {191 try {192 for(String s : args)193 {194 layoutZone = Integer.parseInt(s)-1;195 if(layoutZone < 0 || layoutZone > 3) {196 layoutZone = DEFAULT_ZONE;197 }198 break;199 }200 } catch(NumberFormatException e) {}201 }202 updateParameters(layoutZone);203 }204 205 @Override206 public String[] allCodes() {207 String[] zones = new String[4];208 for (int zone = 0; zone < 4; zone++) {209 zones[zone] = "EPSG:"+(27561+zone);210 }211 return zones;212 }213 214 @Override215 public Collection<String> getPreferencesFromCode(String code) {216 if (code.startsWith("EPSG:2756") && code.length() == 10) {217 try {218 String zonestring = code.substring(9);219 int zoneval = Integer.parseInt(zonestring);220 if(zoneval >= 1 && zoneval <= 4)221 return Collections.singleton(zonestring);222 } catch(NumberFormatException e) {}223 }224 return null;225 }226 227 153 } -
trunk/src/org/openstreetmap/josm/data/projection/LambertCC9Zones.java
r5066 r5234 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.GridBagLayout;7 import java.awt.event.ActionListener;8 import java.util.Collection;9 import java.util.Collections;10 11 import javax.swing.JComboBox;12 import javax.swing.JLabel;13 import javax.swing.JPanel;14 5 15 6 import org.openstreetmap.josm.data.Bounds; … … 18 9 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic; 19 10 import org.openstreetmap.josm.data.projection.proj.ProjParameters; 20 import org.openstreetmap.josm.tools.GBC;21 import org.openstreetmap.josm.tools.ImageProvider;22 11 23 12 /** … … 27 16 * 28 17 */ 29 public class LambertCC9Zones extends AbstractProjection implements ProjectionSubPrefs{18 public class LambertCC9Zones extends AbstractProjection { 30 19 31 20 /** … … 40 29 public static final int DEFAULT_ZONE = 0; 41 30 42 private int layoutZone = DEFAULT_ZONE;31 private final int layoutZone; 43 32 44 33 public LambertCC9Zones() { … … 46 35 } 47 36 48 public LambertCC9Zones(int layoutZone) { 49 updateParameters(layoutZone); 50 } 51 52 public void updateParameters(final int layoutZone) { 37 public LambertCC9Zones(final int layoutZone) { 53 38 ellps = Ellipsoid.GRS80; 54 39 datum = GRS80Datum.INSTANCE; … … 112 97 } 113 98 114 private static String[] lambert9zones = {115 tr("{0} ({1} to {2} degrees)", 1,41,43),116 tr("{0} ({1} to {2} degrees)", 2,42,44),117 tr("{0} ({1} to {2} degrees)", 3,43,45),118 tr("{0} ({1} to {2} degrees)", 4,44,46),119 tr("{0} ({1} to {2} degrees)", 5,45,47),120 tr("{0} ({1} to {2} degrees)", 6,46,48),121 tr("{0} ({1} to {2} degrees)", 7,47,49),122 tr("{0} ({1} to {2} degrees)", 8,48,50),123 tr("{0} ({1} to {2} degrees)", 9,49,51)124 };125 126 @Override127 public void setupPreferencePanel(JPanel p, ActionListener listener) {128 JComboBox prefcb = new JComboBox(lambert9zones);129 130 prefcb.setSelectedIndex(layoutZone);131 p.setLayout(new GridBagLayout());132 p.add(new JLabel(tr("Lambert CC Zone")), GBC.std().insets(5,5,0,5));133 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));134 /* Note: we use component position 2 below to find this again */135 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));136 p.add(new JLabel(ImageProvider.get("data/projection", "LambertCC9Zones.png")), GBC.eol().fill(GBC.HORIZONTAL));137 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));138 139 if (listener != null) {140 prefcb.addActionListener(listener);141 }142 }143 144 @Override145 public Collection<String> getPreferences(JPanel p) {146 Object prefcb = p.getComponent(2);147 if(!(prefcb instanceof JComboBox))148 return null;149 int layoutZone = ((JComboBox)prefcb).getSelectedIndex();150 return Collections.singleton(Integer.toString(layoutZone+1));151 }152 153 @Override154 public void setPreferences(Collection<String> args) {155 int layoutZone = DEFAULT_ZONE;156 if (args != null) {157 try {158 for(String s : args)159 {160 layoutZone = Integer.parseInt(s)-1;161 if(layoutZone < 0 || layoutZone > 8) {162 layoutZone = DEFAULT_ZONE;163 }164 break;165 }166 } catch(NumberFormatException e) {}167 }168 updateParameters(layoutZone);169 }170 171 @Override172 public String[] allCodes() {173 String[] zones = new String[9];174 for (int zone = 0; zone < 9; zone++) {175 zones[zone] = "EPSG:" + (3942 + zone);176 }177 return zones;178 }179 180 @Override181 public Collection<String> getPreferencesFromCode(String code)182 {183 //zone 1=CC42=EPSG:3942 up to zone 9=CC50=EPSG:3950184 if (code.startsWith("EPSG:39") && code.length() == 9) {185 try {186 String zonestring = code.substring(5,9);187 int zoneval = Integer.parseInt(zonestring)-3942;188 if(zoneval >= 0 && zoneval <= 8)189 return Collections.singleton(String.valueOf(zoneval+1));190 } catch(NumberFormatException ex) {}191 }192 return null;193 }194 99 } -
trunk/src/org/openstreetmap/josm/data/projection/ProjectionInfo.java
r3872 r5234 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.projection; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.util.Collection; 7 5 import java.util.HashMap; 8 6 7 import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice; 8 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 9 9 10 public class ProjectionInfo { 11 private static HashMap<String, ProjectionChoice> allCodesPC; 10 12 private static HashMap<String, Projection> allCodes; 11 12 private static ProjectionSubPrefs recreateProj(ProjectionSubPrefs proj) {13 try {14 return proj.getClass().newInstance();15 } catch (Exception e) {16 throw new IllegalStateException(17 tr("Cannot instantiate projection ''{0}''", proj.getClass().toString()), e);18 }19 }20 13 21 14 static { 22 15 allCodes = new HashMap<String, Projection>(); 23 for (Projection proj : Projections.getProjections()) { 24 if (proj instanceof ProjectionSubPrefs) { 25 ProjectionSubPrefs projSub = recreateProj((ProjectionSubPrefs)proj); 26 for (String code : projSub.allCodes()) { 27 allCodes.put(code, projSub); 28 } 29 } else { 30 allCodes.put(proj.toCode(), proj); 16 for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) { 17 for (String code : pc.allCodes()) { 18 allCodesPC.put(code, pc); 31 19 } 32 20 } … … 34 22 35 23 public static Projection getProjectionByCode(String code) { 36 Projection proj = allCodes.get(code); 37 if (proj == null) return null; 38 if (code.equals(proj.toCode())) return proj; 39 if (!(proj instanceof ProjectionSubPrefs)) 40 throw new IllegalStateException(tr( 41 "Projection code mismatch in ''{0}'': toCode() returns ''{1}'', expected ''{2}''.", 42 proj.getClass().toString(), proj.toCode(), code)); 43 ProjectionSubPrefs projSub = recreateProj((ProjectionSubPrefs)proj); 44 Collection<String> prefs = projSub.getPreferencesFromCode(code); 45 if (prefs != null) { 46 projSub.setPreferences(prefs); 47 } 48 if (!code.equals(projSub.toCode())) 49 throw new IllegalStateException(tr( 50 "Bad implementation of ''{0}'' projection class: cannot set preferences to match code ''{1}''.", 51 projSub.getClass().toString(), code)); 52 allCodes.put(code, projSub); 53 return projSub; 24 Projection p = allCodes.get(code); 25 if (p != null) return p; 26 ProjectionChoice pc = allCodesPC.get(code); 27 if (pc == null) return null; 28 Collection<String> pref = pc.getPreferencesFromCode(code); 29 pc.setPreferences(pref); 30 p = pc.getProjection(); 31 allCodes.put(code, p); 32 return p; 54 33 } 55 34 } -
trunk/src/org/openstreetmap/josm/data/projection/Projections.java
r5228 r5234 6 6 import java.io.InputStream; 7 7 import java.io.InputStreamReader; 8 import java.util.ArrayList;9 import java.util.Arrays;10 8 import java.util.HashMap; 11 9 import java.util.Map; … … 33 31 */ 34 32 public class Projections { 35 /**36 * List of all available projections.37 */38 private static ArrayList<Projection> allProjections =39 new ArrayList<Projection>(Arrays.asList(new Projection[] {40 // global projections41 new Epsg4326(),42 new Mercator(),43 new UTM(),44 // regional - alphabetical order by country code45 new BelgianLambert1972(), // BE46 new BelgianLambert2008(), // BE47 new SwissGrid(), // CH48 new GaussKrueger(), // DE49 new LambertEST(), // EE50 new Lambert(), // FR51 new Lambert93(), // FR52 new LambertCC9Zones(), // FR53 new UTM_France_DOM(), // FR54 new TransverseMercatorLV(), // LV55 new Puwg(), // PL56 new Epsg3008(), // SE57 new CustomProjectionPrefGui()58 }));59 60 public static ArrayList<Projection> getProjections() {61 return allProjections;62 }63 64 /**65 * Adds a new projection to the list of known projections.66 *67 * For Plugins authors: make sure your plugin is an early plugin, i.e. put68 * Plugin-Early=true in your Manifest.69 */70 public static void addProjection(Projection proj) {71 allProjections.add(proj);72 }73 33 74 34 public static EastNorth project(LatLon ll) { -
trunk/src/org/openstreetmap/josm/data/projection/Puwg.java
r5066 r5234 4 4 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 7 import java.awt.GridBagLayout;8 import java.awt.event.ActionListener;9 import java.util.Collection;10 import java.util.Collections;11 12 import javax.swing.JComboBox;13 import javax.swing.JLabel;14 import javax.swing.JPanel;15 6 16 7 import org.openstreetmap.josm.data.Bounds; … … 18 9 import org.openstreetmap.josm.data.projection.datum.GRS80Datum; 19 10 import org.openstreetmap.josm.data.projection.proj.ProjParameters; 20 import org.openstreetmap.josm.tools.GBC;21 11 22 12 /** … … 26 16 * @author steelman 27 17 */ 28 public class Puwg extends AbstractProjection implements ProjectionSubPrefs{18 public class Puwg extends AbstractProjection { 29 19 30 20 public static final int DEFAULT_ZONE = 0; 31 21 32 private int zone; 33 34 static PuwgData[] Zones = new PuwgData[] { 22 private final int zone; 23 24 static public PuwgData[] Zones = new PuwgData[] { 35 25 new Epsg2180(), 36 26 new Epsg2176(), … … 53 43 } 54 44 datum = GRS80Datum.INSTANCE; 55 updateParameters(zone);56 }57 58 public void updateParameters(int zone) {59 45 this.zone = zone; 60 46 PuwgData z = Zones[zone]; … … 90 76 } 91 77 92 @Override 93 public void setupPreferencePanel(JPanel p, ActionListener listener) { 94 JComboBox prefcb = new JComboBox(Puwg.Zones); 95 96 prefcb.setSelectedIndex(zone); 97 p.setLayout(new GridBagLayout()); 98 p.add(new JLabel(tr("PUWG Zone")), GBC.std().insets(5,5,0,5)); 99 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 100 /* Note: we use component position 2 below to find this again */ 101 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL)); 102 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 103 104 if (listener != null) { 105 prefcb.addActionListener(listener); 106 } 107 } 108 109 @Override 110 public Collection<String> getPreferences(JPanel p) { 111 Object prefcb = p.getComponent(2); 112 if(!(prefcb instanceof JComboBox)) 113 return null; 114 int zone = ((JComboBox)prefcb).getSelectedIndex(); 115 return Collections.singleton((Puwg.Zones[zone]).toCode()); 116 } 117 118 @Override 119 public String[] allCodes() { 120 String[] zones = new String[Zones.length]; 121 for (int zone = 0; zone < Zones.length; zone++) { 122 zones[zone] = Zones[zone].toCode(); 123 } 124 return zones; 125 } 126 127 @Override 128 public Collection<String> getPreferencesFromCode(String code) { 129 for (PuwgData p : Puwg.Zones) { 130 if (code.equals(p.toCode())) 131 return Collections.singleton(code); 132 } 133 return null; 134 } 135 136 @Override 137 public void setPreferences(Collection<String> args) { 138 int z = DEFAULT_ZONE; 139 if (args != null) { 140 try { 141 for (String s : args) { 142 for (int i=0; i < Zones.length; ++i) 143 if (s.equals(Zones[i].toCode())) { 144 z = i; 145 break; 146 } 147 break; 148 } 149 } catch (NullPointerException e) {} 150 } 151 updateParameters(z); 78 public interface PuwgData { 79 double getPuwgCentralMeridianDeg(); 80 double getPuwgCentralMeridian(); 81 double getPuwgFalseEasting(); 82 double getPuwgFalseNorthing(); 83 double getPuwgScaleFactor(); 84 85 // Projection methods 86 Integer getEpsgCode(); 87 String toCode(); 88 String getCacheDirectoryName(); 89 Bounds getWorldBoundsLatLon(); 90 } 91 92 public static class Epsg2180 implements PuwgData { 93 94 private static final double Epsg2180FalseEasting = 500000.0; /* y */ 95 private static final double Epsg2180FalseNorthing = -5300000.0; /* x */ 96 private static final double Epsg2180ScaleFactor = 0.9993; 97 private static final double Epsg2180CentralMeridian = 19.0; 98 99 @Override public String toString() { 100 return tr("PUWG 1992 (Poland)"); 101 } 102 103 @Override 104 public Integer getEpsgCode() { 105 return 2180; 106 } 107 108 @Override 109 public String toCode() { 110 return "EPSG:" + getEpsgCode(); 111 } 112 113 @Override 114 public String getCacheDirectoryName() { 115 return "epsg2180"; 116 } 117 118 @Override 119 public Bounds getWorldBoundsLatLon() 120 { 121 return new Bounds( 122 new LatLon(49.00, 14.12), 123 new LatLon(54.84, 24.15)); 124 } 125 126 @Override public double getPuwgCentralMeridianDeg() { return Epsg2180CentralMeridian; } 127 @Override public double getPuwgCentralMeridian() { return Math.toRadians(Epsg2180CentralMeridian); } 128 @Override public double getPuwgFalseEasting() { return Epsg2180FalseEasting; } 129 @Override public double getPuwgFalseNorthing() { return Epsg2180FalseNorthing; } 130 @Override public double getPuwgScaleFactor() { return Epsg2180ScaleFactor; } 131 } 132 133 abstract static class Puwg2000 implements PuwgData { 134 135 private static final double PuwgFalseEasting = 500000.0; 136 private static final double PuwgFalseNorthing = 0; 137 private static final double PuwgScaleFactor = 0.999923; 138 //final private double[] Puwg2000CentralMeridian = {15.0, 18.0, 21.0, 24.0}; 139 final private Integer[] Puwg2000Code = { 2176, 2177, 2178, 2179 }; 140 final private String[] Puwg2000CDName = { "epsg2176", "epsg2177", "epsg2178", "epsg2179" }; 141 142 @Override public String toString() { 143 return tr("PUWG 2000 Zone {0} (Poland)", Integer.toString(getZone())); 144 } 145 146 @Override 147 public Integer getEpsgCode() { 148 return Puwg2000Code[getZoneIndex()]; 149 } 150 151 @Override 152 public String toCode() { 153 return "EPSG:" + getEpsgCode(); 154 } 155 156 @Override 157 public String getCacheDirectoryName() { 158 return Puwg2000CDName[getZoneIndex()]; 159 } 160 161 @Override 162 public Bounds getWorldBoundsLatLon() 163 { 164 return new Bounds( 165 new LatLon(49.00, (3 * getZone()) - 1.5), 166 new LatLon(54.84, (3 * getZone()) + 1.5)); 167 } 168 169 @Override public double getPuwgCentralMeridianDeg() { return getZone() * 3.0; } 170 @Override public double getPuwgCentralMeridian() { return Math.toRadians(getZone() * 3.0); } 171 @Override public double getPuwgFalseNorthing() { return PuwgFalseNorthing;} 172 @Override public double getPuwgFalseEasting() { return 1e6 * getZone() + PuwgFalseEasting; } 173 @Override public double getPuwgScaleFactor() { return PuwgScaleFactor; } 174 public abstract int getZone(); 175 176 public int getZoneIndex() { return getZone() - 5; } 177 178 } 179 180 public static class Epsg2176 extends Puwg2000 { 181 private static final int PuwgZone = 5; 182 183 @Override 184 public int getZone() { return PuwgZone; } 185 } 186 187 public static class Epsg2177 extends Puwg2000 { 188 private static final int PuwgZone = 6; 189 190 @Override 191 public int getZone() { return PuwgZone; } 192 } 193 194 public static class Epsg2178 extends Puwg2000 { 195 private static final int PuwgZone = 7; 196 197 @Override 198 public int getZone() { return PuwgZone; } 199 } 200 201 public static class Epsg2179 extends Puwg2000 { 202 private static final int PuwgZone = 8; 203 204 @Override 205 public int getZone() { return PuwgZone; } 152 206 } 153 207 } 154 155 interface PuwgData {156 double getPuwgCentralMeridianDeg();157 double getPuwgCentralMeridian();158 double getPuwgFalseEasting();159 double getPuwgFalseNorthing();160 double getPuwgScaleFactor();161 162 // Projection methods163 Integer getEpsgCode();164 String toCode();165 String getCacheDirectoryName();166 Bounds getWorldBoundsLatLon();167 }168 169 class Epsg2180 implements PuwgData {170 171 private static final double Epsg2180FalseEasting = 500000.0; /* y */172 private static final double Epsg2180FalseNorthing = -5300000.0; /* x */173 private static final double Epsg2180ScaleFactor = 0.9993;174 private static final double Epsg2180CentralMeridian = 19.0;175 176 @Override public String toString() {177 return tr("PUWG 1992 (Poland)");178 }179 180 @Override181 public Integer getEpsgCode() {182 return 2180;183 }184 185 @Override186 public String toCode() {187 return "EPSG:" + getEpsgCode();188 }189 190 @Override191 public String getCacheDirectoryName() {192 return "epsg2180";193 }194 195 @Override196 public Bounds getWorldBoundsLatLon()197 {198 return new Bounds(199 new LatLon(49.00, 14.12),200 new LatLon(54.84, 24.15));201 }202 203 @Override public double getPuwgCentralMeridianDeg() { return Epsg2180CentralMeridian; }204 @Override public double getPuwgCentralMeridian() { return Math.toRadians(Epsg2180CentralMeridian); }205 @Override public double getPuwgFalseEasting() { return Epsg2180FalseEasting; }206 @Override public double getPuwgFalseNorthing() { return Epsg2180FalseNorthing; }207 @Override public double getPuwgScaleFactor() { return Epsg2180ScaleFactor; }208 }209 210 abstract class Puwg2000 implements PuwgData {211 212 private static final double PuwgFalseEasting = 500000.0;213 private static final double PuwgFalseNorthing = 0;214 private static final double PuwgScaleFactor = 0.999923;215 //final private double[] Puwg2000CentralMeridian = {15.0, 18.0, 21.0, 24.0};216 final private Integer[] Puwg2000Code = { 2176, 2177, 2178, 2179 };217 final private String[] Puwg2000CDName = { "epsg2176", "epsg2177", "epsg2178", "epsg2179" };218 219 @Override public String toString() {220 return tr("PUWG 2000 Zone {0} (Poland)", Integer.toString(getZone()));221 }222 223 @Override224 public Integer getEpsgCode() {225 return Puwg2000Code[getZoneIndex()];226 }227 228 @Override229 public String toCode() {230 return "EPSG:" + getEpsgCode();231 }232 233 @Override234 public String getCacheDirectoryName() {235 return Puwg2000CDName[getZoneIndex()];236 }237 238 @Override239 public Bounds getWorldBoundsLatLon()240 {241 return new Bounds(242 new LatLon(49.00, (3 * getZone()) - 1.5),243 new LatLon(54.84, (3 * getZone()) + 1.5));244 }245 246 @Override public double getPuwgCentralMeridianDeg() { return getZone() * 3.0; }247 @Override public double getPuwgCentralMeridian() { return Math.toRadians(getZone() * 3.0); }248 @Override public double getPuwgFalseNorthing() { return PuwgFalseNorthing;}249 @Override public double getPuwgFalseEasting() { return 1e6 * getZone() + PuwgFalseEasting; }250 @Override public double getPuwgScaleFactor() { return PuwgScaleFactor; }251 public abstract int getZone();252 253 public int getZoneIndex() { return getZone() - 5; }254 255 }256 257 class Epsg2176 extends Puwg2000 {258 private static final int PuwgZone = 5;259 260 @Override261 public int getZone() { return PuwgZone; }262 }263 264 class Epsg2177 extends Puwg2000 {265 private static final int PuwgZone = 6;266 267 @Override268 public int getZone() { return PuwgZone; }269 }270 271 class Epsg2178 extends Puwg2000 {272 private static final int PuwgZone = 7;273 274 @Override275 public int getZone() { return PuwgZone; }276 }277 278 class Epsg2179 extends Puwg2000 {279 private static final int PuwgZone = 8;280 281 @Override282 public int getZone() { return PuwgZone; }283 } -
trunk/src/org/openstreetmap/josm/data/projection/SwissGrid.java
r5066 r5234 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.event.ActionListener;7 import java.util.Collection;8 import java.util.Collections;9 10 import javax.swing.Box;11 import javax.swing.JPanel;12 5 13 6 import org.openstreetmap.josm.data.Bounds; … … 16 9 import org.openstreetmap.josm.data.projection.proj.ProjParameters; 17 10 import org.openstreetmap.josm.data.projection.proj.SwissObliqueMercator; 18 import org.openstreetmap.josm.gui.widgets.HtmlPanel;19 import org.openstreetmap.josm.tools.GBC;20 11 21 12 /** … … 31 22 * ProjectionSubPrefs to show a warning that the grid file correction is not done. 32 23 */ 33 public class SwissGrid extends AbstractProjection implements ProjectionSubPrefs{24 public class SwissGrid extends AbstractProjection { 34 25 35 26 public SwissGrid() { … … 75 66 } 76 67 77 @Override78 public void setupPreferencePanel(JPanel p, ActionListener listener) {79 p.add(new HtmlPanel(tr("<i>CH1903 / LV03 (without local corrections)</i>")), GBC.eol().fill(GBC.HORIZONTAL));80 p.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));81 }82 83 @Override84 public void setPreferences(Collection<String> args) {85 }86 87 @Override88 public Collection<String> getPreferences(JPanel p) {89 return Collections.singletonList("CH1903");90 }91 92 @Override93 public String[] allCodes() {94 return new String[] { "EPSG:21781" };95 }96 97 @Override98 public Collection<String> getPreferencesFromCode(String code) {99 if ("EPSG:21781".equals(code))100 return Collections.singletonList("CH1903");101 return null;102 }103 68 } -
trunk/src/org/openstreetmap/josm/data/projection/UTM.java
r5232 r5234 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagLayout;7 import java.awt.event.ActionListener;8 import java.util.ArrayList;9 import java.util.Arrays;10 import java.util.Collection;11 12 import javax.swing.ButtonGroup;13 import javax.swing.JCheckBox;14 import javax.swing.JComboBox;15 import javax.swing.JLabel;16 import javax.swing.JPanel;17 import javax.swing.JRadioButton;18 19 6 import org.openstreetmap.josm.data.Bounds; 20 7 import org.openstreetmap.josm.data.coor.LatLon; 21 8 import org.openstreetmap.josm.data.projection.datum.WGS84Datum; 22 9 import org.openstreetmap.josm.data.projection.proj.ProjParameters; 23 import org.openstreetmap.josm.tools.GBC;24 10 25 11 /** … … 29 15 * 30 16 */ 31 public class UTM extends AbstractProjection implements ProjectionSubPrefs{17 public class UTM extends AbstractProjection { 32 18 33 19 private static final int DEFAULT_ZONE = 30; … … 56 42 } 57 43 datum = WGS84Datum.INSTANCE; 58 updateParameters(zone, hemisphere, offset);59 }60 61 public void updateParameters(int zone, Hemisphere hemisphere, boolean offset) {62 44 this.zone = zone; 63 45 this.hemisphere = hemisphere; … … 125 107 } 126 108 127 @Override128 public void setupPreferencePanel(JPanel p, ActionListener listener) {129 //Zone130 JComboBox zonecb = new JComboBox();131 for(int i = 1; i <= 60; i++) {132 zonecb.addItem(i);133 }134 135 zonecb.setSelectedIndex(zone - 1);136 p.setLayout(new GridBagLayout());137 p.add(new JLabel(tr("UTM Zone")), GBC.std().insets(5,5,0,5));138 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));139 /* Note: we use component position 2 below to find this again */140 p.add(zonecb, GBC.eop().fill(GBC.HORIZONTAL));141 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));142 143 //Hemisphere144 JRadioButton north = new JRadioButton();145 north.setSelected(hemisphere == Hemisphere.North);146 JRadioButton south = new JRadioButton();147 south.setSelected(hemisphere == Hemisphere.South);148 149 ButtonGroup group = new ButtonGroup();150 group.add(north);151 group.add(south);152 153 JPanel bPanel = new JPanel();154 bPanel.setLayout(new GridBagLayout());155 156 bPanel.add(new JLabel(tr("North")), GBC.std().insets(5, 5, 0, 5));157 bPanel.add(north, GBC.std().fill(GBC.HORIZONTAL));158 bPanel.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));159 bPanel.add(new JLabel(tr("South")), GBC.std().insets(5, 5, 0, 5));160 bPanel.add(south, GBC.std().fill(GBC.HORIZONTAL));161 bPanel.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));162 163 p.add(new JLabel(tr("Hemisphere")), GBC.std().insets(5,5,0,5));164 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));165 p.add(bPanel, GBC.eop().fill(GBC.HORIZONTAL));166 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));167 168 //Offset169 JCheckBox offsetBox = new JCheckBox();170 offsetBox.setSelected(offset);171 172 p.add(new JLabel(tr("Offset 3.000.000m east")), GBC.std().insets(5,5,0,5));173 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));174 /* Note: we use component position 2 below to find this again */175 p.add(offsetBox, GBC.eop().fill(GBC.HORIZONTAL));176 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));177 178 if (listener != null) {179 north.addActionListener(listener);180 south.addActionListener(listener);181 zonecb.addActionListener(listener);182 offsetBox.addActionListener(listener);183 }184 }185 186 @Override187 public Collection<String> getPreferences(JPanel p) {188 int zone = DEFAULT_ZONE;189 Hemisphere hemisphere = DEFAULT_HEMISPHERE;190 boolean offset = false;191 192 Object zonecb = p.getComponent(2);193 if (zonecb instanceof JComboBox) {194 zone = ((JComboBox)zonecb).getSelectedIndex() + 1;195 }196 197 Object bPanel = p.getComponent(6);198 if (bPanel instanceof JPanel) {199 Object south = ((JPanel)bPanel).getComponent(4);200 if (south instanceof JRadioButton) {201 hemisphere = ((JRadioButton)south).isSelected()?Hemisphere.South:Hemisphere.North;202 }203 }204 205 Object offsetBox = p.getComponent(10);206 if (offsetBox instanceof JCheckBox) {207 offset = ((JCheckBox) offsetBox).isSelected();208 }209 210 return Arrays.asList(Integer.toString(zone), hemisphere.toString(), (offset?"offset":"standard"));211 }212 213 @Override214 public void setPreferences(Collection<String> args) {215 int zone = DEFAULT_ZONE;216 Hemisphere hemisphere = DEFAULT_HEMISPHERE;217 boolean offset = false;218 219 if(args != null)220 {221 String[] array = args.toArray(new String[0]);222 try {223 zone = Integer.parseInt(array[0]);224 if(zone <= 0 || zone > 60) {225 zone = DEFAULT_ZONE;226 }227 } catch(NumberFormatException e) {}228 229 if (array.length > 1) {230 hemisphere = Hemisphere.valueOf(array[1]);231 }232 233 if (array.length > 2) {234 offset = array[2].equals("offset");235 }236 }237 updateParameters(zone, hemisphere, offset);238 }239 240 @Override241 public String[] allCodes() {242 ArrayList<String> projections = new ArrayList<String>(60*4);243 for (int zone = 1;zone <= 60; zone++) {244 for (boolean offset : new boolean[] { false, true }) {245 for (Hemisphere hemisphere : Hemisphere.values()) {246 projections.add("EPSG:" + ((offset?325800:32600) + zone + (hemisphere == Hemisphere.South?100:0)));247 }248 }249 }250 return projections.toArray(new String[0]);251 }252 253 @Override254 public Collection<String> getPreferencesFromCode(String code) {255 256 boolean offset = code.startsWith("EPSG:3258") || code.startsWith("EPSG:3259");257 258 if(code.startsWith("EPSG:326") || code.startsWith("EPSG:327") || offset)259 {260 try {261 Hemisphere hemisphere;262 String zonestring;263 if (offset) {264 hemisphere = code.charAt(8)=='8'?Hemisphere.North:Hemisphere.South;265 zonestring = code.substring(9);266 } else {267 hemisphere = code.charAt(7)=='6'?Hemisphere.North:Hemisphere.South;268 zonestring = code.substring(8);269 }270 271 int zoneval = Integer.parseInt(zonestring);272 if(zoneval > 0 && zoneval <= 60)273 return Arrays.asList(zonestring, hemisphere.toString(), (offset?"offset":"standard"));274 } catch(NumberFormatException e) {}275 }276 return null;277 }278 109 } -
trunk/src/org/openstreetmap/josm/data/projection/UTM_France_DOM.java
r5067 r5234 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.GridBagLayout;7 import java.awt.event.ActionListener;8 import java.util.Collection;9 import java.util.Collections;10 11 import javax.swing.JComboBox;12 import javax.swing.JLabel;13 import javax.swing.JPanel;14 5 15 6 import org.openstreetmap.josm.data.Bounds; … … 20 11 import org.openstreetmap.josm.data.projection.datum.ThreeParameterDatum; 21 12 import org.openstreetmap.josm.data.projection.proj.ProjParameters; 22 import org.openstreetmap.josm.tools.GBC;23 13 24 14 /** … … 27 17 * 28 18 */ 29 public class UTM_France_DOM extends AbstractProjection implements ProjectionSubPrefs { 30 31 private final static String FortMarigotName = tr("Guadeloupe Fort-Marigot 1949"); 32 private final static String SainteAnneName = tr("Guadeloupe Ste-Anne 1948"); 33 private final static String MartiniqueName = tr("Martinique Fort Desaix 1952"); 34 private final static String Reunion92Name = tr("Reunion RGR92"); 35 private final static String Guyane92Name = tr("Guyane RGFG95"); 36 private final static String[] utmGeodesicsNames = { FortMarigotName, SainteAnneName, MartiniqueName, Reunion92Name, Guyane92Name}; 19 public class UTM_France_DOM extends AbstractProjection { 37 20 38 21 private final static Bounds FortMarigotBounds = new Bounds( new LatLon(17.6,-63.25), new LatLon(18.5,-62.5)); … … 48 31 private final static Integer ReunionEPSG = 2975; 49 32 private final static Integer GuyaneEPSG = 2972; 50 p rivatefinal static Integer[] utmEPSGs = { FortMarigotEPSG, SainteAnneEPSG, MartiniqueEPSG, ReunionEPSG, GuyaneEPSG };33 public final static Integer[] utmEPSGs = { FortMarigotEPSG, SainteAnneEPSG, MartiniqueEPSG, ReunionEPSG, GuyaneEPSG }; 51 34 52 35 private final static Datum FortMarigotDatum = new ThreeParameterDatum("FortMarigot Datum", null, Ellipsoid.hayford, 136.596, 248.148, -429.789); … … 74 57 75 58 public UTM_France_DOM() { 76 updateParameters(DEFAULT_GEODESIC);59 this(DEFAULT_GEODESIC); 77 60 } 78 61 79 public void updateParameters(int currentGeodesic) {62 public UTM_France_DOM(int currentGeodesic) { 80 63 this.currentGeodesic = currentGeodesic; 81 64 datum = utmDatums[currentGeodesic]; … … 124 107 } 125 108 126 @Override127 public void setupPreferencePanel(JPanel p, ActionListener listener) {128 JComboBox prefcb = new JComboBox(utmGeodesicsNames);129 130 prefcb.setSelectedIndex(currentGeodesic);131 p.setLayout(new GridBagLayout());132 p.add(new JLabel(tr("UTM Geodesic system")), GBC.std().insets(5,5,0,5));133 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));134 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));135 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));136 if (listener != null) {137 prefcb.addActionListener(listener);138 }139 }140 141 @Override142 public Collection<String> getPreferences(JPanel p) {143 Object prefcb = p.getComponent(2);144 if(!(prefcb instanceof JComboBox))145 return null;146 currentGeodesic = ((JComboBox)prefcb).getSelectedIndex();147 return Collections.singleton(Integer.toString(currentGeodesic+1));148 }149 150 @Override151 public String[] allCodes() {152 String[] res = new String[utmEPSGs.length];153 for (int i=0; i<utmEPSGs.length; ++i) {154 res[i] = "EPSG:"+utmEPSGs[i];155 }156 return res;157 }158 159 @Override160 public Collection<String> getPreferencesFromCode(String code) {161 for (int i=0; i < utmEPSGs.length; i++ )162 if (("EPSG:"+utmEPSGs[i]).equals(code))163 return Collections.singleton(Integer.toString(i+1));164 return null;165 }166 167 @Override168 public void setPreferences(Collection<String> args) {169 int currentGeodesic = DEFAULT_GEODESIC;170 if (args != null) {171 try {172 for(String s : args)173 {174 currentGeodesic = Integer.parseInt(s)-1;175 if(currentGeodesic < 0 || currentGeodesic >= utmEPSGs.length) {176 currentGeodesic = DEFAULT_GEODESIC;177 }178 break;179 }180 } catch(NumberFormatException e) {}181 }182 updateParameters(currentGeodesic);183 }184 109 } -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java
r4968 r5234 54 54 import org.openstreetmap.josm.data.imagery.ImageryInfo; 55 55 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 56 import org.openstreetmap.josm.data.projection.Projection;57 import org.openstreetmap.josm.data.projection.ProjectionSubPrefs;58 import org.openstreetmap.josm.data.projection.Projections;59 56 import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; 60 57 import org.openstreetmap.josm.gui.layer.TMSLayer; 58 import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice; 59 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 61 60 import org.openstreetmap.josm.io.UTFInputStreamReader; 62 61 import org.openstreetmap.josm.tools.GBC; … … 492 491 493 492 private boolean isProjSupported(String crs) { 494 for (Projection proj : Projections.getProjections()) { 495 if (proj instanceof ProjectionSubPrefs) { 496 if (((ProjectionSubPrefs) proj).getPreferencesFromCode(crs) == null) 497 return true; 498 } else { 499 if (proj.toCode().equals(crs)) 500 return true; 501 } 493 for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) { 494 if (pc.getPreferencesFromCode(crs) != null) return true; 502 495 } 503 496 return false; -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r5226 r5234 10 10 import java.util.ArrayList; 11 11 import java.util.Collection; 12 import java.util.Collections; 13 import java.util.HashMap; 14 import java.util.List; 15 import java.util.Map; 12 16 13 17 import javax.swing.BorderFactory; … … 23 27 import org.openstreetmap.josm.data.coor.CoordinateFormat; 24 28 import org.openstreetmap.josm.data.preferences.CollectionProperty; 25 import org.openstreetmap.josm.data.preferences.ParametrizedCollectionProperty;26 29 import org.openstreetmap.josm.data.preferences.StringProperty; 30 import org.openstreetmap.josm.data.projection.BelgianLambert1972; 31 import org.openstreetmap.josm.data.projection.BelgianLambert2008; 32 import org.openstreetmap.josm.data.projection.Epsg3008; 33 import org.openstreetmap.josm.data.projection.Epsg4326; 34 import org.openstreetmap.josm.data.projection.Lambert93; 35 import org.openstreetmap.josm.data.projection.LambertEST; 27 36 import org.openstreetmap.josm.data.projection.Mercator; 28 37 import org.openstreetmap.josm.data.projection.Projection; 29 import org.openstreetmap.josm.data.projection.ProjectionSubPrefs; 30 import org.openstreetmap.josm.data.projection.Projections; 38 import org.openstreetmap.josm.data.projection.TransverseMercatorLV; 31 39 import org.openstreetmap.josm.gui.NavigatableComponent; 32 40 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; … … 35 43 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 36 44 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 37 import org.openstreetmap.josm.plugins.PluginHandler;38 45 import org.openstreetmap.josm.tools.GBC; 39 46 … … 46 53 } 47 54 48 private static final StringProperty PROP_PROJECTION = new StringProperty("projection", Mercator.class.getName()); 55 private static List<ProjectionChoice> projectionChoices = new ArrayList<ProjectionChoice>(); 56 private static Map<String, ProjectionChoice> projectionChoicesById = new HashMap<String, ProjectionChoice>(); 57 private static Map<String, String> aliasNormalizer = new HashMap<String, String>(); 58 59 public static ProjectionChoice mercator = new SingleProjectionChoice("core:mercator", new Mercator()); 60 static { 61 // global projections 62 registerProjectionChoice("core:wgs84", new Epsg4326()); 63 registerProjectionChoice(mercator); 64 registerProjectionChoice(new UTMProjectionChoice()); 65 // regional - alphabetical order by country code 66 registerProjectionChoice("core:belambert1972", new BelgianLambert1972()); // BE 67 registerProjectionChoice("core:belambert2008", new BelgianLambert2008()); // BE 68 registerProjectionChoice(new SwissGridProjectionChoice()); // CH 69 registerProjectionChoice(new GaussKruegerProjectionChoice()); // DE 70 registerProjectionChoice("core:lambertest", new LambertEST()); // EE 71 registerProjectionChoice(new LambertProjectionChoice()); // FR 72 registerProjectionChoice("core:lambert93", new Lambert93()); // FR 73 registerProjectionChoice(new LambertCC9ZonesProjectionChoice()); // FR 74 registerProjectionChoice(new UTM_France_DOM_ProjectionChoice()); // FR 75 registerProjectionChoice("core:tmerclv", new TransverseMercatorLV()); // LV 76 registerProjectionChoice(new PuwgProjectionChoice()); // PL 77 registerProjectionChoice("core:sweref99", new Epsg3008()); // SE 78 registerProjectionChoice(new CustomProjectionChoice()); 79 } 80 81 public static void registerProjectionChoice(ProjectionChoice c) { 82 projectionChoices.add(c); 83 projectionChoicesById.put(c.getId(), c); 84 aliasNormalizer.put(c.getId(), c.getId()); 85 if (c instanceof Alias) { 86 String alias = ((Alias) c).getAlias(); 87 projectionChoicesById.put(alias, c); 88 aliasNormalizer.put(alias, c.getId()); 89 } 90 } 91 92 public static void registerProjectionChoice(String id, Projection projection) { 93 registerProjectionChoice(new SingleProjectionChoice(id, projection)); 94 } 95 96 public static List<ProjectionChoice> getProjectionChoices() { 97 return Collections.unmodifiableList(projectionChoices); 98 } 99 100 private static final StringProperty PROP_PROJECTION = new StringProperty("projection", mercator.getId()); 49 101 private static final StringProperty PROP_COORDINATES = new StringProperty("coordinates", null); 50 102 private static final CollectionProperty PROP_SUB_PROJECTION = new CollectionProperty("projection.sub", null); 51 private static final ParametrizedCollectionProperty PROP_PROJECTION_SUBPROJECTION = new ParametrizedCollectionProperty(null) {52 @Override53 protected String getKey(String... params) {54 String name = params[0];55 String sname = name.substring(name.lastIndexOf(".")+1);56 return "projection.sub."+sname;57 }58 };59 103 public static final StringProperty PROP_SYSTEM_OF_MEASUREMENT = new StringProperty("system_of_measurement", "Metric"); 60 104 private static final String[] unitsValues = (new ArrayList<String>(NavigatableComponent.SYSTEMS_OF_MEASUREMENT.keySet())).toArray(new String[0]); … … 69 113 * Combobox with all projections available 70 114 */ 71 private JComboBox projectionCombo = new JComboBox( Projections.getProjections().toArray());115 private JComboBox projectionCombo = new JComboBox(projectionChoices.toArray()); 72 116 73 117 /** … … 104 148 105 149 public void addGui(PreferenceTabbedPane gui) { 106 setupProjectionCombo(); 150 ProjectionChoice pc = setupProjectionCombo(); 107 151 108 152 for (int i = 0; i < coordinatesCombo.getItemCount(); ++i) { … … 131 175 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 132 176 projPanel.add(bounds, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 133 projSubPrefPanelWrapper.add(projSubPrefPanel, projSubPrefPanelGBC);134 177 projPanel.add(projSubPrefPanelWrapper, GBC.eol().fill(GBC.HORIZONTAL).insets(20,5,5,5)); 135 178 … … 146 189 gui.getMapPreference().mapcontent.addTab(tr("Map Projection"), scrollpane); 147 190 148 updateMeta(Main.getProjection()); 149 } 150 151 private void updateMeta(Projection proj) 152 { 191 selectedProjectionChanged(pc); 192 } 193 194 private void updateMeta(ProjectionChoice pc) { 195 pc.setPreferences(pc.getPreferences(projSubPrefPanel)); 196 Projection proj = pc.getProjection(); 153 197 projectionCode.setText(proj.toCode()); 154 198 Bounds b = proj.getWorldBoundsLatLon(); 155 199 CoordinateFormat cf = CoordinateFormat.getDefaultFormat(); 156 200 bounds.setText(b.getMin().latToString(cf)+"; "+b.getMin().lonToString(cf)+" : "+b.getMax().latToString(cf)+"; "+b.getMax().lonToString(cf)); 157 boolean hideCode = proj instanceof SubPrefsOptions && !((SubPrefsOptions) proj).showProjectionCode(); 158 projectionCodeLabel.setVisible(!hideCode); 159 projectionCodeGlue.setVisible(!hideCode); 160 projectionCode.setVisible(!hideCode); 161 } 162 201 boolean showCode = true; 202 if (pc instanceof SubPrefsOptions) { 203 showCode = ((SubPrefsOptions) pc).showProjectionCode(); 204 } 205 projectionCodeLabel.setVisible(showCode); 206 projectionCodeGlue.setVisible(showCode); 207 projectionCode.setVisible(showCode); 208 } 209 210 @Override 163 211 public boolean ok() { 164 Projection proj = (Projection) projectionCombo.getSelectedItem(); 165 166 String projname = proj.getClass().getName(); 167 Collection<String> prefs = null; 168 if(proj instanceof ProjectionSubPrefs) { 169 prefs = ((ProjectionSubPrefs) proj).getPreferences(projSubPrefPanel); 170 } 171 172 PROP_PROJECTION.put(projname); 173 setProjection(projname, prefs); 212 ProjectionChoice pc = (ProjectionChoice) projectionCombo.getSelectedItem(); 213 214 String id = pc.getId(); 215 Collection<String> prefs = pc.getPreferences(projSubPrefPanel); 216 217 setProjection(id, prefs); 174 218 175 219 if(PROP_COORDINATES.put(((CoordinateFormat)coordinatesCombo.getSelectedItem()).name())) { … … 183 227 } 184 228 185 static public void setProjection() 186 { 229 static public void setProjection() { 187 230 setProjection(PROP_PROJECTION.get(), PROP_SUB_PROJECTION.get()); 188 231 } 189 232 190 static public void setProjection(String name, Collection<String> coll) 191 { 192 Bounds b = (Main.map != null && Main.map.mapView != null) ? Main.map.mapView.getRealBounds() : null; 193 194 Projection proj = null; 195 for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) { 196 try { 197 proj = (Projection) Class.forName(name, true, cl).newInstance(); 198 } catch (final Exception e) { 199 } 200 if (proj != null) { 201 break; 202 } 203 } 204 if (proj == null) { 233 static public void setProjection(String id, Collection<String> pref) { 234 ProjectionChoice pc = projectionChoicesById.get(id); 235 236 if (pc == null) { 205 237 JOptionPane.showMessageDialog( 206 238 Main.parent, 207 tr("The projection {0} could not be activated. Using Mercator", name),239 tr("The projection {0} could not be activated. Using Mercator", id), 208 240 tr("Error"), 209 241 JOptionPane.ERROR_MESSAGE 210 242 ); 211 coll = null; 212 proj = new Mercator(); 213 name = proj.getClass().getName(); 214 PROP_PROJECTION.put(name); 215 } 216 PROP_SUB_PROJECTION.put(coll); 217 PROP_PROJECTION_SUBPROJECTION.put(coll, name); 218 if (proj instanceof ProjectionSubPrefs) { 219 ((ProjectionSubPrefs) proj).setPreferences(coll); 220 } 221 Projection oldProj = Main.getProjection(); 243 pref = null; 244 pc = mercator; 245 } 246 id = pc.getId(); 247 PROP_PROJECTION.put(id); 248 PROP_SUB_PROJECTION.put(pref); 249 Main.pref.putCollection("projection.sub."+id, pref); 250 pc.setPreferences(pref); 251 Projection proj = pc.getProjection(); 222 252 Main.setProjection(proj); 223 if (b != null && (!proj.getClass().getName().equals(oldProj.getClass().getName()) || proj.hashCode() != oldProj.hashCode()))224 {225 Main.map.mapView.zoomTo(b);226 /* TODO - remove layers with fixed projection */227 }228 }229 230 private class SBPanel extends JPanel implements ActionListener231 {232 private ProjectionSubPrefs p;233 public SBPanel(ProjectionSubPrefs pr)234 {235 super();236 p = pr;237 }238 239 @Override240 public void actionPerformed(ActionEvent e) {241 p.setPreferences(p.getPreferences(this));242 updateMeta(p);243 }244 253 } 245 254 … … 249 258 * @param proj 250 259 */ 251 private void selectedProjectionChanged(Projection proj) { 252 if(!(proj instanceof ProjectionSubPrefs)) { 253 projSubPrefPanel = new JPanel(); 254 } else { 255 ProjectionSubPrefs projPref = (ProjectionSubPrefs) proj; 256 projSubPrefPanel = new SBPanel(projPref); 257 projPref.setupPreferencePanel(projSubPrefPanel, (SBPanel)projSubPrefPanel); 258 } 259 260 private void selectedProjectionChanged(final ProjectionChoice pc) { 260 261 // Don't try to update if we're still starting up 261 262 int size = projPanel.getComponentCount(); … … 263 264 return; 264 265 266 final ActionListener listener = new ActionListener() { 267 @Override 268 public void actionPerformed(ActionEvent e) { 269 updateMeta(pc); 270 } 271 }; 272 265 273 // Replace old panel with new one 266 274 projSubPrefPanelWrapper.removeAll(); 275 projSubPrefPanel = pc.getPreferencePanel(listener); 267 276 projSubPrefPanelWrapper.add(projSubPrefPanel, projSubPrefPanelGBC); 268 277 projPanel.revalidate(); 269 278 projSubPrefPanel.repaint(); 270 updateMeta(p roj);279 updateMeta(pc); 271 280 } 272 281 … … 274 283 * Sets up projection combobox with default values and action listener 275 284 */ 276 private voidsetupProjectionCombo() {277 boolean found = false;285 private ProjectionChoice setupProjectionCombo() { 286 ProjectionChoice pc = null; 278 287 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 279 Projection proj = (Projection)projectionCombo.getItemAt(i); 280 String name = proj.getClass().getName(); 281 if(proj instanceof ProjectionSubPrefs) { 282 ((ProjectionSubPrefs) proj).setPreferences(PROP_PROJECTION_SUBPROJECTION.get(name)); 283 } 284 if (name.equals(PROP_PROJECTION.get())) { 288 ProjectionChoice pc1 = (ProjectionChoice) projectionCombo.getItemAt(i); 289 pc1.setPreferences(getSubprojectionPreference(pc1)); 290 if (pc1.getId().equals(aliasNormalizer.get(PROP_PROJECTION.get()))) { 285 291 projectionCombo.setSelectedIndex(i); 286 selectedProjectionChanged(proj); 287 found = true; 288 break; 289 } 290 } 291 if (!found) 292 selectedProjectionChanged(pc1); 293 pc = pc1; 294 } 295 } 296 // If the ProjectionChoice from the preferences is not available, it 297 // should have been set to Mercator at JOSM start. 298 if (pc == null) 292 299 throw new RuntimeException("Couldn't find the current projection in the list of available projections!"); 293 300 294 301 projectionCombo.addActionListener(new ActionListener() { 295 302 public void actionPerformed(ActionEvent e) { 296 JComboBox cb = (JComboBox)e.getSource(); 297 Projection proj = (Projection)cb.getSelectedItem(); 298 selectedProjectionChanged(proj); 303 ProjectionChoice pc = (ProjectionChoice) projectionCombo.getSelectedItem(); 304 selectedProjectionChanged(pc); 299 305 } 300 306 }); 307 return pc; 308 } 309 310 private Collection<String> getSubprojectionPreference(ProjectionChoice pc) { 311 Collection<String> c1 = Main.pref.getCollection("projection.sub."+pc.getId(), null); 312 if (c1 != null) 313 return c1; 314 if (pc instanceof Alias) { 315 String alias = ((Alias) pc).getAlias(); 316 String sname = alias.substring(alias.lastIndexOf(".")+1); 317 return Main.pref.getCollection("projection.sub."+sname, null); 318 } 319 return null; 301 320 } 302 321 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/SubPrefsOptions.java
r5226 r5234 3 3 4 4 /** 5 * Projection SubPrefscan implement this interface to set some additional options5 * ProjectionChoice can implement this interface to set some additional options 6 6 */ 7 7 public interface SubPrefsOptions {
Note:
See TracChangeset
for help on using the changeset viewer.