From: Niki Roo Date: Mon, 11 May 2020 22:11:49 +0000 (+0200) Subject: update viewer text for fanfix/utils update X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=cdc9ad9a9e88616c65400a4ef0dfaed883ce270d;p=fanfix-swing.git update viewer text for fanfix/utils update --- diff --git a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerNonImages.java b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerNonImages.java index f72524ee..cdbaf027 100644 --- a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerNonImages.java +++ b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerNonImages.java @@ -24,6 +24,7 @@ import be.nikiroo.fanfix.bundles.StringIdGui; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix.reader.TextOutput; import be.nikiroo.fanfix_swing.gui.PropertiesPanel; import be.nikiroo.fanfix_swing.gui.utils.UiHelper; import be.nikiroo.fanfix_swing.images.IconGenerator; @@ -46,7 +47,7 @@ public class ViewerNonImages extends JFrame { private BasicLibrary lib; private Story story; - private ViewerTextOutput html; + private TextOutput html; /** The navigation bar. */ protected NavBar navbar; @@ -79,7 +80,7 @@ public class ViewerNonImages extends JFrame { this.setSize(800, 600); - html = new ViewerTextOutput(); + html = new TextOutput(true); worker = new DelayWorker(100); worker.start(); diff --git a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerTextOutput.java b/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerTextOutput.java deleted file mode 100644 index 82f0a97b..00000000 --- a/src/be/nikiroo/fanfix_swing/gui/viewer/ViewerTextOutput.java +++ /dev/null @@ -1,140 +0,0 @@ -package be.nikiroo.fanfix_swing.gui.viewer; - -import java.io.IOException; -import java.util.Arrays; - -import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.data.Chapter; -import be.nikiroo.fanfix.data.Paragraph; -import be.nikiroo.fanfix.data.Paragraph.ParagraphType; -import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.output.BasicOutput; - -/** - * This class can export a chapter into HTML3 code ready for Java Swing support. - * - * @author niki - */ -class ViewerTextOutput { - private StringBuilder builder; - private BasicOutput output; - private Story fakeStory; - private boolean chapterName; - - /** - * Create a new {@link ViewerTextOutput} that will convert a {@link Chapter} - * into HTML3 suited for Java Swing. - */ - public ViewerTextOutput() { - builder = new StringBuilder(); - fakeStory = new Story(); - - output = new BasicOutput() { - private boolean paraInQuote; - - @Override - protected void writeChapterHeader(Chapter chap) throws IOException { - builder.append(""); - - if (chapterName) { - builder.append("

"); - builder.append("Chapter "); - builder.append(chap.getNumber()); - if (chap.getName() != null - && !chap.getName().trim().isEmpty()) { - builder.append(": "); - builder.append(chap.getName()); - } - builder.append("

"); - } - - builder.append("
"); - } - - @Override - protected void writeChapterFooter(Chapter chap) throws IOException { - if (paraInQuote) { - builder.append("
"); - } - paraInQuote = false; - - builder.append(""); - builder.append(""); - } - - @Override - protected void writeParagraph(Paragraph para) throws IOException { - if ((para.getType() == ParagraphType.QUOTE) == !paraInQuote) { - paraInQuote = !paraInQuote; - if (paraInQuote) { - builder.append("
"); - builder.append("
"); - } else { - builder.append("
"); - builder.append("
"); - } - } - - switch (para.getType()) { - case NORMAL: - builder.append("    "); - builder.append(decorateText(para.getContent())); - builder.append("
"); - break; - case BLANK: - builder.append("
"); - break; - case BREAK: - // Used to be 7777DD - builder.append("

"); - builder.append("* * *"); - builder.append("

"); - builder.append("
"); - break; - case QUOTE: - builder.append("
"); - builder.append("    "); - builder.append("— "); - builder.append(decorateText(para.getContent())); - builder.append("
"); - - break; - case IMAGE: - } - } - - @Override - protected String enbold(String word) { - // Used to be COLOR='#7777DD' - return "" + word + ""; - } - - @Override - protected String italize(String word) { - return "" + word + ""; - } - }; - } - - /** - * Convert the chapter into HTML3 code. - * - * @param chap - * the {@link Chapter} to convert - * @param chapterName - * display the chapter name - * - * @return HTML3 code tested with Java Swing - */ - public String convert(Chapter chap, boolean chapterName) { - this.chapterName = chapterName; - builder.setLength(0); - try { - fakeStory.setChapters(Arrays.asList(chap)); - output.process(fakeStory, null, null); - } catch (IOException e) { - Instance.getInstance().getTraceHandler().error(e); - } - return builder.toString(); - } -}