/**
* Translate the given {@link StringId} into user text.
*
- * @param stringId
+ * @param id
* the ID to translate
* @param values
* the values to insert instead of the place holders in the
package be.nikiroo.jvcard.tui;
-import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class TuiLauncherJexer extends TApplication {
/**
* Application is in fullscreen mode, no windows.
+ *
+ * TODO: make it an option
*/
static public final boolean FULLSCREEN = true;
* emulator, null to automatically determine the best choice
* @param files
* the files to show at startup
+ *
* @throws UnsupportedEncodingException
+ * if an exception is thrown when creating the InputStreamReader
*/
public TuiLauncherJexer(final Boolean textMode, final List<String> files)
throws UnsupportedEncodingException {
addFileMenu();
addWindowMenu();
- // TODO investigate why that is
+ int width = getBackend().getScreen().getWidth();
+ int height = getBackend().getScreen().getHeight() - 2;
+
if (backend(textMode) == BackendType.SWING) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- showMainWindow(files);
- }
- }).start();
- } else {
- showMainWindow(files);
+ // TODO: why does the size change after the FIRST window has been
+ // created (SWING mode only?) ?
+ // A problem with the graphical size not an exact number of
+ // cols/lines?
+ width--;
+ height--;
}
- }
- private void showMainWindow(final List<String> files) {
+ width = Math.max(1, width);
+ height = Math.max(1, height);
+
TuiBrowserWindow main = new TuiFileListWindow(TuiLauncherJexer.this,
- files);
+ width, height, files);
+
main.addCloseListener(new TAction() {
@Override
public void DO() {
/**
* Start the TUI program.
- *
- * @throws IOException
- * in case of IO error
*/
- public void start() throws IOException {
+ public void start() {
(new Thread(this)).start();
}
* Select the most appropriate backend.
*
* @param textMode
- * NULL for auto-dection
+ * NULL for auto-detection
* @return the backend type to use
*/
private static BackendType backend(Boolean textMode) {
import jexer.TAction;
import jexer.TApplication;
import jexer.TKeypress;
+import jexer.TStatusBar;
import jexer.TWindow;
import jexer.event.TKeypressEvent;
import be.nikiroo.jvcard.tui.TuiLauncherJexer;
private Map<TKeypress, TAction> keyBindings;
private List<TAction> closeListeners;
+ /**
+ * Create a new window with the given title.
+ *
+ * @param parent
+ * the parent {@link TuiBasicWindow}
+ * @param title
+ * the window title
+ */
+ public TuiBasicWindow(TuiBasicWindow parent, String title) {
+ this(parent.app, title, parent.getWidth(), parent.getHeight());
+ }
+
/**
* Create a new window with the given title.
*
* the application that will manage this window
* @param title
* the window title
+ * @param width
+ * the window width
+ * @param height
+ * the window height
*/
- public TuiBasicWindow(TApplication app, String title) {
- // Note: will not support screen with less than 10x10
- super(app, title, //
- Math.min(36, app.getScreen().getWidth() - 9), //
- Math.min(16, app.getScreen().getHeight() - 9) //
- );
+ public TuiBasicWindow(TApplication app, String title, int width, int height) {
+ super(app, title, width, height);
this.app = app;
*
* @param key
* the key to press
+ * @param text
+ * the text to display for this command
* @param action
* the action
*/
- public void addKeyBinding(TKeypress key, TAction action) {
+ public void addKeyBinding(TKeypress key, String text, TAction action) {
keyBindings.put(key, action);
+
+ TStatusBar statusbar = getStatusBar();
+ if (statusbar == null) {
+ statusbar = newStatusBar("");
+ }
+
+ statusbar.addShortcutKeypress(key, null, text);
}
/**
closeListeners.add(listener);
}
- /**
- * Close the window.
- */
- public void close() {
- app.closeWindow(this);
- }
-
@Override
public void onClose() {
super.onClose();
private TTable table;
private boolean showHeader;
- public TuiBrowserWindow(TApplication app, String title, boolean showHeaders) {
- super(app, title);
+ public TuiBrowserWindow(TuiBasicWindow parent, String title,
+ boolean showHeaders) {
+ super(parent, title);
+ init(showHeaders);
+ }
+
+ public TuiBrowserWindow(TApplication app, int width, int height,
+ String title, boolean showHeaders) {
+ super(app, title, width, height);
+ init(showHeaders);
+ }
+ private void init(boolean showHeaders) {
this.showHeader = showHeaders;
table = new TTable(this, 0, 0, getWidth() - 2, getHeight() - 2,
new TAction() {
@Override
public void DO() {
- onAction(table.getSelectedLine(),
+ onAction(table.getSelectedRow(),
table.getSelectedColumn());
}
}, null);
*
* @param headers
* the table headers (mandatory)
- * @param lines
+ * @param rows
* the data to display
*/
- public void setData(List<String> headers, List<List<String>> lines) {
- int prevLine = table.getSelectedLine();
+ public void setData(List<String> headers, List<List<String>> rows) {
+ int prevRow = table.getSelectedRow();
int prevColumn = table.getSelectedColumn();
table.clear();
table.setHeaders(headers, showHeader);
- for (List<String> line : lines) {
- table.addLine(line);
+ for (List<String> row : rows) {
+ table.addRow(row);
}
table.reflow();
- table.setSelectedLine(Math.min(prevLine, table.getNumberOfLines() - 1));
+ table.setSelectedRow(Math.min(prevRow, table.getNumberOfRows() - 1));
table.setSelectedColumn(Math.min(prevColumn,
table.getNumberOfColumns() - 1));
}
* @return -1 or the number of present items
*/
public int size() {
- return table.getNumberOfLines();
+ return table.getNumberOfRows();
}
/**
* An item has been selected.
*
- * @param selectedLine
- * the currently selected line
+ * @param selectedRow
+ * the currently selected row
* @param selectedColumn
* the currently selected column
*/
@SuppressWarnings("unused")
- public void onAction(int selectedLine, int selectedColumn) {
+ public void onAction(int selectedRow, int selectedColumn) {
}
@Override
import be.nikiroo.jvcard.resources.DisplayOption;
public class TuiContactListWindow extends TuiBrowserWindow {
- private TApplication app;
private Card card;
private String filter;
private List<String> formats;
private int selectedFormat;
private String format;
- public TuiContactListWindow(TApplication app, Card card) {
- super(app, "Contacts", false);
+ public TuiContactListWindow(TuiBasicWindow parent, Card card) {
+ super(parent, "Contacts", false);
- this.app = app;
this.card = card;
this.selectedFormat = -1;
formats.add(format);
}
- addKeyBinding(TKeypress.kbTab, new TAction() {
+ addKeyBinding(TKeypress.kbQ, "Quit", new TAction() {
@Override
public void DO() {
- switchFormat();
+ close();
}
});
-
- addKeyBinding(TKeypress.kbQ, new TAction() {
+
+ addKeyBinding(TKeypress.kbTab, "Switch format", new TAction() {
@Override
public void DO() {
- close();
+ switchFormat();
}
});
public void onAction(int selectedLine, int selectedColumn) {
try {
@SuppressWarnings("unused")
- TWindow w = new TuiContactWindow(app, card.get(selectedLine));
+ TWindow w = new TuiContactWindow(TuiContactListWindow.this, card.get(selectedLine));
} catch (IndexOutOfBoundsException e) {
setMessage("Fail to get contact", true);
}
package be.nikiroo.jvcard.tui.windows;
import jexer.TAction;
-import jexer.TApplication;
import jexer.TKeypress;
import jexer.TLabel;
import jexer.TWindow;
import be.nikiroo.jvcard.Contact;
public class TuiContactWindow extends TuiBasicWindow {
- public TuiContactWindow(final TApplication app, final Contact contact) {
- super(app, "Contact view");
+ public TuiContactWindow(final TuiBasicWindow parent, final Contact contact) {
+ super(parent, "Contact view");
- addKeyBinding(TKeypress.kbQ, new TAction() {
+ addKeyBinding(TKeypress.kbQ, "Quit", new TAction() {
@Override
public void DO() {
- app.closeWindow(TuiContactWindow.this);
+ parent.getApplication().closeWindow(TuiContactWindow.this);
}
});
- addKeyBinding(TKeypress.kbR, new TAction() {
+ addKeyBinding(TKeypress.kbR, "Raw view", new TAction() {
@Override
public void DO() {
@SuppressWarnings("unused")
- TWindow w = new TuiRawContactWindow(app, contact);
+ TWindow w = new TuiRawContactWindow(TuiContactWindow.this,
+ contact);
}
});
import be.nikiroo.jvcard.parsers.Format;
public class TuiFileListWindow extends TuiBrowserWindow {
- private TApplication app;
private List<String> files;
private List<CardResult> cards;
- public TuiFileListWindow(TApplication app, List<String> files) {
- super(app, "Contacts", false);
+ public TuiFileListWindow(TApplication app, int width, int height,
+ List<String> files) {
+ super(app, width, height, "Contacts", false);
- this.app = app;
this.files = files;
cards = new ArrayList<CardResult>();
dataLines.add(listOfOneFile);
}
- addKeyBinding(TKeypress.kbQ, new TAction() {
+ addKeyBinding(TKeypress.kbQ, "Quit", new TAction() {
@Override
public void DO() {
close();
public void onAction(int selectedLine, int selectedColumn) {
try {
@SuppressWarnings("unused")
- TWindow w = new TuiContactListWindow(app, getCard(selectedLine));
+ TWindow w = new TuiContactListWindow(TuiFileListWindow.this,
+ getCard(selectedLine));
} catch (IOException e) {
setMessage("Fail to get file: " + e.getMessage(), true);
}
public class TuiRawContactWindow extends TuiBrowserWindow {
- public TuiRawContactWindow(TApplication app, Contact contact) {
- super(app, "Contact RAW mode", false);
+ public TuiRawContactWindow(TuiBasicWindow parent, Contact contact) {
+ super(parent, "Contact RAW mode", false);
List<String> headers = new ArrayList<String>();
headers.add("Name");
dataLines.add(dataLine);
}
- addKeyBinding(TKeypress.kbQ, new TAction() {
+ addKeyBinding(TKeypress.kbQ, "Quit", new TAction() {
@Override
public void DO() {
close();