X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FTuiReaderMainWindow.java;h=f0765809adb67b303eea69a1a07d3598bd8f3223;hb=bc2ea776b67cabcbdcbbc6d8a4e2df1aafa9101a;hp=55072664e9ae9376a0f7e4f119cbfb81f7d7f8bc;hpb=396e924c2cf7e7a6fe41e95a6395c9f9faf401f1;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java b/src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java index 5507266..f076580 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java +++ b/src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java @@ -1,29 +1,56 @@ package be.nikiroo.fanfix.reader; +import java.io.IOException; import java.util.ArrayList; import java.util.List; -import jexer.*; +import jexer.TAction; +import jexer.TCommand; +import jexer.TKeypress; +import jexer.TList; +import jexer.TWindow; +import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.library.BasicLibrary; -public class TuiReaderMainWindow extends TWindow { +/** + * The library window, that will list all the (filtered) stories available in + * this {@link BasicLibrary}. + * + * @author niki + */ +class TuiReaderMainWindow extends TWindow { private TList list; private List listKeys; private List listItems; - private TuiReaderApplication reader; + private Reader reader; /** - * Constructor. + * Create a new {@link TuiReaderMainWindow} with the given story in the + * list. * - * @param parent - * the main application - * @param flags - * bitmask of MODAL, CENTERED, or RESIZABLE + * @param reader + * the reader and main application + * @param meta + * the story to display */ - public TuiReaderMainWindow(TuiReaderApplication reader, - List stories) { + public TuiReaderMainWindow(TuiReaderApplication reader, MetaData meta) { + this(reader); + + List metas = new ArrayList(); + metas.add(meta); + setMetas(metas); + } + + /** + * Create a new {@link TuiReaderMainWindow} without any stories in the list. + * + * @param reader + * the reader and main application + */ + public TuiReaderMainWindow(TuiReaderApplication reader) { // Construct a demo window. X and Y don't matter because it will be - // centered on screen. + // centred on screen. super(reader, "Library", 0, 0, 60, 18, CENTERED | RESIZABLE | UNCLOSABLE); @@ -33,14 +60,6 @@ public class TuiReaderMainWindow extends TWindow { listKeys = new ArrayList(); listItems = new ArrayList(); - - if (stories != null) { - for (MetaData meta : stories) { - listKeys.add(meta); - listItems.add(desc(meta)); - } - } - list = addList(listItems, 0, 0, getWidth(), getHeight(), new TAction() { @Override public void DO() { @@ -49,39 +68,79 @@ public class TuiReaderMainWindow extends TWindow { } } }); - - // TODO: add the current "type" or filter + + // TODO: add the current "source/type" or filter statusBar = newStatusBar("Library"); statusBar.addShortcutKeypress(TKeypress.kbF10, TCommand.cmExit, "Exit"); - if (false) { - addLabel("Label (1,1)", 1, 1); - addButton("&Button (35,1)", 35, 1, new TAction() { - public void DO() { - } - }); - addCheckbox(1, 2, "Checky (1,2)", false); - addProgressBar(1, 3, 30, 42); - TRadioGroup groupy = addRadioGroup(1, 4, "Radio groupy"); - groupy.addRadioButton("Fanfan"); - groupy.addRadioButton("Tulipe"); - addField(1, 10, 20, false, "text not fixed."); - addField(1, 11, 20, true, "text fixed."); - addText("20x4 Text in (12,20)", 1, 12, 20, 4); - - TTreeView tree = addTreeView(30, 5, 20, 5); - TTreeItem root = new TTreeItem(tree, "expended root", true); - tree.setSelected(root); // needed to allow arrow navigation without - // mouse-clicking before - - root.addChild("child"); - root.addChild("child 2").addChild("sub child"); + // TODO: remove when not used anymore + + // addLabel("Label (1,1)", 1, 1); + // addButton("&Button (35,1)", 35, 1, new TAction() { + // public void DO() { + // } + // }); + // addCheckbox(1, 2, "Checky (1,2)", false); + // addProgressBar(1, 3, 30, 42); + // TRadioGroup groupy = addRadioGroup(1, 4, "Radio groupy"); + // groupy.addRadioButton("Fanfan"); + // groupy.addRadioButton("Tulipe"); + // addField(1, 10, 20, false, "text not fixed."); + // addField(1, 11, 20, true, "text fixed."); + // addText("20x4 Text in (12,20)", 1, 12, 20, 4); + // + // TTreeView tree = addTreeView(30, 5, 20, 5); + // TTreeItem root = new TTreeItem(tree, "expended root", true); + // tree.setSelected(root); // needed to allow arrow navigation without + // // mouse-clicking before + // + // root.addChild("child"); + // root.addChild("child 2").addChild("sub child"); + } + /** + * Update the list of stories displayed in this {@link TWindow}. + * + * @param meta + * the new (unique) story to display + */ + public void setMeta(MetaData meta) { + List metas = new ArrayList(); + if (meta != null) { + metas.add(meta); + } + + setMetas(metas); + } + + /** + * Update the list of stories displayed in this {@link TWindow}. + * + * @param metas + * the new list of stories to display + */ + public void setMetas(List metas) { + listKeys.clear(); + listItems.clear(); + + if (metas != null) { + for (MetaData meta : metas) { + listKeys.add(meta); + listItems.add(desc(meta)); + } } + + list.setList(listItems); } private void enterOnStory(MetaData meta) { - reader.open(meta); + try { + reader.setChapter(-1); + reader.setMeta(meta); + reader.read(); + } catch (IOException e) { + Instance.syserr(e); + } } private String desc(MetaData meta) {