9572566fe9e462a14efdb39c09f6dc42cc037612
1 package be
.nikiroo
.fanfix
.reader
;
4 import jexer
.event
.TResizeEvent
;
5 import be
.nikiroo
.fanfix
.Instance
;
6 import be
.nikiroo
.fanfix
.data
.Chapter
;
7 import be
.nikiroo
.fanfix
.data
.MetaData
;
8 import be
.nikiroo
.fanfix
.data
.Paragraph
;
9 import be
.nikiroo
.fanfix
.data
.Story
;
11 public class TuiReaderStoryWindow
extends TWindow
{
12 private MetaData meta
;
14 private TText textField
;
16 public TuiReaderStoryWindow(TApplication app
, MetaData meta
) {
17 super(app
, desc(meta
), 0, 0, 60, 18, CENTERED
| RESIZABLE
);
20 // /TODO: status bar with info, buttons to change chapter << < Chapter 0
21 // : xxx.. > >> (max size for name = getWith() - X)
23 // TODO: show all meta info before
24 // TODO: text.append("Resume:\n\n "); -> to status bar
26 // -2 because 0-based, 2 for borders, -1 to hide the HScroll
27 textField
= addText("", 0, 0, getWidth() - 2, getHeight() - 2);
29 Chapter resume
= getStory().getMeta().getResume();
31 for (Paragraph para
: resume
) {
32 // TODO: This is not efficient, should be changed
33 for (String line
: para
.getContent().split("\n")) {
34 textField
.addLine(line
);
39 statusBar
= newStatusBar(desc(meta
));
40 statusBar
.addShortcutKeypress(TKeypress
.kbF10
, TCommand
.cmExit
, "Exit");
42 // -3 because 0-based and 2 for borders
43 TButton first
= addButton("<<", 0, getHeight() - 3,
50 addButton("<", 3, getHeight() - 3, null);
51 addButton(">", 5, getHeight() - 3, null);
52 addButton(">>", 7, getHeight() - 3, null);
53 // TODO: pad with space up to end of window
54 // TODO: do not show "0/x: " for desc, only for other chapters
55 addLabel(String
.format(" %d/%d: %s", resume
.getNumber(), getStory().getChapters().size(), resume
.getName()), 11, getHeight() - 3);
59 public void onResize(TResizeEvent resize
) {
60 super.onResize(resize
);
62 // Resize the text field
63 textField
.setWidth(resize
.getWidth());
64 textField
.setHeight(resize
.getHeight() - 2);
68 private Story
getStory() {
71 story
= Instance
.getLibrary().getStory(meta
.getLuid(), null);
76 private static String
desc(MetaData meta
) {
77 return String
.format("%s: %s", meta
.getLuid(), meta
.getTitle());