/************************************************************************** /* A HTML GUI-component for presentation of search-results. /* /* Copyright (c) 2003-2004 by Bernhard Bablok (mail@bablokb.de) /* /* This library is free software; you can redistribute it and/or modify /* it under the terms of the GNU Lesser General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This library is distributed in the hope that it will be useful, but /* WITHOUT ANY WARRANTY; without even the implied warranty of /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /* GNU Lesser General Public License for more details. /* /* You should have received a copy of the GNU Lesser General Public License /* along with this library; see the file COPYING.LESSER. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ package de.bablokb.luala.lib.gui; import java.net.*; import java.awt.*; import java.io.*; import javax.swing.*; import javax.swing.event.*; import de.bablokb.luala.lib.event.*; /** A HTML GUI-component for presentation of search-results. @version $Revision: 1.7 $ @author $Author: bablokb $ */ public class HtmlResultView implements ResultView { ///////////////////////////////////////////////////////////////////////////// /** Default window-size constant. */ private final static int DEFAULT_WIDTH = 500, DEFAULT_HEIGHT = 500; //////////////////////////////////////////////////////////////////////////// /** The JEditorPane for the presentation of the results. This pane uses the HTMLEditorKit, since we want to use hyperlink events. */ private JEditorPane iResultPane; //////////////////////////////////////////////////////////////////////////// /** The {@link ShowDocumentEventListener}. We actually nead a list, but in most cases a single {@link ShowDocumentEventListener} should do. */ private ShowDocumentEventListener iListener; //////////////////////////////////////////////////////////////////////////// /** Create a HtmlResultView object. */ public HtmlResultView(URL page) throws IOException { iResultPane = new JEditorPane(page); iResultPane.setContentType("text/html"); iResultPane.setEditable(false); iResultPane.setPreferredSize(new Dimension(DEFAULT_WIDTH,DEFAULT_HEIGHT)); iResultPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (iListener != null && e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { iListener.showDocument( new ShowDocumentEvent(e.getSource(),e.getURL().toString())); } } } ); } //////////////////////////////////////////////////////////////////////////// /** {@inheritDoc} */ public JComponent getGUI() { return new JScrollPane(iResultPane); } //////////////////////////////////////////////////////////////////////////// /** {@inheritDoc} */ public void addShowDocumentEventListener(ShowDocumentEventListener sdel) { iListener = sdel; } //////////////////////////////////////////////////////////////////////////// /** {@inheritDoc} */ public void setData(Object data) { iResultPane.setText((String) data); } }