1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.wikipedia.gui;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 |
|
---|
8 | import javax.swing.BorderFactory;
|
---|
9 | import javax.swing.Box;
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JPanel;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
14 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
15 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
16 | import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
|
---|
17 | import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
---|
18 | import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
|
---|
19 | import org.openstreetmap.josm.tools.GBC;
|
---|
20 | import org.wikipedia.io.WikosmDownloadReader;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Preferences related to Wikosm API servers.
|
---|
24 | */
|
---|
25 | public class WikosmServerPreference implements SubPreferenceSetting {
|
---|
26 |
|
---|
27 | private final HistoryComboBox wikosmServer = new HistoryComboBox();
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Factory used to create a new {@link WikosmServerPreference}.
|
---|
31 | */
|
---|
32 | public static class Factory implements PreferenceSettingFactory {
|
---|
33 | @Override
|
---|
34 | public PreferenceSetting createPreferenceSetting() {
|
---|
35 | return new WikosmServerPreference();
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Override
|
---|
40 | public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) {
|
---|
41 | return gui.getServerPreference();
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | public void addGui(PreferenceTabbedPane gui) {
|
---|
46 | final JPanel panel = new JPanel(new GridBagLayout());
|
---|
47 |
|
---|
48 | panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
---|
49 | panel.add(new JLabel(tr("Server: ")), GBC.std().insets(5, 5, 5, 5));
|
---|
50 | panel.add(wikosmServer, GBC.eop().fill(GBC.HORIZONTAL));
|
---|
51 | wikosmServer.setPossibleItems(WikosmDownloadReader.WIKOSM_SERVER_HISTORY.get());
|
---|
52 | wikosmServer.setText(WikosmDownloadReader.WIKOSM_SERVER.get());
|
---|
53 |
|
---|
54 | panel.add(Box.createVerticalGlue(), GBC.eol().fill());
|
---|
55 |
|
---|
56 | getTabPreferenceSetting(gui).addSubTab(this, tr("Wikidata+OSM server"), panel);
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public boolean ok() {
|
---|
61 | WikosmDownloadReader.WIKOSM_SERVER.put(wikosmServer.getText());
|
---|
62 | WikosmDownloadReader.WIKOSM_SERVER_HISTORY.put(wikosmServer.getHistory());
|
---|
63 | return false;
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | public boolean isExpert() {
|
---|
68 | return true;
|
---|
69 | }
|
---|
70 | }
|
---|