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

Last change on this file was 14153, checked in by Don-vip, 6 years ago

see #15229 - deprecate Main.parent and Main itself

  • Property svn:eol-style set to native
File size: 4.2 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.WindowEvent;
8import java.util.Arrays;
9import java.util.Collection;
10
11import javax.swing.JCheckBox;
12
13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
14import org.openstreetmap.josm.gui.MainApplication;
15import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog;
16import org.openstreetmap.josm.io.NetworkManager;
17import org.openstreetmap.josm.io.OnlineResource;
18import org.openstreetmap.josm.spi.preferences.Config;
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 // CHECKSTYLE.OFF: SingleSpaceSeparator
27 protected final JCheckBox referrers = new JCheckBox(tr("Download referrers (parent relations)"));
28 protected final JCheckBox fullRel = new JCheckBox(tr("Download relation members"));
29 protected final JCheckBox newLayer = new JCheckBox(tr("Download as new layer"));
30 // CHECKSTYLE.ON: SingleSpaceSeparator
31
32 /**
33 * Constructs a new DownloadObjectDialog with MainApplication.getMainFrame() as parent component.
34 */
35 public DownloadObjectDialog() {
36 this(MainApplication.getMainFrame());
37 }
38
39 /**
40 * Constructs a new DownloadObjectDialog.
41 * @param parent The parent component
42 */
43 public DownloadObjectDialog(Component parent) {
44 super(parent, tr("Download object"), tr("Download object"), tr("Cancel"));
45 init();
46 setButtonIcons("download", "cancel");
47 setToolTipTexts(
48 tr("Start downloading"),
49 tr("Close dialog and cancel downloading")
50 );
51 configureContextsensitiveHelp("/Action/DownloadObject", true /* show help button */);
52 }
53
54 @Override
55 public void setupDialog() {
56 super.setupDialog();
57 buttons.get(0).setEnabled(!NetworkManager.isOffline(OnlineResource.OSM_API));
58 }
59
60 @Override
61 protected Collection<Component> getComponentsBeforeHelp() {
62 newLayer.setToolTipText(tr("Select if the data should be downloaded into a new layer"));
63 newLayer.setSelected(Config.getPref().getBoolean("download.newlayer"));
64
65 referrers.setToolTipText(tr("Select if the referrers of the object should be downloaded as well, i.e.,"
66 + "parent relations and for nodes, additionally, parent ways"));
67 referrers.setSelected(Config.getPref().getBoolean("downloadprimitive.referrers", true));
68
69 fullRel.setToolTipText(tr("Select if the members of a relation should be downloaded as well"));
70 fullRel.setSelected(Config.getPref().getBoolean("downloadprimitive.full", true));
71
72 cbType.addItemListener(e -> referrers.setText(cbType.getType() == OsmPrimitiveType.NODE
73 ? tr("Download referrers (parent relations and ways)")
74 : tr("Download referrers (parent relations)")));
75
76 return Arrays.<Component>asList(referrers, fullRel, newLayer);
77 }
78
79 /**
80 * Determines if a new layer has been requested.
81 * @return true if a new layer has been requested, false otherwise
82 */
83 public final boolean isNewLayerRequested() {
84 return newLayer.isSelected();
85 }
86
87 /**
88 * Determines if relation members have been requested.
89 * @return true if relation members have been requested, false otherwise
90 */
91 public final boolean isFullRelationRequested() {
92 return fullRel.isSelected();
93 }
94
95 /**
96 * Determines if referrers have been requested.
97 * @return true if referrers have been requested, false otherwise
98 */
99 public final boolean isReferrersRequested() {
100 return referrers.isSelected();
101 }
102
103 @Override
104 public void windowClosed(WindowEvent e) {
105 super.windowClosed(e);
106 if (e != null && e.getComponent() == this && getValue() == 1) {
107 Config.getPref().putBoolean("downloadprimitive.referrers", referrers.isSelected());
108 Config.getPref().putBoolean("downloadprimitive.full", fullRel.isSelected());
109 Config.getPref().putBoolean("download.newlayer", newLayer.isSelected());
110 }
111 }
112}
Note: See TracBrowser for help on using the repository browser.