X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Ftui%2FTuiReaderStoryWindow.java;h=4848ef82afc12f936c1b1eaf3adbf167c926484a;hb=a6c830bb1ea8527a3600aa6d0e05d5b2291c4b15;hp=dc0afc245c9a8a1fb42401a5651830fe15dba42b;hpb=8f34a7954f96acdd5d7be5ed6f08fea2713f7d75;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java b/src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java index dc0afc2..4848ef8 100644 --- a/src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java +++ b/src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java @@ -1,11 +1,9 @@ package be.nikiroo.fanfix.reader.tui; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.List; +import java.util.Map; import jexer.TAction; import jexer.TButton; @@ -19,8 +17,9 @@ 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.reader.BasicReader; +import be.nikiroo.jexer.TSizeConstraint; import be.nikiroo.jexer.TTable; -import be.nikiroo.utils.StringUtils; /** * This window will contain the {@link Story} in a readable format, with a @@ -50,33 +49,32 @@ class TuiReaderStoryWindow extends TWindow { // last = use window background titleField = new TLabel(this, " Title", 0, 1, "tlabel", false); textField = new TText(this, "", 0, 0, 1, 1); - table = new TTable(this, 0, 0, 1, 1, null, null, Arrays.asList("Key", "Value"), true); + table = new TTable(this, 0, 0, 1, 1, null, null, Arrays.asList("Key", + "Value"), true); titleField.setEnabled(false); navigationButtons = new ArrayList(5); - // for bg colour when << button is pressed - navigationButtons.add(addButton(" ", 0, 0, null)); - navigationButtons.add(addButton("<< ", 0, 0, new TAction() { + navigationButtons.add(addButton("<<", 0, 0, new TAction() { @Override public void DO() { setChapter(-1); } })); - navigationButtons.add(addButton("< ", 4, 0, new TAction() { + navigationButtons.add(addButton("< ", 4, 0, new TAction() { @Override public void DO() { setChapter(TuiReaderStoryWindow.this.chapter - 1); } })); - navigationButtons.add(addButton("> ", 7, 0, new TAction() { + navigationButtons.add(addButton("> ", 7, 0, new TAction() { @Override public void DO() { setChapter(TuiReaderStoryWindow.this.chapter + 1); } })); - navigationButtons.add(addButton(">> ", 10, 0, new TAction() { + navigationButtons.add(addButton(">>", 10, 0, new TAction() { @Override public void DO() { setChapter(getStory().getChapters().size()); @@ -85,16 +83,17 @@ class TuiReaderStoryWindow extends TWindow { navigationButtons.get(0).setEnabled(false); navigationButtons.get(1).setEnabled(false); - navigationButtons.get(2).setEnabled(false); currentChapter = addLabel("", 0, 0); - TSizeConstraint.setSize(sizeConstraints, textField, 1, 3, -1, 0); - TSizeConstraint.setSize(sizeConstraints, table, 0, 3, 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); } @@ -115,8 +114,11 @@ class TuiReaderStoryWindow extends TWindow { TSizeConstraint.resize(sizeConstraints); - textField.getVerticalScroller().setX( - textField.getVerticalScroller().getX() + 1); + // 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); setCurrentChapterText(); } @@ -140,9 +142,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(); @@ -170,54 +171,18 @@ class TuiReaderStoryWindow extends TWindow { setCurrentTitle(meta.getTitle()); - table.setRowData(new String[][] { // - new String[] { " Author", meta.getAuthor() }, // - new String[] { " Publication date", formatDate(meta.getDate()) }, - new String[] { " Word count", format(meta.getWords()) }, - new String[] { " Source", meta.getSource() } // - }); - table.setHeaders(Arrays.asList("key", "value"), false); - table.toTop(); - } - - private String format(long value) { - String display = ""; - - while (value > 0) { - if (!display.isEmpty()) { - display = "." + display; - } - display = (value % 1000) + display; - value = value / 1000; - } - - return display; - } - - private String formatDate(String date) { - long ms = 0; - - try { - ms = StringUtils.toTime(date); - } catch (ParseException e) { - } - - if (ms <= 0) { - SimpleDateFormat sdf = new SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm:ssXXX"); - try { - ms = sdf.parse(date).getTime(); - } catch (ParseException e) { - } + Map metaDesc = BasicReader.getMetaDesc(meta); + String[][] metaDescObj = new String[metaDesc.size()][2]; + int i = 0; + for (String key : metaDesc.keySet()) { + metaDescObj[i][0] = " " + key; + metaDescObj[i][1] = metaDesc.get(key); + i++; } - if (ms > 0) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - return sdf.format(new Date(ms)); - } - - // :( - return date; + table.setRowData(metaDescObj); + table.setHeaders(Arrays.asList("key", "value"), false); + table.toTop(); } /**