X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FTuiReaderStoryWindow.java;h=2b1cace8ba817462473e3bb067ce77010e044d78;hb=5dd985cf7d5e2bb88b07fd43e7b4a4eda4647181;hp=26c1917deb441cf3939b3d669fcbdf89cc2c3323;hpb=0b7e3d78f5e9608540d0f506f31f342823ee0f27;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java b/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java index 26c1917..2b1cace 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java +++ b/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java @@ -9,34 +9,39 @@ import jexer.TButton; import jexer.TCommand; import jexer.TKeypress; import jexer.TLabel; -import jexer.TText2; +import jexer.TText; import jexer.TWindow; import jexer.event.TResizeEvent; -import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.BasicLibrary; 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 { +class TuiReaderStoryWindow extends TWindow { + private BasicLibrary lib; private MetaData meta; private Story story; - private TText2 textField; + private TText textField; private int chapter = -2; 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? - textField = new TText2(this, "", 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"); @@ -46,7 +51,10 @@ public class TuiReaderStoryWindow extends TWindow { // -3 because 0-based and 2 for borders int row = getHeight() - 3; - navigationButtons.add(addButton(" ", 0, row, null)); // for bg colour when << button is pressed + 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); @@ -68,6 +76,10 @@ public class TuiReaderStoryWindow extends TWindow { } })); + 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); @@ -109,6 +121,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) { @@ -116,8 +136,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()) { @@ -139,13 +159,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; }