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