| 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others |
|---|
| 2 | package org.openstreetmap.josm.gui.preferences; |
|---|
| 3 | |
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr; |
|---|
| 5 | |
|---|
| 6 | import java.awt.BorderLayout; |
|---|
| 7 | import java.awt.GridBagConstraints; |
|---|
| 8 | import java.awt.GridBagLayout; |
|---|
| 9 | import java.awt.Insets; |
|---|
| 10 | |
|---|
| 11 | import javax.swing.JPanel; |
|---|
| 12 | import javax.swing.JScrollPane; |
|---|
| 13 | import javax.swing.JTabbedPane; |
|---|
| 14 | |
|---|
| 15 | import org.openstreetmap.josm.gui.help.HelpUtil; |
|---|
| 16 | import org.openstreetmap.josm.gui.preferences.server.AuthenticationPreferencesPanel; |
|---|
| 17 | import org.openstreetmap.josm.gui.preferences.server.OsmApiUrlInputPanel; |
|---|
| 18 | import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel; |
|---|
| 19 | import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; |
|---|
| 20 | public class ServerAccessPreference extends DefaultTabPreferenceSetting { |
|---|
| 21 | |
|---|
| 22 | public static class Factory implements PreferenceSettingFactory { |
|---|
| 23 | public PreferenceSetting createPreferenceSetting() { |
|---|
| 24 | return new ServerAccessPreference(); |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | private ServerAccessPreference() { |
|---|
| 29 | super("connection", tr("Connection Settings"), tr("Connection Settings for the OSM server.")); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | private OsmApiUrlInputPanel pnlApiUrlPreferences; |
|---|
| 33 | |
|---|
| 34 | private JTabbedPane tpServerPreferences; |
|---|
| 35 | /** indicates whether to use the default OSM URL or not */ |
|---|
| 36 | /** panel for configuring authentication preferences */ |
|---|
| 37 | private AuthenticationPreferencesPanel pnlAuthPreferences; |
|---|
| 38 | /** panel for configuring proxy preferences */ |
|---|
| 39 | private ProxyPreferencesPanel pnlProxyPreferences; |
|---|
| 40 | /** panel for backup preferences */ |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * Embeds a vertically scrollable panel in a {@see JScrollPane} |
|---|
| 44 | * @param panel the panel |
|---|
| 45 | * @return the scroll pane |
|---|
| 46 | */ |
|---|
| 47 | protected JScrollPane wrapVerticallyScrollablePanel(VerticallyScrollablePanel panel) { |
|---|
| 48 | JScrollPane sp = new JScrollPane(panel); |
|---|
| 49 | sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
|---|
| 50 | sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
|---|
| 51 | return sp; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | * Builds the tabbed pane with the server preferences |
|---|
| 56 | * |
|---|
| 57 | * @return |
|---|
| 58 | */ |
|---|
| 59 | protected JPanel buildTabbedServerPreferences() { |
|---|
| 60 | JPanel pnl = new JPanel(new BorderLayout()); |
|---|
| 61 | |
|---|
| 62 | tpServerPreferences = new JTabbedPane(); |
|---|
| 63 | pnlAuthPreferences = new AuthenticationPreferencesPanel(); |
|---|
| 64 | tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlAuthPreferences)); |
|---|
| 65 | pnlProxyPreferences = new ProxyPreferencesPanel(); |
|---|
| 66 | tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlProxyPreferences)); |
|---|
| 67 | |
|---|
| 68 | tpServerPreferences.setTitleAt(0, tr("Authentication")); |
|---|
| 69 | tpServerPreferences.setTitleAt(1, tr("Proxy settings")); |
|---|
| 70 | tpServerPreferences.setToolTipTextAt(0, tr("Configure your identity and how to authenticate at the OSM server")); |
|---|
| 71 | tpServerPreferences.setToolTipTextAt(1, tr("Configure whether to use a proxy server")); |
|---|
| 72 | |
|---|
| 73 | pnl.add(tpServerPreferences, BorderLayout.CENTER); |
|---|
| 74 | return pnl; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | /** |
|---|
| 78 | * Builds the panel for entering the server access preferences |
|---|
| 79 | * |
|---|
| 80 | * @return |
|---|
| 81 | */ |
|---|
| 82 | protected JPanel buildContentPanel() { |
|---|
| 83 | JPanel pnl = new JPanel(new GridBagLayout()); |
|---|
| 84 | GridBagConstraints gc = new GridBagConstraints(); |
|---|
| 85 | |
|---|
| 86 | // the checkbox for the default UL |
|---|
| 87 | gc.fill = GridBagConstraints.HORIZONTAL; |
|---|
| 88 | gc.anchor = GridBagConstraints.NORTHWEST; |
|---|
| 89 | gc.weightx = 1.0; |
|---|
| 90 | gc.insets = new Insets(0,0,0,0); |
|---|
| 91 | pnl.add(pnlApiUrlPreferences = new OsmApiUrlInputPanel(), gc); |
|---|
| 92 | |
|---|
| 93 | // the remaining access properties |
|---|
| 94 | gc.gridy = 1; |
|---|
| 95 | gc.fill = GridBagConstraints.BOTH; |
|---|
| 96 | gc.weightx = 1.0; |
|---|
| 97 | gc.weighty = 1.0; |
|---|
| 98 | gc.insets = new Insets(10,0,3,3); |
|---|
| 99 | 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 | } |
|---|