Commit | Line | Data |
---|---|---|
c1873e56 NR |
1 | package be.nikiroo.fanfix.reader; |
2 | ||
396e924c | 3 | import jexer.*; |
c1873e56 NR |
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; | |
10 | ||
11 | public class TuiReaderStoryWindow extends TWindow { | |
12 | private MetaData meta; | |
13 | private Story story; | |
14 | private TText textField; | |
15 | ||
16 | public TuiReaderStoryWindow(TApplication app, MetaData meta) { | |
17 | super(app, desc(meta), 0, 0, 60, 18, CENTERED | RESIZABLE); | |
18 | this.meta = meta; | |
19 | ||
20 | // /TODO: status bar with info, buttons to change chapter << < Chapter 0 | |
21 | // : xxx.. > >> (max size for name = getWith() - X) | |
22 | ||
23 | // TODO: show all meta info before | |
396e924c NR |
24 | // TODO: text.append("Resume:\n\n "); -> to status bar |
25 | ||
26 | // -2 because 0-based, 2 for borders, -1 to hide the HScroll | |
27 | textField = addText("", 0, 0, getWidth() - 2, getHeight() - 2); | |
28 | ||
c1873e56 | 29 | Chapter resume = getStory().getMeta().getResume(); |
c1873e56 | 30 | if (resume != null) { |
c1873e56 | 31 | for (Paragraph para : resume) { |
396e924c NR |
32 | // TODO: This is not efficient, should be changed |
33 | for (String line : para.getContent().split("\n")) { | |
34 | textField.addLine(line); | |
35 | } | |
c1873e56 NR |
36 | } |
37 | } | |
396e924c NR |
38 | |
39 | statusBar = newStatusBar(desc(meta)); | |
40 | statusBar.addShortcutKeypress(TKeypress.kbF10, TCommand.cmExit, "Exit"); | |
41 | ||
42 | // -3 because 0-based and 2 for borders | |
43 | TButton first = addButton("<<", 0, getHeight() - 3, | |
44 | new TAction() { | |
45 | public void DO() { | |
46 | // TODO | |
47 | } | |
48 | } | |
49 | ); | |
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); | |
c1873e56 NR |
56 | } |
57 | ||
58 | @Override | |
59 | public void onResize(TResizeEvent resize) { | |
60 | super.onResize(resize); | |
61 | ||
62 | // Resize the text field | |
63 | textField.setWidth(resize.getWidth()); | |
396e924c | 64 | textField.setHeight(resize.getHeight() - 2); |
c1873e56 NR |
65 | textField.reflow(); |
66 | } | |
67 | ||
68 | private Story getStory() { | |
69 | if (story == null) { | |
70 | // TODO: progress bar | |
71 | story = Instance.getLibrary().getStory(meta.getLuid(), null); | |
72 | } | |
73 | return story; | |
74 | } | |
75 | ||
76 | private static String desc(MetaData meta) { | |
77 | return String.format("%s: %s", meta.getLuid(), meta.getTitle()); | |
78 | } | |
79 | } |