1 | package org.expeditee.agents;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.awt.geom.Point2D;
|
---|
5 |
|
---|
6 | import org.expeditee.gui.Frame;
|
---|
7 | import org.expeditee.gui.FrameIO;
|
---|
8 | import org.expeditee.items.Text;
|
---|
9 |
|
---|
10 | public class SwitchyardTree extends DefaultAgent {
|
---|
11 |
|
---|
12 | @Override
|
---|
13 | protected Frame process(Frame frame) {
|
---|
14 | //FrameGraphics.DisplayMessage("Running switchyard tree...");
|
---|
15 |
|
---|
16 | for (Text textItem : frame.getBodyTextItems(false)) {
|
---|
17 | // Delete all non-annotations with more that one letter
|
---|
18 | if (textItem.getText().length() > 1){
|
---|
19 | frame.removeItem(textItem);
|
---|
20 | if(_stop)
|
---|
21 | return null;
|
---|
22 | }else {
|
---|
23 | // goto child frame of any linked 1 letter items
|
---|
24 | String link = textItem.getAbsoluteLink();
|
---|
25 | if (link != null) {
|
---|
26 | Frame childFrame = FrameIO.LoadFrame(link);
|
---|
27 | if (childFrame != null) {
|
---|
28 | Point2D.Float lastItemEnd = textItem.getEndParagraphPosition();
|
---|
29 | for (Text childItem : childFrame.getBodyTextItems(false)) {
|
---|
30 | // look for red items
|
---|
31 | if (childItem.getColor().equals(Color.RED)) {
|
---|
32 | // make a copy and add to parent frame
|
---|
33 | Text itemCopy = childItem.copy();
|
---|
34 | // add to the right of parent item
|
---|
35 | lastItemEnd.setLocation(lastItemEnd.x + 20, lastItemEnd.y);
|
---|
36 | itemCopy.setPosition(lastItemEnd.x, lastItemEnd.y);
|
---|
37 | lastItemEnd = itemCopy
|
---|
38 | .getEndParagraphPosition();
|
---|
39 | frame.addItem(itemCopy);
|
---|
40 | }
|
---|
41 | _itemCount++;
|
---|
42 | if(_stop)
|
---|
43 | return null;
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 | _frameCount++;
|
---|
50 | return null;
|
---|
51 | }
|
---|
52 | }
|
---|