1 package be
.nikiroo
.fanfix
.reader
;
3 import java
.util
.ArrayList
;
8 import jexer
.TKeypress
;
10 import jexer
.TRadioGroup
;
11 import jexer
.TTreeItem
;
12 import jexer
.TTreeView
;
14 import be
.nikiroo
.fanfix
.data
.MetaData
;
17 * The library window, that will list all the (filtered) stories available in
18 * this {@link Library}.
22 class TuiReaderMainWindow
extends TWindow
{
24 private List
<MetaData
> listKeys
;
25 private List
<String
> listItems
;
26 private TuiReaderApplication reader
;
29 * Create a new {@link TuiReaderMainWindow} with the given stories in the
33 * the reader and main application
35 * the stories to display
37 public TuiReaderMainWindow(TuiReaderApplication reader
, List
<MetaData
> metas
) {
43 * Create a new {@link TuiReaderMainWindow} with only the given
44 * {@link MetaData} in the list, and open this {@link MetaData} at the given
48 * the reader and main application
50 * the story to display
54 public TuiReaderMainWindow(TuiReaderApplication reader
, MetaData meta
,
58 List
<MetaData
> metas
= new ArrayList
<MetaData
>();
62 reader
.open(meta
, chapter
);
66 * Create a new {@link TuiReaderMainWindow} without any stories in the list.
69 * the reader and main application
71 public TuiReaderMainWindow(TuiReaderApplication reader
) {
72 // Construct a demo window. X and Y don't matter because it will be
73 // centered on screen.
74 super(reader
, "Library", 0, 0, 60, 18, CENTERED
| RESIZABLE
81 listKeys
= new ArrayList
<MetaData
>();
82 listItems
= new ArrayList
<String
>();
83 list
= addList(listItems
, 0, 0, getWidth(), getHeight(), new TAction() {
86 if (list
.getSelectedIndex() >= 0) {
87 enterOnStory(listKeys
.get(list
.getSelectedIndex()));
92 // TODO: add the current "source/type" or filter
93 statusBar
= newStatusBar("Library");
94 statusBar
.addShortcutKeypress(TKeypress
.kbF10
, TCommand
.cmExit
, "Exit");
97 addLabel("Label (1,1)", 1, 1);
98 addButton("&Button (35,1)", 35, 1, new TAction() {
102 addCheckbox(1, 2, "Checky (1,2)", false);
103 addProgressBar(1, 3, 30, 42);
104 TRadioGroup groupy
= addRadioGroup(1, 4, "Radio groupy");
105 groupy
.addRadioButton("Fanfan");
106 groupy
.addRadioButton("Tulipe");
107 addField(1, 10, 20, false, "text not fixed.");
108 addField(1, 11, 20, true, "text fixed.");
109 addText("20x4 Text in (12,20)", 1, 12, 20, 4);
111 TTreeView tree
= addTreeView(30, 5, 20, 5);
112 TTreeItem root
= new TTreeItem(tree
, "expended root", true);
113 tree
.setSelected(root
); // needed to allow arrow navigation without
114 // mouse-clicking before
116 root
.addChild("child");
117 root
.addChild("child 2").addChild("sub child");
123 * Update the list of stories displayed in this {@link TWindow}.
126 * the new list of stories to display
128 public void setMetas(List
<MetaData
> metas
) {
133 for (MetaData meta
: metas
) {
135 listItems
.add(desc(meta
));
139 list
.setList(listItems
);
142 private void enterOnStory(MetaData meta
) {
146 private String
desc(MetaData meta
) {
147 return String
.format("%5s: %s", meta
.getLuid(), meta
.getTitle());