X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FTuiReaderStoryWindow.java;h=f556a4b7a77edefd8e808a692dc1111f4fe59a79;hb=68e2c6d20049d713de1bd31b749450b2f60d8340;hp=9613e63258c4c6bdbd7ad5f851842509d4d3bdb7;hpb=edfd3577ad35ca77bc0312849c6f4ccfe3394a5f;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java b/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java index 9613e63..f556a4b 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java +++ b/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java @@ -3,15 +3,25 @@ package be.nikiroo.fanfix.reader; import java.util.ArrayList; import java.util.List; -import jexer.*; +import jexer.TAction; +import jexer.TApplication; +import jexer.TButton; +import jexer.TCommand; +import jexer.TKeypress; +import jexer.TLabel; +import jexer.TText; +import jexer.TWindow; import jexer.event.TResizeEvent; +import be.nikiroo.fanfix.BasicLibrary; import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.LocalLibrary; import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; import be.nikiroo.fanfix.data.Story; public class TuiReaderStoryWindow extends TWindow { + private BasicLibrary lib; private MetaData meta; private Story story; private TText textField; @@ -19,49 +29,60 @@ public class TuiReaderStoryWindow extends TWindow { private List navigationButtons; private TLabel chapterName; - public TuiReaderStoryWindow(TApplication app, MetaData meta) { - this(app, meta, 0); + public TuiReaderStoryWindow(TApplication app, BasicLibrary lib, + MetaData meta) { + this(app, lib, meta, 0); } - public TuiReaderStoryWindow(TApplication app, MetaData meta, int chapter) { + public TuiReaderStoryWindow(TApplication app, BasicLibrary lib, + MetaData meta, int chapter) { super(app, desc(meta), 0, 0, 60, 18, CENTERED | RESIZABLE); + + this.lib = lib; this.meta = meta; // TODO: show all meta info before? - // -2 because 0-based, 2 for borders, -1 to hide the HScroll - textField = addText("", 0, 0, getWidth() - 2, getHeight() - 2); + textField = new TText(this, "", 0, 0, getWidth() - 2, getHeight() - 2); statusBar = newStatusBar(desc(meta)); statusBar.addShortcutKeypress(TKeypress.kbF10, TCommand.cmExit, "Exit"); - navigationButtons = new ArrayList(4); + navigationButtons = new ArrayList(5); // -3 because 0-based and 2 for borders int row = getHeight() - 3; - navigationButtons.add(addButton("<<", 0, row, new TAction() { + navigationButtons.add(addButton(" ", 0, row, null)); // for bg colour + // when << + // button is + // pressed + navigationButtons.add(addButton("<< ", 0, row, new TAction() { public void DO() { setChapter(0); } })); - navigationButtons.add(addButton("<", 3, row, new TAction() { + navigationButtons.add(addButton("< ", 4, row, new TAction() { public void DO() { setChapter(TuiReaderStoryWindow.this.chapter - 1); } })); - navigationButtons.add(addButton(">", 5, row, new TAction() { + navigationButtons.add(addButton("> ", 7, row, new TAction() { public void DO() { setChapter(TuiReaderStoryWindow.this.chapter + 1); } })); - navigationButtons.add(addButton(">>", 7, row, new TAction() { + navigationButtons.add(addButton(">> ", 10, row, new TAction() { public void DO() { setChapter(getStory().getChapters().size()); } })); - chapterName = addLabel("", 11, row); + navigationButtons.get(0).setEnabled(false); + navigationButtons.get(1).setEnabled(false); + navigationButtons.get(2).setEnabled(false); + + chapterName = addLabel("", 14, row); chapterName.setWidth(getWidth() - 10); setChapter(chapter); } @@ -71,7 +92,7 @@ public class TuiReaderStoryWindow extends TWindow { super.onResize(resize); // Resize the text field - textField.setWidth(resize.getWidth()); + textField.setWidth(resize.getWidth() - 2); textField.setHeight(resize.getHeight() - 2); textField.reflow(); @@ -102,6 +123,14 @@ public class TuiReaderStoryWindow extends TWindow { if (chapter != this.chapter) { this.chapter = chapter; + + int max = getStory().getChapters().size(); + navigationButtons.get(0).setEnabled(chapter > 0); + navigationButtons.get(1).setEnabled(chapter > 0); + navigationButtons.get(2).setEnabled(chapter > 0); + navigationButtons.get(3).setEnabled(chapter < max); + navigationButtons.get(4).setEnabled(chapter < max); + Chapter chap; String name; if (chapter == 0) { @@ -109,8 +138,8 @@ public class TuiReaderStoryWindow extends TWindow { name = String.format(" %s", chap.getName()); } else { chap = getStory().getChapters().get(chapter - 1); - name = String.format(" %d/%d: %s", chapter, getStory() - .getChapters().size(), chap.getName()); + name = String + .format(" %d/%d: %s", chapter, max, chap.getName()); } while (name.length() < getWidth() - chapterName.getX()) { @@ -132,13 +161,14 @@ public class TuiReaderStoryWindow extends TWindow { } textField.setText(builder.toString()); textField.reflow(); + textField.toTop(); } } private Story getStory() { if (story == null) { // TODO: progress bar? - story = Instance.getLibrary().getStory(meta.getLuid(), null); + story = lib.getStory(meta.getLuid(), null); } return story; }