Source code: com/eireneh/bible/view/swing/beans/PassageInnerPane.java
1 package com.eireneh.bible.view.swing.beans;
2
3 import java.io.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import javax.swing.*;
7 import javax.swing.event.*;
8 import javax.swing.text.html.*;
9
10 import org.jdom.*;
11 import org.xml.sax.SAXException;
12
13 import com.eireneh.util.*;
14 import com.eireneh.bible.util.*;
15 import com.eireneh.bible.book.*;
16 import com.eireneh.bible.passage.*;
17
18 /**
19 * An inner component of Passage pane that can't show the list.
20 *
21 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
22 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
23 * Distribution Licence:<br />
24 * Project B is free software; you can redistribute it
25 * and/or modify it under the terms of the GNU General Public License,
26 * version 2 as published by the Free Software Foundation.<br />
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 * General Public License for more details.<br />
31 * The License is available on the internet
32 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
33 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
34 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
35 * The copyright to this program is held by it's authors.
36 * </font></td></tr></table>
37 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
38 * @see docs.Licence
39 * @author Joe Walker
40 * @version $Id:$
41 */
42 public class PassageInnerPane extends JPanel
43 {
44 /**
45 * Simple Constructor
46 */
47 public PassageInnerPane()
48 {
49 jbInit();
50 }
51
52 /**
53 * Gui creation
54 */
55 private void jbInit()
56 {
57 txt_view.setEditable(false);
58 txt_view.setEditorKit(new HTMLEditorKit());
59 txt_view.addHyperlinkListener(new HyperlinkListener()
60 {
61 public void hyperlinkUpdate(HyperlinkEvent ev) { link(ev); }
62 });
63 scr_view.getViewport().setPreferredSize(new Dimension(500, 400));
64 scr_view.getViewport().add(txt_view, null);
65
66 this.setLayout(new BorderLayout());
67 this.add(scr_view, BorderLayout.CENTER);
68 }
69
70 /**
71 * Set the version used for lookup
72 */
73 public void setVersion(Bible version)
74 {
75 this.version = version;
76 }
77
78 /**
79 * Set the passage being viewed
80 */
81 public void setPassage(Passage ref) throws IOException, SAXException, BookException
82 {
83 Element root = version.getElement(ref);
84 Document xml = new Document(root);
85
86 String text = style.applyStyleString(xml, "Simple");
87
88 txt_view.setText(text);
89 }
90
91 /**
92 * When a hyperlink is clicked
93 */
94 public void link(HyperlinkEvent ev)
95 {
96 log.warning("No listener for "+ev.getURL());
97 }
98
99 /**
100 * Forward the mouse listener to our child components
101 */
102 public void removeMouseListener(MouseListener li)
103 {
104 txt_view.removeMouseListener(li);
105 }
106
107 /**
108 * Forward the mouse listener to our child components
109 */
110 public void addMouseListener(MouseListener li)
111 {
112 txt_view.addMouseListener(li);
113 }
114
115 /** What is being displayed */
116 private Passage ref = null;
117 private Bible version = null;
118 private Style style = new Style("swing");
119
120 /** The log stream */
121 protected static Logger log = Logger.getLogger("bible.view");
122
123 private JScrollPane scr_view = new JScrollPane();
124 private JEditorPane txt_view = new JEditorPane();
125 }