1 | package org.expeditee.agents;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
4 | import java.util.HashSet;
|
---|
5 | import java.util.Stack;
|
---|
6 |
|
---|
7 | import org.expeditee.gui.DisplayIO;
|
---|
8 | import org.expeditee.gui.Frame;
|
---|
9 | import org.expeditee.gui.FrameIO;
|
---|
10 | import org.expeditee.gui.MessageBay;
|
---|
11 | import org.expeditee.items.Item;
|
---|
12 | import org.expeditee.items.ItemUtils;
|
---|
13 |
|
---|
14 | public class DisplayComet extends DefaultAgent {
|
---|
15 | private Stack<Frame> _frameList = new Stack<Frame>();
|
---|
16 |
|
---|
17 | public DisplayComet(String delay) {
|
---|
18 | super(delay);
|
---|
19 | }
|
---|
20 |
|
---|
21 | public DisplayComet() {
|
---|
22 | super();
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | protected Frame process(Frame frame) {
|
---|
27 | Collection<String> seen = new HashSet<String>();
|
---|
28 |
|
---|
29 | DisplayIO.addToBack(frame);
|
---|
30 |
|
---|
31 | // Goto the end of the comet
|
---|
32 | Item old = null;
|
---|
33 | Frame oldFrame = frame;
|
---|
34 | while (oldFrame != null) {
|
---|
35 | if(_stop)
|
---|
36 | return null;
|
---|
37 | seen.add(oldFrame.getName().toLowerCase());
|
---|
38 | _frameList.push(oldFrame);
|
---|
39 | old = ItemUtils.FindExactTag(oldFrame.getItems(), ItemUtils
|
---|
40 | .GetTag(ItemUtils.TAG_BACKUP));
|
---|
41 | oldFrame = null;
|
---|
42 | if (old != null) {
|
---|
43 | String link = old.getAbsoluteLink();
|
---|
44 | String linkLowerCase = link.toLowerCase();
|
---|
45 | if (link != null && !seen.contains(linkLowerCase)) {
|
---|
46 | oldFrame = FrameIO.LoadFrame(linkLowerCase);
|
---|
47 | MessageBay.overwriteMessage("Loading frames: " + link);
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 | // Back out one frame at a time
|
---|
52 | while (!_frameList.empty()) {
|
---|
53 | if(_stop)
|
---|
54 | return null;
|
---|
55 | DisplayIO.setCurrentFrame(_frameList.pop());
|
---|
56 | _frameCount++;
|
---|
57 | pause(_delay);
|
---|
58 | }
|
---|
59 |
|
---|
60 | return _start;
|
---|
61 | }
|
---|
62 |
|
---|
63 | }
|
---|