Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/ImageData.java
r17579 r18049 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.util.ArrayList; … … 267 265 /** 268 266 * Remove the current selected image from the list 269 */270 public void removeSelectedImage() {271 List<ImageEntry> selectedImages = getSelectedImages();272 if (selectedImages.size() > 1) {273 throw new IllegalStateException(tr("Multiple images have been selected"));274 }275 removeImages(selectedImages);276 }277 278 /**279 * Remove the current selected image from the list280 267 * @since 15348 281 268 */ 282 269 public void removeSelectedImages() { 283 List<ImageEntry> selectedImages = getSelectedImages(); 284 removeImages(selectedImages); 270 removeImages(getSelectedImages()); 285 271 } 286 272 … … 290 276 } 291 277 for (ImageEntry img: getSelectedImages()) { 292 data.remove(img); 293 this.geoImages.remove(img); 294 } 295 if (selectedImagesIndex.get(0) >= data.size()) { 296 setSelectedImageIndex(data.size() - 1); 278 removeImage(img, false); 279 } 280 updateSelectedImage(); 281 } 282 283 /** 284 * Update the selected image after removal of one or more images. 285 * @since 18049 286 */ 287 public void updateSelectedImage() { 288 int size = data.size(); 289 Integer firstSelectedImageIndex = selectedImagesIndex.get(0); 290 if (firstSelectedImageIndex >= size) { 291 setSelectedImageIndex(size - 1); 297 292 } else { 298 setSelectedImageIndex( selectedImagesIndex.get(0), true);293 setSelectedImageIndex(firstSelectedImageIndex, true); 299 294 } 300 295 } … … 307 302 */ 308 303 public boolean isImageSelected(ImageEntry image) { 309 int index = data.indexOf(image); 310 return selectedImagesIndex.contains(index); 304 return selectedImagesIndex.contains(data.indexOf(image)); 311 305 } 312 306 … … 316 310 */ 317 311 public void removeImage(ImageEntry img) { 312 removeImage(img, true); 313 } 314 315 /** 316 * Remove the image from the list and optionnally trigger update listener 317 * @param img the {@link ImageEntry} to remove 318 * @param fireUpdateEvent if {@code true}, notifies listeners of image update 319 * @since xxx 320 */ 321 public void removeImage(ImageEntry img, boolean fireUpdateEvent) { 318 322 data.remove(img); 319 323 this.geoImages.remove(img); 320 notifyImageUpdate(); 324 if (fireUpdateEvent) { 325 notifyImageUpdate(); 326 } 321 327 } 322 328 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r18018 r18049 344 344 345 345 if (result == 2) { 346 currentData.removeSelectedImages();347 346 for (ImageEntry delete : toDelete) { 348 347 if (Utils.deleteFile(delete.getFile())) { 349 Logging.info("File " + delete.getFile() + " deleted."); 348 currentData.removeImage(delete, false); 349 Logging.info("File {0} deleted.", delete.getFile()); 350 350 } else { 351 351 JOptionPane.showMessageDialog( … … 357 357 } 358 358 } 359 currentData.notifyImageUpdate(); 360 currentData.updateSelectedImage(); 359 361 } 360 362 } -
trunk/test/unit/org/openstreetmap/josm/data/ImageDataTest.java
r17715 r18049 55 55 assertFalse(data.hasNextImage()); 56 56 assertFalse(data.hasPreviousImage()); 57 data.removeSelectedImage ();57 data.removeSelectedImages(); 58 58 } 59 59 … … 182 182 183 183 @Test 184 void testRemoveSelectedImage() { 185 List<ImageEntry> list = getOneImage(); 186 ImageData data = new ImageData(list); 187 data.selectFirstImage(); 188 data.removeSelectedImage(); 184 void testRemoveSelectedImages() { 185 List<ImageEntry> list = getOneImage(); 186 list.add(new ImageEntry()); 187 188 ImageData data = new ImageData(list); 189 data.selectFirstImage(); 190 data.addImageToSelection(list.get(1)); 191 data.removeSelectedImages(); 189 192 assertEquals(0, data.getImages().size()); 190 193 assertEquals(0, data.getSelectedImages().size()); … … 192 195 193 196 @Test 194 void testRemoveSelectedImages() {195 List<ImageEntry> list = getOneImage();196 list.add(new ImageEntry());197 198 ImageData data = new ImageData(list);199 data.selectFirstImage();200 data.addImageToSelection(list.get(1));201 data.removeSelectedImages();202 assertEquals(0, data.getImages().size());203 assertEquals(0, data.getSelectedImages().size());204 }205 206 @Test207 197 void testRemoveSelectedImagesWithRemainingImages() { 208 198 List<ImageEntry> list = getOneImage(); … … 261 251 data.addImageDataUpdateListener(listener); 262 252 data.selectFirstImage(); 263 data.removeSelectedImage ();253 data.removeSelectedImages(); 264 254 } 265 255
Note:
See TracChangeset
for help on using the changeset viewer.