001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.preferences.server; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.GridBagConstraints; 007import java.awt.GridBagLayout; 008import java.beans.PropertyChangeListener; 009 010import javax.swing.Box; 011import javax.swing.JPanel; 012import javax.swing.JSeparator; 013 014import org.openstreetmap.josm.gui.help.HelpUtil; 015import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting; 016import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 017import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 018import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 019import org.openstreetmap.josm.tools.GBC; 020 021/** 022 * Connection preferences, including authentication and proxy sub-preferences. 023 */ 024public final class ServerAccessPreference extends DefaultTabPreferenceSetting { 025 026 /** 027 * Factory used to create a new {@code ServerAccessPreference}. 028 */ 029 public static class Factory implements PreferenceSettingFactory { 030 @Override 031 public PreferenceSetting createPreferenceSetting() { 032 return new ServerAccessPreference(); 033 } 034 } 035 036 /** indicates whether to use the default OSM URL or not */ 037 private final OsmApiUrlInputPanel pnlApiUrlPreferences = new OsmApiUrlInputPanel(); 038 private final AuthenticationPreferencesPanel pnlAuthPreferences = new AuthenticationPreferencesPanel(); 039 /** the panel for messages notifier preferences */ 040 private final FeaturesPanel pnlFeaturesPreferences = new FeaturesPanel(); 041 private final OverpassServerPanel pnlOverpassPreferences = new OverpassServerPanel(); 042 043 private ServerAccessPreference() { 044 super(/* ICON(preferences/) */ "connection", tr("OSM Server"), tr("Connection Settings for the OSM server.")); 045 } 046 047 /** 048 * Adds a listener that will be notified of API URL change. 049 * @param listener the listener 050 * @since 6523 051 */ 052 public void addApiUrlChangeListener(PropertyChangeListener listener) { 053 pnlApiUrlPreferences.addPropertyChangeListener(listener); 054 } 055 056 private static GBC eopFilledHorizontal() { 057 return GBC.eop().fill(GridBagConstraints.HORIZONTAL); 058 } 059 060 @Override 061 public void addGui(PreferenceTabbedPane gui) { 062 JPanel panel = new JPanel(new GridBagLayout()); 063 panel.add(pnlApiUrlPreferences, eopFilledHorizontal()); 064 panel.add(new JSeparator(), eopFilledHorizontal()); 065 panel.add(pnlAuthPreferences, eopFilledHorizontal()); 066 panel.add(new JSeparator(), eopFilledHorizontal()); 067 panel.add(pnlFeaturesPreferences, eopFilledHorizontal()); 068 panel.add(new JSeparator(), eopFilledHorizontal()); 069 panel.add(pnlOverpassPreferences, eopFilledHorizontal()); 070 071 pnlApiUrlPreferences.initFromPreferences(); 072 pnlAuthPreferences.initFromPreferences(); 073 pnlFeaturesPreferences.initFromPreferences(); 074 pnlOverpassPreferences.initFromPreferences(); 075 addApiUrlChangeListener(pnlAuthPreferences); 076 077 HelpUtil.setHelpContext(panel, HelpUtil.ht("/Preferences/Connection")); 078 panel.add(Box.createVerticalGlue(), GBC.eol().fill()); 079 createPreferenceTabWithScrollPane(gui, panel); 080 } 081 082 /** 083 * Saves the values to the preferences 084 */ 085 @Override 086 public boolean ok() { 087 pnlApiUrlPreferences.saveToPreferences(); 088 pnlAuthPreferences.saveToPreferences(); 089 // save message notifications preferences. To be done after authentication preferences. 090 pnlFeaturesPreferences.saveToPreferences(); 091 pnlOverpassPreferences.saveToPreferences(); 092 return false; 093 } 094 095 @Override 096 public String getHelpContext() { 097 return HelpUtil.ht("/Preferences/Connection"); 098 } 099}