X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FTuiReaderMainWindow.java;h=3b5dc5dcfff3901c96f7880c244a963e2116b3a8;hb=6322ab64949f9f4ae2b04b9504d58a301039d670;hp=1de9488ae604a6ac3b070521692cafdaddad01db;hpb=c1873e5678fabf306915c54f9c1736e03e027d60;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java b/src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java index 1de9488..3b5dc5d 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java +++ b/src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.List; import jexer.TAction; +import jexer.TCommand; +import jexer.TKeypress; import jexer.TList; import jexer.TRadioGroup; import jexer.TTreeItem; @@ -11,25 +13,65 @@ import jexer.TTreeView; import jexer.TWindow; import be.nikiroo.fanfix.data.MetaData; -public class TuiReaderMainWindow extends TWindow { +/** + * The library window, that will list all the (filtered) stories available in + * this {@link Library}. + * + * @author niki + */ +class TuiReaderMainWindow extends TWindow { private TList list; private List listKeys; private List listItems; private TuiReaderApplication reader; /** - * Constructor. + * Create a new {@link TuiReaderMainWindow} with the given stories in the + * list. * - * @param parent - * the main application - * @param flags - * bitmask of MODAL, CENTERED, or RESIZABLE + * @param reader + * the reader and main application + * @param metas + * the stories to display */ - public TuiReaderMainWindow(TuiReaderApplication reader, - List stories) { + public TuiReaderMainWindow(TuiReaderApplication reader, List metas) { + this(reader); + setMetas(metas); + } + + /** + * Create a new {@link TuiReaderMainWindow} with only the given + * {@link MetaData} in the list, and open this {@link MetaData} at the given + * chapter. + * + * @param reader + * the reader and main application + * @param meta + * the story to display + * @param chapter + * the chapter to open + */ + public TuiReaderMainWindow(TuiReaderApplication reader, MetaData meta, + int chapter) { + this(reader); + + List metas = new ArrayList(); + metas.add(meta); + setMetas(metas); + + reader.open(meta, chapter); + } + + /** + * 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. - super(reader, "Demo Window", 0, 0, 60, 18, CENTERED | RESIZABLE + super(reader, "Library", 0, 0, 60, 18, CENTERED | RESIZABLE | UNCLOSABLE); this.reader = reader; @@ -38,14 +80,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() { @@ -55,6 +89,10 @@ public class TuiReaderMainWindow extends TWindow { } }); + // 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() { @@ -81,6 +119,26 @@ public class TuiReaderMainWindow extends TWindow { } } + /** + * 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); }