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