Ignore:
Timestamp:
2012-05-12T18:23:08+02:00 (12 years ago)
Author:
bastiK
Message:

separate preference gui from core projection code (there may be bugs)

File:
1 edited

Legend:

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

    r5226 r5234  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    5 
    6 import java.awt.GridBagLayout;
    7 import java.awt.event.ActionListener;
    8 import java.util.Collection;
    9 import java.util.Collections;
    10 
    11 import javax.swing.JComboBox;
    12 import javax.swing.JLabel;
    13 import javax.swing.JPanel;
    145
    156import org.openstreetmap.josm.data.Bounds;
     
    1910import org.openstreetmap.josm.data.projection.proj.ProjParameters;
    2011import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
    21 import org.openstreetmap.josm.tools.GBC;
    2212
    23 public class GaussKrueger extends AbstractProjection implements ProjectionSubPrefs {
     13public class GaussKrueger extends AbstractProjection {
    2414
    2515    public static final int DEFAULT_ZONE = 2;
    26     private int zone;
     16    private final int zone;
    2717
    2818    private static Bounds[] bounds = {
     
    3323    };
    3424
    35     private static String[] zones = { "2", "3", "4", "5" };
    36 
    3725    public GaussKrueger() {
    3826        this(DEFAULT_ZONE);
     
    4028
    4129    public GaussKrueger(int zone) {
    42         updateParameters(zone);
    43     }
    44 
    45     private void updateParameters(int zone) {
     30        if (zone < 2 || zone > 5)
     31            throw new IllegalArgumentException();
    4632        this.zone = zone;
    4733        ellps = Ellipsoid.Bessel1841;
     
    6349    @Override
    6450    public String toString() {
    65         return tr("Gau\u00DF-Kr\u00FCger");
     51        return tr("Gau\u00DF-Kr\u00FCger Zone {0}", zone);
    6652    }
    6753
     
    8167    }
    8268
    83     @Override
    84     public void setupPreferencePanel(JPanel p, ActionListener listener) {
    85         JComboBox prefcb = new JComboBox(zones);
    86 
    87         prefcb.setSelectedIndex(zone-2);
    88         p.setLayout(new GridBagLayout());
    89         p.add(new JLabel(tr("GK Zone")), GBC.std().insets(5,5,0,5));
    90         p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
    91         /* Note: we use component position 2 below to find this again */
    92         p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));
    93         p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
    94 
    95         if (listener != null) {
    96             prefcb.addActionListener(listener);
    97         }
    98     }
    99 
    100     @Override
    101     public Collection<String> getPreferences(JPanel p) {
    102         Object prefcb = p.getComponent(2);
    103         if(!(prefcb instanceof JComboBox))
    104             return null;
    105         int zone = ((JComboBox)prefcb).getSelectedIndex();
    106         return Collections.singleton(Integer.toString(zone+2));
    107     }
    108 
    109     @Override
    110     public void setPreferences(Collection<String> args) {
    111         int zone = DEFAULT_ZONE;
    112         if (args != null) {
    113             try {
    114                 for(String s : args)
    115                 {
    116                     zone = Integer.parseInt(s);
    117                     if(zone < 2 || zone > 5) {
    118                         zone = DEFAULT_ZONE;
    119                     }
    120                     break;
    121                 }
    122             } catch(NumberFormatException e) {}
    123         }
    124         updateParameters(zone);
    125     }
    126 
    127     @Override
    128     public String[] allCodes() {
    129         String[] zones = new String[4];
    130         for (int zone = 2; zone <= 5; zone++) {
    131             zones[zone-2] = "EPSG:" + (31464 + zone);
    132         }
    133         return zones;
    134     }
    135 
    136     @Override
    137     public Collection<String> getPreferencesFromCode(String code)
    138     {
    139         //zone 2 = EPSG:31466 up to zone 5 = EPSG:31469
    140         for (int zone = 2; zone <= 5; zone++) {
    141             String epsg = "EPSG:" + (31464 + zone);
    142             if (epsg.equals(code))
    143                 return Collections.singleton(String.valueOf(zone));
    144         }
    145         return null;
    146     }
    147 
    14869}
Note: See TracChangeset for help on using the changeset viewer.