1 package be
.nikiroo
.fanfix
.reader
.ui
;
3 import java
.io
.IOException
;
4 import java
.util
.Arrays
;
6 import be
.nikiroo
.fanfix
.Instance
;
7 import be
.nikiroo
.fanfix
.data
.Chapter
;
8 import be
.nikiroo
.fanfix
.data
.Paragraph
;
9 import be
.nikiroo
.fanfix
.data
.Paragraph
.ParagraphType
;
10 import be
.nikiroo
.fanfix
.data
.Story
;
11 import be
.nikiroo
.fanfix
.output
.BasicOutput
;
14 * This class can export a chapter into HTML3 code ready for Java Swing support.
18 public class GuiReaderViewerTextOutput
{
19 private StringBuilder builder
;
20 private BasicOutput output
;
21 private Story fakeStory
;
24 * Create a new {@link GuiReaderViewerTextOutput} that will convert a
25 * {@link Chapter} into HTML3 suited for Java Swing.
27 public GuiReaderViewerTextOutput() {
28 builder
= new StringBuilder();
29 fakeStory
= new Story();
31 output
= new BasicOutput() {
32 private boolean paraInQuote
;
35 protected void writeChapterHeader(Chapter chap
) throws IOException
{
36 builder
.append("<HTML>");
38 builder
.append("<H1>");
39 builder
.append("Chapter ");
40 builder
.append(chap
.getNumber());
42 builder
.append(chap
.getName());
43 builder
.append("</H1>");
45 builder
.append("<DIV align='justify'>");
49 protected void writeChapterFooter(Chapter chap
) throws IOException
{
51 builder
.append("</DIV>");
55 builder
.append("</DIV>");
56 builder
.append("</HTML>");
60 protected void writeParagraph(Paragraph para
) throws IOException
{
61 if ((para
.getType() == ParagraphType
.QUOTE
) == !paraInQuote
) {
62 paraInQuote
= !paraInQuote
;
64 builder
.append("<BR>");
65 builder
.append("<DIV>");
67 builder
.append("</DIV>");
68 builder
.append("<BR>");
72 switch (para
.getType()) {
74 builder
.append(" ");
75 builder
.append(decorateText(para
.getContent()));
76 builder
.append("<BR>");
79 builder
.append("<BR><BR>");
82 builder
.append("<BR><P COLOR='#7777DD' ALIGN='CENTER'><B>");
83 builder
.append("* * *");
84 builder
.append("</B></P><BR><BR>");
87 builder
.append("<DIV>");
88 builder
.append(" ");
89 builder
.append("— ");
90 builder
.append(decorateText(para
.getContent()));
91 builder
.append("</DIV>");
99 protected String
enbold(String word
) {
100 return "<B COLOR='#7777DD'>" + word
+ "</B>";
104 protected String
italize(String word
) {
105 return "<I COLOR='GRAY'>" + word
+ "</I>";
111 * Convert the chapter into HTML3 code.
114 * the {@link Chapter} to convert.
116 * @return HTML3 code tested with Java Swing
118 public String
convert(Chapter chap
) {
119 builder
.setLength(0);
121 fakeStory
.setChapters(Arrays
.asList(chap
));
122 output
.process(fakeStory
, null, null);
123 } catch (IOException e
) {
124 Instance
.getTraceHandler().error(e
);
126 return builder
.toString();