1   /**
2    * Distribution License:
3    * BibleDesktop is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU General Public License, version 2 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/gpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: TextPaneBookMetaDataDisplay.java 2140 2011-04-03 02:07:01Z dmsmith $
21   */
22  package org.crosswire.bibledesktop.book.install;
23  
24  import java.awt.Component;
25  
26  import javax.swing.JTextPane;
27  import javax.swing.text.html.HTMLEditorKit;
28  import javax.xml.transform.TransformerException;
29  
30  import org.crosswire.bibledesktop.desktop.XSLTProperty;
31  import org.crosswire.common.swing.AntiAliasedTextPane;
32  import org.crosswire.common.util.Logger;
33  import org.crosswire.common.util.Reporter;
34  import org.crosswire.common.xml.Converter;
35  import org.crosswire.common.xml.JDOMSAXEventProvider;
36  import org.crosswire.common.xml.SAXEventProvider;
37  import org.crosswire.common.xml.TransformingSAXEventProvider;
38  import org.crosswire.common.xml.XMLUtil;
39  import org.crosswire.jsword.book.Book;
40  import org.crosswire.jsword.util.ConverterFactory;
41  import org.xml.sax.SAXException;
42  
43  /**
44   * A JTextPane implementation of an OSIS displayer.
45   * 
46   * @see gnu.gpl.License for license details.<br>
47   *      The copyright to this program is held by it's authors.
48   * @author Joe Walker [joe at eireneh dot com]
49   * @author DM Smith [dmsmith555 at yahoo dot com]
50   */
51  public class TextPaneBookMetaDataDisplay {
52      /**
53       * Simple ctor
54       */
55      public TextPaneBookMetaDataDisplay() {
56          converter = ConverterFactory.getConverter();
57          txtView = new AntiAliasedTextPane();
58          txtView.setEditable(false);
59          txtView.setEditorKit(new HTMLEditorKit());
60      }
61  
62      /**
63       * Change the book being displayed to a new one.
64       * 
65       * @param book
66       */
67      public void setBook(Book book) {
68          if (book == null) {
69              txtView.setText("");
70              return;
71          }
72  
73          try {
74  
75              SAXEventProvider osissep = new JDOMSAXEventProvider(book.toOSIS());
76              TransformingSAXEventProvider htmlsep = (TransformingSAXEventProvider) converter.convert(osissep);
77              XSLTProperty.FONT.setProperty(htmlsep);
78              String text = XMLUtil.writeToString(htmlsep);
79  
80              txtView.setText(text);
81              txtView.select(0, 0);
82          } catch (SAXException e) {
83              Reporter.informUser(this, e);
84          } catch (TransformerException e) {
85              Reporter.informUser(this, e);
86          }
87      }
88  
89      /**
90       * Accessor for the Swing component
91       */
92      public Component getComponent() {
93          return txtView;
94      }
95  
96      /**
97       * The log stream
98       */
99      protected static final Logger log = Logger.getLogger(TextPaneBookMetaDataDisplay.class);
100 
101     /**
102      * To convert OSIS to HTML
103      */
104     private Converter converter;
105 
106     /**
107      * The display component
108      */
109     private JTextPane txtView;
110 
111 }
112