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

Last change on this file since 6084 was 6084, checked in by bastiK, 11 years ago

see #8902 - add missing @Override annotations (patch by shinigami)

  • Property svn:eol-style set to native
File size: 5.0 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 extends DefaultTabPreferenceSetting {
21
22 public static class Factory implements PreferenceSettingFactory {
23 @Override
24 public PreferenceSetting createPreferenceSetting() {
25 return new ServerAccessPreference();
26 }
27 }
28
29 private ServerAccessPreference() {
30 super("connection", tr("Connection Settings"), tr("Connection Settings for the OSM server."), false, new JTabbedPane());
31 }
32
33 private OsmApiUrlInputPanel pnlApiUrlPreferences;
34
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 {@link 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 panel with server preferences tabs
58 */
59 protected JPanel buildTabbedServerPreferences() {
60 JPanel pnl = new JPanel(new BorderLayout());
61
62 JTabbedPane tpServerPreferences = getTabPane();
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 preferences panel for server settings
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 @Override
110 public void addGui(PreferenceTabbedPane gui) {
111 GridBagConstraints gc = new GridBagConstraints();
112 gc.fill = GridBagConstraints.BOTH;
113 gc.weightx = 1.0;
114 gc.weighty = 1.0;
115 gc.anchor = GridBagConstraints.NORTHWEST;
116 gui.createPreferenceTab(this).add(buildContentPanel(), gc);
117
118 initFromPreferences();
119 }
120
121 /**
122 * Initializes the configuration panel with values from the preferences
123 */
124 public void initFromPreferences() {
125 pnlApiUrlPreferences.initFromPreferences();
126 pnlAuthPreferences.initFromPreferences();
127 pnlProxyPreferences.initFromPreferences();
128 }
129
130 /**
131 * Saves the values to the preferences
132 */
133 @Override
134 public boolean ok() {
135 pnlApiUrlPreferences.saveToPreferences();
136 pnlAuthPreferences.saveToPreferences();
137 pnlProxyPreferences.saveToPreferences();
138 return false;
139 }
140}
Note: See TracBrowser for help on using the repository browser.