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
.Story
;
10 import be
.nikiroo
.fanfix
.output
.BasicOutput
;
13 * This class can export a chapter into HTML3 code ready for Java Swing support.
17 public class GuiReaderViewerTextOutput
{
18 private StringBuilder builder
;
19 private BasicOutput output
;
20 private Story fakeStory
;
23 * Create a new {@link GuiReaderViewerTextOutput} that will convert a
24 * {@link Chapter} into HTML3 suited for Java Swing.
26 public GuiReaderViewerTextOutput() {
27 builder
= new StringBuilder();
28 fakeStory
= new Story();
30 output
= new BasicOutput() {
31 private boolean paraInQuote
;
34 protected void writeChapterHeader(Chapter chap
) throws IOException
{
35 builder
.append("<HTML>");
37 builder
.append("<H1>");
38 builder
.append("Chapter ");
39 builder
.append(chap
.getNumber());
41 builder
.append(chap
.getName());
42 builder
.append("</H1>");
44 builder
.append("<DIV align='justify'>");
48 protected void writeChapterFooter(Chapter chap
) throws IOException
{
50 builder
.append("</DIV>");
54 builder
.append("</DIV>");
55 builder
.append("</HTML>");
59 protected void writeParagraph(Paragraph para
) throws IOException
{
60 switch (para
.getType()) {
62 builder
.append(decorateText(para
.getContent()));
63 builder
.append("<BR>");
66 builder
.append("<BR>");
69 builder
.append("<BR>* * *<BR><BR>");
73 builder
.append("<DIV>");
75 builder
.append("</DIV>");
77 paraInQuote
= !paraInQuote
;
79 builder
.append("<DIV>");
80 builder
.append("– ");
81 builder
.append(decorateText(para
.getContent()));
82 builder
.append("</DIV>");
90 protected String
enbold(String word
) {
91 return "<B COLOR='BLUE'>" + word
+ "</B>";
95 protected String
italize(String word
) {
96 return "<I COLOR='GRAY'>" + word
+ "</I>";
102 * Convert the chapter into HTML3 code.
105 * the {@link Chapter} to convert.
107 * @return HTML3 code tested with Java Swing
109 public String
convert(Chapter chap
) {
110 builder
.setLength(0);
112 fakeStory
.setChapters(Arrays
.asList(chap
));
113 output
.process(fakeStory
, null, null);
114 } catch (IOException e
) {
115 Instance
.getTraceHandler().error(e
);
117 return builder
.toString();