1 package be
.nikiroo
.fanfix
.reader
.tui
;
3 import java
.io
.IOException
;
4 import java
.util
.ArrayList
;
8 import jexer
.TApplication
;
11 import jexer
.event
.TCommandEvent
;
12 import be
.nikiroo
.utils
.StringUtils
;
13 import be
.nikiroo
.utils
.resources
.Bundle
;
14 import be
.nikiroo
.utils
.resources
.MetaInfo
;
16 public class TOptionWindow
<E
extends Enum
<E
>> extends TSimpleScrollableWindow
{
17 private List
<MetaInfo
<E
>> items
;
19 public TOptionWindow(TApplication parent
, Class
<E
> type
,
20 final Bundle
<E
> bundle
, String title
) {
21 super(parent
, title
, 0, 0, CENTERED
| RESIZABLE
);
23 getMainPane().addLabel(title
, 0, 0);
25 items
= new ArrayList
<MetaInfo
<E
>>();
26 List
<MetaInfo
<E
>> groupedItems
= MetaInfo
.getItems(type
, bundle
);
28 for (MetaInfo
<E
> item
: groupedItems
) {
29 // will populate this.items
30 y
+= addItem(getMainPane(), 5, y
, item
, 0).getHeight();
37 getMainPane().addButton("Reset", 25, y
, new TAction() {
40 for (MetaInfo
<E
> item
: items
) {
46 getMainPane().addButton("Default", 15, y
, new TAction() {
49 Object snap
= bundle
.takeSnapshot();
51 for (MetaInfo
<E
> item
: items
) {
55 bundle
.restoreSnapshot(snap
);
59 getMainPane().addButton("Save", 1, y
, new TAction() {
62 for (MetaInfo
<E
> item
: items
) {
68 } catch (IOException e1
) {
75 private TWidget
addItem(TWidget parent
, int x
, int y
, MetaInfo
<E
> item
,
81 String name
= item
.getName();
82 String info
= item
.getDescription();
83 info
= StringUtils
.justifyTexts(info
, w
- 3); // -3 for borders
85 final TPanel pane
= new TPanel(parent
, x
, y
, w
, 1);
86 pane
.addLabel(name
, 0, 0);
89 if (!info
.isEmpty()) {
90 h
+= info
.split("\n").length
+ 1; // +1 for scroll
91 pane
.addText(info
+ "\n", 0, 1, w
, h
);
97 int paneY
= h
; // for the info desc
98 for (MetaInfo
<E
> subitem
: item
) {
99 paneY
+= addItem(pane
, 4, paneY
, subitem
, nhgap
+ 11)
103 pane
.setHeight(paneY
);
108 return ConfigItem
.createItem(parent
, x
, y
, item
, nhgap
);
112 public void onCommand(TCommandEvent command
) {
113 if (command
.getCmd().equals(TuiReaderApplication
.CMD_EXIT
)) {
114 TuiReaderApplication
.close(this);
116 // Handle our own event if needed here
117 super.onCommand(command
);