Changeset 33808 in osm for applications/editors/josm/plugins/wikipedia/src
- Timestamp:
- 2017-11-13T06:31:02+01:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/wikipedia/src/org/wikipedia
- Files:
-
- 1 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaPlugin.java
r33635 r33808 28 28 MainMenu.add(dataMenu, new WikidataItemSearchDialog.Action()); 29 29 30 DownloadDialog.addDownloadSource(new WikosmDownloadSource());30 DownloadDialog.addDownloadSource(new SophoxDownloadReader()); 31 31 } 32 32 … … 42 42 public PreferenceSetting getPreferenceSetting() { 43 43 if (preferences == null) { 44 preferences = (new WikosmServerPreference.Factory()).createPreferenceSetting();44 preferences = (new SophoxServerPreference.Factory()).createPreferenceSetting(); 45 45 } 46 46 return preferences; -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/gui/SophoxDownloadReader.java
r33807 r33808 37 37 import org.openstreetmap.josm.tools.ImageProvider; 38 38 import org.openstreetmap.josm.tools.OpenBrowser; 39 import org.wikipedia.io.WikosmDownloadReader;40 39 41 40 /** 42 * Class defines the way data is fetched from WikosmAPI.41 * Class defines the way data is fetched from Sophox API. 43 42 */ 44 public class WikosmDownloadSource implements DownloadSource<WikosmDownloadSource.WikosmDownloadData> {43 public class SophoxDownloadReader implements DownloadSource<SophoxDownloadReader.SophoxDownloadData> { 45 44 46 45 @Override 47 public AbstractDownloadSourcePanel< WikosmDownloadData> createPanel(DownloadDialog dialog) {48 return new WikosmDownloadSourcePanel(this);46 public AbstractDownloadSourcePanel<SophoxDownloadData> createPanel(DownloadDialog dialog) { 47 return new SophoxDownloadSourcePanel(this); 49 48 } 50 49 51 50 @Override 52 public void doDownload( WikosmDownloadData data, DownloadSettings settings) {51 public void doDownload(SophoxDownloadData data, DownloadSettings settings) { 53 52 Bounds area = settings.getDownloadBounds().orElse(new Bounds(0, 0, 0, 0)); 54 53 DownloadOsmTask task = new DownloadOsmTask(); 55 54 task.setZoomAfterDownload(settings.zoomToData()); 56 55 Future<?> future = task.download( 57 new WikosmDownloadReader(area, WikosmDownloadReader.WIKOSM_SERVER.get(), data.getQuery(),56 new org.wikipedia.io.SophoxDownloadReader(area, org.wikipedia.io.SophoxDownloadReader.SOPHOX_SERVER.get(), data.getQuery(), 58 57 settings.asNewLayer(), data.getDownloadReferrers(), data.getDownloadFull()), 59 58 … … 64 63 @Override 65 64 public String getLabel() { 66 return tr("Download from WikosmAPI");65 return tr("Download from Sophox API"); 67 66 } 68 67 … … 73 72 74 73 /** 75 * The GUI representation of the Wikosmdownload source.74 * The GUI representation of the Sophox download source. 76 75 */ 77 public static class WikosmDownloadSourcePanel extends AbstractDownloadSourcePanel<WikosmDownloadData> {76 public static class SophoxDownloadSourcePanel extends AbstractDownloadSourcePanel<SophoxDownloadData> { 78 77 79 78 private static final String HELP_PAGE = "https://wiki.openstreetmap.org/wiki/Wikidata%2BOSM_SPARQL_query_service"; 80 private static final String SIMPLE_NAME = " wikosmdownloadpanel";79 private static final String SIMPLE_NAME = "sophoxdownloadpanel"; 81 80 private static final AbstractProperty<Integer> PANEL_SIZE_PROPERTY = 82 81 new IntegerProperty(TAB_SPLIT_NAMESPACE + SIMPLE_NAME, 150).cached(); 83 private static final BooleanProperty WIKOSM_QUERY_LIST_OPENED =84 new BooleanProperty("download. wikosm.query-list.opened", false);82 private static final BooleanProperty SOPHOX_QUERY_LIST_OPENED = 83 new BooleanProperty("download.sophox.query-list.opened", false); 85 84 private static final String ACTION_IMG_SUBDIR = "dialogs"; 86 85 87 private final JosmTextArea wikosmQuery;88 private final UserQueryList wikosmQueryList;86 private final JosmTextArea sophoxQuery; 87 private final UserQueryList sophoxQueryList; 89 88 private final JCheckBox referrers; 90 89 private final JCheckBox fullRel; 91 90 92 91 /** 93 * Create a new {@code WikosmDownloadSourcePanel}92 * Create a new {@code SophoxDownloadSourcePanel} 94 93 * @param ds The download source to create the panel for 95 94 */ 96 public WikosmDownloadSourcePanel(WikosmDownloadSourceds) {95 public SophoxDownloadSourcePanel(SophoxDownloadReader ds) { 97 96 super(ds); 98 97 setLayout(new BorderLayout()); … … 109 108 "}"; 110 109 111 this. wikosmQuery = new JosmTextArea(queryText, 8, 80);112 113 this. wikosmQuery.setFont(GuiHelper.getMonospacedFont(wikosmQuery));114 this. wikosmQuery.addFocusListener(new FocusListener() {110 this.sophoxQuery = new JosmTextArea(queryText, 8, 80); 111 112 this.sophoxQuery.setFont(GuiHelper.getMonospacedFont(sophoxQuery)); 113 this.sophoxQuery.addFocusListener(new FocusListener() { 115 114 @Override 116 115 public void focusGained(FocusEvent e) { 117 wikosmQuery.selectAll();116 sophoxQuery.selectAll(); 118 117 } 119 118 … … 125 124 126 125 127 this. wikosmQueryList = new UserQueryList(this, this.wikosmQuery, "download.wikosm.query");128 this. wikosmQueryList.setPreferredSize(new Dimension(350, 300));126 this.sophoxQueryList = new UserQueryList(this, this.sophoxQuery, "download.sophox.query"); 127 this.sophoxQueryList.setPreferredSize(new Dimension(350, 300)); 129 128 130 129 EditSnippetAction edit = new EditSnippetAction(); 131 130 RemoveSnippetAction remove = new RemoveSnippetAction(); 132 this. wikosmQueryList.addSelectionListener(edit);133 this. wikosmQueryList.addSelectionListener(remove);131 this.sophoxQueryList.addSelectionListener(edit); 132 this.sophoxQueryList.addSelectionListener(remove); 134 133 135 134 JPanel listPanel = new JPanel(new GridBagLayout()); 136 135 listPanel.add(new JLabel(tr("Your saved queries:")), GBC.eol().insets(2).anchor(GBC.CENTER)); 137 listPanel.add(this. wikosmQueryList, GBC.eol().fill(GBC.BOTH));136 listPanel.add(this.sophoxQueryList, GBC.eol().fill(GBC.BOTH)); 138 137 listPanel.add(new JButton(new AddSnippetAction()), GBC.std().fill(GBC.HORIZONTAL)); 139 138 listPanel.add(new JButton(edit), GBC.std().fill(GBC.HORIZONTAL)); 140 139 listPanel.add(new JButton(remove), GBC.std().fill(GBC.HORIZONTAL)); 141 listPanel.setVisible( WIKOSM_QUERY_LIST_OPENED.get());142 143 JScrollPane scrollPane = new JScrollPane( wikosmQuery);140 listPanel.setVisible(SOPHOX_QUERY_LIST_OPENED.get()); 141 142 JScrollPane scrollPane = new JScrollPane(sophoxQuery); 144 143 BasicArrowButton arrowButton = new BasicArrowButton(listPanel.isVisible() 145 144 ? BasicArrowButton.EAST 146 145 : BasicArrowButton.WEST); 147 arrowButton.setToolTipText(tr("Show/hide Wikosmsnippet list"));146 arrowButton.setToolTipText(tr("Show/hide Sophox snippet list")); 148 147 arrowButton.addActionListener(e -> { 149 148 if (listPanel.isVisible()) { 150 149 listPanel.setVisible(false); 151 150 arrowButton.setDirection(BasicArrowButton.WEST); 152 WIKOSM_QUERY_LIST_OPENED.put(Boolean.FALSE);151 SOPHOX_QUERY_LIST_OPENED.put(Boolean.FALSE); 153 152 } else { 154 153 listPanel.setVisible(true); 155 154 arrowButton.setDirection(BasicArrowButton.EAST); 156 WIKOSM_QUERY_LIST_OPENED.put(Boolean.TRUE);155 SOPHOX_QUERY_LIST_OPENED.put(Boolean.TRUE); 157 156 } 158 157 }); … … 165 164 referrers.setToolTipText(tr("Select if the referrers of the object should be downloaded as well, i.e.," 166 165 + "parent relations and for nodes, additionally, parent ways")); 167 referrers.setSelected(Main.pref.getBoolean(" wikosm.downloadprimitive.referrers", true));168 referrers.addActionListener(e -> Main.pref.putBoolean(" wikosm.downloadprimitive.referrers", referrers.isSelected()));166 referrers.setSelected(Main.pref.getBoolean("sophox.downloadprimitive.referrers", true)); 167 referrers.addActionListener(e -> Main.pref.putBoolean("sophox.downloadprimitive.referrers", referrers.isSelected())); 169 168 170 169 fullRel = new JCheckBox(tr("Download relation members")); 171 170 fullRel.setToolTipText(tr("Select if the members of a relation should be downloaded as well")); 172 fullRel.setSelected(Main.pref.getBoolean(" wikosm.downloadprimitive.full", true));173 fullRel.addActionListener(e -> Main.pref.putBoolean(" wikosm.downloadprimitive.full", fullRel.isSelected()));171 fullRel.setSelected(Main.pref.getBoolean("sophox.downloadprimitive.full", true)); 172 fullRel.addActionListener(e -> Main.pref.putBoolean("sophox.downloadprimitive.full", fullRel.isSelected())); 174 173 175 174 // https://stackoverflow.com/questions/527719/how-to-add-hyperlink-in-jlabel … … 201 200 202 201 @Override 203 public WikosmDownloadData getData() {204 String query = wikosmQuery.getText();202 public SophoxDownloadData getData() { 203 String query = sophoxQuery.getText(); 205 204 /* 206 205 * A callback that is passed to PostDownloadReporter that is called once the download task 207 206 * has finished. According to the number of errors happened, their type we decide whether we 208 * want to save the last query in WikosmQueryList.207 * want to save the last query in SophoxQueryList. 209 208 */ 210 209 Consumer<Collection<Object>> errorReporter = errors -> { … … 214 213 215 214 if (errors.isEmpty() || onlyNoDataError) { 216 wikosmQueryList.saveHistoricItem(query);215 sophoxQueryList.saveHistoricItem(query); 217 216 } 218 217 }; 219 218 220 return new WikosmDownloadData(query, referrers.isSelected(), fullRel.isSelected(), errorReporter);219 return new SophoxDownloadData(query, referrers.isSelected(), fullRel.isSelected(), errorReporter); 221 220 } 222 221 … … 236 235 237 236 /* 238 * Absence of the selected area can be justified only if the Wikosmquery237 * Absence of the selected area can be justified only if the Sophox query 239 238 * is not restricted to bbox. 240 239 */ … … 257 256 @Override 258 257 public Icon getIcon() { 259 return ImageProvider.get(ACTION_IMG_SUBDIR, " wikosm");258 return ImageProvider.get(ACTION_IMG_SUBDIR, "sophox"); 260 259 } 261 260 … … 286 285 @Override 287 286 public void actionPerformed(ActionEvent e) { 288 wikosmQueryList.createNewItem();287 sophoxQueryList.createNewItem(); 289 288 } 290 289 } … … 307 306 @Override 308 307 public void actionPerformed(ActionEvent e) { 309 wikosmQueryList.removeSelectedItem();308 sophoxQueryList.removeSelectedItem(); 310 309 } 311 310 … … 314 313 */ 315 314 void checkEnabled() { 316 setEnabled( wikosmQueryList.getSelectedItem().isPresent());315 setEnabled(sophoxQueryList.getSelectedItem().isPresent()); 317 316 } 318 317 … … 340 339 @Override 341 340 public void actionPerformed(ActionEvent e) { 342 wikosmQueryList.editSelectedItem();341 sophoxQueryList.editSelectedItem(); 343 342 } 344 343 … … 347 346 */ 348 347 void checkEnabled() { 349 setEnabled( wikosmQueryList.getSelectedItem().isPresent());348 setEnabled(sophoxQueryList.getSelectedItem().isPresent()); 350 349 } 351 350 … … 358 357 359 358 /** 360 * Encapsulates data that is required to preform download from WikosmAPI.359 * Encapsulates data that is required to preform download from Sophox API. 361 360 */ 362 static class WikosmDownloadData {361 static class SophoxDownloadData { 363 362 private final String query; 364 363 private final boolean downloadReferrers; … … 366 365 private final Consumer<Collection<Object>> errorReporter; 367 366 368 WikosmDownloadData(String query, boolean downloadReferrers, boolean downloadFull, Consumer<Collection<Object>> errorReporter) {367 SophoxDownloadData(String query, boolean downloadReferrers, boolean downloadFull, Consumer<Collection<Object>> errorReporter) { 369 368 this.query = query; 370 369 this.downloadReferrers = downloadReferrers; -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/gui/SophoxServerPreference.java
r33807 r33808 18 18 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 19 19 import org.openstreetmap.josm.tools.GBC; 20 import org.wikipedia.io. WikosmDownloadReader;20 import org.wikipedia.io.SophoxDownloadReader; 21 21 22 22 /** 23 * Preferences related to WikosmAPI servers.23 * Preferences related to Sophox API servers. 24 24 */ 25 public class WikosmServerPreference implements SubPreferenceSetting {25 public class SophoxServerPreference implements SubPreferenceSetting { 26 26 27 private final HistoryComboBox wikosmServer = new HistoryComboBox();27 private final HistoryComboBox SophoxServer = new HistoryComboBox(); 28 28 29 29 /** 30 * Factory used to create a new {@link WikosmServerPreference}.30 * Factory used to create a new {@link SophoxServerPreference}. 31 31 */ 32 32 public static class Factory implements PreferenceSettingFactory { 33 33 @Override 34 34 public PreferenceSetting createPreferenceSetting() { 35 return new WikosmServerPreference();35 return new SophoxServerPreference(); 36 36 } 37 37 } … … 48 48 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 49 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());50 panel.add(SophoxServer, GBC.eop().fill(GBC.HORIZONTAL)); 51 SophoxServer.setPossibleItems(SophoxDownloadReader.SOPHOX_SERVER_HISTORY.get()); 52 SophoxServer.setText(SophoxDownloadReader.SOPHOX_SERVER.get()); 53 53 54 54 panel.add(Box.createVerticalGlue(), GBC.eol().fill()); … … 59 59 @Override 60 60 public boolean ok() { 61 WikosmDownloadReader.WIKOSM_SERVER.put(wikosmServer.getText());62 WikosmDownloadReader.WIKOSM_SERVER_HISTORY.put(wikosmServer.getHistory());61 SophoxDownloadReader.SOPHOX_SERVER.put(SophoxServer.getText()); 62 SophoxDownloadReader.SOPHOX_SERVER_HISTORY.put(SophoxServer.getHistory()); 63 63 return false; 64 64 } -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/io/SophoxDownloadReader.java
r33807 r33808 36 36 37 37 /** 38 * Read content from an Wikosmserver.38 * Read content from an Sophox server. 39 39 */ 40 public class WikosmDownloadReader extends BoundingBoxDownloader {40 public class SophoxDownloadReader extends BoundingBoxDownloader { 41 41 42 42 /** 43 * Property for current Wikosmserver.43 * Property for current Sophox server. 44 44 */ 45 public static final StringProperty WIKOSM_SERVER = new StringProperty("download.wikosm.server",46 "http ://88.99.164.208/bigdata/namespace/wdq/sparql");45 public static final StringProperty SOPHOX_SERVER = new StringProperty("download.sophox.server", 46 "https://sophox.org/bigdata/namespace/wdq/sparql"); 47 47 /** 48 * Property for list of known Wikosmservers.48 * Property for list of known Sophox servers. 49 49 */ 50 50 // TODO: Core dependency: 51 // public static final ListProperty WIKOSM_SERVER_HISTORY = new ListProperty("download.wikosm.servers",52 // Arrays.asList("http ://88.99.164.208/bigdata/namespace/wdq/sparql"));53 public static final ListProperty WIKOSM_SERVER_HISTORY = new ListProperty("download.wikosm.servers",54 Arrays.asList("http ://88.99.164.208/bigdata/namespace/wdq/sparql"));51 // public static final ListProperty SOPHOX_SERVER_HISTORY = new ListProperty("download.sophox.servers", 52 // Arrays.asList("https://sophox.org/bigdata/namespace/wdq/sparql")); 53 public static final ListProperty SOPHOX_SERVER_HISTORY = new ListProperty("download.sophox.servers", 54 Arrays.asList("https://sophox.org/bigdata/namespace/wdq/sparql")); 55 55 56 56 private static final String DATA_PREFIX = "?query="; 57 57 58 private final String wikosmServer;59 private final String wikosmQuery;58 private final String sophoxServer; 59 private final String sophoxQuery; 60 60 private final boolean asNewLayer; 61 61 private final boolean downloadReferrers; … … 63 63 64 64 /** 65 * Constructs a new {@code WikosmDownloadReader}.65 * Constructs a new {@code SophoxDownloadReader}. 66 66 * 67 67 * @param downloadArea The area to download 68 * @param wikosmServer The Wikosmserver to use69 * @param wikosmQuery The Wikosmquery68 * @param sophoxServer The Sophox server to use 69 * @param sophoxQuery The Sophox query 70 70 */ 71 public WikosmDownloadReader(Bounds downloadArea, String wikosmServer, String wikosmQuery,71 public SophoxDownloadReader(Bounds downloadArea, String sophoxServer, String sophoxQuery, 72 72 boolean asNewLayer, boolean downloadReferrers, boolean downloadFull) { 73 73 super(downloadArea); 74 74 setDoAuthenticate(false); 75 this. wikosmServer = wikosmServer;76 this. wikosmQuery = wikosmQuery.trim();75 this.sophoxServer = sophoxServer; 76 this.sophoxQuery = sophoxQuery.trim(); 77 77 this.asNewLayer = asNewLayer; 78 78 this.downloadReferrers = downloadReferrers; … … 82 82 @Override 83 83 protected String getBaseUrl() { 84 return wikosmServer;84 return sophoxServer; 85 85 } 86 86 87 87 @Override 88 88 protected String getRequestForBbox(double lon1, double lat1, double lon2, double lat2) { 89 final String query = this. wikosmQuery89 final String query = this.sophoxQuery 90 90 .replace("{{boxParams}}", boxParams(lon1, lat1, lon2, lat2)) 91 91 .replace("{{center}}", center(lon1, lat1, lon2, lat2)); … … 204 204 protected void adaptRequest(HttpClient request) { 205 205 // see https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#timeout 206 final Matcher timeoutMatcher = Pattern.compile("#timeout:(\\d+)").matcher( wikosmQuery);206 final Matcher timeoutMatcher = Pattern.compile("#timeout:(\\d+)").matcher(sophoxQuery); 207 207 final int timeout; 208 208 if (timeoutMatcher.find()) { … … 265 265 DataSet ds = super.parseOsm(progressMonitor); 266 266 267 // add bounds if necessary (note that WikosmAPI does not return bounds in the response XML)268 if (ds != null && ds.getDataSources().isEmpty() && wikosmQuery.contains("{{boxParams}}")) {267 // add bounds if necessary (note that Sophox API does not return bounds in the response XML) 268 if (ds != null && ds.getDataSources().isEmpty() && sophoxQuery.contains("{{boxParams}}")) { 269 269 if (crosses180th) { 270 270 Bounds bounds = new Bounds(lat1, lon1, lat2, 180.0);
Note:
See TracChangeset
for help on using the changeset viewer.