source: josm/trunk/src/org/openstreetmap/josm/gui/download/DownloadObjectDialog.java@ 7434

Last change on this file since 7434 was 7434, checked in by Don-vip, 10 years ago

fix #8885 (see #4614) - add offline mode with new command line argument --offline which can take one of several of these values (comma separated):

  • josm_website: to disable all accesses to JOSM website (when not cached, disables Getting Started page, help, plugin list, styles, imagery, presets, rules)
  • osm_api: to disable all accesses to OSM API (disables download, upload, changeset queries, history, user message notification)
  • all: alias to disable all values. Currently equivalent to "josm_website,osm_api"

Plus improved javadoc, fixed EDT violations, and fixed a bug with HTTP redirection sent without "Location" header

File size: 4.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.download;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Component;
7import java.awt.event.ItemEvent;
8import java.awt.event.ItemListener;
9import java.awt.event.WindowEvent;
10import java.util.Arrays;
11import java.util.Collection;
12
13import javax.swing.JCheckBox;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
17import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog;
18import org.openstreetmap.josm.io.OnlineResource;
19
20/**
21 * Dialog prompt to user to let him choose OSM primitives to download by specifying their type and IDs
22 * @since 5765
23 */
24public class DownloadObjectDialog extends OsmIdSelectionDialog {
25
26 protected final JCheckBox referrers = new JCheckBox(tr("Download referrers (parent relations)"));
27 protected final JCheckBox fullRel = new JCheckBox(tr("Download relation members"));
28 protected final JCheckBox newLayer = new JCheckBox(tr("Separate Layer"));
29
30 /**
31 * Constructs a new DownloadObjectDialog with Main.parent as parent component.
32 */
33 public DownloadObjectDialog() {
34 this(Main.parent);
35 }
36
37 /**
38 * Constructs a new DownloadObjectDialog.
39 * @param parent The parent component
40 */
41 public DownloadObjectDialog(Component parent) {
42 super(parent, tr("Download object"), new String[]{tr("Download object"), tr("Cancel")});
43 init();
44 setButtonIcons(new String[]{"download.png", "cancel.png"});
45 setToolTipTexts(new String[]{
46 tr("Start downloading"),
47 tr("Close dialog and cancel downloading")
48 });
49 configureContextsensitiveHelp("/Action/DownloadObject", true /* show help button */);
50 }
51
52 @Override
53 public void setupDialog() {
54 super.setupDialog();
55 buttons.get(0).setEnabled(!Main.isOffline(OnlineResource.OSM_API));
56 }
57
58 @Override
59 protected Collection<Component> getComponentsBeforeHelp() {
60 newLayer.setToolTipText(tr("Select if the data should be downloaded into a new layer"));
61 newLayer.setSelected(Main.pref.getBoolean("download.newlayer"));
62
63 referrers.setToolTipText(tr("Select if the referrers of the object should be downloaded as well, i.e.,"
64 + "parent relations and for nodes, additionally, parent ways"));
65 referrers.setSelected(Main.pref.getBoolean("downloadprimitive.referrers", true));
66
67 fullRel.setToolTipText(tr("Select if the members of a relation should be downloaded as well"));
68 fullRel.setSelected(Main.pref.getBoolean("downloadprimitive.full", true));
69
70 cbType.addItemListener(new ItemListener() {
71 @Override
72 public void itemStateChanged(ItemEvent e) {
73 referrers.setText(cbType.getType() == OsmPrimitiveType.NODE
74 ? tr("Download referrers (parent relations and ways)")
75 : tr("Download referrers (parent relations)"));
76 }
77 });
78
79 return Arrays.<Component>asList(referrers, fullRel, newLayer);
80 }
81
82 /**
83 * Determines if a new layer has been requested.
84 * @return true if a new layer has been requested, false otherwise
85 */
86 public final boolean isNewLayerRequested() {
87 return newLayer.isSelected();
88 }
89
90 /**
91 * Determines if relation members have been requested.
92 * @return true if relation members have been requested, false otherwise
93 */
94 public final boolean isFullRelationRequested() {
95 return fullRel.isSelected();
96 }
97
98 /**
99 * Determines if referrers have been requested.
100 * @return true if referrers have been requested, false otherwise
101 */
102 public final boolean isReferrersRequested() {
103 return referrers.isSelected();
104 }
105
106 @Override
107 public void windowClosed(WindowEvent e) {
108 super.windowClosed(e);
109 if (e != null && e.getComponent() == this && getValue() == 1) {
110 Main.pref.put("downloadprimitive.referrers", referrers.isSelected());
111 Main.pref.put("downloadprimitive.full", fullRel.isSelected());
112 Main.pref.put("download.newlayer", newLayer.isSelected());
113 }
114 }
115}
Note: See TracBrowser for help on using the repository browser.