File: ConnectToPointFunction.java

package info (click to toggle)
gpsprune 13.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,008 kB
  • sloc: java: 28,802; sh: 25; makefile: 17; python: 15
file content (63 lines) | stat: -rw-r--r-- 1,727 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package tim.prune.function;

import tim.prune.App;
import tim.prune.DataSubscriber;
import tim.prune.GenericFunction;
import tim.prune.I18nManager;
import tim.prune.UpdateMessageBroker;
import tim.prune.data.AudioClip;
import tim.prune.data.DataPoint;
import tim.prune.data.Photo;
import tim.prune.undo.UndoConnectMedia;
import tim.prune.undo.UndoOperation;

/**
 * Function to connect either a photo or an audio clip to the current point
 */
public class ConnectToPointFunction extends GenericFunction
{
	/**
	 * Constructor
	 * @param inApp app object
	 */
	public ConnectToPointFunction(App inApp) {
		super(inApp);
	}

	/**
	 * @return name key
	 */
	public String getNameKey() {
		return "function.connecttopoint";
	}

	/**
	 * Perform function
	 */
	public void begin()
	{
		Photo photo = _app.getTrackInfo().getCurrentPhoto();
		DataPoint point = _app.getTrackInfo().getCurrentPoint();
		AudioClip audio = _app.getTrackInfo().getCurrentAudio();
		boolean connectPhoto = (point != null && photo != null && point.getPhoto() == null);
		boolean connectAudio = (point != null && audio != null && point.getAudio() == null);

		if (connectPhoto && connectAudio) {
			// TODO: Let user choose whether to connect photo/audio or both
		}
		// Make undo object
		UndoOperation undo = new UndoConnectMedia(point, connectPhoto?photo.getName():null,
			connectAudio?audio.getName():null);
		// Connect the media
		if (connectPhoto) {
			photo.setDataPoint(point);
			point.setPhoto(photo);
		}
		if (connectAudio) {
			audio.setDataPoint(point);
			point.setAudio(audio);
		}
		UpdateMessageBroker.informSubscribers(DataSubscriber.SELECTION_CHANGED);
		_app.completeFunction(undo, I18nManager.getText("confirm.media.connect"));
	}
}