source: josm/trunk/src/org/openstreetmap/josm/gui/download/AbstractDownloadSourcePanel.java@ 17318

Last change on this file since 17318 was 16553, checked in by Don-vip, 4 years ago

see #19334 - javadoc fixes + protected constructors for abstract classes

File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.download;
3
4import java.util.Objects;
5
6import javax.swing.Icon;
7import javax.swing.JPanel;
8
9import org.openstreetmap.josm.data.Bounds;
10import org.openstreetmap.josm.gui.download.DownloadSourceSizingPolicy.FixedDownloadSourceSizePolicy;
11
12/**
13 * GUI representation of {@link DownloadSource} that is shown to the user in
14 * {@link DownloadDialog}.
15 * @param <T> The type of the data that a download source uses.
16 * @since 12652
17 */
18public abstract class AbstractDownloadSourcePanel<T> extends JPanel {
19
20 /**
21 * A prefix to be used for tab height preferences
22 */
23 public static final String TAB_SPLIT_NAMESPACE = "download.tabsplit.";
24
25 /**
26 * Called when creating a new {@link AbstractDownloadSourcePanel} for the given download source
27 * @param downloadSource The download source this panel is for
28 */
29 protected AbstractDownloadSourcePanel(final DownloadSource<T> downloadSource) {
30 Objects.requireNonNull(downloadSource);
31 this.downloadSource = downloadSource;
32 }
33
34 /**
35 * The download source of this panel.
36 */
37 protected transient DownloadSource<T> downloadSource;
38
39 /**
40 * Gets the data.
41 * @return Returns the data.
42 */
43 public abstract T getData();
44
45 /**
46 * Gets the download source of this panel.
47 * @return Returns the download source of this panel.
48 */
49 public DownloadSource<T> getDownloadSource() {
50 return this.downloadSource;
51 }
52
53 /**
54 * Saves the current user preferences devoted to the data source.
55 */
56 public abstract void rememberSettings();
57
58 /**
59 * Restores the latest user preferences devoted to the data source.
60 */
61 public abstract void restoreSettings();
62
63 /**
64 * Performs the logic needed in case if the user triggered the download
65 * action in {@link DownloadDialog}.
66 * @param settings The settings to check.
67 * @return Returns {@code true} if the required procedure of handling the
68 * download action succeeded and {@link DownloadDialog} can be closed, e.g. validation,
69 * otherwise {@code false}.
70 */
71 public abstract boolean checkDownload(DownloadSettings settings);
72
73 /**
74 * Performs the logic needed in case if the user triggered the cancel
75 * action in {@link DownloadDialog}.
76 */
77 public void checkCancel() {
78 // nothing, let download dialog to close
79 // override if necessary
80 }
81
82 /**
83 * Gets the icon of the download source panel.
84 * @return The icon. Can be {@code null} if there is no icon associated with
85 * this download source.
86 */
87 public Icon getIcon() {
88 return null;
89 }
90
91 /**
92 * Updates GUI components of the panel according to the bbox changes.
93 * @param bbox The new value for the bounding box.
94 * @since 13498
95 */
96 public void boundingBoxChanged(Bounds bbox) {
97 // override this if the panel must react on bbox changes
98 }
99
100 /**
101 * Tells the {@link DownloadSource} to start downloading
102 * @param downloadSettings The download settings
103 */
104 public void triggerDownload(DownloadSettings downloadSettings) {
105 getDownloadSource().doDownload(getData(), downloadSettings);
106 }
107
108 /**
109 * Returns a simple name describing this panel. This string can be used from other GUI parts
110 * of JOSM to save the user preferences related to the GUI settings. For example, the panel for downloading
111 * the OSM data can be named 'downloadosmpanel'. Note, choose the name such that it is unique to avoid
112 * collisions with other names.
113 * @return A simple name describing this panel.
114 */
115 public abstract String getSimpleName();
116
117 /**
118 * Gets the policy that defines how this component should be sized
119 * @return The sizing policy. A fixed policy on default.
120 * @since 12705
121 */
122 public DownloadSourceSizingPolicy getSizingPolicy() {
123 return new FixedDownloadSourceSizePolicy(this);
124 }
125}
Note: See TracBrowser for help on using the repository browser.