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.util.Arrays; 007import java.util.Collection; 008import java.util.Collections; 009import java.util.stream.IntStream; 010 011import org.openstreetmap.josm.tools.Utils; 012 013/** 014 * ProjectionChoice for PUWG 1992 (EPSG:2180) and PUWG 2000 for Poland (Zone 5-8, EPSG:2176-2179). 015 * <p> 016 * @see <a href="https://pl.wikipedia.org/wiki/Uk%C5%82ad_wsp%C3%B3%C5%82rz%C4%99dnych_1992">PUWG 1992</a> 017 * @see <a href="https://pl.wikipedia.org/wiki/Uk%C5%82ad_wsp%C3%B3%C5%82rz%C4%99dnych_2000">PUWG 2000</a> 018 */ 019public class PuwgProjectionChoice extends ListProjectionChoice { 020 021 private static final String[] CODES = { 022 "EPSG:2180", 023 "EPSG:2176", 024 "EPSG:2177", 025 "EPSG:2178", 026 "EPSG:2179" 027 }; 028 029 private static final String[] NAMES = { 030 tr("PUWG 1992 (Poland)"), 031 tr("PUWG 2000 Zone {0} (Poland)", 5), 032 tr("PUWG 2000 Zone {0} (Poland)", 6), 033 tr("PUWG 2000 Zone {0} (Poland)", 7), 034 tr("PUWG 2000 Zone {0} (Poland)", 8) 035 }; 036 037 /** 038 * Constructs a new {@code PuwgProjectionChoice}. 039 */ 040 public PuwgProjectionChoice() { 041 super(tr("PUWG (Poland)"), /* NO-ICON */ "core:puwg", NAMES, tr("PUWG Zone")); 042 } 043 044 @Override 045 public String getCurrentCode() { 046 return CODES[index]; 047 } 048 049 @Override 050 public String getProjectionName() { 051 return NAMES[index]; 052 } 053 054 @Override 055 public String[] allCodes() { 056 return Utils.copyArray(CODES); 057 } 058 059 @Override 060 public Collection<String> getPreferencesFromCode(String code) { 061 return Arrays.stream(CODES).filter(code::equals).findFirst().map(Collections::singleton).orElse(null); 062 } 063 064 @Override 065 protected String indexToZone(int index) { 066 return CODES[index]; 067 } 068 069 @Override 070 protected int zoneToIndex(String zone) { 071 return IntStream.range(0, CODES.length) 072 .filter(i -> zone.equals(CODES[i])) 073 .findFirst().orElse(defaultIndex); 074 } 075}