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

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

added gui preference for autosave; fixed #5359 - Button to delete autosaved data

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