001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.preferences.projection; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.event.ActionListener; 007import java.util.Collection; 008import java.util.Collections; 009 010import javax.swing.JLabel; 011import javax.swing.JPanel; 012 013import org.openstreetmap.josm.tools.GBC; 014import org.openstreetmap.josm.tools.ImageProvider; 015 016public class LambertProjectionChoice extends ListProjectionChoice { 017 018 private static final String[] lambert4zones = { 019 tr("{0} ({1} to {2} degrees)", 1,"51.30","48.15"), 020 tr("{0} ({1} to {2} degrees)", 2,"48.15","45.45"), 021 tr("{0} ({1} to {2} degrees)", 3,"45.45","42.76"), 022 tr("{0} (Corsica)", 4) 023 }; 024 025 /** 026 * Constructs a new {@code LambertProjectionChoice}. 027 */ 028 public LambertProjectionChoice() { 029 super(tr("Lambert 4 Zones (France)"), "core:lambert", lambert4zones, tr("Lambert CC Zone")); 030 } 031 032 private class LambertCBPanel extends CBPanel { 033 public LambertCBPanel(Object[] entries, int initialIndex, String label, ActionListener listener) { 034 super(entries, initialIndex, label, listener); 035 this.add(new JLabel(ImageProvider.get("data/projection", "Departements_Lambert4Zones.png")), GBC.eol().fill(GBC.HORIZONTAL)); 036 this.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 037 } 038 } 039 040 @Override 041 public JPanel getPreferencePanel(ActionListener listener) { 042 return new LambertCBPanel(entries, index, label, listener); 043 } 044 045 @Override 046 public String getCurrentCode() { 047 return "EPSG:" + Integer.toString(27561+index); 048 } 049 050 @Override 051 public String getProjectionName() { 052 return tr("Lambert 4 Zones (France)"); 053 } 054 055 @Override 056 public String[] allCodes() { 057 String[] codes = new String[4]; 058 for (int zone = 0; zone < 4; zone++) { 059 codes[zone] = "EPSG:"+(27561+zone); 060 } 061 return codes; 062 } 063 064 @Override 065 public Collection<String> getPreferencesFromCode(String code) { 066 if (code.startsWith("EPSG:2756") && code.length() == 10) { 067 try { 068 String zonestring = code.substring(9); 069 int zoneval = Integer.parseInt(zonestring); 070 if(zoneval >= 1 && zoneval <= 4) 071 return Collections.singleton(zonestring); 072 } catch(NumberFormatException e) {} 073 } 074 return null; 075 } 076 077 @Override 078 protected String indexToZone(int index) { 079 return Integer.toString(index + 1); 080 } 081 082 @Override 083 protected int zoneToIndex(String zone) { 084 try { 085 return Integer.parseInt(zone) - 1; 086 } catch(NumberFormatException e) {} 087 return defaultIndex; 088 } 089 090}