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

Last change on this file since 6523 was 6523, checked in by Don-vip, 10 years ago

Ask user to change proxy settings when proxy errors occur at startup (useful when a laptop is often used between two locations with different proxy settings)

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
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;
10import java.beans.PropertyChangeListener;
11
12import javax.swing.JPanel;
13import javax.swing.JScrollPane;
14import javax.swing.JTabbedPane;
15
16import org.openstreetmap.josm.gui.help.HelpUtil;
17import org.openstreetmap.josm.gui.preferences.server.OsmApiUrlInputPanel;
18import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
19
20/**
21 * Connection preferences, including authentication and proxy sub-preferences.
22 */
23public final class ServerAccessPreference extends DefaultTabPreferenceSetting {
24
25 /**
26 * Factory used to create a new {@code ServerAccessPreference}.
27 */
28 public static class Factory implements PreferenceSettingFactory {
29 @Override
30 public PreferenceSetting createPreferenceSetting() {
31 return new ServerAccessPreference();
32 }
33 }
34
35 private ServerAccessPreference() {
36 super("connection", tr("Connection Settings"), tr("Connection Settings for the OSM server."), false, new JTabbedPane());
37 }
38
39 /** indicates whether to use the default OSM URL or not */
40 private OsmApiUrlInputPanel pnlApiUrlPreferences;
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 pnl.add(getTabPane(), BorderLayout.CENTER);
62 return pnl;
63 }
64
65 /**
66 * Builds the panel for entering the server access preferences
67 *
68 * @return preferences panel for server settings
69 */
70 protected JPanel buildContentPanel() {
71 JPanel pnl = new JPanel(new GridBagLayout());
72 GridBagConstraints gc = new GridBagConstraints();
73
74 // the checkbox for the default UL
75 gc.fill = GridBagConstraints.HORIZONTAL;
76 gc.anchor = GridBagConstraints.NORTHWEST;
77 gc.weightx = 1.0;
78 gc.insets = new Insets(0,0,0,0);
79 pnl.add(pnlApiUrlPreferences = new OsmApiUrlInputPanel(), gc);
80
81 // the remaining access properties
82 gc.gridy = 1;
83 gc.fill = GridBagConstraints.BOTH;
84 gc.weightx = 1.0;
85 gc.weighty = 1.0;
86 gc.insets = new Insets(10,0,3,3);
87 pnl.add(buildTabbedServerPreferences(), gc);
88
89 HelpUtil.setHelpContext(pnl, HelpUtil.ht("/Preferences/Connection"));
90 return pnl;
91 }
92
93 /**
94 * Adds a listener that will be notified of API URL change.
95 * @param listener the listener
96 * @since 6523
97 */
98 public final void addApiUrlChangeListener(PropertyChangeListener listener) {
99 pnlApiUrlPreferences.addPropertyChangeListener(listener);
100 }
101
102 @Override
103 public void addGui(PreferenceTabbedPane gui) {
104 GridBagConstraints gc = new GridBagConstraints();
105 gc.fill = GridBagConstraints.BOTH;
106 gc.weightx = 1.0;
107 gc.weighty = 1.0;
108 gc.anchor = GridBagConstraints.NORTHWEST;
109 gui.createPreferenceTab(this).add(buildContentPanel(), gc);
110
111 initFromPreferences();
112 }
113
114 /**
115 * Initializes the configuration panel with values from the preferences
116 */
117 public void initFromPreferences() {
118 pnlApiUrlPreferences.initFromPreferences();
119 }
120
121 /**
122 * Saves the values to the preferences
123 */
124 @Override
125 public boolean ok() {
126 pnlApiUrlPreferences.saveToPreferences();
127 return false;
128 }
129}
Note: See TracBrowser for help on using the repository browser.