1 package be
.nikiroo
.fanfix
.reader
.tui
;
3 import java
.io
.IOException
;
4 import java
.util
.ArrayList
;
8 import jexer
.TFileOpenBox
.Type
;
11 import jexer
.event
.TMenuEvent
;
12 import be
.nikiroo
.fanfix
.Instance
;
13 import be
.nikiroo
.fanfix
.data
.MetaData
;
14 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
15 import be
.nikiroo
.fanfix
.output
.BasicOutput
.OutputType
;
16 import be
.nikiroo
.fanfix
.reader
.Reader
;
19 * The library window, that will list all the (filtered) stories available in
20 * this {@link BasicLibrary}.
24 class TuiReaderMainWindow
extends TWindow
{
26 private List
<MetaData
> listKeys
;
27 private List
<String
> listItems
;
28 private Reader reader
;
29 private String source
;
32 * Create a new {@link TuiReaderMainWindow} without any stories in the list.
35 * the reader and main application
37 public TuiReaderMainWindow(TuiReaderApplication reader
) {
38 // Construct a demo window. X and Y don't matter because it will be
40 super(reader
, "Library", 0, 0, 60, 18, CENTERED
| RESIZABLE
);
46 listKeys
= new ArrayList
<MetaData
>();
47 listItems
= new ArrayList
<String
>();
48 list
= addList(listItems
, 0, 0, getWidth(), getHeight(), new TAction() {
51 MetaData meta
= getSelectedMeta();
58 // TODO: add the current "source/type" or filter
59 reader
.setStatusBar(this, "Library");
61 // TODO: remove when not used anymore
63 // addLabel("Label (1,1)", 1, 1);
64 // addButton("&Button (35,1)", 35, 1, new TAction() {
68 // addCheckbox(1, 2, "Checky (1,2)", false);
69 // addProgressBar(1, 3, 30, 42);
70 // TRadioGroup groupy = addRadioGroup(1, 4, "Radio groupy");
71 // groupy.addRadioButton("Fanfan");
72 // groupy.addRadioButton("Tulipe");
73 // addField(1, 10, 20, false, "text not fixed.");
74 // addField(1, 11, 20, true, "text fixed.");
75 // addText("20x4 Text in (12,20)", 1, 12, 20, 4);
77 // TTreeView tree = addTreeView(30, 5, 20, 5);
78 // TTreeItem root = new TTreeItem(tree, "expended root", true);
79 // tree.setSelected(root); // needed to allow arrow navigation without
80 // // mouse-clicking before
82 // root.addChild("child");
83 // root.addChild("child 2").addChild("sub child");
87 public void onClose() {
93 * Change the source filter and display all stories matching this source.
96 * the new source or NULL for all sources
98 public void setSource(String source
) {
103 public void refreshStories() {
104 List
<MetaData
> metas
= reader
.getLibrary().getListBySource(source
);
109 * Update the list of stories displayed in this {@link TWindow}.
112 * the new (unique) story to display
114 public void setMeta(MetaData meta
) {
115 List
<MetaData
> metas
= new ArrayList
<MetaData
>();
124 * Update the list of stories displayed in this {@link TWindow}.
127 * the new list of stories to display
129 private void setMetas(List
<MetaData
> metas
) {
134 for (MetaData meta
: metas
) {
136 listItems
.add(desc(meta
));
140 list
.setList(listItems
);
143 public MetaData
getSelectedMeta() {
144 if (list
.getSelectedIndex() >= 0) {
145 return listKeys
.get(list
.getSelectedIndex());
151 public void readStory(MetaData meta
) {
153 reader
.setChapter(-1);
154 reader
.setMeta(meta
);
156 } catch (IOException e
) {
157 Instance
.getTraceHandler().error(e
);
161 private String
desc(MetaData meta
) {
162 return String
.format("%5s: %s", meta
.getLuid(), meta
.getTitle());
166 public void onMenu(TMenuEvent menu
) {
167 MetaData meta
= getSelectedMeta();
169 switch (menu
.getId()) {
170 case TuiReaderApplication
.MENU_OPEN
:
174 case TuiReaderApplication
.MENU_EXPORT
:
177 // TODO: choose type, pg, error
178 OutputType outputType
= OutputType
.EPUB
;
179 String path
= fileOpenBox(".", Type
.SAVE
);
180 reader
.getLibrary().export(meta
.getLuid(), outputType
,
182 } catch (IOException e
) {
190 reader
.getLibrary().delete(meta
.getLuid());
191 } catch (IOException e
) {