]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/RemovePhotoFunction.java
Version 13, August 2011
[GpsPrune.git] / tim / prune / function / RemovePhotoFunction.java
1 package tim.prune.function;
2
3 import javax.swing.JOptionPane;
4
5 import tim.prune.App;
6 import tim.prune.GenericFunction;
7 import tim.prune.I18nManager;
8 import tim.prune.data.Photo;
9 import tim.prune.undo.UndoDeletePhoto;
10
11 /**
12  * Function to remove the currently selected photo
13  */
14 public class RemovePhotoFunction extends GenericFunction
15 {
16         /**
17          * Constructor
18          * @param inApp App object
19          */
20         public RemovePhotoFunction(App inApp) {
21                 super(inApp);
22         }
23
24         /** @return name key */
25         public String getNameKey() {
26                 return "function.removephoto";
27         }
28
29         /**
30          * Perform the function
31          */
32         public void begin()
33         {
34                 // Delete the current photo, and optionally its point too, keeping undo information
35                 Photo currentPhoto = _app.getTrackInfo().getCurrentPhoto();
36                 if (currentPhoto != null)
37                 {
38                         // Photo is selected, see if it has a point or not
39                         boolean photoDeleted = false;
40                         UndoDeletePhoto undoAction = null;
41                         if (currentPhoto.getDataPoint() == null)
42                         {
43                                 // no point attached, so just delete photo
44                                 undoAction = new UndoDeletePhoto(currentPhoto, _app.getTrackInfo().getSelection().getCurrentPhotoIndex(),
45                                         null, -1);
46                                 photoDeleted = _app.getTrackInfo().deleteCurrentPhoto(false);
47                         }
48                         else
49                         {
50                                 // point is attached, so need to confirm point deletion
51                                 undoAction = new UndoDeletePhoto(currentPhoto, _app.getTrackInfo().getSelection().getCurrentPhotoIndex(),
52                                         currentPhoto.getDataPoint(), _app.getTrackInfo().getTrack().getPointIndex(currentPhoto.getDataPoint()));
53                                 int response = JOptionPane.showConfirmDialog(_app.getFrame(),
54                                         I18nManager.getText("dialog.deletephoto.deletepoint"),
55                                         I18nManager.getText("dialog.deletephoto.title"),
56                                         JOptionPane.YES_NO_CANCEL_OPTION);
57                                 boolean deletePointToo = (response == JOptionPane.YES_OPTION);
58                                 // Cancel delete if cancel pressed or dialog closed
59                                 if (response == JOptionPane.YES_OPTION || response == JOptionPane.NO_OPTION) {
60                                         photoDeleted = _app.getTrackInfo().deleteCurrentPhoto(deletePointToo);
61                                 }
62                         }
63                         // Add undo information to stack if necessary
64                         if (photoDeleted) {
65                                 _app.completeFunction(undoAction, currentPhoto.getName() + " " + I18nManager.getText("confirm.media.removed"));
66                         }
67                 }
68         }
69 }