]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/function/RemovePhotoFunction.java
86f3ae80621281ad1ec8a1b3498b84be38875c1a
[GpsPrune.git] / src / 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                                 final int pointIndex = _app.getTrackInfo().getTrack().getPointIndex(currentPhoto.getDataPoint());
52                                 undoAction = new UndoDeletePhoto(currentPhoto, _app.getTrackInfo().getSelection().getCurrentPhotoIndex(),
53                                         currentPhoto.getDataPoint(), pointIndex);
54                                 undoAction.setAtBoundaryOfSelectedRange(pointIndex == _app.getTrackInfo().getSelection().getStart() ||
55                                         pointIndex == _app.getTrackInfo().getSelection().getEnd());
56                                 int response = JOptionPane.showConfirmDialog(_app.getFrame(),
57                                         I18nManager.getText("dialog.deletephoto.deletepoint"),
58                                         I18nManager.getText("dialog.deletephoto.title"),
59                                         JOptionPane.YES_NO_CANCEL_OPTION);
60                                 boolean deletePointToo = (response == JOptionPane.YES_OPTION);
61                                 // Cancel delete if cancel pressed or dialog closed
62                                 if (response == JOptionPane.YES_OPTION || response == JOptionPane.NO_OPTION) {
63                                         photoDeleted = _app.getTrackInfo().deleteCurrentPhoto(deletePointToo);
64                                 }
65                         }
66                         // Add undo information to stack if necessary
67                         if (photoDeleted) {
68                                 _app.completeFunction(undoAction, currentPhoto.getName() + " " + I18nManager.getText("confirm.media.removed"));
69                         }
70                 }
71         }
72 }