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

Last change on this file since 11002 was 10611, checked in by Don-vip, 8 years ago

see #11390 - sonar - squid:S1604 - Java 8: Anonymous inner classes containing only one method should become lambdas

  • Property svn:eol-style set to native
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.WindowEvent;
8import java.util.Arrays;
9import java.util.Collection;
10
11import javax.swing.JCheckBox;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
15import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog;
16import org.openstreetmap.josm.io.OnlineResource;
17
18/**
19 * Dialog prompt to user to let him choose OSM primitives to download by specifying their type and IDs
20 * @since 5765
21 */
22public class DownloadObjectDialog extends OsmIdSelectionDialog {
23
24 // CHECKSTYLE.OFF: SingleSpaceSeparator
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 // CHECKSTYLE.ON: SingleSpaceSeparator
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", "cancel"});
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(e -> referrers.setText(cbType.getType() == OsmPrimitiveType.NODE
71 ? tr("Download referrers (parent relations and ways)")
72 : tr("Download referrers (parent relations)")));
73
74 return Arrays.<Component>asList(referrers, fullRel, newLayer);
75 }
76
77 /**
78 * Determines if a new layer has been requested.
79 * @return true if a new layer has been requested, false otherwise
80 */
81 public final boolean isNewLayerRequested() {
82 return newLayer.isSelected();
83 }
84
85 /**
86 * Determines if relation members have been requested.
87 * @return true if relation members have been requested, false otherwise
88 */
89 public final boolean isFullRelationRequested() {
90 return fullRel.isSelected();
91 }
92
93 /**
94 * Determines if referrers have been requested.
95 * @return true if referrers have been requested, false otherwise
96 */
97 public final boolean isReferrersRequested() {
98 return referrers.isSelected();
99 }
100
101 @Override
102 public void windowClosed(WindowEvent e) {
103 super.windowClosed(e);
104 if (e != null && e.getComponent() == this && getValue() == 1) {
105 Main.pref.put("downloadprimitive.referrers", referrers.isSelected());
106 Main.pref.put("downloadprimitive.full", fullRel.isSelected());
107 Main.pref.put("download.newlayer", newLayer.isSelected());
108 }
109 }
110}
Note: See TracBrowser for help on using the repository browser.