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 import org.openstreetmap.josm.data.projection.Projection; 011 012 /** 013 * ProjectionChoice, that offers just one projection as choice. 014 * 015 * The GUI is an empty panel. 016 */ 017 public class SingleProjectionChoice implements ProjectionChoice, Alias { 018 019 private String id; 020 private String name; 021 private Projection projection; 022 023 public SingleProjectionChoice(String id, String name, Projection projection) { 024 this.id = id; 025 this.name = name; 026 this.projection = projection; 027 } 028 029 public SingleProjectionChoice(String id, Projection projection) { 030 this(id, projection.toString(), projection); 031 } 032 033 @Override 034 public JPanel getPreferencePanel(ActionListener listener) { 035 return new JPanel(); 036 } 037 038 @Override 039 public String getId() { 040 return id; 041 } 042 043 @Override 044 public String[] allCodes() { 045 return new String[] { projection.toCode() }; 046 } 047 048 @Override 049 public void setPreferences(Collection<String> args) { 050 } 051 052 @Override 053 public Collection<String> getPreferences(JPanel p) { 054 return Collections.emptyList(); 055 } 056 057 @Override 058 public Projection getProjection() { 059 return projection; 060 } 061 062 @Override 063 public String toString() { 064 return name; 065 } 066 067 @Override 068 public Collection<String> getPreferencesFromCode(String code) { 069 if (code.equals(projection.toCode())) 070 return Collections.emptyList(); 071 else 072 return null; 073 } 074 075 @Override 076 public String getAlias() { 077 return projection.getClass().getName(); 078 } 079 }