[4] | 1 | package org.expeditee.agents;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Color;
|
---|
[108] | 4 | import java.awt.geom.Point2D;
|
---|
[4] | 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) {
|
---|
[121] | 14 | //MessageBay.displayMessage("Running switchyard tree...");
|
---|
[4] | 15 |
|
---|
[19] | 16 | for (Text textItem : frame.getBodyTextItems(false)) {
|
---|
[4] | 17 | // Delete all non-annotations with more that one letter
|
---|
[108] | 18 | if (textItem.getText().length() > 1){
|
---|
[4] | 19 | frame.removeItem(textItem);
|
---|
[108] | 20 | if(_stop)
|
---|
| 21 | return null;
|
---|
[179] | 22 | } else {
|
---|
[4] | 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) {
|
---|
[147] | 28 | Point2D.Float lastItemEnd = textItem.getParagraphEndPosition();
|
---|
[19] | 29 | for (Text childItem : childFrame.getBodyTextItems(false)) {
|
---|
[179] | 30 | // look for red items (remember get color may be null
|
---|
| 31 | if (Color.RED.equals(childItem.getPaintColor())) {
|
---|
[4] | 32 | // make a copy and add to parent frame
|
---|
| 33 | Text itemCopy = childItem.copy();
|
---|
| 34 | // add to the right of parent item
|
---|
[108] | 35 | lastItemEnd.setLocation(lastItemEnd.x + 20, lastItemEnd.y);
|
---|
| 36 | itemCopy.setPosition(lastItemEnd.x, lastItemEnd.y);
|
---|
[4] | 37 | lastItemEnd = itemCopy
|
---|
[147] | 38 | .getParagraphEndPosition();
|
---|
[179] | 39 | itemCopy.setID(frame.getNextItemID());
|
---|
[4] | 40 | frame.addItem(itemCopy);
|
---|
| 41 | }
|
---|
[45] | 42 | _itemCount++;
|
---|
[108] | 43 | if(_stop)
|
---|
| 44 | return null;
|
---|
[4] | 45 | }
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
[45] | 50 | _frameCount++;
|
---|
[4] | 51 | return null;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|