- Timestamp:
- 2009-10-27T14:51:46+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DownloadAction.java
r2330 r2331 35 35 public class DownloadAction extends JosmAction { 36 36 private static final Logger logger = Logger.getLogger(DownloadAction.class.getName()); 37 38 private DownloadDialog dialog; 39 private ExtendedDialog downloadDialog; 40 37 41 38 public DownloadAction() { 42 39 super(tr("Download from OSM..."), "download", tr("Download map data from the OSM server."), … … 45 42 } 46 43 47 /**48 * Creates the download dialog49 *50 * @return the downlaod dialog51 */52 protected ExtendedDialog createDownloadDialog() {53 if (dialog == null)54 dialog = new DownloadDialog();55 dialog.restoreSettings();56 57 final String prefName = dialog.getClass().getName()+ ".geometry";58 final WindowGeometry wg = WindowGeometry.centerInWindow(Main.parent,59 new Dimension(1000,600));60 61 if (downloadDialog == null) {62 JPanel downPanel = new JPanel(new BorderLayout());63 downPanel.add(dialog, BorderLayout.CENTER);64 downloadDialog= new ExtendedDialog(Main.parent,65 tr("Download"),66 new String[] {tr("OK"), tr("Cancel")});67 downloadDialog.setContent(downPanel, false /* don't use a scroll pane inside the dialog */);68 downloadDialog.setButtonIcons(new String[] {"ok", "cancel"});69 downloadDialog.setRememberWindowGeometry(prefName, wg);70 }71 return downloadDialog;72 }73 74 44 public void actionPerformed(ActionEvent e) { 75 ExtendedDialog dlg = createDownloadDialog(); 76 boolean finish = false; 77 while (!finish) { 78 dlg.showDialog(); 79 if (dlg.getValue() == 1 /* OK */) { 80 dialog.rememberSettings(); 81 Bounds area = dialog.getSelectedDownloadArea(); 82 if (dialog.isDownloadOsmData()) { 83 DownloadOsmTask task = new DownloadOsmTask(); 84 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null); 85 Main.worker.submit(new PostDownloadHandler(task, future)); 86 finish = true; 87 } 88 if (dialog.isDownloadGpxData()) { 89 DownloadGpsTask task = new DownloadGpsTask(); 90 Future<?> future = task.download(dialog.isNewLayerRequired(),area, null); 91 Main.worker.submit(new PostDownloadHandler(task, future)); 92 finish = true; 93 } 94 } else { 95 finish = true; 45 DownloadDialog dialog = DownloadDialog.getInstance(); 46 dialog.setVisible(true); 47 if (! dialog.isCanceled()) { 48 dialog.rememberSettings(); 49 Bounds area = dialog.getSelectedDownloadArea(); 50 if (dialog.isDownloadOsmData()) { 51 DownloadOsmTask task = new DownloadOsmTask(); 52 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null); 53 Main.worker.submit(new PostDownloadHandler(task, future)); 96 54 } 97 if (!finish) { 98 JOptionPane.showMessageDialog( 99 Main.parent, 100 tr("Please select at least one task to download"), 101 tr("Error"), 102 JOptionPane.ERROR_MESSAGE 103 ); 55 if (dialog.isDownloadGpxData()) { 56 DownloadGpsTask task = new DownloadGpsTask(); 57 Future<?> future = task.download(dialog.isNewLayerRequired(),area, null); 58 Main.worker.submit(new PostDownloadHandler(task, future)); 104 59 } 105 } 106 } 60 } 61 } 107 62 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r2330 r2331 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.BorderLayout; 6 7 import java.awt.Color; 8 import java.awt.Component; 9 import java.awt.Dimension; 10 import java.awt.FlowLayout; 7 11 import java.awt.Font; 8 12 import java.awt.GridBagLayout; … … 13 17 import java.awt.event.InputEvent; 14 18 import java.awt.event.KeyEvent; 19 import java.awt.event.WindowAdapter; 20 import java.awt.event.WindowEvent; 15 21 import java.util.ArrayList; 16 22 import java.util.List; … … 19 25 import javax.swing.AbstractAction; 20 26 import javax.swing.JCheckBox; 27 import javax.swing.JComponent; 28 import javax.swing.JDialog; 21 29 import javax.swing.JLabel; 30 import javax.swing.JOptionPane; 22 31 import javax.swing.JPanel; 23 32 import javax.swing.JTabbedPane; … … 27 36 import org.openstreetmap.josm.data.Bounds; 28 37 import org.openstreetmap.josm.gui.MapView; 38 import org.openstreetmap.josm.gui.SideButton; 39 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 40 import org.openstreetmap.josm.gui.help.HelpUtil; 29 41 import org.openstreetmap.josm.plugins.PluginHandler; 30 42 import org.openstreetmap.josm.tools.GBC; 43 import org.openstreetmap.josm.tools.ImageProvider; 31 44 import org.openstreetmap.josm.tools.OsmUrlToBounds; 45 import org.openstreetmap.josm.tools.WindowGeometry; 46 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 32 47 33 48 /** 34 * Main download dialog. 35 * 36 * Can be extended by plugins in two ways: 37 * (1) by adding download tasks that are then called with the selected bounding box 38 * (2) by adding "DownloadSelection" objects that implement different ways of selecting a bounding box 39 * 40 * @author Frederik Ramm <frederik@remote.org> 41 * 49 * 42 50 */ 43 public class DownloadDialog extends J Panel{51 public class DownloadDialog extends JDialog { 44 52 static private final Logger logger = Logger.getLogger(DownloadDialog.class.getName()); 53 54 /** the unique instance of the download dialog */ 55 static private DownloadDialog instance; 56 57 /** 58 * Replies the unique instance of the download dialog 59 * 60 * @return the unique instance of the download dialog 61 */ 62 static public DownloadDialog getInstance() { 63 if (instance == null) 64 instance = new DownloadDialog(Main.parent); 65 return instance; 66 } 45 67 46 68 private final List<DownloadSelection> downloadSelections = new ArrayList<DownloadSelection>(); 47 69 private final JTabbedPane tpDownloadAreaSelectors = new JTabbedPane(); 48 private finalJCheckBox cbNewLayer;70 private JCheckBox cbNewLayer; 49 71 private final JLabel sizeCheck = new JLabel(); 50 51 72 private Bounds currentBounds = null; 73 private boolean canceled; 52 74 53 75 private JCheckBox cbDownloadOsmData = new JCheckBox(tr("OpenStreetMap data"), true); 54 76 private JCheckBox cbDownloadGpxData = new JCheckBox(tr("Raw GPS data")); 55 77 56 57 public DownloadDialog() { 58 setLayout(new GridBagLayout()); 78 79 public JPanel buildMainPanel() { 80 JPanel pnl = new JPanel(); 81 pnl.setLayout(new GridBagLayout()); 59 82 60 83 // adding the download tasks 61 add(new JLabel(tr("Data Sources and Types")), GBC.eol().insets(0,5,0,0));62 add(cbDownloadOsmData, GBC.eol().insets(20,0,0,0));63 add(cbDownloadGpxData, GBC.eol().insets(20,0,0,0));84 pnl.add(new JLabel(tr("Data Sources and Types")), GBC.eol().insets(0,5,0,0)); 85 pnl.add(cbDownloadOsmData, GBC.eol().insets(20,0,0,0)); 86 pnl.add(cbDownloadGpxData, GBC.eol().insets(20,0,0,0)); 64 87 65 88 // predefined download selections … … 81 104 82 105 cbNewLayer = new JCheckBox(tr("Download as new layer")); 83 add(cbNewLayer, GBC.eol().insets(0,5,0,0));84 85 add(new JLabel(tr("Download Area")), GBC.eol().insets(0,5,0,0));86 add(tpDownloadAreaSelectors, GBC.eol().fill());106 pnl.add(cbNewLayer, GBC.eol().insets(0,5,0,0)); 107 108 pnl. add(new JLabel(tr("Download Area")), GBC.eol().insets(0,5,0,0)); 109 pnl.add(tpDownloadAreaSelectors, GBC.eol().fill()); 87 110 88 111 try { … … 94 117 Font labelFont = sizeCheck.getFont(); 95 118 sizeCheck.setFont(labelFont.deriveFont(Font.PLAIN, labelFont.getSize())); 96 add(sizeCheck, GBC.eop().insets(0,5,5,10)); 97 98 getInputMap(WHEN_IN_FOCUSED_WINDOW).put( 119 pnl.add(sizeCheck, GBC.eop().insets(0,5,5,10)); 120 return pnl; 121 } 122 123 protected JPanel buildButtonPanel() { 124 JPanel pnl = new JPanel(); 125 pnl.setLayout(new FlowLayout()); 126 127 pnl.add(new SideButton(new DownloadAction())); 128 pnl.add(new SideButton(new CancelAction())); 129 pnl.add(new SideButton(new ContextSensitiveHelpAction(ht("/Dialog/DownloadDialog")))); 130 return pnl; 131 } 132 133 public DownloadDialog(Component parent) { 134 super(JOptionPane.getFrameForComponent(parent),tr("Download"), true /* modal */); 135 getContentPane().setLayout(new BorderLayout()); 136 getContentPane().add(buildMainPanel(), BorderLayout.CENTER); 137 getContentPane().add(buildButtonPanel(), BorderLayout.SOUTH); 138 139 getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 99 140 KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), "checkClipboardContents"); 100 141 101 get ActionMap().put("checkClipboardContents", new AbstractAction() {142 getRootPane().getActionMap().put("checkClipboardContents", new AbstractAction() { 102 143 public void actionPerformed(ActionEvent e) { 103 144 checkClipboardContents(); 104 145 } 105 146 }); 106 147 HelpUtil.setHelpContext(getRootPane(), ht("/Dialog/DownloadDialog")); 148 addWindowListener(new WindowEventHandler()); 107 149 restoreSettings(); 108 150 } 151 109 152 110 153 private void checkClipboardContents() { … … 247 290 } 248 291 292 @Override 293 public void setVisible(boolean visible) { 294 if (visible) { 295 new WindowGeometry( 296 getClass().getName() + ".geometry", 297 WindowGeometry.centerInWindow( 298 getParent(), 299 new Dimension(1000,600) 300 ) 301 ).apply(this); 302 } else if (!visible && isShowing()){ 303 new WindowGeometry(this).remember(getClass().getName() + ".geometry"); 304 } 305 super.setVisible(visible); 306 } 307 308 /** 309 * Replies true if the dialog was canceled 310 * 311 * @return true if the dialog was canceled 312 */ 313 public boolean isCanceled() { 314 return canceled; 315 } 316 317 protected void setCanceled(boolean canceled) { 318 this.canceled = canceled; 319 } 320 321 class CancelAction extends AbstractAction { 322 public CancelAction() { 323 putValue(NAME, tr("Cancel")); 324 putValue(SMALL_ICON, ImageProvider.get("cancel")); 325 putValue(SHORT_DESCRIPTION, tr("Click to close the dialog and to abort downloading")); 326 } 327 328 public void run() { 329 setCanceled(true); 330 setVisible(false); 331 } 332 333 public void actionPerformed(ActionEvent e) { 334 run(); 335 } 336 } 337 338 class DownloadAction extends AbstractAction { 339 public DownloadAction() { 340 putValue(NAME, tr("Download")); 341 putValue(SMALL_ICON, ImageProvider.get("download")); 342 putValue(SHORT_DESCRIPTION, tr("Click do download the currently selected area")); 343 } 344 345 public void actionPerformed(ActionEvent e) { 346 if (currentBounds == null) { 347 JOptionPane.showMessageDialog( 348 DownloadDialog.this, 349 tr("Please select a download area first."), 350 tr("Error"), 351 JOptionPane.ERROR_MESSAGE 352 ); 353 return; 354 } 355 if (!isDownloadOsmData() && !isDownloadOsmData()) { 356 JOptionPane.showMessageDialog( 357 DownloadDialog.this, 358 tr("<html>Neither <strong>{0}</strong> nor <strong>{1}</strong> is enabled.<br>" 359 + "Please chose to either download OSM data, or GPX data, or both.</html>", 360 cbDownloadOsmData.getText(), 361 cbDownloadGpxData.getText() 362 ), 363 tr("Error"), 364 JOptionPane.ERROR_MESSAGE 365 ); 366 return; 367 } 368 setCanceled(false); 369 setVisible(false); 370 } 371 } 372 373 class WindowEventHandler extends WindowAdapter { 374 @Override 375 public void windowClosing(WindowEvent e) { 376 new CancelAction().run(); 377 } 378 } 249 379 } -
trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java
r2327 r2331 233 233 submitSearch.addActionListener(new ActionListener() { 234 234 public void actionPerformed(ActionEvent e) { 235 queryServer(gui );235 queryServer(gui.getRootPane()); 236 236 } 237 237 }); … … 239 239 searchTerm.addActionListener(new ActionListener() { 240 240 public void actionPerformed(ActionEvent e) { 241 queryServer(gui );241 queryServer(gui.getRootPane()); 242 242 } 243 243 });
Note:
See TracChangeset
for help on using the changeset viewer.