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        // Do nothing
057    }
058
059    @Override
060    public Collection<String> getPreferences(JPanel p) {
061        return Collections.emptyList();
062    }
063
064    @Override
065    public Collection<String> getPreferencesFromCode(String code) {
066        if (code.equals(this.code))
067            return Collections.emptyList();
068        else
069            return null;
070    }
071
072    @Override
073    public String getCurrentCode() {
074        return code;
075    }
076
077    @Override
078    public String getProjectionName() {
079        return name; // the same name as the projection choice
080    }
081
082}