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