| 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.GridBagConstraints;
|
|---|
| 7 | import java.awt.GridBagLayout;
|
|---|
| 8 | import java.beans.PropertyChangeListener;
|
|---|
| 9 |
|
|---|
| 10 | import javax.swing.Box;
|
|---|
| 11 | import javax.swing.JPanel;
|
|---|
| 12 | import javax.swing.JSeparator;
|
|---|
| 13 |
|
|---|
| 14 | import org.openstreetmap.josm.gui.help.HelpUtil;
|
|---|
| 15 | import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
|
|---|
| 16 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
|---|
| 17 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
|---|
| 18 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
|---|
| 19 | import org.openstreetmap.josm.tools.GBC;
|
|---|
| 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 | /** indicates whether to use the default OSM URL or not */
|
|---|
| 37 | private final OsmApiUrlInputPanel pnlApiUrlPreferences = new OsmApiUrlInputPanel();
|
|---|
| 38 | private final AuthenticationPreferencesPanel pnlAuthPreferences = new AuthenticationPreferencesPanel();
|
|---|
| 39 | /** the panel for messages notifier preferences */
|
|---|
| 40 | private final FeaturesPanel pnlFeaturesPreferences = new FeaturesPanel();
|
|---|
| 41 | private final OverpassServerPanel pnlOverpassPreferences = new OverpassServerPanel();
|
|---|
| 42 |
|
|---|
| 43 | private ServerAccessPreference() {
|
|---|
| 44 | super(/* ICON(preferences/) */ "connection", tr("OSM Server"), tr("Connection Settings for the OSM server."));
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | /**
|
|---|
| 48 | * Adds a listener that will be notified of API URL change.
|
|---|
| 49 | * @param listener the listener
|
|---|
| 50 | * @since 6523
|
|---|
| 51 | */
|
|---|
| 52 | public void addApiUrlChangeListener(PropertyChangeListener listener) {
|
|---|
| 53 | pnlApiUrlPreferences.addPropertyChangeListener(listener);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | private static GBC eopFilledHorizontal() {
|
|---|
| 57 | return GBC.eop().fill(GridBagConstraints.HORIZONTAL);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | @Override
|
|---|
| 61 | public void addGui(PreferenceTabbedPane gui) {
|
|---|
| 62 | JPanel panel = new JPanel(new GridBagLayout());
|
|---|
| 63 | panel.add(pnlApiUrlPreferences, eopFilledHorizontal());
|
|---|
| 64 | panel.add(new JSeparator(), eopFilledHorizontal());
|
|---|
| 65 | panel.add(pnlAuthPreferences, eopFilledHorizontal());
|
|---|
| 66 | panel.add(new JSeparator(), eopFilledHorizontal());
|
|---|
| 67 | panel.add(pnlFeaturesPreferences, eopFilledHorizontal());
|
|---|
| 68 | panel.add(new JSeparator(), eopFilledHorizontal());
|
|---|
| 69 | panel.add(pnlOverpassPreferences, eopFilledHorizontal());
|
|---|
| 70 |
|
|---|
| 71 | pnlApiUrlPreferences.initFromPreferences();
|
|---|
| 72 | pnlAuthPreferences.initFromPreferences();
|
|---|
| 73 | pnlFeaturesPreferences.initFromPreferences();
|
|---|
| 74 | pnlOverpassPreferences.initFromPreferences();
|
|---|
| 75 | addApiUrlChangeListener(pnlAuthPreferences);
|
|---|
| 76 |
|
|---|
| 77 | HelpUtil.setHelpContext(panel, HelpUtil.ht("/Preferences/Connection"));
|
|---|
| 78 | panel.add(Box.createVerticalGlue(), GBC.eol().fill());
|
|---|
| 79 | createPreferenceTabWithScrollPane(gui, panel);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | /**
|
|---|
| 83 | * Saves the values to the preferences
|
|---|
| 84 | */
|
|---|
| 85 | @Override
|
|---|
| 86 | public boolean ok() {
|
|---|
| 87 | pnlApiUrlPreferences.saveToPreferences();
|
|---|
| 88 | pnlAuthPreferences.saveToPreferences();
|
|---|
| 89 | // save message notifications preferences. To be done after authentication preferences.
|
|---|
| 90 | pnlFeaturesPreferences.saveToPreferences();
|
|---|
| 91 | pnlOverpassPreferences.saveToPreferences();
|
|---|
| 92 | return false;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | @Override
|
|---|
| 96 | public String getHelpContext() {
|
|---|
| 97 | return HelpUtil.ht("/Preferences/Connection");
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|