001: package bdd.search;
002:
003: import java.awt.Frame;
004: import java.awt.Panel;
005: import java.awt.List;
006: import java.awt.BorderLayout;
007: import java.awt.FlowLayout;
008: import java.awt.Label;
009: import java.awt.Checkbox;
010: import java.awt.GridLayout;
011: import java.awt.Button;
012: import java.awt.Event;
013: import java.net.URL;
014: import bdd.search.spider.Crawler;
015: import bdd.search.query.QueryWebServer;
016:
017: /** Written by Tim Macinta 1997 <br>
018: * Distributed under the GNU Public License
019: * (a copy of which is enclosed with the source). <br>
020: * <br>
021: * Provides a graphical monitor to watch the progress of
022: * the crawler and the search engine.
023: */
024:
025: public class Monitor extends Frame {
026:
027: EnginePrefs prefs; // preferences
028: List query_list; // list of queries
029: List url_list; // list of indexed URLs
030: List error_list; // list of URLs with errors
031: Checkbox track_queries;
032: Checkbox track_urls;
033: Button clear_urls;
034: Button clear_queries;
035: Button start_crawler;
036: Label current_url;
037: Label bytes_indexed;
038:
039: /** Starts a monitor with the custom web server running on the default
040: * port. */
041: public Monitor() {
042: this (EnginePrefs.port);
043: }
044:
045: /** Starts a monitor with the custom web server running on the
046: * specified port. */
047: public Monitor(int port) {
048: super ("BDDBot");
049: prefs = new EnginePrefs();
050: Panel p = new Panel();
051: setLayout(new GridLayout(0, 1));
052:
053: // set up query monitor
054:
055: add(p);
056: p.setLayout(new BorderLayout());
057: Panel p2 = new Panel();
058: p2.setLayout(new FlowLayout());
059: p.add("North", p2);
060: p.add("Center", query_list = new List());
061: p2
062: .add(track_queries = new Checkbox("Watch Queries",
063: null, true));
064: p2.add(clear_queries = new Button("Clear List"));
065: p2.add(start_crawler = new Button("Start Crawler"));
066: p.add("South", new Label("_______________________________",
067: Label.CENTER));
068:
069: // set up spider monitor
070:
071: add(p = new Panel());
072: p.setLayout(new BorderLayout());
073: p.add("North", p2 = new Panel());
074: p2.setLayout(new GridLayout(0, 1));
075: p2.add(current_url = new Label("Current URL:"));
076: p2.add(bytes_indexed = new Label("Total Bytes: 0"));
077: p.add("Center", url_list = new List());
078: add(p = new Panel());
079: p.setLayout(new BorderLayout());
080: p.add("Center", error_list = new List());
081: p2 = new Panel();
082: p2.setLayout(new FlowLayout());
083: p2.add(track_urls = new Checkbox("Watch Indexed URLs", null,
084: true));
085: p2.add(clear_urls = new Button("Clear URL List"));
086: p.add("South", p2);
087:
088: // work around a bug in the Java 1.0 List
089:
090: for (int i = 0; i < 200; i++) {
091: query_list.addItem("");
092: url_list.addItem("");
093: error_list.addItem("");
094: }
095: resize(408, 469);
096: show(); // display this monitor
097: clearQueryList();
098: clearURLList();
099: clearErrorList();
100:
101: // register this monitor and start the web server
102:
103: prefs.monitor = this ;
104: new QueryWebServer(port, prefs);
105: }
106:
107: public boolean action(Event evt, Object what) {
108: if (evt.target == clear_urls) {
109: clearURLList();
110: clearErrorList();
111: } else if (evt.target == clear_queries) {
112: clearQueryList();
113: } else if (evt.target == start_crawler) {
114: start_crawler.disable();
115: Crawler.main(prefs.getStartingFile(), prefs);
116: }
117: return super .action(evt, what);
118: }
119:
120: /** Call this method when a new URL is being indexed. */
121: public void indexing(URL current_url) {
122: if (track_urls.getState()) {
123: String u = current_url.toString();
124: url_list.addItem(u);
125: this .current_url.setText("Current URL: " + u);
126: this .url_list.makeVisible(this .url_list.countItems() - 1);
127: }
128: }
129:
130: /** Call this method when a new query is being placed. */
131: public void querying(String words) {
132: if (track_queries.getState()) {
133: query_list.addItem(words);
134: if (query_list.countItems() > 201) {
135: query_list.delItem(2);
136: }
137: query_list.makeVisible(query_list.countItems() - 1);
138: }
139: }
140:
141: /** Call this method to report an error during crawling. */
142: public void reportError(URL bad_url) {
143: if (track_urls.getState()) {
144: error_list.addItem(bad_url.toString());
145: error_list.makeVisible(error_list.countItems() - 1);
146: }
147: }
148:
149: /** Call this method when a crawler has finished crawling. */
150: public void crawlerDone(Crawler c) {
151: start_crawler.enable();
152: }
153:
154: public void clearURLList() {
155: url_list.clear();
156: url_list.addItem("Processed");
157: url_list.addItem("---------");
158: }
159:
160: public void clearErrorList() {
161: error_list.clear();
162: error_list.addItem("Errors");
163: error_list.addItem("------");
164: }
165:
166: public void clearQueryList() {
167: query_list.clear();
168: query_list.addItem("Queries");
169: query_list.addItem("-------");
170: }
171:
172: public void bytesIndexed(long total_bytes) {
173: this .bytes_indexed.setText("Total Bytes: " + total_bytes);
174: }
175:
176: public static void main(String arg[]) {
177: new Monitor();
178: }
179:
180: }
|