01: package snow.html;
02:
03: import javax.swing.*;
04: import javax.swing.event.*;
05: import javax.swing.text.*;
06: import java.awt.*;
07:
08: /** Just a primitive viewer with a statusbar
09: */
10: public class HTMLViewer extends JPanel implements HyperlinkListener {
11:
12: final private JTextPane textPane = new JTextPane();
13: final private JTextField statusBar = new JTextField(); // Better than JLabel : can be copy pasted
14:
15: public HTMLViewer() {
16: super (new BorderLayout(0, 0));
17: add(new JScrollPane(textPane), BorderLayout.CENTER);
18: textPane.setEditable(false);
19: textPane.setContentType("text/html");
20: add(statusBar, BorderLayout.SOUTH);
21: statusBar.setEditable(false);
22:
23: textPane.addHyperlinkListener(this );
24: } // Constructor
25:
26: public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent hle) {
27: if (hle.getURL() != null) {
28: statusBar.setText("URL: " + hle.getURL());
29: } else {
30: statusBar.setText(hle.getDescription());
31: }
32: }
33:
34: public void setHTMLContent(String cont) {
35: textPane.setText(cont);
36: textPane.setCaretPosition(0);
37: statusBar.setText("");
38: }
39:
40: }
|