001: /*
002: * Apollo - Motion capture and animation system
003: * Copyright (c) 2005 Apollo
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: *
019: * http://www.gnu.org/copyleft/gpl.html
020: *
021: * @author Giovane.Kuhn - brain@netuno.com.br
022: *
023: */
024: package org.apollo.datamodel;
025:
026: import java.io.File;
027: import java.io.IOException;
028: import java.io.Serializable;
029: import java.util.ArrayList;
030: import java.util.Collections;
031: import java.util.Comparator;
032: import java.util.List;
033: import java.util.Map;
034:
035: import org.apollo.ApolloUtil;
036:
037: /**
038: * Class represents a video that was transformed with some effects.
039: * @author Giovane.Kuhn on 03/05/2005
040: */
041: public final class EffectingVideo implements Serializable {
042:
043: private static final long serialVersionUID = 1L;
044:
045: /** List of effects to be applied in the video */
046: private List<VideoEffect> effects;
047:
048: /** Effecting video file name */
049: private String relativeVideoFile;
050:
051: /** Effecting video frames, that contain the markers info */
052: private Map<Integer, EffectingFrame> frames;
053:
054: /** Project that's owner */
055: private Project project;
056:
057: public Project getProject() {
058: return project;
059: }
060:
061: public void setProject(Project project) {
062: this .project = project;
063: if (effects != null) {
064: for (VideoEffect effect : effects) {
065: effect.setProject(project);
066: }
067: }
068: }
069:
070: public List<VideoEffect> getEffects() {
071: return effects;
072: }
073:
074: public void setEffects(List<VideoEffect> effects) {
075: this .effects = effects;
076: if (effects != null) {
077: for (VideoEffect effect : effects) {
078: effect.setProject(project);
079: }
080: }
081: }
082:
083: public boolean addEffect(VideoEffect effect) {
084: if (effects == null) {
085: effects = new ArrayList<VideoEffect>();
086: }
087: boolean ret = effects.add(effect);
088: effect.setProject(project);
089: project.setChanged(EffectingVideo.class);
090: return ret;
091: }
092:
093: public boolean removeEffect(VideoEffect effect) {
094: if (effects == null) {
095: return false;
096: }
097: boolean ret = effects.remove(effect);
098: effect.setProject(null);
099: project.setChanged(EffectingVideo.class);
100: return ret;
101: }
102:
103: public boolean removeEffects(List<VideoEffect> effect) {
104: if (effects == null) {
105: return false;
106: }
107: boolean ret = effects.removeAll(effect);
108: for (VideoEffect e : effect) {
109: e.setProject(null);
110: }
111: project.setChanged(EffectingVideo.class);
112: return ret;
113: }
114:
115: public boolean replaceAllEffects(List<VideoEffect> newEffects) {
116: if (effects != null) {
117: for (VideoEffect effect : effects) {
118: effect.setProject(null);
119: }
120: }
121: this .setEffects(new ArrayList<VideoEffect>(newEffects));
122: if (project != null) {
123: project.setChanged(EffectingVideo.class);
124: }
125: return true;
126: }
127:
128: public boolean changeEffectOrder(VideoEffect effect, int sum) {
129: if (effects == null || sum == 0) {
130: // are not change order
131: return false;
132: }
133: int index = effects.indexOf(effect);
134: if (index < 0 || sum == 0) {
135: // effect doesn't exists
136: return false;
137: }
138: if (index == effects.size() - 1 && sum > 0) {
139: // effect is already last
140: return false;
141: }
142: if (index == 0 && sum < 0) {
143: // effect is already first
144: return false;
145: }
146: int newIndex = index + sum;
147: VideoEffect other = effects.get(newIndex);
148: assert other != null;
149: effects.set(newIndex, effect);
150: effects.set(index, other);
151: if (project != null) {
152: project.setChanged(EffectingVideo.class);
153: }
154: return true;
155: }
156:
157: public String getCanonicalVideoFile() {
158: if (relativeVideoFile == null) {
159: return null;
160: }
161: try {
162: return new File(ApolloUtil.getPathName(project
163: .getProjectFile()), relativeVideoFile)
164: .getCanonicalPath();
165: } catch (IOException e) {
166: throw new RuntimeException(e);
167: }
168: }
169:
170: public String getRelativeVideoFile() {
171: return relativeVideoFile;
172: }
173:
174: public void setRelativeVideoFile(String relativeVideoFile) {
175: boolean changed = (this .relativeVideoFile != relativeVideoFile || (relativeVideoFile != null && !relativeVideoFile
176: .equalsIgnoreCase(this .relativeVideoFile)));
177: this .relativeVideoFile = relativeVideoFile;
178: if (project != null && changed) {
179: project.setChanged(EffectingVideo.class);
180: }
181: }
182:
183: public Map<Integer, EffectingFrame> getFrames() {
184: if (frames == null) {
185: return Collections.emptyMap();
186: }
187: return frames;
188: }
189:
190: public List<EffectingFrame> getOrderedFrames() {
191: if (frames == null) {
192: return Collections.emptyList();
193: }
194: List<EffectingFrame> ret = new ArrayList<EffectingFrame>(frames
195: .values());
196: Collections.sort(ret, new Comparator<EffectingFrame>() {
197:
198: public int compare(EffectingFrame o1, EffectingFrame o2) {
199: return o1.getSequence() - o2.getSequence();
200: }
201:
202: });
203: return ret;
204: }
205:
206: public void setFrames(Map<Integer, EffectingFrame> frames) {
207: this .frames = frames;
208: }
209:
210: public EffectingFrame getFrame(Integer sequence) {
211: if (frames == null) {
212: return null;
213: }
214: return frames.get(sequence);
215: }
216:
217: public void reset(boolean toOriginalMarkers) {
218: if (frames == null) {
219: return;
220: }
221: for (EffectingFrame f : frames.values()) {
222: f.reset(toOriginalMarkers);
223: }
224: }
225:
226: public void uncolorizeMarkers() {
227: if (frames == null) {
228: return;
229: }
230: for (EffectingFrame f : frames.values()) {
231: f.uncolorizeMarkers();
232: }
233: }
234:
235: public String toString() {
236: return ApolloUtil.getFileName(relativeVideoFile, true);
237: }
238:
239: }
|