Changeset 16504 in josm
- Timestamp:
- 2020-05-27T08:03:42+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/download/OSMDownloadSource.java
r16503 r16504 11 11 import java.lang.reflect.InvocationTargetException; 12 12 import java.util.ArrayList; 13 import java.util.Collection; 13 14 import java.util.Collections; 14 15 import java.util.List; 15 16 import java.util.concurrent.ExecutionException; 16 17 import java.util.concurrent.Future; 18 import java.util.stream.Collectors; 17 19 18 20 import javax.swing.Icon; … … 131 133 132 134 /** 133 * @return The possible downloads that JOSM can make in the default Download 134 * screen 135 * @return The possible downloads that JOSM can make in the default Download screen 135 136 * @since 16503 136 137 */ … … 153 154 /** 154 155 * @param type The IDownloadSourceType object to remove 155 * @return true See {@link List#remove}, but it also returns false if the 156 * parameter is a class from JOSM core. 156 * @return {@code true} if this download types contained the specified object 157 157 * @since 16503 158 158 */ 159 159 public static boolean removeDownloadType(IDownloadSourceType type) { 160 boolean modified = false; 161 if (!(type instanceof OsmDataDownloadType) && !(type instanceof GpsDataDownloadType) 162 && !(type instanceof NotesDataDownloadType)) { 163 modified = DOWNLOAD_SOURCES.remove(type); 164 } 165 return modified; 160 if (type instanceof OsmDataDownloadType || type instanceof GpsDataDownloadType || type instanceof NotesDataDownloadType) { 161 throw new IllegalArgumentException(type.getClass().getName()); 162 } 163 return DOWNLOAD_SOURCES.remove(type); 166 164 } 167 165 … … 170 168 * 171 169 * @param type The initialized type to download 172 * @return See {@link List#add}, but it also returns false if the class 173 * already has an instance in the list or it is a class from JOSM core. 170 * @return {@code true} (as specified by {@link Collection#add}), but it also returns false if the class already has an instance in the list 174 171 * @since 16503 175 172 */ 176 173 public static boolean addDownloadType(IDownloadSourceType type) { 177 boolean modified = false; 178 if (!(type instanceof OsmDataDownloadType) && !(type instanceof GpsDataDownloadType) 179 && !(type instanceof NotesDataDownloadType) 180 || DOWNLOAD_SOURCES.stream() 181 .noneMatch(possibility -> type.getClass().isInstance(possibility))) { 182 modified = DOWNLOAD_SOURCES.add(type); 183 } else { 184 throw new IllegalArgumentException("There can only be one instance of a class added, and it cannot be a built-in class."); 185 } 186 return modified; 174 if (type instanceof OsmDataDownloadType || type instanceof GpsDataDownloadType || type instanceof NotesDataDownloadType) { 175 throw new IllegalArgumentException(type.getClass().getName()); 176 } else if (getDownloadType(type.getClass()) != null) { 177 return false; 178 } 179 return DOWNLOAD_SOURCES.add(type); 187 180 } 188 181 … … 195 188 196 189 /** This is used to keep track of the components for download sources, and to dynamically update/remove them */ 197 private JPanel downloadSourcesPanel;198 199 private ChangeListener checkboxChangeListener;190 private final JPanel downloadSourcesPanel; 191 192 private final ChangeListener checkboxChangeListener; 200 193 201 194 /** … … 285 278 */ 286 279 if (DOWNLOAD_SOURCES.stream().noneMatch(IDownloadSourceType::isEnabled)) { 287 StringBuilder line1 = new StringBuilder("<html>").append(tr("None of")); 288 StringBuilder line2 = new StringBuilder(tr("Please choose to either download")); 289 290 DOWNLOAD_SOURCES.forEach(type -> { 291 line1.append(" <strong>").append(type.getCheckBox().getText()).append("</strong> "); 292 line2.append(' ').append(type.getCheckBox().getText()).append(tr(", or")); 293 }); 294 line1.append(tr("is enabled.")).append("<br>"); 295 line2.append(tr(" all.")).append("</html>"); 280 String sources = DOWNLOAD_SOURCES.stream() 281 .map(type -> type.getCheckBox().getText()) 282 .collect(Collectors.joining(", ")); 283 String message = "<html>" 284 + tr("None of {0} is enabled!", sources) 285 + "<br>" 286 + tr("Please select at least one of {0}.", sources); 296 287 JOptionPane.showMessageDialog( 297 288 this.getParent(), 298 line1.append(line2).toString(),289 message, 299 290 tr("Error"), 300 291 JOptionPane.ERROR_MESSAGE … … 313 304 * 314 305 * @return true if the user selected to download OSM data 315 * @deprecated since xxx -- use {@link OSMDownloadSource#getDownloadTypes} with 316 * {@code get(0).getCheckBox().isSelected()} 306 * @deprecated since xxx -- use {@code getDownloadType(OsmDataDownloadType.class).getCheckBox().isSelected()} 317 307 */ 318 308 @Deprecated 319 309 public boolean isDownloadOsmData() { 320 return DOWNLOAD_SOURCES.get(0).getCheckBox().isSelected();310 return getDownloadType(OsmDataDownloadType.class).getCheckBox().isSelected(); 321 311 } 322 312 … … 325 315 * 326 316 * @return true if the user selected to download GPX data 327 * @deprecated since xxx -- use {@link OSMDownloadSource#getDownloadTypes} with 328 * {@code get(1).getCheckBox().isSelected()} 317 * @deprecated since xxx -- use {@code getDownloadType(GpsDataDownloadType.class).getCheckBox().isSelected()} 329 318 */ 330 319 @Deprecated 331 320 public boolean isDownloadGpxData() { 332 return DOWNLOAD_SOURCES.get(1).getCheckBox().isSelected();321 return getDownloadType(GpsDataDownloadType.class).getCheckBox().isSelected(); 333 322 } 334 323 … … 337 326 * 338 327 * @return true if user selected to download notes 339 * @deprecated since xxx -- use {@link OSMDownloadSource#getDownloadTypes} with 340 * {@code get(2).getCheckBox().isSelected()} 328 * @deprecated since xxx -- use {@code getDownloadType(NotesDataDownloadType.class).getCheckBox().isSelected()} 341 329 */ 342 330 @Deprecated 343 331 public boolean isDownloadNotes() { 344 return DOWNLOAD_SOURCES.get(2).getCheckBox().isSelected();332 return getDownloadType(NotesDataDownloadType.class).getCheckBox().isSelected(); 345 333 } 346 334 … … 388 376 static class OSMDownloadData { 389 377 390 private List<IDownloadSourceType> downloadPossibilities;378 private final List<IDownloadSourceType> downloadPossibilities; 391 379 392 380 /**
Note:
See TracChangeset
for help on using the changeset viewer.