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 |
|
---|
19 | package org.expeditee.agents;
|
---|
20 |
|
---|
21 | import org.expeditee.core.Colour;
|
---|
22 | import org.expeditee.core.Point;
|
---|
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) {
|
---|
31 | //MessageBay.displayMessage("Running switchyard tree...");
|
---|
32 |
|
---|
33 | for (Text textItem : frame.getBodyTextItems(false)) {
|
---|
34 | // Delete all non-annotations with more that one letter
|
---|
35 | if (textItem.getText().length() > 1){
|
---|
36 | frame.removeItem(textItem);
|
---|
37 | if(_stop)
|
---|
38 | return null;
|
---|
39 | } else {
|
---|
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) {
|
---|
45 | Point lastItemEnd = textItem.getParagraphEndPosition();
|
---|
46 | for (Text childItem : childFrame.getBodyTextItems(false)) {
|
---|
47 | // look for red items (remember get color may be null
|
---|
48 | if (Colour.RED.equals(childItem.getPaintColor())) {
|
---|
49 | // make a copy and add to parent frame
|
---|
50 | Text itemCopy = childItem.copy();
|
---|
51 | // add to the right of parent item
|
---|
52 | lastItemEnd.set(lastItemEnd.x + 20, lastItemEnd.y);
|
---|
53 | itemCopy.setPosition(lastItemEnd.x, lastItemEnd.y);
|
---|
54 | lastItemEnd = itemCopy
|
---|
55 | .getParagraphEndPosition();
|
---|
56 | itemCopy.setID(frame.getNextItemID());
|
---|
57 | frame.addItem(itemCopy);
|
---|
58 | }
|
---|
59 | _itemCount++;
|
---|
60 | if(_stop)
|
---|
61 | return null;
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 | _frameCount++;
|
---|
68 | return null;
|
---|
69 | }
|
---|
70 | }
|
---|