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

Last change on this file since 3128 was 2801, checked in by stoecker, 14 years ago

fixed line endings of recent checkins

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