Commit | Line | Data |
---|---|---|
fae07ea7 NR |
1 | package be.nikiroo.jvcard.tui.panes; |
2 | ||
5ad0e17e | 3 | import java.io.IOException; |
fae07ea7 NR |
4 | import java.util.List; |
5 | ||
6 | import be.nikiroo.jvcard.tui.KeyAction; | |
7 | ||
8 | import com.googlecode.lanterna.gui2.Direction; | |
9 | import com.googlecode.lanterna.gui2.LinearLayout; | |
10 | import com.googlecode.lanterna.gui2.Panel; | |
11 | ||
12 | /** | |
13 | * This class represents the main content that you can see in this application | |
14 | * (i.e., everything but the title and the actions keys is a {@link Panel} | |
15 | * extended from this class). | |
16 | * | |
17 | * @author niki | |
18 | * | |
19 | */ | |
20 | abstract public class MainContent extends Panel { | |
21 | ||
22 | public MainContent() { | |
23 | super(); | |
24 | } | |
25 | ||
26 | public MainContent(Direction dir) { | |
27 | super(); | |
28 | LinearLayout layout = new LinearLayout(dir); | |
29 | layout.setSpacing(0); | |
30 | setLayoutManager(layout); | |
31 | } | |
32 | ||
fae07ea7 NR |
33 | /** |
34 | * The kind of data displayed by this {@link MainContent}. | |
35 | * | |
36 | * @return the kind of data displayed | |
37 | */ | |
38 | abstract public KeyAction.DataType getDataType(); | |
39 | ||
40 | /** | |
41 | * Returns the list of actions and the keys that are bound to it. | |
42 | * | |
43 | * @return the list of actions | |
44 | */ | |
45 | abstract public List<KeyAction> getKeyBindings(); | |
46 | ||
0b0b2b0f | 47 | /** |
bcb54330 | 48 | * The title to display in addition to the application name, or NULL for the |
0b0b2b0f NR |
49 | * default application name. |
50 | * | |
51 | * @return the title or NULL | |
52 | */ | |
bcb54330 NR |
53 | public String getTitle() { |
54 | return null; | |
55 | } | |
0b0b2b0f NR |
56 | |
57 | /** | |
58 | * Returns an error message ready to be displayed if we should ask something | |
59 | * to the user before exiting. | |
60 | * | |
61 | * @return an error message or NULL | |
62 | */ | |
63 | public String getExitWarning() { | |
64 | return null; | |
65 | } | |
66 | ||
fae07ea7 NR |
67 | /** |
68 | * Move the active cursor (not the text cursor, but the currently active | |
69 | * item). | |
70 | * | |
71 | * @param x | |
72 | * the horizontal move (< 0 for left, > 0 for right) | |
73 | * @param y | |
74 | * the vertical move (< 0 for up, > 0 for down) | |
75 | * | |
76 | * @return the error message to display if any | |
77 | */ | |
0b0b2b0f NR |
78 | public String move(int x, int y) { |
79 | return null; | |
80 | } | |
81 | ||
82 | /** | |
83 | * Return the number of items in this {@link MainContent}, or -1 if this | |
84 | * {@link MainContent} is not countable. | |
85 | * | |
86 | * @return -1 or the number of present items | |
87 | */ | |
88 | public int getCount() { | |
89 | return -1; | |
90 | } | |
bcb54330 NR |
91 | |
92 | /** | |
93 | * Refresh the display according to the actual data (this method should be | |
94 | * called when the data changed). | |
95 | */ | |
96 | public void refreshData() { | |
97 | invalidate(); | |
98 | } | |
5ad0e17e NR |
99 | |
100 | /** | |
101 | * Wake up call when the content is popped-back into view. You should call | |
102 | * this method when you exit a previous content and come back to this one. | |
103 | * | |
3634193b NR |
104 | * <p> |
105 | * By default, it will just refresh the data. | |
106 | * </p> | |
107 | * | |
5ad0e17e NR |
108 | * @return a message to display, or NULL |
109 | * | |
110 | * @throws IOException | |
111 | * in case of error (the message of the {@link IOException} will | |
112 | * be displayed to the user) | |
113 | */ | |
114 | public String wakeup() throws IOException { | |
3634193b | 115 | refreshData(); |
5ad0e17e NR |
116 | return null; |
117 | } | |
fae07ea7 | 118 | } |