source: trunk/src/org/expeditee/agents/SearchTree.java@ 156

Last change on this file since 156 was 156, checked in by ra33, 16 years ago

Added calculate action

File size: 1.6 KB
Line 
1package org.expeditee.agents;
2
3import java.util.Collection;
4import java.util.HashSet;
5
6import org.expeditee.gui.Frame;
7import org.expeditee.gui.FrameGraphics;
8import org.expeditee.gui.FrameIO;
9import org.expeditee.items.Text;
10
11public class SearchTree extends SearchAgent {
12 @Override
13 protected Frame process(Frame frame) {
14 try {
15 searchTree(new HashSet<String>(), _startName);
16 } catch (Exception e) {
17 e.printStackTrace();
18 }
19 _results.save();
20
21 String resultFrameName = _results.getName();
22 if (_clicked != null)
23 _clicked.setLink(resultFrameName);
24
25 return _results.getFirstFrame();
26 }
27
28 public boolean searchTree(Collection<String> visitedFrames, String frameName)
29 throws Exception {
30 if (_stop) {
31 return false;
32 }
33 // Avoid infinate loops
34 if (visitedFrames.contains(frameName))
35 return false;
36 visitedFrames.add(frameName);
37
38 Frame frameToSearch = FrameIO.LoadFrame(frameName);
39 if (frameToSearch == null)
40 return false;
41
42 overwriteMessage("Searching " + frameName);
43
44 for (Text itemToSearch : frameToSearch.getTextItems()) {
45 // Search for the item and add it to the results page if
46 // it is found
47 if (searchItem(itemToSearch, _pattern,
48 _replacementString)) {
49 // Add a linked item to the results frame
50 _results.addText(frameName, null, frameName, null, false);
51 }
52 if (!itemToSearch.isAnnotation()) {
53 String link = itemToSearch.getAbsoluteLink();
54 if (link != null) {
55 searchTree(visitedFrames, link);
56 }
57 }
58 }
59 FrameGraphics.requestRefresh(true);
60 FrameIO.SaveFrame(frameToSearch, false);
61 return true;
62 }
63}
Note: See TracBrowser for help on using the repository browser.