1 package be
.nikiroo
.fanfix
.reader
;
3 import java
.io
.IOException
;
4 import java
.util
.ArrayList
;
9 import jexer
.TFileOpenBox
.Type
;
10 import jexer
.TKeypress
;
13 import jexer
.event
.TMenuEvent
;
14 import be
.nikiroo
.fanfix
.Instance
;
15 import be
.nikiroo
.fanfix
.data
.MetaData
;
16 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
17 import be
.nikiroo
.fanfix
.output
.BasicOutput
.OutputType
;
20 * The library window, that will list all the (filtered) stories available in
21 * this {@link BasicLibrary}.
25 class TuiReaderMainWindow
extends TWindow
{
27 private List
<MetaData
> listKeys
;
28 private List
<String
> listItems
;
29 private Reader reader
;
30 private String source
;
33 * Create a new {@link TuiReaderMainWindow} without any stories in the list.
36 * the reader and main application
38 public TuiReaderMainWindow(TuiReaderApplication reader
) {
39 // Construct a demo window. X and Y don't matter because it will be
41 super(reader
, "Library", 0, 0, 60, 18, CENTERED
| RESIZABLE
48 listKeys
= new ArrayList
<MetaData
>();
49 listItems
= new ArrayList
<String
>();
50 list
= addList(listItems
, 0, 0, getWidth(), getHeight(), new TAction() {
53 MetaData meta
= getSelectedMeta();
60 // TODO: add the current "source/type" or filter
61 statusBar
= newStatusBar("Library");
62 statusBar
.addShortcutKeypress(TKeypress
.kbF10
, TCommand
.cmExit
, "Exit");
64 // TODO: remove when not used anymore
66 // addLabel("Label (1,1)", 1, 1);
67 // addButton("&Button (35,1)", 35, 1, new TAction() {
71 // addCheckbox(1, 2, "Checky (1,2)", false);
72 // addProgressBar(1, 3, 30, 42);
73 // TRadioGroup groupy = addRadioGroup(1, 4, "Radio groupy");
74 // groupy.addRadioButton("Fanfan");
75 // groupy.addRadioButton("Tulipe");
76 // addField(1, 10, 20, false, "text not fixed.");
77 // addField(1, 11, 20, true, "text fixed.");
78 // addText("20x4 Text in (12,20)", 1, 12, 20, 4);
80 // TTreeView tree = addTreeView(30, 5, 20, 5);
81 // TTreeItem root = new TTreeItem(tree, "expended root", true);
82 // tree.setSelected(root); // needed to allow arrow navigation without
83 // // mouse-clicking before
85 // root.addChild("child");
86 // root.addChild("child 2").addChild("sub child");
90 * Change the source filter and display all stories matching this source.
93 * the new source or NULL for all sources
95 public void setSource(String source
) {
100 public void refreshStories() {
101 List
<MetaData
> metas
= reader
.getLibrary().getListBySource(source
);
106 * Update the list of stories displayed in this {@link TWindow}.
109 * the new (unique) story to display
111 public void setMeta(MetaData meta
) {
112 List
<MetaData
> metas
= new ArrayList
<MetaData
>();
121 * Update the list of stories displayed in this {@link TWindow}.
124 * the new list of stories to display
126 private void setMetas(List
<MetaData
> metas
) {
131 for (MetaData meta
: metas
) {
133 listItems
.add(desc(meta
));
137 list
.setList(listItems
);
140 public MetaData
getSelectedMeta() {
141 if (list
.getSelectedIndex() >= 0) {
142 return listKeys
.get(list
.getSelectedIndex());
148 public void readStory(MetaData meta
) {
150 reader
.setChapter(-1);
151 reader
.setMeta(meta
);
153 } catch (IOException e
) {
158 private String
desc(MetaData meta
) {
159 return String
.format("%5s: %s", meta
.getLuid(), meta
.getTitle());
163 public void onMenu(TMenuEvent menu
) {
164 MetaData meta
= getSelectedMeta();
166 switch (menu
.getId()) {
167 case TuiReaderApplication
.MENU_OPEN
:
171 case TuiReaderApplication
.MENU_EXPORT
:
174 // TODO: choose type, pg, error
175 OutputType outputType
= OutputType
.EPUB
;
176 String path
= fileOpenBox(".", Type
.SAVE
);
177 reader
.getLibrary().export(meta
.getLuid(), outputType
,
179 } catch (IOException e
) {
187 reader
.getLibrary().delete(meta
.getLuid());
188 } catch (IOException e
) {