1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.server;
|
---|
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 | import java.beans.PropertyChangeListener;
|
---|
11 |
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JTabbedPane;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.gui.help.HelpUtil;
|
---|
16 | import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
|
---|
17 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
18 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
19 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Connection preferences, including authentication and proxy sub-preferences.
|
---|
23 | */
|
---|
24 | public 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 | private ServerAccessPreference() {
|
---|
37 | super("connection", tr("Connection Settings"), tr("Connection Settings for the OSM server."), false, new JTabbedPane());
|
---|
38 | }
|
---|
39 |
|
---|
40 | /** indicates whether to use the default OSM URL or not */
|
---|
41 | private OsmApiUrlInputPanel pnlApiUrlPreferences;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Builds the tabbed pane with the server preferences
|
---|
45 | *
|
---|
46 | * @return panel with server preferences tabs
|
---|
47 | */
|
---|
48 | protected JPanel buildTabbedServerPreferences() {
|
---|
49 | JPanel pnl = new JPanel(new BorderLayout());
|
---|
50 | pnl.add(getTabPane(), BorderLayout.CENTER);
|
---|
51 | return pnl;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Builds the panel for entering the server access preferences
|
---|
56 | *
|
---|
57 | * @return preferences panel for server settings
|
---|
58 | */
|
---|
59 | protected JPanel buildContentPanel() {
|
---|
60 | JPanel pnl = new JPanel(new GridBagLayout());
|
---|
61 | GridBagConstraints gc = new GridBagConstraints();
|
---|
62 |
|
---|
63 | // the checkbox for the default UL
|
---|
64 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
65 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
66 | gc.weightx = 1.0;
|
---|
67 | gc.insets = new Insets(0,0,0,0);
|
---|
68 | pnlApiUrlPreferences = new OsmApiUrlInputPanel();
|
---|
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 final 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 | }
|
---|