File: InsertMediaCmd.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 (56 lines) | stat: -rw-r--r-- 1,324 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
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.Photo;
import tim.prune.data.TrackInfo;

/**
 * Command to insert multiple photos and/or audios back where they were
 */
public class InsertMediaCmd extends Command
{
	private final List<MediaInsertion> _media;

	/**
	 * Constructor
	 * @param inParent parent command
	 * @param inMedia media to insert
	 */
	public InsertMediaCmd(Command inParent, List<MediaInsertion> inMedia)
	{
		super(inParent);
		_media = new ArrayList<>(inMedia);
	}

	@Override
	protected boolean executeCommand(TrackInfo inInfo)
	{
		for (MediaInsertion item : _media)
		{
			if (item.getMedia() instanceof Photo) {
				inInfo.getPhotoList().add((Photo) item.getMedia(), item.getInsertIndex());
			}
			else if (item.getMedia() instanceof AudioClip) {
				inInfo.getAudioList().add((AudioClip) item.getMedia(), item.getInsertIndex());
			}
			else {
				return false;
			}
		}
		return true;
	}

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

	@Override
	protected Command makeInverse(TrackInfo inInfo) {
		throw new IllegalArgumentException("InsertMediaCmd can only be an inverse");
	}
}