Changeset 5634 in josm for trunk/src


Ignore:
Timestamp:
2012-12-26T15:47:43+01:00 (12 years ago)
Author:
bastiK
Message:

add option to select projection by code

this means it is no longer necessary to write a GUI for each new projection, because they are accessible in this list

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/Projections.java

    r5554 r5634  
    77import java.io.InputStreamReader;
    88import java.util.Collection;
     9import java.util.Collections;
    910import java.util.HashMap;
     11import java.util.HashSet;
    1012import java.util.Map;
     13import java.util.Set;
    1114import java.util.regex.Matcher;
    1215import java.util.regex.Pattern;
     
    113116
    114117    public static String getInit(String id) {
    115         return inits.get(id.toLowerCase()).b;
     118        return inits.get(id.toUpperCase()).b;
    116119    }
    117120
     
    132135                    Matcher m = epsgPattern.matcher(line);
    133136                    if (m.matches()) {
    134                         inits.put("epsg:" + m.group(1), Pair.create(name, m.group(2).trim()));
     137                        inits.put("EPSG:" + m.group(1), Pair.create(name, m.group(2).trim()));
    135138                    } else {
    136139                        System.err.println("Warning: failed to parse line from the epsg projection definition: "+line);
     
    144147    }
    145148
    146     private final static Map<String, ProjectionChoice> allCodesPC = new HashMap<String, ProjectionChoice>();
    147     private final static Map<String, Projection> allCodes = new HashMap<String, Projection>();
     149    private final static Set<String> allCodes = new HashSet<String>();
     150    private final static Map<String, ProjectionChoice> allProjectionChoicesByCode = new HashMap<String, ProjectionChoice>();
     151    private final static Map<String, Projection> projectionsByCode_cache = new HashMap<String, Projection>();
    148152
    149153    static {
    150         // FIXME: use {@link #inits}, because it may contain more codes in future
    151         // than exposed by the ProjectionChoices
    152154        for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) {
    153155            for (String code : pc.allCodes()) {
    154                 allCodesPC.put(code, pc);
     156                allProjectionChoicesByCode.put(code, pc);
    155157            }
    156158        }
     159        allCodes.addAll(inits.keySet());
     160        allCodes.addAll(allProjectionChoicesByCode.keySet());
    157161    }
    158162
    159163    public static Projection getProjectionByCode(String code) {
    160         Projection p = allCodes.get(code);
    161         if (p != null) return p;
    162         ProjectionChoice pc = allCodesPC.get(code);
    163         if (pc == null) return null;
    164         Collection<String> pref = pc.getPreferencesFromCode(code);
    165         pc.setPreferences(pref);
    166         p = pc.getProjection();
    167         allCodes.put(code, p);
    168         return p;
     164        Projection proj = projectionsByCode_cache.get(code);
     165        if (proj != null) return proj;
     166        ProjectionChoice pc = allProjectionChoicesByCode.get(code);
     167        if (pc != null) {
     168            Pair<String, String> pair = inits.get(code);
     169            if (pair == null) return null;
     170            String name = pair.a;
     171            String init = pair.b;
     172            proj = new CustomProjection(name, code, init, null);
     173        } else {
     174            Collection<String> pref = pc.getPreferencesFromCode(code);
     175            pc.setPreferences(pref);
     176            proj = pc.getProjection();
     177        }
     178        projectionsByCode_cache.put(code, proj);
     179        return proj;
     180    }
     181
     182    public static Collection<String> getAllProjectionCodes() {
     183        return Collections.unmodifiableCollection(allCodes);
    169184    }
    170185
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CustomProjectionChoice.java

    r5548 r5634  
    245245        return false;
    246246    }
     247
     248    @Override
     249    public boolean showProjectionName() {
     250        return false;
     251    }
    247252}
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java

    r5631 r5634  
    204204
    205205        /************************
     206         * Projection by Code.
     207         */
     208        registerProjectionChoice(new CodeProjectionChoice());
     209
     210        /************************
    206211         * Custom projection.
    207212         */
     
    265270    private Component projectionCodeGlue;
    266271    private JLabel projectionCode = new JLabel();
     272    private JLabel projectionNameLabel;
     273    private Component projectionNameGlue;
     274    private JLabel projectionName = new JLabel();
    267275    private JLabel bounds = new JLabel();
    268276
     
    304312        projPanel.add(projectionCodeGlue = GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    305313        projPanel.add(projectionCode, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
     314        projPanel.add(projectionNameLabel = new JLabel(tr("Projection name")), GBC.std().insets(25,5,0,5));
     315        projPanel.add(projectionNameGlue = GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
     316        projPanel.add(projectionName, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
    306317        projPanel.add(new JLabel(tr("Bounds")), GBC.std().insets(25,5,0,5));
    307318        projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
     
    328339        Projection proj = pc.getProjection();
    329340        projectionCode.setText(proj.toCode());
     341        projectionName.setText(proj.toString());
    330342        Bounds b = proj.getWorldBoundsLatLon();
    331343        CoordinateFormat cf = CoordinateFormat.getDefaultFormat();
    332344        bounds.setText(b.getMin().lonToString(cf)+", "+b.getMin().latToString(cf)+" : "+b.getMax().lonToString(cf)+", "+b.getMax().latToString(cf));
    333345        boolean showCode = true;
     346        boolean showName = false;
    334347        if (pc instanceof SubPrefsOptions) {
    335348            showCode = ((SubPrefsOptions) pc).showProjectionCode();
     349            showName = ((SubPrefsOptions) pc).showProjectionName();
    336350        }
    337351        projectionCodeLabel.setVisible(showCode);
    338352        projectionCodeGlue.setVisible(showCode);
    339353        projectionCode.setVisible(showCode);
     354        projectionNameLabel.setVisible(showName);
     355        projectionNameGlue.setVisible(showName);
     356        projectionName.setVisible(showName);
    340357    }
    341358
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/SubPrefsOptions.java

    r5234 r5634  
    1111     */
    1212    boolean showProjectionCode();
     13
     14    /**
     15     * @return true, if the projection name should be displayed in the top panel
     16     */
     17    boolean showProjectionName();
    1318}
Note: See TracChangeset for help on using the changeset viewer.