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

Last change on this file since 13724 was 13498, checked in by Don-vip, 6 years ago

fix typo

File size: 4.3 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 public 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 * @deprecated Use {@link #boundingBoxChanged} instead
95 */
96 @Deprecated
97 public void boudingBoxChanged(Bounds bbox) {
98 // override this if the panel must react on bbox changes
99 }
100
101 /**
102 * Updates GUI components of the panel according to the bbox changes.
103 * @param bbox The new value for the bounding box.
104 * @since 13498
105 */
106 public void boundingBoxChanged(Bounds bbox) {
107 // override this if the panel must react on bbox changes
108 }
109
110 /**
111 * Tells the {@link DownloadSource} to start downloading
112 * @param downloadSettings The download settings
113 */
114 public void triggerDownload(DownloadSettings downloadSettings) {
115 getDownloadSource().doDownload(getData(), downloadSettings);
116 }
117
118 /**
119 * Returns a simple name describing this panel. This string can be used from other GUI parts
120 * of JOSM to save the user preferences related to the GUI settings. For example, the panel for downloading
121 * the OSM data can be named 'downloadosmpanel'. Note, choose the name such that it is unique to avoid
122 * collisions with other names.
123 * @return A simple name describing this panel.
124 */
125 public abstract String getSimpleName();
126
127 /**
128 * Gets the policy that defines how this component should be sized
129 * @return The sizing policy. A fixed policy on default.
130 * @since 12705
131 */
132 public DownloadSourceSizingPolicy getSizingPolicy() {
133 return new FixedDownloadSourceSizePolicy(this);
134 }
135}
Note: See TracBrowser for help on using the repository browser.