1 package be
.nikiroo
.fanfix
.reader
;
3 import java
.io
.IOException
;
4 import java
.util
.ArrayList
;
9 import jexer
.TKeypress
;
12 import be
.nikiroo
.fanfix
.Instance
;
13 import be
.nikiroo
.fanfix
.data
.MetaData
;
14 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
17 * The library window, that will list all the (filtered) stories available in
18 * this {@link BasicLibrary}.
22 class TuiReaderMainWindow
extends TWindow
{
24 private List
<MetaData
> listKeys
;
25 private List
<String
> listItems
;
26 private Reader reader
;
29 * Create a new {@link TuiReaderMainWindow} with the given story in the
33 * the reader and main application
35 * the story to display
37 public TuiReaderMainWindow(TuiReaderApplication reader
, MetaData meta
) {
40 List
<MetaData
> metas
= new ArrayList
<MetaData
>();
46 * Create a new {@link TuiReaderMainWindow} without any stories in the list.
49 * the reader and main application
51 public TuiReaderMainWindow(TuiReaderApplication reader
) {
52 // Construct a demo window. X and Y don't matter because it will be
54 super(reader
, "Library", 0, 0, 60, 18, CENTERED
| RESIZABLE
61 listKeys
= new ArrayList
<MetaData
>();
62 listItems
= new ArrayList
<String
>();
63 list
= addList(listItems
, 0, 0, getWidth(), getHeight(), new TAction() {
66 if (list
.getSelectedIndex() >= 0) {
67 enterOnStory(listKeys
.get(list
.getSelectedIndex()));
72 // TODO: add the current "source/type" or filter
73 statusBar
= newStatusBar("Library");
74 statusBar
.addShortcutKeypress(TKeypress
.kbF10
, TCommand
.cmExit
, "Exit");
76 // TODO: remove when not used anymore
78 // addLabel("Label (1,1)", 1, 1);
79 // addButton("&Button (35,1)", 35, 1, new TAction() {
83 // addCheckbox(1, 2, "Checky (1,2)", false);
84 // addProgressBar(1, 3, 30, 42);
85 // TRadioGroup groupy = addRadioGroup(1, 4, "Radio groupy");
86 // groupy.addRadioButton("Fanfan");
87 // groupy.addRadioButton("Tulipe");
88 // addField(1, 10, 20, false, "text not fixed.");
89 // addField(1, 11, 20, true, "text fixed.");
90 // addText("20x4 Text in (12,20)", 1, 12, 20, 4);
92 // TTreeView tree = addTreeView(30, 5, 20, 5);
93 // TTreeItem root = new TTreeItem(tree, "expended root", true);
94 // tree.setSelected(root); // needed to allow arrow navigation without
95 // // mouse-clicking before
97 // root.addChild("child");
98 // root.addChild("child 2").addChild("sub child");
102 * Update the list of stories displayed in this {@link TWindow}.
105 * the new (unique) story to display
107 public void setMeta(MetaData meta
) {
108 List
<MetaData
> metas
= new ArrayList
<MetaData
>();
117 * Update the list of stories displayed in this {@link TWindow}.
120 * the new list of stories to display
122 public void setMetas(List
<MetaData
> metas
) {
127 for (MetaData meta
: metas
) {
129 listItems
.add(desc(meta
));
133 list
.setList(listItems
);
136 private void enterOnStory(MetaData meta
) {
138 reader
.setChapter(-1);
139 reader
.setMeta(meta
);
141 } catch (IOException e
) {
146 private String
desc(MetaData meta
) {
147 return String
.format("%5s: %s", meta
.getLuid(), meta
.getTitle());