]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoDeletePhoto.java
Version 5, May 2008
[GpsPrune.git] / tim / prune / undo / UndoDeletePhoto.java
1 package tim.prune.undo;\r
2 \r
3 import tim.prune.I18nManager;\r
4 import tim.prune.UpdateMessageBroker;\r
5 import tim.prune.data.DataPoint;\r
6 import tim.prune.data.Photo;\r
7 import tim.prune.data.TrackInfo;\r
8 \r
9 /**\r
10  * Operation to undo a delete of a single photo, either with or without point\r
11  */\r
12 public class UndoDeletePhoto implements UndoOperation\r
13 {\r
14         private int _photoIndex = -1;\r
15         private Photo _photo = null;\r
16         private int _pointIndex = -1;\r
17         private DataPoint _point = null;\r
18 \r
19 \r
20         /**\r
21          * Constructor\r
22          * @param inPhoto photo\r
23          * @param inPhotoIndex index number of photo within photo list\r
24          * @param inPoint data point\r
25          * @param inPointIndex index number of point within track\r
26          */\r
27         public UndoDeletePhoto(Photo inPhoto, int inPhotoIndex, DataPoint inPoint, int inPointIndex)\r
28         {\r
29                 _photo = inPhoto;\r
30                 _photoIndex = inPhotoIndex;\r
31                 _point = inPoint;\r
32                 _pointIndex = inPointIndex;\r
33         }\r
34 \r
35 \r
36         /**\r
37          * @return description of operation including photo name\r
38          */\r
39         public String getDescription()\r
40         {\r
41                 String desc = I18nManager.getText("undo.deletephoto") + " " + _photo.getFile().getName();\r
42                 return desc;\r
43         }\r
44 \r
45 \r
46         /**\r
47          * Perform the undo operation on the given Track\r
48          * @param inTrackInfo TrackInfo object on which to perform the operation\r
49          */\r
50         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
51         {\r
52                 // restore photo\r
53                 inTrackInfo.getPhotoList().addPhoto(_photo, _photoIndex);\r
54                 // if there's a point to restore, restore it\r
55                 if (_point != null)\r
56                 {\r
57                         if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex))\r
58                         {\r
59                                 throw new UndoException(getDescription());\r
60                         }\r
61                 }\r
62                 else\r
63                 {\r
64                         // update needed if not already triggered by track update\r
65                         UpdateMessageBroker.informSubscribers();\r
66                 }\r
67                 // Ensure that photo is associated with point and vice versa\r
68                 _photo.setDataPoint(_point);\r
69                 if (_point != null)\r
70                 {\r
71                         _point.setPhoto(_photo);\r
72                 }\r
73         }\r
74 }\r