GROUP_TIMELINES_R0: GROUP_TIMELINES_R0-first.patch
File GROUP_TIMELINES_R0-first.patch, 8.7 KB (added by boyan, 16 years ago) |
---|
-
src/main/java/org/sophie2/base/model/book/timelines/Channel.java
1 package org.sophie2.base.model.book.timelines; 2 3 import org.sophie2.core.prolib.impl.BaseProObject; 4 import org.sophie2.core.prolib.interfaces.ListProp; 5 6 /** 7 * Represents a timeline channel. 8 * 9 * @author boyan 10 */ 11 public class Channel extends BaseProObject { 12 13 /** 14 * The channel entries. 15 * 16 * @return A list property, holding the entries. 17 */ 18 public ListProp<TimelineEntry> entries() { 19 // TODO Auto-generated method stub 20 return null; 21 } 22 23 /** 24 * Adds an entry to the channel. 25 * 26 * @param timelineEntry 27 * the entry to be added. 28 */ 29 public void addEntry(TimelineEntry timelineEntry) { 30 // TODO Auto-generated method stub 31 32 } 33 34 /** 35 * Removes an entry from the channel. 36 * 37 * @param timelineEntry 38 * the entry to be removed 39 */ 40 public void removeEntry(TimelineEntry timelineEntry) { 41 // TODO Auto-generated method stub 42 43 } 44 } -
src/main/java/org/sophie2/base/model/book/timelines/Timeline.java
1 package org.sophie2.base.model.book.timelines; 2 3 import org.sophie2.base.model.book.Page; 4 import org.sophie2.core.prolib.impl.BaseProObject; 5 import org.sophie2.core.prolib.interfaces.ListProp; 6 import org.sophie2.core.prolib.interfaces.Prop; 7 8 /** 9 * Represents a Sophie2 timeline. 10 * 11 * @author boyan 12 */ 13 public class Timeline extends BaseProObject { 14 15 /** 16 * Constructs a timeline for a given page with a default duration. 17 * 18 * @param page 19 * the page this timeline corresponds to. 20 */ 21 public Timeline(Page page) { 22 // nothing for now 23 } 24 25 /** 26 * Constructs a timeline for a given page with a given length. 27 * 28 * @param page 29 * the page this timeline corresponds to. 30 * @param duration 31 * the length of the timeline in seconds 32 */ 33 public Timeline(Page page, int duration) { 34 // nothing for now 35 } 36 37 /** 38 * The channels of this timeline. Each channel corresponds to a group of 39 * elements on the page. 40 * 41 * @return the list property 42 */ 43 public ListProp<Channel> channels() { 44 // TODO Auto-generated method stub 45 return null; 46 } 47 48 /** 49 * Moves the head position to a specified time in the timeline. If it 50 * exceeds the length of the timeline, the position is not changed. 51 * 52 * @param time 53 * the time to jump to (in seconds). 54 * @return the new head position. 55 */ 56 public int jumpTo(int time) { 57 // TODO Auto-generated method stub 58 return 0; 59 } 60 61 /** 62 * The position of the timeline head in seconds. 63 * 64 * @return a property holding the head position 65 */ 66 public Prop<Integer> headPosition() { 67 // TODO Auto-generated method stub 68 return null; 69 } 70 71 /** 72 * Indicates whether the timeline is currently playing. 73 * 74 * @return a property, holding a boolean value. 75 */ 76 public Prop<Boolean> playing() { 77 // TODO Auto-generated method stub 78 return null; 79 } 80 81 /** 82 * Plays the timeline. 83 */ 84 public void play() { 85 // TODO Auto-generated method stub 86 87 } 88 89 /** 90 * Pauses the timeline and keeps the head position to resume playing. 91 */ 92 public void pause() { 93 // TODO Auto-generated method stub 94 95 } 96 97 /** 98 * Stops the timeline and resets its head position. 99 */ 100 public void stop() { 101 // TODO Auto-generated method stub 102 103 } 104 } -
src/main/java/org/sophie2/base/model/book/timelines/TimelineEntry.java
1 package org.sophie2.base.model.book.timelines; 2 3 import org.sophie2.base.model.book.PageElement; 4 import org.sophie2.core.prolib.impl.BaseProObject; 5 6 /** 7 * Represents a timeline entry. 8 * 9 * @author boyan 10 */ 11 public class TimelineEntry extends BaseProObject { 12 13 /** 14 * Constructs a timeline entry by a given element (or group of elements) on 15 * the page. 16 * 17 * @param element 18 */ 19 public TimelineEntry(PageElement element) { 20 // TODO Auto-generated constructor stub 21 } 22 } -
src/test/java/org/sophie2/base/model/book/timelines/TimelineUnitTest.java
1 package org.sophie2.base.model.book.timelines; 2 3 import org.junit.Test; 4 import org.sophie2.base.model.book.Book; 5 import org.sophie2.base.model.book.Page; 6 import org.sophie2.core.testing.UnitTestBase; 7 8 /** 9 * A unit test for the {@link Timeline}s class. Ensures timeline navigation is 10 * working correctly (playing, pausing, jumping). 11 * 12 * @author boyan 13 */ 14 public class TimelineUnitTest extends UnitTestBase { 15 16 /** 17 * A reference to a page that is needed in the {@link Timeline} constructor. 18 */ 19 public Page page; 20 21 @Override 22 public void setUp() { 23 Book book = Book.createDefaultBook().get(Book.class); 24 Page p = new Page(book.getSpace()); 25 this.page = p; 26 } 27 28 @Override 29 public void tearDown() { 30 this.page.delete(); 31 } 32 33 /** 34 * Tests whether playing/pausing the timeline works. This should affect the 35 * playing() property of the {@link Timeline}. 36 */ 37 @Test 38 public void testPlayPause() { 39 Timeline t = new Timeline(this.page); 40 assertFalse(t.playing().get()); 41 t.play(); 42 assertTrue(t.playing().get()); 43 t.pause(); 44 assertFalse(t.playing().get()); 45 } 46 47 /** 48 * Tests whether a user is able to jump to a location within the timeline. 49 * If the time specified exceeds the timeline length, that should not be 50 * possible. 51 */ 52 @Test 53 public void testJumpTo() { 54 Timeline t = new Timeline(this.page, 30); 55 56 assertFalse(t.playing().get()); 57 assertEquals(t.headPosition(), t.jumpTo(45)); 58 59 t.jumpTo(15); 60 assertEquals(15, t.headPosition()); 61 } 62 } -
src/test/java/org/sophie2/base/model/book/timelines/TimelinesIntegrationTest.java
1 package org.sophie2.base.model.book.timelines; 2 3 import org.junit.Test; 4 import org.sophie2.base.model.book.Book; 5 import org.sophie2.base.model.book.Frame; 6 import org.sophie2.base.model.book.Page; 7 import org.sophie2.core.testing.IntegrationTestBase; 8 9 /** 10 * An integration test for timelines, channels and entries. Ensures they are 11 * corresponding to the page structure. 12 * 13 * @author boyan 14 */ 15 public class TimelinesIntegrationTest extends IntegrationTestBase { 16 17 /** 18 * A reference to a page that is needed in the {@link Timeline} constructor. 19 */ 20 public Page page; 21 22 @Override 23 public void setUp() { 24 Book book = Book.createDefaultBook().get(Book.class); 25 Page p = new Page(book.getSpace()); 26 this.page = p; 27 } 28 29 @Override 30 public void tearDown() { 31 this.page.delete(); 32 } 33 34 /** 35 * Tests that channels are automatically created and removed according to 36 * the groups of elements on the page. 37 */ 38 @Test 39 public void testChannels() { 40 Timeline t = new Timeline(this.page); 41 assertEquals(0, t.channels().size()); 42 43 this.page.addNewFrame("newFrame"); 44 assertEquals(1, t.channels().size()); 45 46 this.page.frames().get().clear(); 47 assertEquals(0, t.channels().size()); 48 } 49 50 /** 51 * Tests timeline entries are added/removed corerctly. An entry holding a 52 * different element from the one the channel holds should not be added to 53 * that channel. 54 */ 55 @Test 56 public void testAddRemoveEntries() { 57 Timeline t = new Timeline(this.page); 58 Frame f = this.page.addNewFrame("newFrame"); 59 assertEquals(1, t.channels().size()); 60 Channel ch = t.channels().get(1); 61 62 assertEquals(1, ch.entries().size()); 63 ch.addEntry(new TimelineEntry(f)); 64 assertEquals(2, ch.entries().size()); 65 ch.addEntry(new TimelineEntry(this.page.addNewFrame("Another Frame"))); 66 assertEquals(2, ch.entries().size()); 67 ch.removeEntry(ch.entries().get(0)); 68 assertEquals(1, ch.entries().size()); 69 } 70 }