001 // License: GPL. Copyright 2007 by Immanuel Scholz and others 002 package org.openstreetmap.josm.gui.preferences; 003 004 import static org.openstreetmap.josm.tools.I18n.tr; 005 006 import java.awt.BorderLayout; 007 import java.awt.GridBagConstraints; 008 import java.awt.GridBagLayout; 009 import java.awt.Insets; 010 011 import javax.swing.JPanel; 012 import javax.swing.JScrollPane; 013 import javax.swing.JTabbedPane; 014 015 import org.openstreetmap.josm.gui.help.HelpUtil; 016 import org.openstreetmap.josm.gui.preferences.server.AuthenticationPreferencesPanel; 017 import org.openstreetmap.josm.gui.preferences.server.OsmApiUrlInputPanel; 018 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel; 019 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 020 public class ServerAccessPreference extends DefaultTabPreferenceSetting { 021 022 public static class Factory implements PreferenceSettingFactory { 023 public PreferenceSetting createPreferenceSetting() { 024 return new ServerAccessPreference(); 025 } 026 } 027 028 private ServerAccessPreference() { 029 super("connection", tr("Connection Settings"), tr("Connection Settings for the OSM server.")); 030 } 031 032 private OsmApiUrlInputPanel pnlApiUrlPreferences; 033 034 private JTabbedPane tpServerPreferences; 035 /** indicates whether to use the default OSM URL or not */ 036 /** panel for configuring authentication preferences */ 037 private AuthenticationPreferencesPanel pnlAuthPreferences; 038 /** panel for configuring proxy preferences */ 039 private ProxyPreferencesPanel pnlProxyPreferences; 040 /** panel for backup preferences */ 041 042 /** 043 * Embeds a vertically scrollable panel in a {@link JScrollPane} 044 * @param panel the panel 045 * @return the scroll pane 046 */ 047 protected JScrollPane wrapVerticallyScrollablePanel(VerticallyScrollablePanel panel) { 048 JScrollPane sp = new JScrollPane(panel); 049 sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 050 sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 051 return sp; 052 } 053 054 /** 055 * Builds the tabbed pane with the server preferences 056 * 057 * @return 058 */ 059 protected JPanel buildTabbedServerPreferences() { 060 JPanel pnl = new JPanel(new BorderLayout()); 061 062 tpServerPreferences = new JTabbedPane(); 063 pnlAuthPreferences = new AuthenticationPreferencesPanel(); 064 tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlAuthPreferences)); 065 pnlProxyPreferences = new ProxyPreferencesPanel(); 066 tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlProxyPreferences)); 067 068 tpServerPreferences.setTitleAt(0, tr("Authentication")); 069 tpServerPreferences.setTitleAt(1, tr("Proxy settings")); 070 tpServerPreferences.setToolTipTextAt(0, tr("Configure your identity and how to authenticate at the OSM server")); 071 tpServerPreferences.setToolTipTextAt(1, tr("Configure whether to use a proxy server")); 072 073 pnl.add(tpServerPreferences, BorderLayout.CENTER); 074 return pnl; 075 } 076 077 /** 078 * Builds the panel for entering the server access preferences 079 * 080 * @return 081 */ 082 protected JPanel buildContentPanel() { 083 JPanel pnl = new JPanel(new GridBagLayout()); 084 GridBagConstraints gc = new GridBagConstraints(); 085 086 // the checkbox for the default UL 087 gc.fill = GridBagConstraints.HORIZONTAL; 088 gc.anchor = GridBagConstraints.NORTHWEST; 089 gc.weightx = 1.0; 090 gc.insets = new Insets(0,0,0,0); 091 pnl.add(pnlApiUrlPreferences = new OsmApiUrlInputPanel(), gc); 092 093 // the remaining access properties 094 gc.gridy = 1; 095 gc.fill = GridBagConstraints.BOTH; 096 gc.weightx = 1.0; 097 gc.weighty = 1.0; 098 gc.insets = new Insets(10,0,3,3); 099 pnl.add(buildTabbedServerPreferences(), gc); 100 101 // let the AuthPreferencesPanel know when the API URL changes 102 // 103 pnlApiUrlPreferences.addPropertyChangeListener(pnlAuthPreferences); 104 105 HelpUtil.setHelpContext(pnl, HelpUtil.ht("/Preferences/Connection")); 106 return pnl; 107 } 108 109 public void addGui(PreferenceTabbedPane gui) { 110 GridBagConstraints gc = new GridBagConstraints(); 111 gc.fill = GridBagConstraints.BOTH; 112 gc.weightx = 1.0; 113 gc.weighty = 1.0; 114 gc.anchor = GridBagConstraints.NORTHWEST; 115 gui.createPreferenceTab(this).add(buildContentPanel(), gc); 116 117 initFromPreferences(); 118 } 119 120 /** 121 * Initializes the configuration panel with values from the preferences 122 */ 123 public void initFromPreferences() { 124 pnlApiUrlPreferences.initFromPreferences(); 125 pnlAuthPreferences.initFromPreferences(); 126 pnlProxyPreferences.initFromPreferences(); 127 } 128 129 /** 130 * Saves the values to the preferences 131 */ 132 public boolean ok() { 133 pnlApiUrlPreferences.saveToPreferences(); 134 pnlAuthPreferences.saveToPreferences(); 135 pnlProxyPreferences.saveToPreferences(); 136 return false; 137 } 138 }