| 1 | package be.nikiroo.fanfix.reader; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import jexer.TAction; |
| 7 | import jexer.TCommand; |
| 8 | import jexer.TKeypress; |
| 9 | import jexer.TList; |
| 10 | import jexer.TRadioGroup; |
| 11 | import jexer.TTreeItem; |
| 12 | import jexer.TTreeView; |
| 13 | import jexer.TWindow; |
| 14 | import be.nikiroo.fanfix.data.MetaData; |
| 15 | |
| 16 | class TuiReaderMainWindow extends TWindow { |
| 17 | private TList list; |
| 18 | private List<MetaData> listKeys; |
| 19 | private List<String> listItems; |
| 20 | private TuiReaderApplication reader; |
| 21 | |
| 22 | /** |
| 23 | * Constructor. |
| 24 | * |
| 25 | * @param reader |
| 26 | * the reader and main application |
| 27 | * @param stories |
| 28 | * the stories to display |
| 29 | */ |
| 30 | public TuiReaderMainWindow(TuiReaderApplication reader, |
| 31 | List<MetaData> stories) { |
| 32 | // Construct a demo window. X and Y don't matter because it will be |
| 33 | // centered on screen. |
| 34 | super(reader, "Library", 0, 0, 60, 18, CENTERED | RESIZABLE |
| 35 | | UNCLOSABLE); |
| 36 | |
| 37 | this.reader = reader; |
| 38 | |
| 39 | maximize(); |
| 40 | |
| 41 | listKeys = new ArrayList<MetaData>(); |
| 42 | listItems = new ArrayList<String>(); |
| 43 | |
| 44 | if (stories != null) { |
| 45 | for (MetaData meta : stories) { |
| 46 | listKeys.add(meta); |
| 47 | listItems.add(desc(meta)); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | list = addList(listItems, 0, 0, getWidth(), getHeight(), new TAction() { |
| 52 | @Override |
| 53 | public void DO() { |
| 54 | if (list.getSelectedIndex() >= 0) { |
| 55 | enterOnStory(listKeys.get(list.getSelectedIndex())); |
| 56 | } |
| 57 | } |
| 58 | }); |
| 59 | |
| 60 | // TODO: add the current "type" or filter |
| 61 | statusBar = newStatusBar("Library"); |
| 62 | statusBar.addShortcutKeypress(TKeypress.kbF10, TCommand.cmExit, "Exit"); |
| 63 | |
| 64 | if (false) { |
| 65 | addLabel("Label (1,1)", 1, 1); |
| 66 | addButton("&Button (35,1)", 35, 1, new TAction() { |
| 67 | public void DO() { |
| 68 | } |
| 69 | }); |
| 70 | addCheckbox(1, 2, "Checky (1,2)", false); |
| 71 | addProgressBar(1, 3, 30, 42); |
| 72 | TRadioGroup groupy = addRadioGroup(1, 4, "Radio groupy"); |
| 73 | groupy.addRadioButton("Fanfan"); |
| 74 | groupy.addRadioButton("Tulipe"); |
| 75 | addField(1, 10, 20, false, "text not fixed."); |
| 76 | addField(1, 11, 20, true, "text fixed."); |
| 77 | addText("20x4 Text in (12,20)", 1, 12, 20, 4); |
| 78 | |
| 79 | TTreeView tree = addTreeView(30, 5, 20, 5); |
| 80 | TTreeItem root = new TTreeItem(tree, "expended root", true); |
| 81 | tree.setSelected(root); // needed to allow arrow navigation without |
| 82 | // mouse-clicking before |
| 83 | |
| 84 | root.addChild("child"); |
| 85 | root.addChild("child 2").addChild("sub child"); |
| 86 | |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | private void enterOnStory(MetaData meta) { |
| 91 | reader.open(meta); |
| 92 | } |
| 93 | |
| 94 | private String desc(MetaData meta) { |
| 95 | return String.format("%5s: %s", meta.getLuid(), meta.getTitle()); |
| 96 | } |
| 97 | } |