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

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

Various stuff:

  • see #9414: remove old DeprecatedTags test
  • refactor some classes in gui.preferences package
  • improve javadoc
  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.server;
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.DefaultTabPreferenceSetting;
18import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
19import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
20import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
21import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
22
23/**
24 * Connection preferences, including authentication and proxy sub-preferences.
25 */
26public final class ServerAccessPreference extends DefaultTabPreferenceSetting {
27
28 /**
29 * Factory used to create a new {@code ServerAccessPreference}.
30 */
31 public static class Factory implements PreferenceSettingFactory {
32 @Override
33 public PreferenceSetting createPreferenceSetting() {
34 return new ServerAccessPreference();
35 }
36 }
37
38 private ServerAccessPreference() {
39 super("connection", tr("Connection Settings"), tr("Connection Settings for the OSM server."), false, new JTabbedPane());
40 }
41
42 /** indicates whether to use the default OSM URL or not */
43 private OsmApiUrlInputPanel pnlApiUrlPreferences;
44
45 /**
46 * Embeds a vertically scrollable panel in a {@link JScrollPane}
47 * @param panel the panel
48 * @return the scroll pane
49 */
50 public static JScrollPane wrapVerticallyScrollablePanel(VerticallyScrollablePanel panel) {
51 JScrollPane sp = new JScrollPane(panel);
52 sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
53 sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
54 return sp;
55 }
56
57 /**
58 * Builds the tabbed pane with the server preferences
59 *
60 * @return panel with server preferences tabs
61 */
62 protected JPanel buildTabbedServerPreferences() {
63 JPanel pnl = new JPanel(new BorderLayout());
64 pnl.add(getTabPane(), BorderLayout.CENTER);
65 return pnl;
66 }
67
68 /**
69 * Builds the panel for entering the server access preferences
70 *
71 * @return preferences panel for server settings
72 */
73 protected JPanel buildContentPanel() {
74 JPanel pnl = new JPanel(new GridBagLayout());
75 GridBagConstraints gc = new GridBagConstraints();
76
77 // the checkbox for the default UL
78 gc.fill = GridBagConstraints.HORIZONTAL;
79 gc.anchor = GridBagConstraints.NORTHWEST;
80 gc.weightx = 1.0;
81 gc.insets = new Insets(0,0,0,0);
82 pnl.add(pnlApiUrlPreferences = new OsmApiUrlInputPanel(), gc);
83
84 // the remaining access properties
85 gc.gridy = 1;
86 gc.fill = GridBagConstraints.BOTH;
87 gc.weightx = 1.0;
88 gc.weighty = 1.0;
89 gc.insets = new Insets(10,0,3,3);
90 pnl.add(buildTabbedServerPreferences(), gc);
91
92 HelpUtil.setHelpContext(pnl, HelpUtil.ht("/Preferences/Connection"));
93 return pnl;
94 }
95
96 /**
97 * Adds a listener that will be notified of API URL change.
98 * @param listener the listener
99 * @since 6523
100 */
101 public final void addApiUrlChangeListener(PropertyChangeListener listener) {
102 pnlApiUrlPreferences.addPropertyChangeListener(listener);
103 }
104
105 @Override
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.createPreferenceTab(this).add(buildContentPanel(), gc);
113
114 pnlApiUrlPreferences.initFromPreferences();
115 }
116
117 /**
118 * Saves the values to the preferences
119 */
120 @Override
121 public boolean ok() {
122 pnlApiUrlPreferences.saveToPreferences();
123 return false;
124 }
125}
Note: See TracBrowser for help on using the repository browser.