0d873daa26287010a46183d84c001544b3601e93
[jvcard.git] / src / be / nikiroo / jvcard / tui / panes / MainContent.java
1 package be.nikiroo.jvcard.tui.panes;
2
3 import java.io.IOException;
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
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
47 /**
48 * The title to display in addition to the application name, or NULL for the
49 * default application name.
50 *
51 * @return the title or NULL
52 */
53 public String getTitle() {
54 return null;
55 }
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
67 /**
68 * Move the active cursor (not the text cursor, but the currently active
69 * item).
70 *
71 * @param x
72 * the horizontal move (&lt; 0 for left, &gt; 0 for right)
73 * @param y
74 * the vertical move (&lt; 0 for up, &gt; 0 for down)
75 *
76 * @return the error message to display if any
77 */
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 }
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 }
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 *
104 * <p>
105 * By default, it will just refresh the data.
106 * </p>
107 *
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 {
115 refreshData();
116 return null;
117 }
118 }