source: trunk/src/org/expeditee/agents/DisplayTree.java@ 376

Last change on this file since 376 was 156, checked in by ra33, 16 years ago

Added calculate action

File size: 2.8 KB
Line 
1package org.expeditee.agents;
2
3import org.expeditee.gui.DisplayIO;
4import org.expeditee.gui.Frame;
5import org.expeditee.gui.MessageBay;
6import org.expeditee.items.Item;
7import org.expeditee.items.ItemUtils;
8import org.expeditee.items.Text;
9
10/**
11 * Displays the Tree of Frames starting from the given frame. The delay between
12 * frames can be adjusted, either per-frame with the
13 *
14 * @DisplayFramePause tag, or mid-stream with the
15 * @DisplayTreePause tag, both tags should be followed with the desired delay in
16 * ms. The default delay between Frames is 50ms.
17 * @author jdm18
18 *
19 */
20public class DisplayTree extends TreeProcessor {
21
22 public static final int GARBAGE_COLLECTION_THRESHOLD = 100000;
23
24 private Runtime _runtime = Runtime.getRuntime();
25
26 public DisplayTree(String delay) {
27 super(delay);
28 }
29
30 public DisplayTree() {
31 super();
32 }
33
34 @Override
35 public boolean initialise(Frame start, Item launcher) {
36
37 // push current frame on to back-stack
38 DisplayIO.addToBack(start);
39
40 return super.initialise(start, launcher);
41 }
42
43 @Override
44 protected void finalise(Frame start) {
45 // return the user to the Frame they started on
46 if (!_stop) {
47 DisplayIO.Back();
48 }
49 super.finalise(start);
50 }
51
52 @Override
53 protected void processFrame(Frame toProcess) {
54 long freeMemory = _runtime.freeMemory();
55 if (freeMemory < GARBAGE_COLLECTION_THRESHOLD) {
56 _runtime.gc();
57 MessageBay.displayMessage("Force Garbage Collection!");
58 }
59
60 // FrameUtils.ResponseTimer.restart();
61
62 // ignore loops
63 if (toProcess != DisplayIO.getCurrentFrame())
64 DisplayIO.setCurrentFrame(toProcess, false);
65 // parse the frame for any pause settings
66 delay(toProcess);
67
68 _frameCount++;
69 }
70
71 /**
72 * Parses through the given Frame to find any
73 *
74 * @DisplayTreePause or
75 * @DisplayFramePause tags, and updates the delay or pause as necessary
76 * @param toSearch
77 */
78 private void delay(Frame toSearch) {
79 // check for change in globaly delay time
80 Item delay = ItemUtils.FindTag(toSearch.getItems(),
81 "@DisplayTreePause:");
82
83 if (delay != null) {
84 try {
85 // attempt to read in the delay value
86 _delay = Long.parseLong(ItemUtils.StripTag(((Text) delay)
87 .getFirstLine(), "@DisplayTreePause"));
88 message("DisplayTree delay changed to: " + _delay + "ms");
89 } catch (NumberFormatException nfe) {
90 message("Incorrect paramter for DisplayTreePause");
91 }
92
93 }
94
95 // check for change in delay for this frame only
96 delay = ItemUtils.FindTag(toSearch.getItems(), "@DisplayFramePause:");
97 if (delay != null) {
98 try {
99 // attempt to read in the delay value
100 long pause = Long.parseLong(ItemUtils.StripTag(((Text) delay)
101 .getFirstLine(), "@DisplayFramePause"));
102 pause(pause);
103 } catch (NumberFormatException nfe) {
104 message("Incorrect paramter for DisplayFramePause");
105 }
106 } else
107 pause(_delay);
108 }
109}
Note: See TracBrowser for help on using the repository browser.