001: package org.columba.core.gui.search;
002:
003: import java.awt.BorderLayout;
004: import java.util.Iterator;
005: import java.util.List;
006:
007: import javax.swing.JPanel;
008:
009: import org.columba.core.gui.htmlviewer.HTMLViewerFactory;
010: import org.columba.core.gui.htmlviewer.api.IHTMLViewerPlugin;
011: import org.columba.core.search.api.IResultEvent;
012: import org.columba.core.search.api.IResultListener;
013: import org.columba.core.search.api.ISearchCriteria;
014: import org.columba.core.search.api.ISearchResult;
015:
016: public class HTMLResultView extends JPanel implements IResultListener {
017:
018: private IHTMLViewerPlugin viewerPlugin;
019:
020: private StringBuffer buf;
021:
022: public HTMLResultView() {
023: super ();
024:
025: viewerPlugin = HTMLViewerFactory.createHTMLViewer();
026:
027: setLayout(new BorderLayout());
028:
029: add(viewerPlugin.getContainer(), BorderLayout.CENTER);
030: }
031:
032: public void resultArrived(IResultEvent event) {
033: List<ISearchResult> result = event.getSearchResults();
034:
035: buf.append("<p>" + createCriteria(event.getSearchCriteria())
036: + "</p><br>");
037:
038: Iterator<ISearchResult> it = result.iterator();
039: while (it.hasNext()) {
040: ISearchResult r = it.next();
041: buf.append("<p>");
042: buf.append(createTitle(r));
043: buf.append("</p><p>");
044: buf.append(getDescription(r));
045: buf.append("</p><p><br></p>");
046: }
047:
048: StringBuffer doc = new StringBuffer();
049: startDocument(doc);
050: doc.append(buf.toString());
051: endDocument(doc);
052:
053: viewerPlugin.view(doc.toString());
054:
055: }
056:
057: private String createCriteria(ISearchCriteria r) {
058: return "Search Results for \"<font class=\"italic\">"
059: + r.getTitle() + "</font>\":";
060: }
061:
062: private String createTitle(ISearchResult r) {
063: return "<a href=\"" + r.getLocation().toString() + "\">"
064: + r.getTitle() + "</a>";
065: }
066:
067: private String getDescription(ISearchResult r) {
068: return "<font class=\"quoting\">" + r.getDescription()
069: + "</font>";
070: }
071:
072: public void clearSearch(IResultEvent event) {
073: buf = new StringBuffer();
074: viewerPlugin.view("");
075: }
076:
077: private void startDocument(StringBuffer b) {
078: String css = "<style type=\"text/css\">\n"
079: + "a { color: blue; text-decoration: underline }\n"
080: + "font.quoting {color:#949494;} \n font.italic {font-style:italic;color:#000;} \n"
081: + "</style>\n";
082:
083: b.append("<HTML><HEAD>" + css + "</HEAD><BODY>");
084: }
085:
086: private void endDocument(StringBuffer b) {
087: b.append("</P></BODY></HTML>");
088: }
089:
090: public void reset(IResultEvent event) {
091: buf = new StringBuffer();
092: viewerPlugin.view("");
093: }
094:
095: public void finished(IResultEvent event) {
096: // TODO Auto-generated method stub
097:
098: }
099:
100: }
|