Changeset 5226 in josm
- Timestamp:
- 2012-05-09T21:29:17+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 added
- 9 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r5195 r5226 69 69 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference; 70 70 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference; 71 import org.openstreetmap.josm.gui.preferences.map.ProjectionPreference;72 71 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 72 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 73 73 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 74 74 import org.openstreetmap.josm.gui.progress.ProgressMonitorExecutor; -
trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java
r5202 r5226 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagLayout;7 import java.awt.event.ActionListener;8 6 import java.util.ArrayList; 9 import java.util.Collection;10 import java.util.Collections;11 7 import java.util.HashMap; 12 8 import java.util.List; … … 14 10 import java.util.regex.Matcher; 15 11 import java.util.regex.Pattern; 16 import javax.swing.JPanel;17 import javax.swing.JTextField;18 12 19 13 import org.openstreetmap.josm.data.Bounds; … … 21 15 import org.openstreetmap.josm.data.projection.datum.CentricDatum; 22 16 import org.openstreetmap.josm.data.projection.datum.Datum; 17 import org.openstreetmap.josm.data.projection.datum.NTV2Datum; 18 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper; 23 19 import org.openstreetmap.josm.data.projection.datum.SevenParameterDatum; 24 20 import org.openstreetmap.josm.data.projection.datum.ThreeParameterDatum; 21 import org.openstreetmap.josm.data.projection.datum.WGS84Datum; 25 22 import org.openstreetmap.josm.data.projection.proj.Proj; 26 23 import org.openstreetmap.josm.data.projection.proj.ProjParameters; … … 32 29 * Inspired by PROJ.4 and Proj4J. 33 30 */ 34 public class CustomProjection extends AbstractProjection implements ProjectionSubPrefs { 35 36 private String pref = ""; 37 38 public void update(String pref) { 39 try { 31 public class CustomProjection extends AbstractProjection { 32 33 /** 34 * pref String that defines the projection 35 * 36 * null means fall back mode (Mercator) 37 */ 38 protected String pref = null; 39 40 public void update(String pref) throws ProjectionConfigurationException { 41 if (pref == null) { 42 this.pref = null; 43 ellps = Ellipsoid.WGS84; 44 datum = WGS84Datum.INSTANCE; 45 proj = new org.openstreetmap.josm.data.projection.proj.Mercator(); 46 } else { 40 47 Map<String, String> parameters = new HashMap<String, String>(); 41 48 String[] parts = pref.trim().split("\\s+"); 42 49 for (int i = 0; i < parts.length; i++) { 43 50 String part = parts[i]; 44 if (part.charAt(0) != '+') 51 if (part.isEmpty() || part.charAt(0) != '+') 45 52 throw new ProjectionConfigurationException(tr("Parameter must begin with a ''+'' sign (found ''{0}'')", part)); 46 53 Matcher m = Pattern.compile("\\+([a-zA-Z0-9_]+)(=(.*))?").matcher(part); … … 74 81 this.k_0 = parseDouble(s, "k_0"); 75 82 } 76 } catch (ProjectionConfigurationException e) { 77 System.err.println(e.toString()); // FIXME 78 } 79 this.pref = pref; 83 this.pref = pref; 84 } 80 85 } 81 86 … … 121 126 122 127 public Datum parseDatum(Map<String, String> parameters, Ellipsoid ellps) throws ProjectionConfigurationException { 128 String nadgridsId = parameters.get("nadgrids"); 129 if (nadgridsId != null) { 130 NTV2GridShiftFileWrapper nadgrids = Projections.getNadgrids(nadgridsId); 131 if (nadgrids == null) 132 throw new ProjectionConfigurationException(tr("Grid shift file ''{0}'' for option +nadgrids not supported.", nadgridsId)); 133 return new NTV2Datum(nadgridsId, null, ellps, nadgrids); 134 } 135 123 136 String towgs84 = parameters.get("towgs84"); 124 137 if (towgs84 != null) … … 298 311 @Override 299 312 public String toCode() { 300 return Utils.md5Hex(pref).substring(0, 10);313 return "proj:" + (pref == null ? "ERROR" : pref); 301 314 } 302 315 303 316 @Override 304 317 public String getCacheDirectoryName() { 305 return toCode();318 return "proj-"+Utils.md5Hex(pref == null ? "" : pref).substring(0, 4); 306 319 } 307 320 … … 317 330 return tr("Custom Projection (from PROJ.4 string)"); 318 331 } 319 320 @Override321 public void setupPreferencePanel(JPanel p, ActionListener listener) {322 JTextField input = new JTextField(pref, 50);323 p.setLayout(new GridBagLayout());324 p.add(input);325 }326 327 @Override328 public Collection<String> getPreferences(JPanel p) {329 Object prefTf = p.getComponent(0);330 if (!(prefTf instanceof JTextField))331 return null;332 String pref = ((JTextField) prefTf).getText();333 return Collections.singleton(pref);334 }335 336 @Override337 public void setPreferences(Collection<String> args) {338 update(args.iterator().next());339 }340 341 @Override342 public String[] allCodes() {343 return new String[0];344 }345 346 @Override347 public Collection<String> getPreferencesFromCode(String code) {348 return null;349 }350 351 332 } -
trunk/src/org/openstreetmap/josm/data/projection/GaussKrueger.java
r5073 r5226 6 6 import java.awt.GridBagLayout; 7 7 import java.awt.event.ActionListener; 8 import java.io.InputStream;9 8 import java.util.Collection; 10 9 import java.util.Collections; … … 14 13 import javax.swing.JPanel; 15 14 16 import org.openstreetmap.josm.Main;17 15 import org.openstreetmap.josm.data.Bounds; 18 16 import org.openstreetmap.josm.data.coor.LatLon; 19 17 import org.openstreetmap.josm.data.projection.datum.NTV2Datum; 20 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFile; 18 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper; 21 19 import org.openstreetmap.josm.data.projection.proj.ProjParameters; 22 20 import org.openstreetmap.josm.data.projection.proj.TransverseMercator; … … 35 33 }; 36 34 37 private static NTV2GridShiftFile BETA2007 = null;38 39 35 private static String[] zones = { "2", "3", "4", "5" }; 40 36 … … 44 40 45 41 public GaussKrueger(int zone) { 46 if (BETA2007 == null) {47 try {48 String gridFileName = "BETA2007.gsb";49 InputStream is = Main.class.getResourceAsStream("/data/"+gridFileName);50 if (is == null)51 throw new RuntimeException(tr("Error: failed to open input stream for resource ''/data/{0}''.", gridFileName));52 BETA2007 = new NTV2GridShiftFile();53 BETA2007.loadGridShiftFile(is, false);54 } catch (Exception e) {55 throw new RuntimeException(e);56 }57 }58 42 updateParameters(zone); 59 43 } … … 62 46 this.zone = zone; 63 47 ellps = Ellipsoid.Bessel1841; 64 datum = new NTV2Datum("BETA2007", null, ellps, BETA2007); 48 datum = new NTV2Datum("BETA2007", null, ellps, NTV2GridShiftFileWrapper.BETA2007); 65 49 ////less acurrate datum (errors up to 3m): 66 50 //datum = new SevenParameterDatum( -
trunk/src/org/openstreetmap/josm/data/projection/Lambert.java
r5073 r5226 19 19 import org.openstreetmap.josm.data.projection.datum.NTV2Datum; 20 20 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFile; 21 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper; 21 22 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic; 22 23 import org.openstreetmap.josm.data.projection.proj.ProjParameters; … … 77 78 private int layoutZone; 78 79 79 private static NTV2GridShiftFile ntf_rgf93Grid = null;80 81 public static NTV2GridShiftFile getNtf_rgf93Grid() {82 return ntf_rgf93Grid;83 }84 85 80 public Lambert() { 86 if (ntf_rgf93Grid == null) {87 try {88 String gridFileName = "ntf_r93_b.gsb";89 InputStream is = Main.class.getResourceAsStream("/data/"+gridFileName);90 if (is == null) {91 throw new RuntimeException(tr("Error: failed to open input stream for resource ''/data/{0}''. Cannot load NTF<->RGF93 grid", gridFileName));92 }93 ntf_rgf93Grid = new NTV2GridShiftFile();94 ntf_rgf93Grid.loadGridShiftFile(is, false);95 } catch (Exception e) {96 throw new RuntimeException(e);97 }98 }99 81 updateParameters(DEFAULT_ZONE); 100 82 } … … 103 85 this.layoutZone = layoutZone; 104 86 ellps = Ellipsoid.clarkeIGN; 105 datum = new NTV2Datum("ntf_rgf93Grid", null, ellps, ntf_rgf93 Grid);87 datum = new NTV2Datum("ntf_rgf93Grid", null, ellps, NTV2GridShiftFileWrapper.ntf_rgf93); 106 88 x_0 = x_0s[layoutZone]; 107 89 lon_0 = 2.0 + 20.0 / 60 + 14.025 / 3600; // 0 grade Paris -
trunk/src/org/openstreetmap/josm/data/projection/Projections.java
r5072 r5226 11 11 import org.openstreetmap.josm.data.coor.LatLon; 12 12 import org.openstreetmap.josm.data.projection.datum.Datum; 13 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper; 13 14 import org.openstreetmap.josm.data.projection.datum.WGS84Datum; 14 15 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic; … … 16 17 import org.openstreetmap.josm.data.projection.proj.SwissObliqueMercator; 17 18 import org.openstreetmap.josm.data.projection.proj.TransverseMercator; 18 import org.openstreetmap.josm.tools.CheckParameterUtil;19 19 20 20 /** … … 49 49 static { 50 50 if (Main.pref.getBoolean("customprojection")) { 51 addProjection(new CustomProjection()); 51 addProjection(new CustomProjectionPrefGui()); 52 52 } 53 53 } … … 86 86 private static Map<String, Class<? extends Proj>> projs = new HashMap<String, Class<? extends Proj>>(); 87 87 private static Map<String, Datum> datums = new HashMap<String, Datum>(); 88 private static Map<String, NTV2GridShiftFileWrapper> nadgrids = new HashMap<String, NTV2GridShiftFileWrapper>(); 88 89 89 90 static { … … 99 100 100 101 datums.put("WGS84", WGS84Datum.INSTANCE); 102 103 nadgrids.put("BETA2007.gsb", NTV2GridShiftFileWrapper.BETA2007); 104 nadgrids.put("ntf_r93_b.gsb", NTV2GridShiftFileWrapper.ntf_rgf93); 101 105 } 102 106 … … 122 126 return datums.get(id); 123 127 } 128 129 public static NTV2GridShiftFileWrapper getNadgrids(String id) { 130 return nadgrids.get(id); 131 } 124 132 } -
trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2Datum.java
r5073 r5226 10 10 public class NTV2Datum extends AbstractDatum { 11 11 12 protected NTV2GridShiftFile nadgrids; 12 protected NTV2GridShiftFileWrapper nadgrids; 13 13 14 public NTV2Datum(String name, String proj4Id, Ellipsoid ellps, NTV2GridShiftFile nadgrids) { 14 public NTV2Datum(String name, String proj4Id, Ellipsoid ellps, NTV2GridShiftFileWrapper nadgrids) { 15 15 super(name, proj4Id, ellps); 16 16 this.nadgrids = nadgrids; … … 20 20 public LatLon toWGS84(LatLon ll) { 21 21 NTV2GridShift gs = new NTV2GridShift(ll); 22 nadgrids.gridShiftForward(gs); 22 nadgrids.getShiftFile().gridShiftForward(gs); 23 23 return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees()); 24 24 } … … 27 27 public LatLon fromWGS84(LatLon ll) { 28 28 NTV2GridShift gs = new NTV2GridShift(ll); 29 nadgrids.gridShiftReverse(gs); 29 nadgrids.getShiftFile().gridShiftReverse(gs); 30 30 return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees()); 31 31 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r5016 r5226 43 43 import org.openstreetmap.josm.data.projection.Projections; 44 44 import org.openstreetmap.josm.gui.help.Helpful; 45 import org.openstreetmap.josm.gui.preferences. map.ProjectionPreference;45 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 46 46 import org.openstreetmap.josm.tools.Predicate; 47 47 -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
r4987 r5226 39 39 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference; 40 40 import org.openstreetmap.josm.gui.preferences.map.MapPreference; 41 import org.openstreetmap.josm.gui.preferences.map.ProjectionPreference;42 41 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 42 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 43 43 import org.openstreetmap.josm.gui.preferences.shortcut.ShortcutPreference; 44 44 import org.openstreetmap.josm.plugins.PluginDownloadTask; -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r5223 r5226 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 package org.openstreetmap.josm.gui.preferences. map;2 package org.openstreetmap.josm.gui.preferences.projection; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component; 6 7 import java.awt.GridBagLayout; 7 8 import java.awt.event.ActionEvent; … … 85 86 private JPanel projSubPrefPanelWrapper = new JPanel(new GridBagLayout()); 86 87 88 private JLabel projectionCodeLabel; 89 private Component projectionCodeGlue; 87 90 private JLabel projectionCode = new JLabel(); 88 91 private JLabel bounds = new JLabel(); … … 122 125 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 123 126 projPanel.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 124 projPanel.add(new JLabel(tr("Projection code")), GBC.std().insets(25,5,0,5)); 125 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 127 projPanel.add(projectionCodeLabel = new JLabel(tr("Projection code")), GBC.std().insets(25,5,0,5)); 128 projPanel.add(projectionCodeGlue = GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 126 129 projPanel.add(projectionCode, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 127 130 projPanel.add(new JLabel(tr("Bounds")), GBC.std().insets(25,5,0,5)); … … 152 155 CoordinateFormat cf = CoordinateFormat.getDefaultFormat(); 153 156 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); 154 161 } 155 162 -
trunk/src/org/openstreetmap/josm/gui/widgets/AbstractTextComponentValidator.java
r3083 r5226 19 19 20 20 import org.openstreetmap.josm.tools.CheckParameterUtil; 21 import org.openstreetmap.josm.tools.Utils; 21 22 22 23 /** … … 41 42 */ 42 43 private Boolean valid = null; 44 // remember the message 45 private String msg; 43 46 44 47 protected void feedbackInvalid(String msg) { 45 if (valid == null || valid) { 48 if (valid == null || valid || !Utils.equal(msg, this.msg)) { 46 49 // only provide feedback if the validity has changed. This avoids 47 50 // unnecessary UI updates. … … 50 53 tc.setToolTipText(msg); 51 54 valid = false; 55 this.msg = msg; 52 56 } 53 57 } … … 58 62 59 63 protected void feedbackValid(String msg) { 60 if (valid == null || !valid) { 64 if (valid == null || !valid || !Utils.equal(msg, this.msg)) { 61 65 // only provide feedback if the validity has changed. This avoids 62 66 // unnecessary UI updates. … … 65 69 tc.setToolTipText(msg == null ? "" : msg); 66 70 valid = true; 71 this.msg = msg; 67 72 } 68 73 } … … 92 97 */ 93 98 public AbstractTextComponentValidator(JTextComponent tc, boolean addActionListener) throws IllegalArgumentException { 99 this(tc, true, true, addActionListener); 100 } 101 102 public AbstractTextComponentValidator(JTextComponent tc, boolean addFocusListener, boolean addDocumentListener, boolean addActionListener) throws IllegalArgumentException { 94 103 CheckParameterUtil.ensureParameterNotNull(tc, "tc"); 95 104 this.tc = tc; 96 tc.addFocusListener(this); 97 tc.getDocument().addDocumentListener(this); 105 if (addFocusListener) { 106 tc.addFocusListener(this); 107 } 108 if (addDocumentListener) { 109 tc.getDocument().addDocumentListener(this); 110 } 98 111 if (addActionListener) { 99 112 if (tc instanceof JTextField) {
Note:
See TracChangeset
for help on using the changeset viewer.