File: ConnectMultipleMediaCmd.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (90 lines) | stat: -rw-r--r-- 2,232 bytes parent folder | download | duplicates (4)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package tim.prune.cmd;

import java.util.ArrayList;
import java.util.List;

import tim.prune.DataSubscriber;
import tim.prune.data.AudioClip;
import tim.prune.data.DataPoint;
import tim.prune.data.Photo;
import tim.prune.data.TrackInfo;

/**
 * Connect or disconnect multiple photos and/or audios and their corresponding points
 */
public class ConnectMultipleMediaCmd extends Command
{
	private final MediaLinkType _linkType;
	private final ArrayList<PointAndMedia> _data = new ArrayList<>();

	public ConnectMultipleMediaCmd(MediaLinkType inLinkType, List<PointAndMedia> inData) {
		this(null, inLinkType, inData);
	}

	private ConnectMultipleMediaCmd(ConnectMultipleMediaCmd inParent, MediaLinkType inLinkType,
		List<PointAndMedia> inData)
	{
		super(inParent);
		_linkType = inLinkType;
		_data.addAll(inData);
	}

	@Override
	public int getUpdateFlags() {
		return DataSubscriber.MEDIA_MODIFIED;
	}

	@Override
	protected boolean executeCommand(TrackInfo inInfo)
	{
		if (_data.isEmpty()) {
			return false;
		}
		for (PointAndMedia pointData : _data)
		{
			DataPoint point = pointData.getPoint();
			if (point == null) {
				continue;
			}
			if (_linkType.handlePhotos())
			{
				// Deal with the photo
				Photo photo = pointData.getPhoto();
				if (point.getPhoto() != null) {
					point.getPhoto().setDataPoint(null);
				}
				point.setPhoto(photo);
				if (photo != null) {
					photo.setDataPoint(point);
				}
			}
			if (_linkType.handleAudios())
			{
				// Deal with the audio
				AudioClip audio = pointData.getAudio();
				if (point.getAudio() != null) {
					point.getAudio().setDataPoint(null);
				}
				point.setAudio(audio);
				if (audio != null) {
					audio.setDataPoint(point);
				}
			}
		}
		return true;
	}

	@Override
	protected Command makeInverse(TrackInfo inInfo)
	{
		ArrayList<PointAndMedia> currentData = new ArrayList<>();
		for (PointAndMedia pointData : _data)
		{
			DataPoint point = pointData.getPoint();
			if (point != null) {
				currentData.add(new PointAndMedia(point, point.getPhoto(), point.getAudio()));
			}
		}
		return new ConnectMultipleMediaCmd(this, _linkType, currentData);
	}
}