1 package be
.nikiroo
.fanfix
.reader
.tui
;
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
;
18 import be
.nikiroo
.fanfix
.reader
.Reader
;
21 * The library window, that will list all the (filtered) stories available in
22 * this {@link BasicLibrary}.
26 class TuiReaderMainWindow
extends TWindow
{
28 private List
<MetaData
> listKeys
;
29 private List
<String
> listItems
;
30 private Reader reader
;
31 private String source
;
34 * Create a new {@link TuiReaderMainWindow} without any stories in the list.
37 * the reader and main application
39 public TuiReaderMainWindow(TuiReaderApplication reader
) {
40 // Construct a demo window. X and Y don't matter because it will be
42 super(reader
, "Library", 0, 0, 60, 18, CENTERED
| RESIZABLE
49 listKeys
= new ArrayList
<MetaData
>();
50 listItems
= new ArrayList
<String
>();
51 list
= addList(listItems
, 0, 0, getWidth(), getHeight(), new TAction() {
54 MetaData meta
= getSelectedMeta();
61 // TODO: add the current "source/type" or filter
62 statusBar
= newStatusBar("Library");
63 statusBar
.addShortcutKeypress(TKeypress
.kbF10
, TCommand
.cmExit
, "Exit");
65 // TODO: remove when not used anymore
67 // addLabel("Label (1,1)", 1, 1);
68 // addButton("&Button (35,1)", 35, 1, new TAction() {
72 // addCheckbox(1, 2, "Checky (1,2)", false);
73 // addProgressBar(1, 3, 30, 42);
74 // TRadioGroup groupy = addRadioGroup(1, 4, "Radio groupy");
75 // groupy.addRadioButton("Fanfan");
76 // groupy.addRadioButton("Tulipe");
77 // addField(1, 10, 20, false, "text not fixed.");
78 // addField(1, 11, 20, true, "text fixed.");
79 // addText("20x4 Text in (12,20)", 1, 12, 20, 4);
81 // TTreeView tree = addTreeView(30, 5, 20, 5);
82 // TTreeItem root = new TTreeItem(tree, "expended root", true);
83 // tree.setSelected(root); // needed to allow arrow navigation without
84 // // mouse-clicking before
86 // root.addChild("child");
87 // root.addChild("child 2").addChild("sub child");
91 * Change the source filter and display all stories matching this source.
94 * the new source or NULL for all sources
96 public void setSource(String source
) {
101 public void refreshStories() {
102 List
<MetaData
> metas
= reader
.getLibrary().getListBySource(source
);
107 * Update the list of stories displayed in this {@link TWindow}.
110 * the new (unique) story to display
112 public void setMeta(MetaData meta
) {
113 List
<MetaData
> metas
= new ArrayList
<MetaData
>();
122 * Update the list of stories displayed in this {@link TWindow}.
125 * the new list of stories to display
127 private void setMetas(List
<MetaData
> metas
) {
132 for (MetaData meta
: metas
) {
134 listItems
.add(desc(meta
));
138 list
.setList(listItems
);
141 public MetaData
getSelectedMeta() {
142 if (list
.getSelectedIndex() >= 0) {
143 return listKeys
.get(list
.getSelectedIndex());
149 public void readStory(MetaData meta
) {
151 reader
.setChapter(-1);
152 reader
.setMeta(meta
);
154 } catch (IOException e
) {
155 Instance
.getTraceHandler().error(e
);
159 private String
desc(MetaData meta
) {
160 return String
.format("%5s: %s", meta
.getLuid(), meta
.getTitle());
164 public void onMenu(TMenuEvent menu
) {
165 MetaData meta
= getSelectedMeta();
167 switch (menu
.getId()) {
168 case TuiReaderApplication
.MENU_OPEN
:
172 case TuiReaderApplication
.MENU_EXPORT
:
175 // TODO: choose type, pg, error
176 OutputType outputType
= OutputType
.EPUB
;
177 String path
= fileOpenBox(".", Type
.SAVE
);
178 reader
.getLibrary().export(meta
.getLuid(), outputType
,
180 } catch (IOException e
) {
188 reader
.getLibrary().delete(meta
.getLuid());
189 } catch (IOException e
) {