[919] | 1 | /**
|
---|
| 2 | * SwitchyardTree.java
|
---|
| 3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
| 4 | *
|
---|
| 5 | * This program is free software: you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
[4] | 19 | package org.expeditee.agents;
|
---|
| 20 |
|
---|
[1102] | 21 | import org.expeditee.core.Colour;
|
---|
| 22 | import org.expeditee.core.Point;
|
---|
[4] | 23 | import org.expeditee.gui.Frame;
|
---|
| 24 | import org.expeditee.gui.FrameIO;
|
---|
| 25 | import org.expeditee.items.Text;
|
---|
| 26 |
|
---|
| 27 | public class SwitchyardTree extends DefaultAgent {
|
---|
| 28 |
|
---|
| 29 | @Override
|
---|
| 30 | protected Frame process(Frame frame) {
|
---|
[121] | 31 | //MessageBay.displayMessage("Running switchyard tree...");
|
---|
[4] | 32 |
|
---|
[19] | 33 | for (Text textItem : frame.getBodyTextItems(false)) {
|
---|
[4] | 34 | // Delete all non-annotations with more that one letter
|
---|
[108] | 35 | if (textItem.getText().length() > 1){
|
---|
[4] | 36 | frame.removeItem(textItem);
|
---|
[108] | 37 | if(_stop)
|
---|
| 38 | return null;
|
---|
[179] | 39 | } else {
|
---|
[4] | 40 | // goto child frame of any linked 1 letter items
|
---|
| 41 | String link = textItem.getAbsoluteLink();
|
---|
| 42 | if (link != null) {
|
---|
| 43 | Frame childFrame = FrameIO.LoadFrame(link);
|
---|
| 44 | if (childFrame != null) {
|
---|
[1102] | 45 | Point lastItemEnd = textItem.getParagraphEndPosition();
|
---|
[19] | 46 | for (Text childItem : childFrame.getBodyTextItems(false)) {
|
---|
[179] | 47 | // look for red items (remember get color may be null
|
---|
[1102] | 48 | if (Colour.RED.equals(childItem.getPaintColor())) {
|
---|
[4] | 49 | // make a copy and add to parent frame
|
---|
| 50 | Text itemCopy = childItem.copy();
|
---|
| 51 | // add to the right of parent item
|
---|
[1102] | 52 | lastItemEnd.set(lastItemEnd.x + 20, lastItemEnd.y);
|
---|
[108] | 53 | itemCopy.setPosition(lastItemEnd.x, lastItemEnd.y);
|
---|
[4] | 54 | lastItemEnd = itemCopy
|
---|
[147] | 55 | .getParagraphEndPosition();
|
---|
[179] | 56 | itemCopy.setID(frame.getNextItemID());
|
---|
[4] | 57 | frame.addItem(itemCopy);
|
---|
| 58 | }
|
---|
[45] | 59 | _itemCount++;
|
---|
[108] | 60 | if(_stop)
|
---|
| 61 | return null;
|
---|
[4] | 62 | }
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
[45] | 67 | _frameCount++;
|
---|
[4] | 68 | return null;
|
---|
| 69 | }
|
---|
| 70 | }
|
---|