--- /dev/null
+package be.nikiroo.fanfix_swing.gui.search;
+
+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 COPY_OF_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 COPY_OF_ViewerTextOutput() {
+ builder = new StringBuilder();
+ fakeStory = new Story();
+
+ output = new BasicOutput() {
+ private boolean paraInQuote;
+
+ @Override
+ protected void writeChapterHeader(Chapter chap) throws IOException {
+ builder.append("<HTML style='line-height: normal;'>");
+
+ if (chapterName) {
+ builder.append("<H1>");
+ builder.append("Chapter ");
+ builder.append(chap.getNumber());
+ if (chap.getName() != null
+ && !chap.getName().trim().isEmpty()) {
+ builder.append(": ");
+ builder.append(chap.getName());
+ }
+ builder.append("</H1>");
+ }
+
+ builder.append("<DIV align='justify'>");
+ }
+
+ @Override
+ protected void writeChapterFooter(Chapter chap) throws IOException {
+ if (paraInQuote) {
+ builder.append("</DIV>");
+ }
+ paraInQuote = false;
+
+ builder.append("</DIV>");
+ builder.append("</HTML>");
+ }
+
+ @Override
+ protected void writeParagraph(Paragraph para) throws IOException {
+ if ((para.getType() == ParagraphType.QUOTE) == !paraInQuote) {
+ paraInQuote = !paraInQuote;
+ if (paraInQuote) {
+ builder.append("<BR>");
+ builder.append("<DIV>");
+ } else {
+ builder.append("</DIV>");
+ builder.append("<BR>");
+ }
+ }
+
+ switch (para.getType()) {
+ case NORMAL:
+ builder.append(" ");
+ builder.append(decorateText(para.getContent()));
+ builder.append("<BR>");
+ break;
+ case BLANK:
+ builder.append("<BR><BR>");
+ break;
+ case BREAK:
+ builder.append("<BR><P COLOR='#7777DD' ALIGN='CENTER'><B>");
+ builder.append("* * *");
+ builder.append("</B></P><BR><BR>");
+ break;
+ case QUOTE:
+ builder.append("<DIV>");
+ builder.append(" ");
+ builder.append("— ");
+ builder.append(decorateText(para.getContent()));
+ builder.append("</DIV>");
+
+ break;
+ case IMAGE:
+ }
+ }
+
+ @Override
+ protected String enbold(String word) {
+ return "<B COLOR='#7777DD'>" + word + "</B>";
+ }
+
+ @Override
+ protected String italize(String word) {
+ return "<I COLOR='GRAY'>" + word + "</I>";
+ }
+ };
+ }
+
+ /**
+ * 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();
+ }
+}
import be.nikiroo.fanfix_swing.gui.PropertiesPanel;
import be.nikiroo.fanfix_swing.gui.book.BookInfo;
import be.nikiroo.fanfix_swing.gui.utils.UiHelper;
-import be.nikiroo.fanfix_swing.gui.viewer.TODEL_ViewerPanel;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.ui.ProgressBar;
-package be.nikiroo.fanfix_swing.gui.viewer;
+package be.nikiroo.fanfix_swing.gui.search;
import java.awt.BorderLayout;
import java.awt.EventQueue;
private boolean imageDocument;
private Chapter chap;
private JScrollPane scroll;
- private ViewerTextOutput htmlOutput;
+ private COPY_OF_ViewerTextOutput htmlOutput;
// text only:
private JEditorPane text;
this.text = new JEditorPane("text/html", "");
text.setEditable(false);
text.setAlignmentY(TOP_ALIGNMENT);
- htmlOutput = new ViewerTextOutput();
+ htmlOutput = new COPY_OF_ViewerTextOutput();
image = new JLabel();
image.setHorizontalAlignment(SwingConstants.CENTER);
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
+import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
-import be.nikiroo.fanfix_swing.images.IconGenerator;
-import be.nikiroo.fanfix_swing.images.IconGenerator.Icon;
-import be.nikiroo.fanfix_swing.images.IconGenerator.Size;
import be.nikiroo.utils.ui.ListenerPanel;
/**
setLayout(layout);
// Page navigation
- first = new JButton(
- IconGenerator.get(Icon.arrow_double_left, Size.x32));
+ first = new JButton();
first.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
- previous = new JButton(IconGenerator.get(Icon.arrow_left, Size.x32));
+ previous = new JButton();
previous.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
maxPage = new JLabel(" of " + max);
- next = new JButton(IconGenerator.get(Icon.arrow_right, Size.x32));
+ next = new JButton();
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
- last = new JButton(
- IconGenerator.get(Icon.arrow_double_right, Size.x32));
+ last = new JButton();
last.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
+ // Set the << < > >> "icons"
+ setIcons(null, null, null, null);
+
this.add(first);
this.add(previous);
this.add(page);
return false;
}
+ /**
+ * Set icons for the buttons instead of square brackets.
+ * <p>
+ * Any NULL value will make the button use square brackets again.
+ *
+ * @param first
+ * the icon of the button "go to first page"
+ * @param previous
+ * the icon of the button "go to previous page"
+ * @param next
+ * the icon of the button "go to next page"
+ * @param last
+ * the icon of the button "go to last page"
+ */
+ public void setIcons(Icon first, Icon previous, Icon next, Icon last) {
+ this.first.setIcon(first);
+ this.first.setText(first == null ? "<<" : "");
+ this.previous.setIcon(previous);
+ this.previous.setText(previous == null ? "<" : "");
+ this.next.setIcon(next);
+ this.next.setText(next == null ? ">" : "");
+ this.last.setIcon(last);
+ this.last.setText(last == null ? ">>" : "");
+ }
+
/**
* Update the label displayed in the UI.
*/
import be.nikiroo.fanfix.library.BasicLibrary;
import be.nikiroo.fanfix_swing.gui.PropertiesPanel;
import be.nikiroo.fanfix_swing.gui.utils.UiHelper;
+import be.nikiroo.fanfix_swing.images.IconGenerator;
+import be.nikiroo.fanfix_swing.images.IconGenerator.Icon;
+import be.nikiroo.fanfix_swing.images.IconGenerator.Size;
import be.nikiroo.utils.ui.DelayWorker;
import be.nikiroo.utils.ui.UIUtils;
private JToolBar createToolBar() {
JToolBar toolbar = new JToolBar();
navbar = new NavBar(0, story.getChapters().size());
+ navbar.setIcons( //
+ IconGenerator.get(Icon.arrow_double_left, Size.x32), //
+ IconGenerator.get(Icon.arrow_left, Size.x32), //
+ IconGenerator.get(Icon.arrow_right, Size.x32), //
+ IconGenerator.get(Icon.arrow_double_right, Size.x32) //
+ );
toolbar.add(navbar);
return toolbar;
}