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.BackupPreferencesPanel;
|
---|
18 | import org.openstreetmap.josm.gui.preferences.server.OsmApiUrlInputPanel;
|
---|
19 | import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
|
---|
20 | import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
|
---|
21 | public 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 | }
|
---|