001 // License: GPL. For details, see LICENSE file.
002 package org.openstreetmap.josm.gui.preferences.projection;
003
004 import java.awt.event.ActionListener;
005 import java.util.Collection;
006 import java.util.Collections;
007
008 import javax.swing.JPanel;
009
010 /**
011 * ProjectionChoice, that offers just one projection as choice.
012 *
013 * The GUI is an empty panel.
014 */
015 public class SingleProjectionChoice extends AbstractProjectionChoice {
016
017 protected String code;
018
019 /**
020 * Constructor.
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 public SingleProjectionChoice(String name, String id, String code) {
033 super(name, id);
034 this.code = code;
035 }
036
037 @Override
038 public JPanel getPreferencePanel(ActionListener listener) {
039 return new JPanel();
040 }
041
042 @Override
043 public String[] allCodes() {
044 return new String[] { code };
045 }
046
047 @Override
048 public void setPreferences(Collection<String> args) {
049 }
050
051 @Override
052 public Collection<String> getPreferences(JPanel p) {
053 return Collections.emptyList();
054 }
055
056 @Override
057 public String toString() {
058 return name;
059 }
060
061 @Override
062 public Collection<String> getPreferencesFromCode(String code) {
063 if (code.equals(this.code))
064 return Collections.emptyList();
065 else
066 return null;
067 }
068
069 @Override
070 public String getCurrentCode() {
071 return code;
072 }
073
074 @Override
075 public String getProjectionName() {
076 return name; // the same name as the projection choice
077 }
078
079 }