1 package tim.prune.function;
3 import javax.swing.JOptionPane;
6 import tim.prune.GenericFunction;
7 import tim.prune.I18nManager;
8 import tim.prune.data.Photo;
9 import tim.prune.undo.UndoDeletePhoto;
12 * Function to remove the currently selected photo
14 public class RemovePhotoFunction extends GenericFunction
18 * @param inApp App object
20 public RemovePhotoFunction(App inApp) {
24 /** @return name key */
25 public String getNameKey() {
26 return "function.removephoto";
30 * Perform the function
34 // Delete the current photo, and optionally its point too, keeping undo information
35 Photo currentPhoto = _app.getTrackInfo().getCurrentPhoto();
36 if (currentPhoto != null)
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)
43 // no point attached, so just delete photo
44 undoAction = new UndoDeletePhoto(currentPhoto, _app.getTrackInfo().getSelection().getCurrentPhotoIndex(),
46 photoDeleted = _app.getTrackInfo().deleteCurrentPhoto(false);
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);
66 // Add undo information to stack if necessary
68 _app.completeFunction(undoAction, currentPhoto.getName() + " " + I18nManager.getText("confirm.media.removed"));