001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.preferences.projection; 003 004import java.awt.event.ActionListener; 005import java.util.Collection; 006import java.util.Collections; 007 008import javax.swing.JPanel; 009 010/** 011 * ProjectionChoice, that offers just one projection as choice. 012 * 013 * The GUI is an empty panel. 014 */ 015public class SingleProjectionChoice extends AbstractProjectionChoice { 016 017 protected String code; 018 019 /** 020 * Constructs a new {@code SingleProjectionChoice}. 021 * 022 * @param name short name of the projection choice as shown in the GUI 023 * @param id unique identifier for the projection choice, e.g. "core:thisproj" 024 * @param code the unique identifier for the projection, e.g. "EPSG:1234" 025 * @param cacheDir a cache directory name 026 */ 027 public SingleProjectionChoice(String name, String id, String code, String cacheDir) { 028 super(name, id, cacheDir); 029 this.code = code; 030 } 031 032 /** 033 * Constructs a new {@code SingleProjectionChoice}. 034 * 035 * @param name short name of the projection choice as shown in the GUI 036 * @param id unique identifier for the projection choice, e.g. "core:thisproj" 037 * @param code the unique identifier for the projection, e.g. "EPSG:1234" 038 */ 039 public SingleProjectionChoice(String name, String id, String code) { 040 super(name, id); 041 this.code = code; 042 } 043 044 @Override 045 public JPanel getPreferencePanel(ActionListener listener) { 046 return new JPanel(); 047 } 048 049 @Override 050 public String[] allCodes() { 051 return new String[] { code }; 052 } 053 054 @Override 055 public void setPreferences(Collection<String> args) { 056 } 057 058 @Override 059 public Collection<String> getPreferences(JPanel p) { 060 return Collections.emptyList(); 061 } 062 063 @Override 064 public Collection<String> getPreferencesFromCode(String code) { 065 if (code.equals(this.code)) 066 return Collections.emptyList(); 067 else 068 return null; 069 } 070 071 @Override 072 public String getCurrentCode() { 073 return code; 074 } 075 076 @Override 077 public String getProjectionName() { 078 return name; // the same name as the projection choice 079 } 080 081}