X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Ftui%2FTuiReaderStoryWindow.java;h=79840b9d20071b418c16b8022558d708de3c5699;hb=f435c113751b9c91633873a74d35adf4e184e8c0;hp=f5a2bfa547d8804835667f5140d2bcd8f632a873;hpb=cf9c5ed1164709d753d9c93ae8589f09b2f90ac0;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java b/src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java index f5a2bfa..79840b9 100644 --- a/src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java +++ b/src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java @@ -10,18 +10,16 @@ import java.util.List; import jexer.TAction; import jexer.TButton; import jexer.TLabel; -import jexer.TTable; import jexer.TText; import jexer.TWindow; import jexer.event.TCommandEvent; import jexer.event.TResizeEvent; -import jexer.event.TResizeEvent.Type; import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; import be.nikiroo.fanfix.data.Paragraph.ParagraphType; import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.jexer.TTable; import be.nikiroo.utils.StringUtils; /** @@ -31,8 +29,6 @@ import be.nikiroo.utils.StringUtils; * @author niki */ class TuiReaderStoryWindow extends TWindow { - private BasicLibrary lib; - private MetaData meta; private Story story; private TLabel titleField; private TText textField; @@ -40,53 +36,46 @@ class TuiReaderStoryWindow extends TWindow { private int chapter = -99; // invalid value private List navigationButtons; private TLabel currentChapter; + private List sizeConstraints = new ArrayList(); // chapter: -1 for "none" (0 is desc) - public TuiReaderStoryWindow(TuiReaderApplication app, BasicLibrary lib, - MetaData meta, int chapter) { - super(app, desc(meta), 0, 0, 60, 18, CENTERED | RESIZABLE); + public TuiReaderStoryWindow(TuiReaderApplication app, Story story, + int chapter) { + super(app, desc(story.getMeta()), 0, 0, 60, 18, CENTERED | RESIZABLE); - this.lib = lib; - this.meta = meta; + this.story = story; - app.setStatusBar(this, desc(meta)); + app.setStatusBar(this, desc(story.getMeta())); // last = use window background titleField = new TLabel(this, " Title", 0, 1, "tlabel", false); - textField = new TText(this, "", 1, 3, getWidth() - 4, getHeight() - 5); - table = new TTable(this, 0, 3, getWidth(), getHeight() - 4, null, null, - Arrays.asList("Key", "Value"), true); + textField = new TText(this, "", 0, 0, 1, 1); + table = new TTable(this, 0, 0, 1, 1, null, null, Arrays.asList("Key", + "Value"), true); titleField.setEnabled(false); - textField.getVerticalScroller().setX( - textField.getVerticalScroller().getX() + 1); navigationButtons = new ArrayList(5); - // -3 because 0-based and 2 for borders - int row = getHeight() - 3; - - // for bg colour when << button is pressed - navigationButtons.add(addButton(" ", 0, row, null)); - navigationButtons.add(addButton("<< ", 0, row, new TAction() { + navigationButtons.add(addButton("<<", 0, 0, new TAction() { @Override public void DO() { setChapter(-1); } })); - navigationButtons.add(addButton("< ", 4, row, new TAction() { + navigationButtons.add(addButton("< ", 4, 0, new TAction() { @Override public void DO() { setChapter(TuiReaderStoryWindow.this.chapter - 1); } })); - navigationButtons.add(addButton("> ", 7, row, new TAction() { + navigationButtons.add(addButton("> ", 7, 0, new TAction() { @Override public void DO() { setChapter(TuiReaderStoryWindow.this.chapter + 1); } })); - navigationButtons.add(addButton(">> ", 10, row, new TAction() { + navigationButtons.add(addButton(">>", 10, 0, new TAction() { @Override public void DO() { setChapter(getStory().getChapters().size()); @@ -95,43 +84,44 @@ class TuiReaderStoryWindow extends TWindow { navigationButtons.get(0).setEnabled(false); navigationButtons.get(1).setEnabled(false); - navigationButtons.get(2).setEnabled(false); - currentChapter = addLabel("", 14, row); - currentChapter.setWidth(getWidth() - 10); + currentChapter = addLabel("", 0, 0); + + TSizeConstraint.setSize(sizeConstraints, textField, 1, 3, -1, -1); + TSizeConstraint.setSize(sizeConstraints, table, 0, 3, 0, -1); + TSizeConstraint.setSize(sizeConstraints, currentChapter, 14, -3, -1, + null); + + for (TButton navigationButton : navigationButtons) { + navigationButton.setShadowColor(null); + // navigationButton.setEmptyBorders(false); + TSizeConstraint.setSize(sizeConstraints, navigationButton, null, + -3, null, null); + } + + onResize(null); setChapter(chapter); } @Override public void onResize(TResizeEvent resize) { - super.onResize(resize); - - // Resize the text field - // TODO: why setW/setH/reflow not enough for the scrollbars? - textField.onResize(new TResizeEvent(Type.WIDGET, resize.getWidth() - 4, - resize.getHeight() - 5)); - textField.getVerticalScroller().setX( - textField.getVerticalScroller().getX() + 1); + if (resize != null) { + super.onResize(resize); + } - table.setWidth(getWidth()); - table.setHeight(getHeight() - 4); - table.reflowData(); + // TODO: find out why TText and TTable does not behave the same way + // (offset of 2 for height and width) - // -3 because 0-based and 2 for borders - int row = getHeight() - 3; + TSizeConstraint.resize(sizeConstraints); - String name = currentChapter.getLabel(); - while (name.length() < resize.getWidth() - currentChapter.getX()) { - name += " "; - } - currentChapter.setLabel(name); - currentChapter.setWidth(resize.getWidth() - 10); - currentChapter.setY(row); + // Improve the disposition of the scrollbars + textField.getVerticalScroller().setX(textField.getWidth()); + textField.getVerticalScroller().setHeight(textField.getHeight()); + textField.getHorizontalScroller().setX(-1); + textField.getHorizontalScroller().setWidth(textField.getWidth() + 1); - for (TButton button : navigationButtons) { - button.setY(row); - } + setCurrentChapterText(); } /** @@ -153,9 +143,8 @@ class TuiReaderStoryWindow extends TWindow { int max = getStory().getChapters().size(); navigationButtons.get(0).setEnabled(chapter > -1); navigationButtons.get(1).setEnabled(chapter > -1); - navigationButtons.get(2).setEnabled(chapter > -1); + navigationButtons.get(2).setEnabled(chapter < max); navigationButtons.get(3).setEnabled(chapter < max); - navigationButtons.get(4).setEnabled(chapter < max); if (chapter < 0) { displayInfoPage(); @@ -183,11 +172,24 @@ class TuiReaderStoryWindow extends TWindow { setCurrentTitle(meta.getTitle()); + StringBuilder tags = new StringBuilder(); + for (String tag : meta.getTags()) { + if (tags.length() > 0) { + tags.append(", "); + } + tags.append(tag); + } + table.setRowData(new String[][] { // new String[] { " Author", meta.getAuthor() }, // new String[] { " Publication date", formatDate(meta.getDate()) }, + new String[] { " Published on", meta.getPublisher() }, + new String[] { " URL", meta.getUrl() }, new String[] { " Word count", format(meta.getWords()) }, - new String[] { " Source", meta.getSource() } // + new String[] { " Source", meta.getSource() }, + new String[] { " Subject", meta.getSubject() }, + new String[] { " Language", meta.getLang() }, + new String[] { " Tags", tags.toString() } // }); table.setHeaders(Arrays.asList("key", "value"), false); table.toTop(); @@ -274,10 +276,6 @@ class TuiReaderStoryWindow extends TWindow { } private Story getStory() { - if (story == null) { - // TODO: progress bar? - story = lib.getStory(meta.getLuid(), null); - } return story; } @@ -315,10 +313,7 @@ class TuiReaderStoryWindow extends TWindow { } int width = getWidth() - currentChapter.getX(); - while (name.length() < width) { - name += " "; - } - + name = String.format("%-" + width + "s", name); if (name.length() > width) { name = name.substring(0, width); }