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