Changeset 3779 in josm


Ignore:
Timestamp:
Jan 8, 2011 1:04:23 AM (2 years ago)
Author:
Upliner
Message:

Identify projections in offset bookmarks by EPSG codes, bugfixes in getPreferencesFromCode() functions as they're critical now.

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java

    r3775 r3779  
    1414import org.openstreetmap.josm.data.coor.LatLon; 
    1515import org.openstreetmap.josm.data.projection.Projection; 
     16import org.openstreetmap.josm.data.projection.ProjectionInfo; 
    1617import org.openstreetmap.josm.gui.layer.ImageryLayer; 
    1718 
     
    2627 
    2728    public boolean isUsable(ImageryLayer layer) { 
    28         return Main.proj.getClass() == proj.getClass() && 
    29         layer.getInfo().getName().equals(layerName); 
     29        if (proj == null) return false; 
     30        if (!Main.proj.toCode().equals(proj.toCode())) return false; 
     31        return layer.getInfo().getName().equals(layerName); 
    3032    } 
    3133 
     
    4648    public OffsetBookmark(Collection<String> list) { 
    4749        ArrayList<String> array = new ArrayList<String>(list); 
    48         String projectionName = array.get(0); 
    49         for (Projection proj : Projection.allProjections) { 
    50             if (proj.getCacheDirectoryName().equals(projectionName)) { 
    51                 this.proj = proj; 
    52                 break; 
     50        String projectionStr = array.get(0); 
     51        proj = ProjectionInfo.getProjectionByCode(projectionStr); 
     52        if (proj == null) { 
     53            for (Projection proj : Projection.allProjections) { 
     54                if (proj.getCacheDirectoryName().equals(projectionStr)) { 
     55                    this.proj = proj; 
     56                    break; 
     57                } 
    5358            } 
    5459        } 
    55         if (this.proj == null) 
    56             throw new IllegalStateException(tr("Projection ''{0}'' not found", projectionName)); 
    5760        this.layerName = array.get(1); 
    5861        this.name = array.get(2); 
     
    6366            this.centerY = Double.valueOf(array.get(6)); 
    6467        } 
     68        if (proj == null) { 
     69            System.err.println(tr("Projection ''{0}'' is not found, bookmark ''{1}'' is not usable", projectionStr, name)); 
     70        } 
    6571    } 
    6672 
    6773    public ArrayList<String> getInfoArray() { 
    68         ArrayList<String> res = new ArrayList<String>(5); 
    69         res.add(proj.getCacheDirectoryName()); // we should use non-localized projection name 
     74        ArrayList<String> res = new ArrayList<String>(7); 
     75        if (proj != null) { 
     76            res.add(proj.toCode()); 
     77        } else { 
     78            res.add(""); 
     79        } 
    7080        res.add(layerName); 
    7181        res.add(name); 
  • trunk/src/org/openstreetmap/josm/data/projection/Lambert.java

    r3480 r3779  
    55 
    66import java.awt.GridBagLayout; 
     7import java.awt.event.ActionListener; 
    78import java.io.IOException; 
    89import java.io.InputStream; 
     
    254255    }; 
    255256 
    256     public void setupPreferencePanel(JPanel p) { 
     257    @Override 
     258    public void setupPreferencePanel(JPanel p, ActionListener listener) { 
    257259        JComboBox prefcb = new JComboBox(lambert4zones); 
    258260 
     
    265267        p.add(new JLabel(ImageProvider.get("data/projection", "Departements_Lambert4Zones.png")), GBC.eol().fill(GBC.HORIZONTAL)); 
    266268        p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 
     269 
     270        if (listener != null) { 
     271            prefcb.addActionListener(listener); 
     272        } 
    267273    } 
    268274 
     
    291297    } 
    292298 
     299    @Override 
     300    public String[] allCodes() { 
     301        String[] zones = new String[4]; 
     302        for (int zone = 0; zone < 4; zone++) { 
     303            zones[zone] = "EPSG:"+(27561+zone); 
     304        } 
     305        return zones; 
     306    } 
     307 
    293308    public Collection<String> getPreferencesFromCode(String code) { 
    294         if (code.startsWith("EPSG:2756") && code.length() == 9) { 
     309        if (code.startsWith("EPSG:2756") && code.length() == 10) { 
    295310            try { 
    296311                String zonestring = code.substring(9); 
  • trunk/src/org/openstreetmap/josm/data/projection/LambertCC9Zones.java

    r3480 r3779  
    55 
    66import java.awt.GridBagLayout; 
     7import java.awt.event.ActionListener; 
    78import java.util.Collection; 
    89import java.util.Collections; 
     
    1516import org.openstreetmap.josm.data.coor.EastNorth; 
    1617import org.openstreetmap.josm.data.coor.LatLon; 
    17 import org.openstreetmap.josm.data.projection.Projection; 
    18 import org.openstreetmap.josm.data.projection.Ellipsoid; 
    1918import org.openstreetmap.josm.tools.GBC; 
    2019import org.openstreetmap.josm.tools.ImageProvider; 
     
    186185    }; 
    187186 
    188     public void setupPreferencePanel(JPanel p) { 
     187    @Override 
     188    public void setupPreferencePanel(JPanel p, ActionListener listener) { 
    189189        JComboBox prefcb = new JComboBox(lambert9zones); 
    190190 
     
    197197        p.add(new JLabel(ImageProvider.get("data/projection", "LambertCC9Zones.png")), GBC.eol().fill(GBC.HORIZONTAL)); 
    198198        p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 
     199 
     200        if (listener != null) { 
     201            prefcb.addActionListener(listener); 
     202        } 
    199203    } 
    200204 
     
    224228    } 
    225229 
     230    @Override 
     231    public String[] allCodes() { 
     232        String[] zones = new String[9]; 
     233        for (int zone = 0; zone < 9; zone++) { 
     234            zones[zone] = "EPSG:" + (3942 + zone); 
     235        } 
     236        return zones; 
     237    } 
     238 
    226239    public Collection<String> getPreferencesFromCode(String code) 
    227240    { 
     
    229242        if (code.startsWith("EPSG:39") && code.length() == 9) { 
    230243            try { 
    231                 String zonestring = code.substring(5,4); 
     244                String zonestring = code.substring(5,9); 
    232245                int zoneval = Integer.parseInt(zonestring)-3942; 
    233246                if(zoneval >= 0 && zoneval <= 8) 
    234                     return Collections.singleton(zonestring); 
     247                    return Collections.singleton(String.valueOf(zoneval+1)); 
    235248            } catch(NumberFormatException e) {} 
    236249        } 
  • trunk/src/org/openstreetmap/josm/data/projection/ProjectionSubPrefs.java

    r3083 r3779  
    22package org.openstreetmap.josm.data.projection; 
    33 
     4import java.awt.event.ActionListener; 
    45import java.util.Collection; 
    56 
    67import javax.swing.JPanel; 
    78 
    8 public interface ProjectionSubPrefs { 
     9public interface ProjectionSubPrefs extends Projection { 
    910    /** 
    1011     * Generates the GUI for the given preference and packs them in a JPanel 
    1112     * so they may be displayed if the projection is selected. 
     13     *  
     14     * @param listener   listener for any change of preferences 
    1215     */ 
    13     public void setupPreferencePanel(JPanel p); 
     16    public void setupPreferencePanel(JPanel p, ActionListener listener); 
    1417 
    1518    /** 
     
    1720     */ 
    1821    public Collection<String> getPreferences(JPanel p); 
     22 
     23    /** 
     24     * Return all projection codes supported by this projection class. 
     25     */ 
     26    public String[] allCodes(); 
    1927 
    2028    /** 
  • trunk/src/org/openstreetmap/josm/data/projection/Puwg.java

    r3480 r3779  
    66 
    77import java.awt.GridBagLayout; 
     8import java.awt.event.ActionListener; 
    89import java.text.DecimalFormat; 
    910import java.util.Collection; 
     
    99100 
    100101    @Override 
    101     public void setupPreferencePanel(JPanel p) { 
     102    public void setupPreferencePanel(JPanel p, ActionListener listener) { 
    102103        JComboBox prefcb = new JComboBox(Puwg.Zones); 
    103104 
     
    109110        p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL)); 
    110111        p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 
     112 
     113        if (listener != null) { 
     114            prefcb.addActionListener(listener); 
     115        } 
    111116    } 
    112117 
     
    118123        int zone = ((JComboBox)prefcb).getSelectedIndex(); 
    119124        return Collections.singleton((Puwg.Zones[zone]).toCode()); 
     125    } 
     126 
     127    @Override 
     128    public String[] allCodes() { 
     129        String[] zones = new String[Zones.length]; 
     130        for (int zone = 0; zone < Zones.length; zone++) { 
     131            zones[zone] = Zones[zone].toCode(); 
     132        } 
     133        return zones; 
    120134    } 
    121135 
  • trunk/src/org/openstreetmap/josm/data/projection/SwissGrid.java

    r3473 r3779  
    44import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
     6import java.awt.event.ActionListener; 
    67import java.util.Collection; 
    78import java.util.Collections; 
     9 
    810import javax.swing.Box; 
    911import javax.swing.JPanel; 
     
    3638    private static final double b0 = Math.asin(Math.sin(phi0) / alpha); 
    3739    private static final double K = Math.log(Math.tan(Math.PI / 4 + b0 / 2)) - alpha 
    38             * Math.log(Math.tan(Math.PI / 4 + phi0 / 2)) + alpha * Ellipsoid.Bessel1841.e / 2 
    39             * Math.log((1 + Ellipsoid.Bessel1841.e * Math.sin(phi0)) / (1 - Ellipsoid.Bessel1841.e * Math.sin(phi0))); 
     40    * Math.log(Math.tan(Math.PI / 4 + phi0 / 2)) + alpha * Ellipsoid.Bessel1841.e / 2 
     41    * Math.log((1 + Ellipsoid.Bessel1841.e * Math.sin(phi0)) / (1 - Ellipsoid.Bessel1841.e * Math.sin(phi0))); 
    4042 
    4143    private static final double xTrans = 200000; 
     
    7173 
    7274        double S = alpha * Math.log(Math.tan(Math.PI / 4 + phi / 2)) - alpha * Ellipsoid.Bessel1841.e / 2 
    73                 * Math.log((1 + Ellipsoid.Bessel1841.e * Math.sin(phi)) / (1 - Ellipsoid.Bessel1841.e * Math.sin(phi))) + K; 
     75        * Math.log((1 + Ellipsoid.Bessel1841.e * Math.sin(phi)) / (1 - Ellipsoid.Bessel1841.e * Math.sin(phi))) + K; 
    7476        double b = 2 * (Math.atan(Math.exp(S)) - Math.PI / 4); 
    7577        double l = alpha * (lambda - lambda0); 
     
    107109        // iteration to finds S and phi 
    108110        while (Math.abs(phi - prevPhi) > DELTA_PHI) { 
    109             if (++iteration > 30) { 
     111            if (++iteration > 30) 
    110112                throw new RuntimeException("Two many iterations"); 
    111             } 
    112113            prevPhi = phi; 
    113114            S = 1 / alpha * (Math.log(Math.tan(Math.PI / 4 + b / 2)) - K) + Ellipsoid.Bessel1841.e 
    114                     * Math.log(Math.tan(Math.PI / 4 + Math.asin(Ellipsoid.Bessel1841.e * Math.sin(phi)) / 2)); 
     115            * Math.log(Math.tan(Math.PI / 4 + Math.asin(Ellipsoid.Bessel1841.e * Math.sin(phi)) / 2)); 
    115116            phi = 2 * Math.atan(Math.exp(S)) - Math.PI / 2; 
    116117        } 
     
    152153 
    153154    @Override 
    154     public void setupPreferencePanel(JPanel p) { 
     155    public void setupPreferencePanel(JPanel p, ActionListener listener) { 
    155156        p.add(new HtmlPanel("<i>CH1903 / LV03 (without local corrections)</i>"), GBC.eol().fill(GBC.HORIZONTAL)); 
    156157        p.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH)); 
     
    167168 
    168169    @Override 
     170    public String[] allCodes() { 
     171        return new String[] { "EPSG:21781" }; 
     172    } 
     173 
     174    @Override 
    169175    public Collection<String> getPreferencesFromCode(String code) { 
    170176        if ("EPSG:21781".equals(code)) 
  • trunk/src/org/openstreetmap/josm/data/projection/UTM.java

    r3635 r3779  
    55 
    66import java.awt.GridBagLayout; 
     7import java.awt.event.ActionListener; 
     8import java.util.ArrayList; 
    79import java.util.Arrays; 
    810import java.util.Collection; 
     
    112114    } 
    113115 
    114     public void setupPreferencePanel(JPanel p) { 
     116    @Override 
     117    public void setupPreferencePanel(JPanel p, ActionListener listener) { 
    115118        //Zone 
    116119        JComboBox zonecb = new JComboBox(); 
     
    161164        p.add(offsetBox, GBC.eop().fill(GBC.HORIZONTAL)); 
    162165        p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 
     166 
     167        if (listener != null) { 
     168            north.addActionListener(listener); 
     169            south.addActionListener(listener); 
     170            zonecb.addActionListener(listener); 
     171            offsetBox.addActionListener(listener); 
     172        } 
    163173    } 
    164174 
     
    214224        } 
    215225        updateParameters(); 
     226    } 
     227 
     228    public String[] allCodes() { 
     229        ArrayList<String> projections = new ArrayList<String>(60*4); 
     230        for (int zone = 1;zone <= 60; zone++) { 
     231            for (boolean offset : new boolean[] { false, true }) { 
     232                for (Hemisphere hemisphere : Hemisphere.values()) { 
     233                    projections.add("EPSG:" + ((offset?325800:32600) + zone + (hemisphere == Hemisphere.South?100:0))); 
     234                } 
     235            } 
     236        } 
     237        return projections.toArray(new String[0]); 
     238 
    216239    } 
    217240 
  • trunk/src/org/openstreetmap/josm/data/projection/UTM_France_DOM.java

    r3473 r3779  
    99 
    1010import java.awt.GridBagLayout; 
     11import java.awt.event.ActionListener; 
    1112import java.util.Collection; 
    1213import java.util.Collections; 
     
    410411    } 
    411412 
    412     public void setupPreferencePanel(JPanel p) { 
     413    @Override 
     414    public void setupPreferencePanel(JPanel p, ActionListener listener) { 
    413415        JComboBox prefcb = new JComboBox(utmGeodesicsNames); 
    414416 
     
    419421        p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL)); 
    420422        p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 
     423        if (listener != null) { 
     424            prefcb.addActionListener(listener); 
     425        } 
    421426    } 
    422427 
     
    430435    } 
    431436 
     437    @Override 
     438    public String[] allCodes() { 
     439        return utmEPSGs; 
     440    } 
     441 
    432442    public Collection<String> getPreferencesFromCode(String code) { 
    433443        for (int i=0; i < utmEPSGs.length; i++ ) 
    434444            if (utmEPSGs[i].endsWith(code)) 
    435                 return Collections.singleton(Integer.toString(i)); 
     445                return Collections.singleton(Integer.toString(i+1)); 
    436446        return null; 
    437447    } 
     
    444454                { 
    445455                    currentGeodesic = Integer.parseInt(s)-1; 
    446                     if(currentGeodesic < 0 || currentGeodesic > 4) { 
     456                    if(currentGeodesic < 0 || currentGeodesic >= utmEPSGs.length) { 
    447457                        currentGeodesic = DEFAULT_GEODESIC; 
    448458                    } 
  • trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java

    r3777 r3779  
    708708                switch (column) { 
    709709                case 0: 
     710                    if (info.proj == null) return ""; 
    710711                    return info.proj.toString(); 
    711712                case 1: 
  • trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java

    r3490 r3779  
    228228    } 
    229229 
    230     private class SBPanel extends JPanel 
    231     { 
    232         private Projection p; 
    233         public SBPanel(Projection pr) 
     230    private class SBPanel extends JPanel implements ActionListener 
     231    { 
     232        private ProjectionSubPrefs p; 
     233        public SBPanel(ProjectionSubPrefs pr) 
    234234        { 
    235235            super(); 
    236236            p = pr; 
    237237        } 
     238 
    238239        @Override 
    239         public void paint(java.awt.Graphics g) 
    240         { 
    241             super.paint(g); 
    242             ((ProjectionSubPrefs) p).setPreferences(((ProjectionSubPrefs) p).getPreferences(this)); 
     240        public void actionPerformed(ActionEvent e) { 
     241            p.setPreferences(p.getPreferences(this)); 
    243242            updateMeta(p); 
    244243        } 
     
    255254        } else { 
    256255            ProjectionSubPrefs projPref = (ProjectionSubPrefs) proj; 
    257             projSubPrefPanel = new SBPanel(proj); 
    258             projPref.setupPreferencePanel(projSubPrefPanel); 
     256            projSubPrefPanel = new SBPanel(projPref); 
     257            projPref.setupPreferencePanel(projSubPrefPanel, (SBPanel)projSubPrefPanel); 
    259258        } 
    260259 
Note: See TracChangeset for help on using the changeset viewer.