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

Last change on this file since 12654 was 12654, checked in by michael2402, 7 years ago

See #15167: Fix generics.

File size: 2.8 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;
10
11/**
12 * GUI representation of {@link DownloadSource} that is shown to the user in
13 * {@link DownloadDialog}.
14 * @param <T> The type of the data that a download source uses.
15 */
16public abstract class AbstractDownloadSourcePanel<T> extends JPanel {
17
18 public AbstractDownloadSourcePanel(final DownloadSource<T> downloadSource) {
19 Objects.requireNonNull(downloadSource);
20 this.downloadSource = downloadSource;
21 }
22
23 /**
24 * The download source of this panel.
25 */
26 protected transient DownloadSource<T> downloadSource;
27
28 /**
29 * Gets the data.
30 * @return Returns the data.
31 */
32 public abstract T getData();
33
34 /**
35 * Gets the download source of this panel.
36 * @return Returns the download source of this panel.
37 */
38 public DownloadSource<T> getDownloadSource() {
39 return this.downloadSource;
40 }
41
42 /**
43 * Saves the current user preferences devoted to the data source.
44 */
45 public abstract void rememberSettings();
46
47 /**
48 * Restores the latest user preferences devoted to the data source.
49 */
50 public abstract void restoreSettings();
51
52 /**
53 * Performs the logic needed in case if the user triggered the download
54 * action in {@link DownloadDialog}.
55 * @return Returns {@code true} if the required procedure of handling the
56 * download action succeeded and {@link DownloadDialog} can be closed, e.g. validation,
57 * otherwise {@code false}.
58 */
59 public abstract boolean checkDownload(Bounds bbox, DownloadSettings settings);
60
61 /**
62 * Performs the logic needed in case if the user triggered the cancel
63 * action in {@link DownloadDialog}.
64 */
65 public void checkCancel() {
66 // nothing, let download dialog to close
67 // override if necessary
68 }
69
70 /**
71 * Gets the icon of the download source panel.
72 * @return The icon. Can be {@code null} if there is no icon associated with
73 * this download source.
74 */
75 public Icon getIcon() {
76 return null;
77 }
78
79 /**
80 * Updates GUI components of the panel according to the bbox changes.
81 * @param bbox The new value for the bounding box.
82 */
83 public void boudingBoxChanged(Bounds bbox) {
84 // override this if the panel must react on bbox changes
85 }
86
87 /**
88 * Tells the {@link DownloadSource} to start downloading
89 * @param currentBounds The bounds to download for
90 * @param downloadSettings The remaining download settings
91 */
92 public void triggerDownload(Bounds currentBounds, DownloadSettings downloadSettings) {
93 getDownloadSource().doDownload(currentBounds, getData(), downloadSettings);
94 }
95}
Note: See TracBrowser for help on using the repository browser.