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

Last change on this file since 6448 was 6448, checked in by simon04, 11 years ago

fix #3626 - Show history for any object in history dialog

If no object is selected, the objects are selected by id via dialog.

File size: 4.0 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;
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 */
23public 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}
Note: See TracBrowser for help on using the repository browser.