| 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.JScrollPane;
|
|---|
| 14 | import javax.swing.JTabbedPane;
|
|---|
| 15 |
|
|---|
| 16 | import org.openstreetmap.josm.gui.help.HelpUtil;
|
|---|
| 17 | import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
|
|---|
| 18 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
|---|
| 19 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
|---|
| 20 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
|---|
| 21 | import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * Connection preferences, including authentication and proxy sub-preferences.
|
|---|
| 25 | */
|
|---|
| 26 | public 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 | pnlApiUrlPreferences = new OsmApiUrlInputPanel();
|
|---|
| 83 | pnl.add(pnlApiUrlPreferences, gc);
|
|---|
| 84 |
|
|---|
| 85 | // the remaining access properties
|
|---|
| 86 | gc.gridy = 1;
|
|---|
| 87 | gc.fill = GridBagConstraints.BOTH;
|
|---|
| 88 | gc.weightx = 1.0;
|
|---|
| 89 | gc.weighty = 1.0;
|
|---|
| 90 | gc.insets = new Insets(10,0,3,3);
|
|---|
| 91 | pnl.add(buildTabbedServerPreferences(), gc);
|
|---|
| 92 |
|
|---|
| 93 | HelpUtil.setHelpContext(pnl, HelpUtil.ht("/Preferences/Connection"));
|
|---|
| 94 | return pnl;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | /**
|
|---|
| 98 | * Adds a listener that will be notified of API URL change.
|
|---|
| 99 | * @param listener the listener
|
|---|
| 100 | * @since 6523
|
|---|
| 101 | */
|
|---|
| 102 | public final void addApiUrlChangeListener(PropertyChangeListener listener) {
|
|---|
| 103 | pnlApiUrlPreferences.addPropertyChangeListener(listener);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | @Override
|
|---|
| 107 | public void addGui(PreferenceTabbedPane gui) {
|
|---|
| 108 | GridBagConstraints gc = new GridBagConstraints();
|
|---|
| 109 | gc.fill = GridBagConstraints.BOTH;
|
|---|
| 110 | gc.weightx = 1.0;
|
|---|
| 111 | gc.weighty = 1.0;
|
|---|
| 112 | gc.anchor = GridBagConstraints.NORTHWEST;
|
|---|
| 113 | gui.createPreferenceTab(this).add(buildContentPanel(), gc);
|
|---|
| 114 |
|
|---|
| 115 | pnlApiUrlPreferences.initFromPreferences();
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * Saves the values to the preferences
|
|---|
| 120 | */
|
|---|
| 121 | @Override
|
|---|
| 122 | public boolean ok() {
|
|---|
| 123 | pnlApiUrlPreferences.saveToPreferences();
|
|---|
| 124 | return false;
|
|---|
| 125 | }
|
|---|
| 126 | }
|
|---|