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

Last change on this file since 13652 was 13431, checked in by Don-vip, 6 years ago

fix #15950 - Preferences Help button should go directly to selected Preferences tab Help page

  • Property svn:eol-style set to native
File size: 3.7 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.JTabbedPane;
14
15import org.openstreetmap.josm.gui.help.HelpUtil;
16import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
17import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
18import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
19import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
20
21/**
22 * Connection preferences, including authentication and proxy sub-preferences.
23 */
24public final class ServerAccessPreference extends DefaultTabPreferenceSetting {
25
26 /**
27 * Factory used to create a new {@code ServerAccessPreference}.
28 */
29 public static class Factory implements PreferenceSettingFactory {
30 @Override
31 public PreferenceSetting createPreferenceSetting() {
32 return new ServerAccessPreference();
33 }
34 }
35
36 /** indicates whether to use the default OSM URL or not */
37 private final OsmApiUrlInputPanel pnlApiUrlPreferences = new OsmApiUrlInputPanel();
38
39 private ServerAccessPreference() {
40 super(/* ICON(preferences/) */ "connection", tr("Connection Settings"),
41 tr("Connection Settings for the OSM server."), false, new JTabbedPane());
42 }
43
44 /**
45 * Builds the tabbed pane with the server preferences
46 *
47 * @return panel with server preferences tabs
48 */
49 private JPanel buildTabbedServerPreferences() {
50 JPanel pnl = new JPanel(new BorderLayout());
51 pnl.add(getTabPane(), BorderLayout.CENTER);
52 return pnl;
53 }
54
55 /**
56 * Builds the panel for entering the server access preferences
57 *
58 * @return preferences panel for server settings
59 */
60 private JPanel buildContentPanel() {
61 JPanel pnl = new JPanel(new GridBagLayout());
62 GridBagConstraints gc = new GridBagConstraints();
63
64 // the checkbox for the default UL
65 gc.fill = GridBagConstraints.HORIZONTAL;
66 gc.anchor = GridBagConstraints.NORTHWEST;
67 gc.weightx = 1.0;
68 gc.insets = new Insets(0, 0, 0, 0);
69 pnl.add(pnlApiUrlPreferences, gc);
70
71 // the remaining access properties
72 gc.gridy = 1;
73 gc.fill = GridBagConstraints.BOTH;
74 gc.weightx = 1.0;
75 gc.weighty = 1.0;
76 gc.insets = new Insets(10, 0, 3, 3);
77 pnl.add(buildTabbedServerPreferences(), gc);
78
79 HelpUtil.setHelpContext(pnl, HelpUtil.ht("/Preferences/Connection"));
80 return pnl;
81 }
82
83 /**
84 * Adds a listener that will be notified of API URL change.
85 * @param listener the listener
86 * @since 6523
87 */
88 public void addApiUrlChangeListener(PropertyChangeListener listener) {
89 pnlApiUrlPreferences.addPropertyChangeListener(listener);
90 }
91
92 @Override
93 public void addGui(PreferenceTabbedPane gui) {
94 GridBagConstraints gc = new GridBagConstraints();
95 gc.fill = GridBagConstraints.BOTH;
96 gc.weightx = 1.0;
97 gc.weighty = 1.0;
98 gc.anchor = GridBagConstraints.NORTHWEST;
99 gui.createPreferenceTab(this).add(buildContentPanel(), gc);
100
101 pnlApiUrlPreferences.initFromPreferences();
102 }
103
104 /**
105 * Saves the values to the preferences
106 */
107 @Override
108 public boolean ok() {
109 pnlApiUrlPreferences.saveToPreferences();
110 return false;
111 }
112
113 @Override
114 public String getHelpContext() {
115 return HelpUtil.ht("/Preferences/Connection");
116 }
117}
Note: See TracBrowser for help on using the repository browser.