source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/ServerAccessPreference.java@ 3915

Last change on this file since 3915 was 3463, checked in by bastiK, 14 years ago

#5370 - fix error from [3461]

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui.preferences;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.BorderLayout;
7import java.awt.GridBagConstraints;
8import java.awt.GridBagLayout;
9import java.awt.Insets;
10
11import javax.swing.JPanel;
12import javax.swing.JScrollPane;
13import javax.swing.JTabbedPane;
14
15import org.openstreetmap.josm.gui.help.HelpUtil;
16import org.openstreetmap.josm.gui.preferences.server.AuthenticationPreferencesPanel;
17import org.openstreetmap.josm.gui.preferences.server.OsmApiUrlInputPanel;
18import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
19import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
20public class ServerAccessPreference implements PreferenceSetting {
21
22 public static class Factory implements PreferenceSettingFactory {
23 public PreferenceSetting createPreferenceSetting() {
24 return new ServerAccessPreference();
25 }
26 }
27
28 private OsmApiUrlInputPanel pnlApiUrlPreferences;
29
30 private JTabbedPane tpServerPreferences;
31 /** indicates whether to use the default OSM URL or not */
32 /** panel for configuring authentication preferences */
33 private AuthenticationPreferencesPanel pnlAuthPreferences;
34 /** panel for configuring proxy preferences */
35 private ProxyPreferencesPanel pnlProxyPreferences;
36 /** panel for backup preferences */
37
38 /**
39 * Embeds a vertically scrollable panel in a {@see JScrollPane}
40 * @param panel the panel
41 * @return the scroll pane
42 */
43 protected JScrollPane wrapVerticallyScrollablePanel(VerticallyScrollablePanel panel) {
44 JScrollPane sp = new JScrollPane(panel);
45 sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
46 sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
47 return sp;
48 }
49
50 /**
51 * Builds the tabbed pane with the server preferences
52 *
53 * @return
54 */
55 protected JPanel buildTabbedServerPreferences() {
56 JPanel pnl = new JPanel(new BorderLayout());
57
58 tpServerPreferences = new JTabbedPane();
59 pnlAuthPreferences = new AuthenticationPreferencesPanel();
60 tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlAuthPreferences));
61 pnlProxyPreferences = new ProxyPreferencesPanel();
62 tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlProxyPreferences));
63
64 tpServerPreferences.setTitleAt(0, tr("Authentication"));
65 tpServerPreferences.setTitleAt(1, tr("Proxy settings"));
66 tpServerPreferences.setToolTipTextAt(0, tr("Configure your identity and how to authenticate at the OSM server"));
67 tpServerPreferences.setToolTipTextAt(1, tr("Configure whether to use a proxy server"));
68
69 pnl.add(tpServerPreferences, BorderLayout.CENTER);
70 return pnl;
71 }
72
73 /**
74 * Builds the panel for entering the server access preferences
75 *
76 * @return
77 */
78 protected JPanel buildContentPanel() {
79 JPanel pnl = new JPanel(new GridBagLayout());
80 GridBagConstraints gc = new GridBagConstraints();
81
82 // the checkbox for the default UL
83 gc.fill = GridBagConstraints.HORIZONTAL;
84 gc.anchor = GridBagConstraints.NORTHWEST;
85 gc.weightx = 1.0;
86 gc.insets = new Insets(0,0,0,0);
87 pnl.add(pnlApiUrlPreferences = new OsmApiUrlInputPanel(), gc);
88
89 // the remaining access properties
90 gc.gridy = 1;
91 gc.fill = GridBagConstraints.BOTH;
92 gc.weightx = 1.0;
93 gc.weighty = 1.0;
94 gc.insets = new Insets(10,0,3,3);
95 pnl.add(buildTabbedServerPreferences(), gc);
96
97 // let the AuthPreferencesPanel know when the API URL changes
98 //
99 pnlApiUrlPreferences.addPropertyChangeListener(pnlAuthPreferences);
100
101 HelpUtil.setHelpContext(pnl, HelpUtil.ht("/Preferences/Connection"));
102 return pnl;
103 }
104
105 public void addGui(PreferenceTabbedPane gui) {
106 GridBagConstraints gc = new GridBagConstraints();
107 gc.fill = GridBagConstraints.BOTH;
108 gc.weightx = 1.0;
109 gc.weighty = 1.0;
110 gc.anchor = GridBagConstraints.NORTHWEST;
111 gui.connection.add(buildContentPanel(), gc);
112
113 initFromPreferences();
114 }
115
116 /**
117 * Initializes the configuration panel with values from the preferences
118 */
119 public void initFromPreferences() {
120 pnlApiUrlPreferences.initFromPreferences();
121 pnlAuthPreferences.initFromPreferences();
122 pnlProxyPreferences.initFromPreferences();
123 }
124
125 /**
126 * Saves the values to the preferences
127 */
128 public boolean ok() {
129 pnlApiUrlPreferences.saveToPreferences();
130 pnlAuthPreferences.saveToPreferences();
131 pnlProxyPreferences.saveToPreferences();
132 return false;
133 }
134}
Note: See TracBrowser for help on using the repository browser.