source: trunk/src/org/expeditee/agents/SwitchyardTree.java@ 919

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 2.3 KB
Line 
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
19package org.expeditee.agents;
20
21import java.awt.Color;
22import java.awt.geom.Point2D;
23
24import org.expeditee.gui.Frame;
25import org.expeditee.gui.FrameIO;
26import org.expeditee.items.Text;
27
28public class SwitchyardTree extends DefaultAgent {
29
30 @Override
31 protected Frame process(Frame frame) {
32 //MessageBay.displayMessage("Running switchyard tree...");
33
34 for (Text textItem : frame.getBodyTextItems(false)) {
35 // Delete all non-annotations with more that one letter
36 if (textItem.getText().length() > 1){
37 frame.removeItem(textItem);
38 if(_stop)
39 return null;
40 } else {
41 // goto child frame of any linked 1 letter items
42 String link = textItem.getAbsoluteLink();
43 if (link != null) {
44 Frame childFrame = FrameIO.LoadFrame(link);
45 if (childFrame != null) {
46 Point2D.Float lastItemEnd = textItem.getParagraphEndPosition();
47 for (Text childItem : childFrame.getBodyTextItems(false)) {
48 // look for red items (remember get color may be null
49 if (Color.RED.equals(childItem.getPaintColor())) {
50 // make a copy and add to parent frame
51 Text itemCopy = childItem.copy();
52 // add to the right of parent item
53 lastItemEnd.setLocation(lastItemEnd.x + 20, lastItemEnd.y);
54 itemCopy.setPosition(lastItemEnd.x, lastItemEnd.y);
55 lastItemEnd = itemCopy
56 .getParagraphEndPosition();
57 itemCopy.setID(frame.getNextItemID());
58 frame.addItem(itemCopy);
59 }
60 _itemCount++;
61 if(_stop)
62 return null;
63 }
64 }
65 }
66 }
67 }
68 _frameCount++;
69 return null;
70 }
71}
Note: See TracBrowser for help on using the repository browser.