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.util.Collection;
007    import java.util.Collections;
008    
009    import org.openstreetmap.josm.data.projection.Projection;
010    import org.openstreetmap.josm.data.projection.Puwg;
011    
012    public class PuwgProjectionChoice extends ListProjectionChoice implements Alias {
013    
014        public PuwgProjectionChoice() {
015            super("core:puwg", tr("PUWG (Poland)"), Puwg.zones, tr("PUWG Zone"));
016        }
017    
018        @Override
019        public Projection getProjection() {
020            return new Puwg(index);
021        }
022    
023        @Override
024        public String[] allCodes() {
025            String[] zones = new String[Puwg.zones.length];
026            for (int index = 0; index < Puwg.zones.length; index++) {
027                zones[index] = Puwg.zones[index].toCode();
028            }
029            return zones;
030        }
031    
032        @Override
033        public Collection<String> getPreferencesFromCode(String code) {
034            for (Puwg.PuwgData p : Puwg.zones) {
035                if (code.equals(p.toCode()))
036                    return Collections.singleton(code);
037            }
038            return null;
039        }
040    
041        @Override
042        public String getAlias() {
043            return Puwg.class.getName();
044        }
045    
046        @Override
047        protected String indexToZone(int index) {
048            return Puwg.zones[index].toCode();
049        }
050    
051        @Override
052        protected int zoneToIndex(String zone) {
053            for (int i=0; i<Puwg.zones.length; i++) {
054                if (zone.equals(Puwg.zones[i].toCode())) {
055                    return i;
056                }
057            }
058            return defaultIndex;
059        }
060    
061    }