1 | package org.expeditee.agents;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.awt.Point;
|
---|
5 |
|
---|
6 | import org.expeditee.gui.Frame;
|
---|
7 | import org.expeditee.gui.FrameGraphics;
|
---|
8 | import org.expeditee.gui.FrameIO;
|
---|
9 | import org.expeditee.items.Text;
|
---|
10 |
|
---|
11 | public class SwitchyardTree extends DefaultAgent {
|
---|
12 |
|
---|
13 | private Long startTime = 0L;
|
---|
14 |
|
---|
15 | private int frameCount = 0;
|
---|
16 |
|
---|
17 | private int itemCount = 0;
|
---|
18 |
|
---|
19 | @Override
|
---|
20 | protected void finalise(Frame frame) {
|
---|
21 | Long total = System.currentTimeMillis() - startTime;
|
---|
22 | FrameGraphics.DisplayMessage("Time: " + total + "ms, frames: "
|
---|
23 | + frameCount + ", items: " + itemCount);
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | protected Frame process(Frame frame) {
|
---|
28 | frameCount = 0;
|
---|
29 | itemCount = 0;
|
---|
30 | FrameGraphics.DisplayMessage("Running switchyard tree...");
|
---|
31 | startTime = System.currentTimeMillis();
|
---|
32 |
|
---|
33 | for (Text textItem : frame.getBodyTextItems()) {
|
---|
34 | // Delete all non-annotations with more that one letter
|
---|
35 | if (textItem.getTextNoList().length() > 1)
|
---|
36 | frame.removeItem(textItem);
|
---|
37 | else {
|
---|
38 | // goto child frame of any linked 1 letter items
|
---|
39 | String link = textItem.getAbsoluteLink();
|
---|
40 | if (link != null) {
|
---|
41 | Frame childFrame = FrameIO.LoadFrame(link);
|
---|
42 | if (childFrame != null) {
|
---|
43 | Point lastItemEnd = textItem.getEndParagraphPosition();
|
---|
44 | for (Text childItem : childFrame.getBodyTextItems()) {
|
---|
45 | // look for red items
|
---|
46 | if (childItem.getColor().equals(Color.RED)) {
|
---|
47 | // make a copy and add to parent frame
|
---|
48 | Text itemCopy = childItem.copy();
|
---|
49 | // add to the right of parent item
|
---|
50 | lastItemEnd.translate(20, 0);
|
---|
51 | itemCopy.setPosition(lastItemEnd);
|
---|
52 | lastItemEnd = itemCopy
|
---|
53 | .getEndParagraphPosition();
|
---|
54 | frame.addItem(itemCopy);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | return null;
|
---|
63 | }
|
---|
64 | }
|
---|