- Timestamp:
- 2017-08-26T00:02:12+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DownloadAction.java
r12635 r12652 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.util.ArrayList;10 import java.util.List;11 import java.util.Optional;12 import java.util.concurrent.ExecutionException;13 import java.util.concurrent.Future;14 9 15 import javax.swing.JOptionPane;16 17 import org.openstreetmap.josm.actions.downloadtasks.AbstractDownloadTask;18 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;19 import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;20 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;21 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;22 import org.openstreetmap.josm.data.Bounds;23 import org.openstreetmap.josm.data.ProjectionBounds;24 import org.openstreetmap.josm.data.ViewportData;25 import org.openstreetmap.josm.gui.MainApplication;26 import org.openstreetmap.josm.gui.MapFrame;27 10 import org.openstreetmap.josm.gui.download.DownloadDialog; 28 import org.openstreetmap.josm.gui.util.GuiHelper;29 import org.openstreetmap.josm.tools.Logging;30 import org.openstreetmap.josm.tools.Pair;31 11 import org.openstreetmap.josm.tools.Shortcut; 32 12 … … 45 25 */ 46 26 public DownloadAction() { 47 super(tr("Download from OSM..."), "download", tr("Download map data from the OSM server."),48 Shortcut.registerShortcut("file:download", tr("File: {0}", tr("Download from OSM...")), KeyEvent.VK_DOWN, Shortcut.CTRL_SHIFT),27 super(tr("Download data"), "download", tr("Download map data from a server of your choice"), 28 Shortcut.registerShortcut("file:download", tr("File: {0}", tr("Download data")), KeyEvent.VK_DOWN, Shortcut.CTRL_SHIFT), 49 29 true); 50 30 putValue("help", ht("/Action/Download")); … … 56 36 dialog.restoreSettings(); 57 37 dialog.setVisible(true); 58 59 if (dialog.isCanceled()) {60 return;61 }62 63 dialog.rememberSettings();64 65 Optional<Bounds> selectedArea = dialog.getSelectedDownloadArea();66 if (!selectedArea.isPresent()) {67 JOptionPane.showMessageDialog(68 dialog,69 tr("Please select a download area first."),70 tr("Error"),71 JOptionPane.ERROR_MESSAGE72 );73 return;74 }75 76 final Bounds area = selectedArea.get();77 final boolean zoom = dialog.isZoomToDownloadedDataRequired();78 final List<Pair<AbstractDownloadTask<?>, Future<?>>> tasks = new ArrayList<>();79 80 if (dialog.isDownloadOsmData()) {81 DownloadOsmTask task = new DownloadOsmTask();82 task.setZoomAfterDownload(zoom && !dialog.isDownloadGpxData() && !dialog.isDownloadNotes());83 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);84 MainApplication.worker.submit(new PostDownloadHandler(task, future));85 if (zoom) {86 tasks.add(new Pair<>(task, future));87 }88 }89 90 if (dialog.isDownloadGpxData()) {91 DownloadGpsTask task = new DownloadGpsTask();92 task.setZoomAfterDownload(zoom && !dialog.isDownloadOsmData() && !dialog.isDownloadNotes());93 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);94 MainApplication.worker.submit(new PostDownloadHandler(task, future));95 if (zoom) {96 tasks.add(new Pair<>(task, future));97 }98 }99 100 if (dialog.isDownloadNotes()) {101 DownloadNotesTask task = new DownloadNotesTask();102 task.setZoomAfterDownload(zoom && !dialog.isDownloadOsmData() && !dialog.isDownloadGpxData());103 Future<?> future = task.download(false, area, null);104 MainApplication.worker.submit(new PostDownloadHandler(task, future));105 if (zoom) {106 tasks.add(new Pair<>(task, future));107 }108 }109 110 if (zoom && tasks.size() > 1) {111 MainApplication.worker.submit(() -> {112 ProjectionBounds bounds = null;113 // Wait for completion of download jobs114 for (Pair<AbstractDownloadTask<?>, Future<?>> p : tasks) {115 try {116 p.b.get();117 ProjectionBounds b = p.a.getDownloadProjectionBounds();118 if (bounds == null) {119 bounds = b;120 } else if (b != null) {121 bounds.extend(b);122 }123 } catch (InterruptedException | ExecutionException ex) {124 Logging.warn(ex);125 }126 }127 // Zoom to the larger download bounds128 MapFrame map = MainApplication.getMap();129 if (map != null && bounds != null) {130 final ProjectionBounds pb = bounds;131 GuiHelper.runInEDTAndWait(() -> map.mapView.zoomTo(new ViewportData(pb)));132 }133 });134 }135 38 } 136 39 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r12641 r12652 73 73 import org.openstreetmap.josm.actions.OrthogonalizeAction; 74 74 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo; 75 import org.openstreetmap.josm.actions.OverpassDownloadAction;76 75 import org.openstreetmap.josm.actions.PasteAction; 77 76 import org.openstreetmap.josm.actions.PasteAtSourcePositionAction; … … 160 159 /** File / Download in current view **/ 161 160 public final DownloadOsmInViewAction downloadInView = new DownloadOsmInViewAction(); 162 /** File / Download from Overpass API... **/163 public final OverpassDownloadAction overpassDownload = new OverpassDownloadAction();164 161 /** File / Download object... **/ 165 162 public final DownloadPrimitiveAction downloadPrimitive = new DownloadPrimitiveAction(); … … 658 655 add(fileMenu, download); 659 656 add(fileMenu, downloadInView, true); 660 add(fileMenu, overpassDownload, true);661 657 add(fileMenu, downloadPrimitive); 662 658 add(fileMenu, searchNotes); -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r12643 r12652 6 6 7 7 import java.awt.BorderLayout; 8 import java.awt.Color;9 8 import java.awt.Component; 10 9 import java.awt.Dimension; 11 10 import java.awt.FlowLayout; 12 import java.awt.Font;13 11 import java.awt.Graphics; 14 12 import java.awt.GridBagLayout; … … 19 17 import java.awt.event.WindowEvent; 20 18 import java.util.ArrayList; 19 import java.util.Arrays; 21 20 import java.util.List; 22 21 import java.util.Optional; 22 import java.util.stream.IntStream; 23 23 24 24 import javax.swing.AbstractAction; 25 import javax.swing.Icon; 25 26 import javax.swing.JButton; 26 27 import javax.swing.JCheckBox; … … 28 29 import javax.swing.JDialog; 29 30 import javax.swing.JLabel; 30 import javax.swing.JOptionPane;31 31 import javax.swing.JPanel; 32 import javax.swing.JSplitPane; 32 33 import javax.swing.JTabbedPane; 33 34 import javax.swing.KeyStroke; 34 import javax.swing.event.ChangeListener;35 35 36 36 import org.openstreetmap.josm.Main; … … 52 52 import org.openstreetmap.josm.tools.Logging; 53 53 import org.openstreetmap.josm.tools.OsmUrlToBounds; 54 import org.openstreetmap.josm.tools.Utils;55 54 import org.openstreetmap.josm.tools.WindowGeometry; 56 55 57 56 /** 58 * Dialog displayed to download OSM and/or GPS data from OSM server.57 * Dialog displayed to the user to download mapping data. 59 58 */ 60 59 public class DownloadDialog extends JDialog { 60 61 /** 62 * Preference properties 63 */ 61 64 private static final IntegerProperty DOWNLOAD_TAB = new IntegerProperty("download.tab", 0); 62 65 private static final IntegerProperty DOWNLOAD_SOURCE_TAB = new IntegerProperty("download-source.tab", 0); 66 private static final IntegerProperty DIALOG_SPLIT = new IntegerProperty("download.split", 200); 63 67 private static final BooleanProperty DOWNLOAD_AUTORUN = new BooleanProperty("download.autorun", false); 64 private static final BooleanProperty DOWNLOAD_OSM = new BooleanProperty("download.osm", true);65 private static final BooleanProperty DOWNLOAD_GPS = new BooleanProperty("download.gps", false);66 private static final BooleanProperty DOWNLOAD_NOTES = new BooleanProperty("download.notes", false);67 68 private static final BooleanProperty DOWNLOAD_NEWLAYER = new BooleanProperty("download.newlayer", false); 68 69 private static final BooleanProperty DOWNLOAD_ZOOMTODATA = new BooleanProperty("download.zoomtodata", true); … … 83 84 } 84 85 85 protected SlippyMapChooser slippyMapChooser;86 protected final transient List<DownloadSource> downloadSources = new ArrayList<>(); 86 87 protected final transient List<DownloadSelection> downloadSelections = new ArrayList<>(); 87 88 protected final JTabbedPane tpDownloadAreaSelectors = new JTabbedPane(); 89 protected final JTabbedPane downloadSourcesTab = new JTabbedPane(); 90 88 91 protected JCheckBox cbNewLayer; 89 92 protected JCheckBox cbStartup; 90 93 protected JCheckBox cbZoomToDownloadedData; 91 protected final JLabel sizeCheck = new JLabel(); 94 protected SlippyMapChooser slippyMapChooser; 95 protected JPanel mainPanel; 96 protected JSplitPane dialogSplit; 97 98 /* 99 * Keep the reference globally to avoid having it garbage collected 100 */ 101 protected final transient ExpertToggleAction.ExpertModeChangeListener expertListener = 102 getExpertModeListenerForDownloadSources(); 92 103 protected transient Bounds currentBounds; 93 104 protected boolean canceled; 94 105 95 protected JCheckBox cbDownloadOsmData; 96 protected JCheckBox cbDownloadGpxData; 97 protected JCheckBox cbDownloadNotes; 98 /** the download action and button */ 99 private final DownloadAction actDownload = new DownloadAction(); 100 protected final JButton btnDownload = new JButton(actDownload); 101 106 protected JButton btnDownload; 107 protected JButton btnCancel; 108 protected JButton btnHelp; 109 110 /** 111 * Builds the main panel of the dialog. 112 * @return The panel of the dialog. 113 */ 102 114 protected final JPanel buildMainPanel() { 103 JPanel pnl = new JPanel(new GridBagLayout()); 104 105 // size check depends on selected data source 106 final ChangeListener checkboxChangeListener = e -> updateSizeCheck(); 107 108 // adding the download tasks 109 pnl.add(new JLabel(tr("Data Sources and Types:")), GBC.std().insets(5, 5, 1, 5)); 110 cbDownloadOsmData = new JCheckBox(tr("OpenStreetMap data"), true); 111 cbDownloadOsmData.setToolTipText(tr("Select to download OSM data in the selected download area.")); 112 cbDownloadOsmData.getModel().addChangeListener(checkboxChangeListener); 113 pnl.add(cbDownloadOsmData, GBC.std().insets(1, 5, 1, 5)); 114 cbDownloadGpxData = new JCheckBox(tr("Raw GPS data")); 115 cbDownloadGpxData.setToolTipText(tr("Select to download GPS traces in the selected download area.")); 116 cbDownloadGpxData.getModel().addChangeListener(checkboxChangeListener); 117 pnl.add(cbDownloadGpxData, GBC.std().insets(5, 5, 1, 5)); 118 cbDownloadNotes = new JCheckBox(tr("Notes")); 119 cbDownloadNotes.setToolTipText(tr("Select to download notes in the selected download area.")); 120 cbDownloadNotes.getModel().addChangeListener(checkboxChangeListener); 121 pnl.add(cbDownloadNotes, GBC.eol().insets(50, 5, 1, 5)); 115 mainPanel = new JPanel(new GridBagLayout()); 116 117 downloadSources.add(new OSMDownloadSource()); 118 downloadSources.add(new OverpassDownloadSource()); 119 120 // register all default download sources 121 for (int i = 0; i < downloadSources.size(); i++) { 122 downloadSources.get(i).addGui(this); 123 } 122 124 123 125 // must be created before hook 124 126 slippyMapChooser = new SlippyMapChooser(); 125 126 // hook for subclasses127 buildMainPanelAboveDownloadSelections(pnl);128 127 129 128 // predefined download selections … … 137 136 PluginHandler.addDownloadSelection(downloadSelections); 138 137 139 // now everybody may add their tab to the tabbed pane 140 // (not done right away to allow plugins to remove one of 141 // the default selectors!) 142 for (DownloadSelection s : downloadSelections) { 143 s.addGui(this); 144 } 145 146 pnl.add(tpDownloadAreaSelectors, GBC.eol().fill()); 147 148 try { 149 tpDownloadAreaSelectors.setSelectedIndex(DOWNLOAD_TAB.get()); 150 } catch (IndexOutOfBoundsException ex) { 151 Logging.trace(ex); 152 DOWNLOAD_TAB.put(0); 153 } 154 155 Font labelFont = sizeCheck.getFont(); 156 sizeCheck.setFont(labelFont.deriveFont(Font.PLAIN, labelFont.getSize())); 138 // register all default download selections 139 for (int i = 0; i < downloadSelections.size(); i++) { 140 downloadSelections.get(i).addGui(this); 141 } 142 143 // allow to collapse the panes completely 144 downloadSourcesTab.setMinimumSize(new Dimension(0, 0)); 145 tpDownloadAreaSelectors.setMinimumSize(new Dimension(0, 0)); 146 147 dialogSplit = new JSplitPane( 148 JSplitPane.VERTICAL_SPLIT, 149 downloadSourcesTab, 150 tpDownloadAreaSelectors); 151 152 mainPanel.add(dialogSplit, GBC.eol().fill()); 157 153 158 154 cbNewLayer = new JCheckBox(tr("Download as new layer")); … … 169 165 cbZoomToDownloadedData.setToolTipText(tr("Select to zoom to entire newly downloaded data.")); 170 166 171 pnl.add(cbNewLayer, GBC.std().anchor(GBC.WEST).insets(5, 5, 5, 5));172 pnl.add(cbStartup, GBC.std().anchor(GBC.WEST).insets(15, 5, 5, 5));173 pnl.add(cbZoomToDownloadedData, GBC.std().anchor(GBC.WEST).insets(15, 5, 5, 5));167 mainPanel.add(cbNewLayer, GBC.std().anchor(GBC.WEST).insets(5, 5, 5, 5)); 168 mainPanel.add(cbStartup, GBC.std().anchor(GBC.WEST).insets(15, 5, 5, 5)); 169 mainPanel.add(cbZoomToDownloadedData, GBC.std().anchor(GBC.WEST).insets(15, 5, 5, 5)); 174 170 175 171 ExpertToggleAction.addVisibilitySwitcher(cbZoomToDownloadedData); 176 177 pnl.add(sizeCheck, GBC.eol().anchor(GBC.EAST).insets(5, 5, 5, 2));178 172 179 173 if (!ExpertToggleAction.isExpert()) { 180 174 JLabel infoLabel = new JLabel( 181 175 tr("Use left click&drag to select area, arrows or right mouse button to scroll map, wheel or +/- to zoom.")); 182 pnl.add(infoLabel, GBC.eol().anchor(GBC.SOUTH).insets(0, 0, 0, 0));183 } 184 return pnl;176 mainPanel.add(infoLabel, GBC.eol().anchor(GBC.SOUTH).insets(0, 0, 0, 0)); 177 } 178 return mainPanel; 185 179 } 186 180 … … 192 186 } 193 187 188 /** 189 * Builds the button pane of the dialog. 190 * @return The button panel of the dialog. 191 */ 194 192 protected final JPanel buildButtonPanel() { 193 btnDownload = new JButton(new DownloadAction()); 194 btnCancel = new JButton(new CancelAction()); 195 btnHelp = new JButton( 196 new ContextSensitiveHelpAction(getRootPane().getClientProperty("help").toString())); 197 195 198 JPanel pnl = new JPanel(new FlowLayout()); 196 199 197 // -- download button198 200 pnl.add(btnDownload); 201 pnl.add(btnCancel); 202 pnl.add(btnHelp); 203 199 204 InputMapUtils.enableEnter(btnDownload); 200 201 InputMapUtils.addEnterActionWhenAncestor(cbDownloadGpxData, actDownload);202 InputMapUtils.addEnterActionWhenAncestor(cbDownloadOsmData, actDownload);203 InputMapUtils.addEnterActionWhenAncestor(cbDownloadNotes, actDownload);204 InputMapUtils.addEnterActionWhenAncestor(cbNewLayer, actDownload);205 InputMapUtils.addEnterActionWhenAncestor(cbStartup, actDownload);206 InputMapUtils.addEnterActionWhenAncestor(cbZoomToDownloadedData, actDownload);207 208 // -- cancel button209 JButton btnCancel;210 CancelAction actCancel = new CancelAction();211 btnCancel = new JButton(actCancel);212 pnl.add(btnCancel);213 205 InputMapUtils.enableEnter(btnCancel); 214 215 // -- cancel on ESC 216 InputMapUtils.addEscapeAction(getRootPane(), actCancel); 217 218 // -- help button 219 JButton btnHelp = new JButton(new ContextSensitiveHelpAction(getRootPane().getClientProperty("help").toString())); 220 pnl.add(btnHelp); 206 InputMapUtils.addEscapeAction(getRootPane(), btnCancel.getAction()); 221 207 InputMapUtils.enableEnter(btnHelp); 208 209 InputMapUtils.addEnterActionWhenAncestor(cbNewLayer, btnDownload.getAction()); 210 InputMapUtils.addEnterActionWhenAncestor(cbStartup, btnDownload.getAction()); 211 InputMapUtils.addEnterActionWhenAncestor(cbZoomToDownloadedData, btnDownload.getAction()); 222 212 223 213 return pnl; … … 261 251 }); 262 252 addWindowListener(new WindowEventHandler()); 253 ExpertToggleAction.addExpertModeChangeListener(expertListener); 263 254 restoreSettings(); 264 255 } 265 256 266 protected void updateSizeCheck() {267 boolean isAreaTooLarge = false;268 if (currentBounds == null) {269 sizeCheck.setText(tr("No area selected yet"));270 sizeCheck.setForeground(Color.darkGray);271 } else if (isDownloadNotes() && !isDownloadOsmData() && !isDownloadGpxData()) {272 // see max_note_request_area in https://github.com/openstreetmap/openstreetmap-website/blob/master/config/example.application.yml273 isAreaTooLarge = currentBounds.getArea() > Main.pref.getDouble("osm-server.max-request-area-notes", 25);274 } else {275 // see max_request_area in https://github.com/openstreetmap/openstreetmap-website/blob/master/config/example.application.yml276 isAreaTooLarge = currentBounds.getArea() > Main.pref.getDouble("osm-server.max-request-area", 0.25);277 }278 displaySizeCheckResult(isAreaTooLarge);279 }280 281 protected void displaySizeCheckResult(boolean isAreaTooLarge) {282 if (isAreaTooLarge) {283 sizeCheck.setText(tr("Download area too large; will probably be rejected by server"));284 sizeCheck.setForeground(Color.red);285 } else {286 sizeCheck.setText(tr("Download area ok, size probably acceptable to server"));287 sizeCheck.setForeground(Color.darkGray);288 }289 }290 291 257 /** 292 258 * Distributes a "bounding box changed" from one DownloadSelection 293 * object to the others, so they may update or clear their input fields. 259 * object to the others, so they may update or clear their input fields. Also informs 260 * download sources about the change, so they can react on it. 294 261 * @param b new current bounds 295 262 * … … 303 270 } 304 271 } 305 updateSizeCheck(); 272 273 for (Component ds : downloadSourcesTab.getComponents()) { 274 if (ds instanceof AbstractDownloadSourcePanel) { 275 ((AbstractDownloadSourcePanel) ds).boudingBoxChanged(b); 276 } 277 } 306 278 } 307 279 … … 312 284 public void startDownload(Bounds b) { 313 285 this.currentBounds = b; 314 actDownload.run(); 315 } 316 317 /** 318 * Replies true if the user selected to download OSM data 319 * 320 * @return true if the user selected to download OSM data 321 */ 322 public boolean isDownloadOsmData() { 323 return cbDownloadOsmData.isSelected(); 324 } 325 326 /** 327 * Replies true if the user selected to download GPX data 328 * 329 * @return true if the user selected to download GPX data 330 */ 331 public boolean isDownloadGpxData() { 332 return cbDownloadGpxData.isSelected(); 333 } 334 335 /** 336 * Replies true if user selected to download notes 337 * 338 * @return true if user selected to download notes 339 */ 340 public boolean isDownloadNotes() { 341 return cbDownloadNotes.isSelected(); 286 startDownload(); 287 } 288 289 /** 290 * Starts download. 291 */ 292 public void startDownload() { 293 btnDownload.doClick(); 342 294 } 343 295 … … 362 314 363 315 /** 316 * Determines if the dialog autorun is enabled in preferences. 317 * @return {@code true} if the download dialog must be open at startup, {@code false} otherwise 318 */ 319 public static boolean isAutorunEnabled() { 320 return DOWNLOAD_AUTORUN.get(); 321 } 322 323 /** 364 324 * Adds a new download area selector to the download dialog 365 325 * … … 372 332 373 333 /** 334 * Adds a new download source to the download dialog 335 * 336 * @param downloadSource The download source to be added. 337 * @param <T> The type of the download data. 338 */ 339 public <T> void addDownloadSource(DownloadSource<T> downloadSource) { 340 if ((ExpertToggleAction.isExpert() && downloadSource.onlyExpert()) || !downloadSource.onlyExpert()) { 341 addNewDownloadSourceTab(downloadSource); 342 } 343 } 344 345 /** 374 346 * Refreshes the tile sources 375 347 * @since 6364 … … 386 358 public void rememberSettings() { 387 359 DOWNLOAD_TAB.put(tpDownloadAreaSelectors.getSelectedIndex()); 388 DOWNLOAD_OSM.put(cbDownloadOsmData.isSelected()); 389 DOWNLOAD_GPS.put(cbDownloadGpxData.isSelected()); 390 DOWNLOAD_NOTES.put(cbDownloadNotes.isSelected()); 360 DOWNLOAD_SOURCE_TAB.put(downloadSourcesTab.getSelectedIndex()); 361 DIALOG_SPLIT.put(dialogSplit.getDividerLocation()); 391 362 DOWNLOAD_NEWLAYER.put(cbNewLayer.isSelected()); 392 363 DOWNLOAD_ZOOMTODATA.put(cbZoomToDownloadedData.isSelected()); … … 400 371 */ 401 372 public void restoreSettings() { 402 cbDownloadOsmData.setSelected(DOWNLOAD_OSM.get());403 cbDownloadGpxData.setSelected(DOWNLOAD_GPS.get());404 cbDownloadNotes.setSelected(DOWNLOAD_NOTES.get());405 373 cbNewLayer.setSelected(DOWNLOAD_NEWLAYER.get()); 406 374 cbStartup.setSelected(isAutorunEnabled()); 407 375 cbZoomToDownloadedData.setSelected(DOWNLOAD_ZOOMTODATA.get()); 408 int idx = Utils.clamp(DOWNLOAD_TAB.get(), 0, tpDownloadAreaSelectors.getTabCount() - 1); 409 tpDownloadAreaSelectors.setSelectedIndex(idx); 376 dialogSplit.setDividerLocation(DIALOG_SPLIT.get()); 377 378 try { 379 tpDownloadAreaSelectors.setSelectedIndex(DOWNLOAD_TAB.get()); 380 } catch (IndexOutOfBoundsException e) { 381 Main.trace(e); 382 tpDownloadAreaSelectors.setSelectedIndex(0); 383 } 384 385 try { 386 downloadSourcesTab.setSelectedIndex(DOWNLOAD_SOURCE_TAB.get()); 387 } catch (IndexOutOfBoundsException e) { 388 Main.trace(e); 389 downloadSourcesTab.setSelectedIndex(0); 390 } 410 391 411 392 if (MainApplication.isDisplayingMapView()) { … … 443 424 444 425 /** 445 * Determines if the dialog autorun is enabled in preferences.446 * @return {@code true} if the download dialog must be open at startup, {@code false} otherwise447 */448 public static boolean isAutorunEnabled() {449 return DOWNLOAD_AUTORUN.get();450 }451 452 /**453 426 * Automatically opens the download dialog, if autorun is enabled. 454 427 * @see #isAutorunEnabled … … 494 467 } 495 468 469 /** 470 * Gets the global settings of the download dialog. 471 * @return The {@link DownloadSettings} object that describes the current state of 472 * the download dialog. 473 */ 474 public DownloadSettings getDownloadSettings() { 475 return new DownloadSettings(isNewLayerRequired(), isZoomToDownloadedDataRequired()); 476 } 477 496 478 protected void setCanceled(boolean canceled) { 497 479 this.canceled = canceled; 498 480 } 499 481 500 protected void buildMainPanelAboveDownloadSelections(JPanel pnl) { 501 // Do nothing 502 } 503 482 /** 483 * Returns position of the download source in the tabbed pane. 484 * @param downloadSource The download source. 485 * @return The index of the download source, or -1 if it not in the pane. 486 */ 487 protected int getDownloadSourceIndex(DownloadSource downloadSource) { 488 return Arrays.stream(downloadSourcesTab.getComponents()) 489 .filter(it -> it instanceof AbstractDownloadSourcePanel) 490 .map(it -> (AbstractDownloadSourcePanel) it) 491 .filter(it -> it.getDownloadSource().equals(downloadSource)) 492 .findAny() 493 .map(downloadSourcesTab::indexOfComponent) 494 .orElse(-1); 495 } 496 497 /** 498 * Adds the download source to the download sources tab. 499 * @param downloadSource The download source to be added. 500 * @param <T> The type of the download data. 501 */ 502 private <T> void addNewDownloadSourceTab(DownloadSource<T> downloadSource) { 503 AbstractDownloadSourcePanel<T> panel = downloadSource.createPanel(); 504 downloadSourcesTab.add(panel, downloadSource.getLabel()); 505 Icon icon = panel.getIcon(); 506 if (icon != null) { 507 int idx = getDownloadSourceIndex(downloadSource); 508 downloadSourcesTab.setIconAt( 509 idx != -1 ? idx : downloadSourcesTab.getTabCount() - 1, 510 icon); 511 } 512 } 513 514 /** 515 * Creates listener that removes/adds download sources from/to {@code downloadSourcesTab} 516 * depending on the current mode. 517 * @return The expert mode listener. 518 */ 519 private ExpertToggleAction.ExpertModeChangeListener getExpertModeListenerForDownloadSources() { 520 return isExpert -> { 521 if (isExpert) { 522 downloadSources.stream() 523 .filter(DownloadSource::onlyExpert) 524 .filter(it -> getDownloadSourceIndex(it) == -1) 525 .forEach(this::addNewDownloadSourceTab); 526 } else { 527 IntStream.range(0, downloadSourcesTab.getTabCount()) 528 .mapToObj(downloadSourcesTab::getComponentAt) 529 .filter(it -> it instanceof AbstractDownloadSourcePanel) 530 .map(it -> (AbstractDownloadSourcePanel) it) 531 .filter(it -> it.getDownloadSource().onlyExpert()) 532 .forEach(downloadSourcesTab::remove); 533 } 534 }; 535 } 536 537 /** 538 * Action that is executed when the cancel button is pressed. 539 */ 504 540 class CancelAction extends AbstractAction { 505 541 CancelAction() { … … 516 552 @Override 517 553 public void actionPerformed(ActionEvent e) { 554 AbstractDownloadSourcePanel pnl = (AbstractDownloadSourcePanel) downloadSourcesTab.getSelectedComponent(); 518 555 run(); 519 } 520 } 521 556 pnl.checkCancel(); 557 } 558 } 559 560 /** 561 * Action that is executed when the download button is pressed. 562 */ 522 563 class DownloadAction extends AbstractAction { 523 564 DownloadAction() { … … 529 570 530 571 public void run() { 531 /* 532 * Checks if the user selected the type of data to download. At least one the following 533 * must be chosen : raw osm data, gpx data, notes. 534 * If none of those are selected, then the corresponding dialog is shown to inform the user. 535 */ 536 if (!isDownloadOsmData() && !isDownloadGpxData() && !isDownloadNotes()) { 537 JOptionPane.showMessageDialog( 538 DownloadDialog.this, 539 tr("<html>Neither <strong>{0}</strong> nor <strong>{1}</strong> nor <strong>{2}</strong> is enabled.<br>" 540 + "Please choose to either download OSM data, or GPX data, or Notes, or all.</html>", 541 cbDownloadOsmData.getText(), 542 cbDownloadGpxData.getText(), 543 cbDownloadNotes.getText() 544 ), 545 tr("Error"), 546 JOptionPane.ERROR_MESSAGE 547 ); 548 return; 572 Component panel = downloadSourcesTab.getSelectedComponent(); 573 if (panel instanceof AbstractDownloadSourcePanel) { 574 AbstractDownloadSourcePanel pnl = (AbstractDownloadSourcePanel) panel; 575 DownloadSettings downloadSettings = getDownloadSettings(); 576 if (pnl.checkDownload(currentBounds, downloadSettings)) { 577 rememberSettings(); 578 setCanceled(false); 579 setVisible(false); 580 pnl.getDownloadSource().doDownload(currentBounds, pnl.getData(), downloadSettings); 581 } 549 582 } 550 551 setCanceled(false);552 setVisible(false);553 583 } 554 584 -
trunk/src/org/openstreetmap/josm/gui/download/OverpassQueryWizardDialog.java
r12620 r12652 20 20 21 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.actions.OverpassDownloadAction.OverpassDownloadDialog;23 22 import org.openstreetmap.josm.data.preferences.CollectionProperty; 24 23 import org.openstreetmap.josm.gui.ExtendedDialog; … … 64 63 + "</style>\n"; 65 64 66 private final OverpassDownload Dialog parentDialog;65 private final OverpassDownloadSource.OverpassDownloadSourcePanel dsPanel; 67 66 68 67 /** 69 68 * Create a new {@link OverpassQueryWizardDialog} 70 * @param parentDialog The parent this dialog should be displayed for71 */ 72 public OverpassQueryWizardDialog(OverpassDownload Dialog parentDialog) {73 super( parentDialog, tr("Overpass Turbo Query Wizard"),69 * @param dsPanel The Overpass download source panel. 70 */ 71 public OverpassQueryWizardDialog(OverpassDownloadSource.OverpassDownloadSourcePanel dsPanel) { 72 super(dsPanel.getParent(), tr("Overpass Turbo Query Wizard"), 74 73 tr("Build query"), tr("Build query and execute"), tr("Cancel")); 75 this. parentDialog = parentDialog;74 this.dsPanel = dsPanel; 76 75 77 76 this.queryWizard = new HistoryComboBox(); … … 91 90 queryWizard.setPossibleItems(OVERPASS_WIZARD_HISTORY.get()); 92 91 93 setCancelButton(CANCEL );94 setDefaultButton(BUILD_AN_EXECUTE_QUERY + 1); // Build and execute button92 setCancelButton(CANCEL + 1); 93 setDefaultButton(BUILD_AN_EXECUTE_QUERY + 1); 95 94 setContent(panel, false); 96 95 } … … 110 109 super.buttonAction(BUILD_AN_EXECUTE_QUERY, evt); 111 110 112 parentDialog.triggerDownload();111 DownloadDialog.getInstance().startDownload(); 113 112 } 114 113 break; … … 143 142 Logging.error(ex); 144 143 JOptionPane.showMessageDialog( 145 parentDialog,144 dsPanel.getParent(), 146 145 "<html>" + 147 146 tr("The Overpass wizard could not parse the following query:") + … … 166 165 if (q.isPresent()) { 167 166 String query = q.get(); 168 parentDialog.setOverpassQuery(query);167 dsPanel.setOverpassQuery(query); 169 168 170 169 return true;
Note:
See TracChangeset
for help on using the changeset viewer.