git://git.nikiroo.be
/
jvcard.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c8398c2
)
Update support code for Jexer
author
Niki Roo
<niki@nikiroo.be>
Sat, 28 Apr 2018 09:55:32 +0000
(11:55 +0200)
committer
Niki Roo
<niki@nikiroo.be>
Sat, 28 Apr 2018 09:55:32 +0000
(11:55 +0200)
src/be/nikiroo/jvcard/launcher/Main.java
patch
|
blob
|
blame
|
history
src/be/nikiroo/jvcard/tui/TuiLauncherJexer.java
patch
|
blob
|
blame
|
history
src/be/nikiroo/jvcard/tui/windows/TuiBasicWindow.java
patch
|
blob
|
blame
|
history
src/be/nikiroo/jvcard/tui/windows/TuiBrowserWindow.java
patch
|
blob
|
blame
|
history
src/be/nikiroo/jvcard/tui/windows/TuiContactListWindow.java
patch
|
blob
|
blame
|
history
src/be/nikiroo/jvcard/tui/windows/TuiContactWindow.java
patch
|
blob
|
blame
|
history
src/be/nikiroo/jvcard/tui/windows/TuiFileListWindow.java
patch
|
blob
|
blame
|
history
src/be/nikiroo/jvcard/tui/windows/TuiRawContactWindow.java
patch
|
blob
|
blame
|
history
diff --git
a/src/be/nikiroo/jvcard/launcher/Main.java
b/src/be/nikiroo/jvcard/launcher/Main.java
index 69ed7e9b4fb123e6dd855000603cd7c6ab677fce..a073e92921a09c0a41b12dc5af2b718de268f7d0 100644
(file)
--- a/
src/be/nikiroo/jvcard/launcher/Main.java
+++ b/
src/be/nikiroo/jvcard/launcher/Main.java
@@
-57,7
+57,7
@@
public class Main {
/**
* Translate the given {@link StringId} into user text.
*
/**
* Translate the given {@link StringId} into user text.
*
- * @param
stringI
d
+ * @param
i
d
* the ID to translate
* @param values
* the values to insert instead of the place holders in the
* the ID to translate
* @param values
* the values to insert instead of the place holders in the
diff --git
a/src/be/nikiroo/jvcard/tui/TuiLauncherJexer.java
b/src/be/nikiroo/jvcard/tui/TuiLauncherJexer.java
index b79488cdd00601ef7db46bf55827f580c1eddef9..3f54633122c445066192cc2c04b420a34e02faea 100644
(file)
--- a/
src/be/nikiroo/jvcard/tui/TuiLauncherJexer.java
+++ b/
src/be/nikiroo/jvcard/tui/TuiLauncherJexer.java
@@
-1,6
+1,5
@@
package be.nikiroo.jvcard.tui;
package be.nikiroo.jvcard.tui;
-import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.io.UnsupportedEncodingException;
import java.util.List;
@@
-17,6
+16,8
@@
import be.nikiroo.jvcard.tui.windows.TuiFileListWindow;
public class TuiLauncherJexer extends TApplication {
/**
* Application is in fullscreen mode, no windows.
public class TuiLauncherJexer extends TApplication {
/**
* Application is in fullscreen mode, no windows.
+ *
+ * TODO: make it an option
*/
static public final boolean FULLSCREEN = true;
*/
static public final boolean FULLSCREEN = true;
@@
-26,7
+27,9
@@
public class TuiLauncherJexer extends TApplication {
* emulator, null to automatically determine the best choice
* @param files
* the files to show at startup
* emulator, null to automatically determine the best choice
* @param files
* the files to show at startup
+ *
* @throws UnsupportedEncodingException
* @throws UnsupportedEncodingException
+ * if an exception is thrown when creating the InputStreamReader
*/
public TuiLauncherJexer(final Boolean textMode, final List<String> files)
throws UnsupportedEncodingException {
*/
public TuiLauncherJexer(final Boolean textMode, final List<String> files)
throws UnsupportedEncodingException {
@@
-35,22
+38,24
@@
public class TuiLauncherJexer extends TApplication {
addFileMenu();
addWindowMenu();
addFileMenu();
addWindowMenu();
- // TODO investigate why that is
+ int width = getBackend().getScreen().getWidth();
+ int height = getBackend().getScreen().getHeight() - 2;
+
if (backend(textMode) == BackendType.SWING) {
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,
TuiBrowserWindow main = new TuiFileListWindow(TuiLauncherJexer.this,
- files);
+ width, height, files);
+
main.addCloseListener(new TAction() {
@Override
public void DO() {
main.addCloseListener(new TAction() {
@Override
public void DO() {
@@
-61,11
+66,8
@@
public class TuiLauncherJexer extends TApplication {
/**
* Start the TUI program.
/**
* Start the TUI program.
- *
- * @throws IOException
- * in case of IO error
*/
*/
- public void start()
throws IOException
{
+ public void start() {
(new Thread(this)).start();
}
(new Thread(this)).start();
}
@@
-73,7
+75,7
@@
public class TuiLauncherJexer extends TApplication {
* Select the most appropriate backend.
*
* @param textMode
* Select the most appropriate backend.
*
* @param textMode
- * NULL for auto-dection
+ * NULL for auto-de
te
ction
* @return the backend type to use
*/
private static BackendType backend(Boolean textMode) {
* @return the backend type to use
*/
private static BackendType backend(Boolean textMode) {
diff --git
a/src/be/nikiroo/jvcard/tui/windows/TuiBasicWindow.java
b/src/be/nikiroo/jvcard/tui/windows/TuiBasicWindow.java
index a87df613c6d2e67cba8f5b3f0b6186a8e4df385e..404d1460177eec84a0e74f896589d747e516c704 100644
(file)
--- a/
src/be/nikiroo/jvcard/tui/windows/TuiBasicWindow.java
+++ b/
src/be/nikiroo/jvcard/tui/windows/TuiBasicWindow.java
@@
-8,6
+8,7
@@
import java.util.Map;
import jexer.TAction;
import jexer.TApplication;
import jexer.TKeypress;
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;
import jexer.TWindow;
import jexer.event.TKeypressEvent;
import be.nikiroo.jvcard.tui.TuiLauncherJexer;
@@
-22,6
+23,18
@@
public abstract class TuiBasicWindow extends TWindow {
private Map<TKeypress, TAction> keyBindings;
private List<TAction> closeListeners;
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.
*
/**
* Create a new window with the given title.
*
@@
-29,13
+42,13
@@
public abstract class TuiBasicWindow extends TWindow {
* the application that will manage this window
* @param title
* the window 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;
this.app = app;
@@
-53,11
+66,20
@@
public abstract class TuiBasicWindow extends TWindow {
*
* @param key
* the key to press
*
* @param key
* the key to press
+ * @param text
+ * the text to display for this command
* @param action
* the action
*/
* @param action
* the action
*/
- public void addKeyBinding(TKeypress key, TAction action) {
+ public void addKeyBinding(TKeypress key,
String text,
TAction action) {
keyBindings.put(key, action);
keyBindings.put(key, action);
+
+ TStatusBar statusbar = getStatusBar();
+ if (statusbar == null) {
+ statusbar = newStatusBar("");
+ }
+
+ statusbar.addShortcutKeypress(key, null, text);
}
/**
}
/**
@@
-71,13
+93,6
@@
public abstract class TuiBasicWindow extends TWindow {
closeListeners.add(listener);
}
closeListeners.add(listener);
}
- /**
- * Close the window.
- */
- public void close() {
- app.closeWindow(this);
- }
-
@Override
public void onClose() {
super.onClose();
@Override
public void onClose() {
super.onClose();
diff --git
a/src/be/nikiroo/jvcard/tui/windows/TuiBrowserWindow.java
b/src/be/nikiroo/jvcard/tui/windows/TuiBrowserWindow.java
index 827f7b9f2a2f2559d31bd767b2b0e001e45330ea..31ffce79909b7aa121f3d2191a5618437c3b6f2e 100644
(file)
--- a/
src/be/nikiroo/jvcard/tui/windows/TuiBrowserWindow.java
+++ b/
src/be/nikiroo/jvcard/tui/windows/TuiBrowserWindow.java
@@
-12,16
+12,26
@@
public abstract class TuiBrowserWindow extends TuiBasicWindow {
private TTable table;
private boolean showHeader;
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() {
this.showHeader = showHeaders;
table = new TTable(this, 0, 0, getWidth() - 2, getHeight() - 2,
new TAction() {
@Override
public void DO() {
- onAction(table.getSelected
Line
(),
+ onAction(table.getSelected
Row
(),
table.getSelectedColumn());
}
}, null);
table.getSelectedColumn());
}
}, null);
@@
-32,22
+42,22
@@
public abstract class TuiBrowserWindow extends TuiBasicWindow {
*
* @param headers
* the table headers (mandatory)
*
* @param headers
* the table headers (mandatory)
- * @param
line
s
+ * @param
row
s
* the data to display
*/
* the data to display
*/
- public void setData(List<String> headers, List<List<String>>
line
s) {
- int prev
Line = table.getSelectedLine
();
+ public void setData(List<String> headers, List<List<String>>
row
s) {
+ int prev
Row = table.getSelectedRow
();
int prevColumn = table.getSelectedColumn();
table.clear();
table.setHeaders(headers, showHeader);
int prevColumn = table.getSelectedColumn();
table.clear();
table.setHeaders(headers, showHeader);
- for (List<String>
line : line
s) {
- table.add
Line(line
);
+ for (List<String>
row : row
s) {
+ table.add
Row(row
);
}
table.reflow();
}
table.reflow();
- table.setSelected
Line(Math.min(prevLine, table.getNumberOfLine
s() - 1));
+ table.setSelected
Row(Math.min(prevRow, table.getNumberOfRow
s() - 1));
table.setSelectedColumn(Math.min(prevColumn,
table.getNumberOfColumns() - 1));
}
table.setSelectedColumn(Math.min(prevColumn,
table.getNumberOfColumns() - 1));
}
@@
-59,19
+69,19
@@
public abstract class TuiBrowserWindow extends TuiBasicWindow {
* @return -1 or the number of present items
*/
public int size() {
* @return -1 or the number of present items
*/
public int size() {
- return table.getNumberOf
Line
s();
+ return table.getNumberOf
Row
s();
}
/**
* An item has been selected.
*
}
/**
* An item has been selected.
*
- * @param selected
Line
- * the currently selected
line
+ * @param selected
Row
+ * the currently selected
row
* @param selectedColumn
* the currently selected column
*/
@SuppressWarnings("unused")
* @param selectedColumn
* the currently selected column
*/
@SuppressWarnings("unused")
- public void onAction(int selected
Line
, int selectedColumn) {
+ public void onAction(int selected
Row
, int selectedColumn) {
}
@Override
}
@Override
diff --git
a/src/be/nikiroo/jvcard/tui/windows/TuiContactListWindow.java
b/src/be/nikiroo/jvcard/tui/windows/TuiContactListWindow.java
index af6b08edd496f471ceaa31ff9d0248cf44add9ad..21a8ca3c6cec2f904be935d622ffd4bad0006564 100644
(file)
--- a/
src/be/nikiroo/jvcard/tui/windows/TuiContactListWindow.java
+++ b/
src/be/nikiroo/jvcard/tui/windows/TuiContactListWindow.java
@@
-15,17
+15,15
@@
import be.nikiroo.jvcard.resources.DisplayBundle;
import be.nikiroo.jvcard.resources.DisplayOption;
public class TuiContactListWindow extends TuiBrowserWindow {
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;
private Card card;
private String filter;
private List<String> formats;
private int selectedFormat;
private String format;
- public TuiContactListWindow(T
Application app
, Card card) {
- super(
app
, "Contacts", false);
+ public TuiContactListWindow(T
uiBasicWindow parent
, Card card) {
+ super(
parent
, "Contacts", false);
- this.app = app;
this.card = card;
this.selectedFormat = -1;
this.card = card;
this.selectedFormat = -1;
@@
-36,17
+34,17
@@
public class TuiContactListWindow extends TuiBrowserWindow {
formats.add(format);
}
formats.add(format);
}
- addKeyBinding(TKeypress.kb
Tab
, new TAction() {
+ addKeyBinding(TKeypress.kb
Q, "Quit"
, new TAction() {
@Override
public void DO() {
@Override
public void DO() {
-
switchFormat
();
+
close
();
}
});
}
});
-
- addKeyBinding(TKeypress.kb
Q
, new TAction() {
+
+ addKeyBinding(TKeypress.kb
Tab, "Switch format"
, new TAction() {
@Override
public void DO() {
@Override
public void DO() {
-
close
();
+
switchFormat
();
}
});
}
});
@@
-58,7
+56,7
@@
public class TuiContactListWindow extends TuiBrowserWindow {
public void onAction(int selectedLine, int selectedColumn) {
try {
@SuppressWarnings("unused")
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);
}
} catch (IndexOutOfBoundsException e) {
setMessage("Fail to get contact", true);
}
diff --git
a/src/be/nikiroo/jvcard/tui/windows/TuiContactWindow.java
b/src/be/nikiroo/jvcard/tui/windows/TuiContactWindow.java
index c8a31b895e00f8e3c725bf14af069c702b8d1509..f1a6c3439d4b3d4d1dfbc23b0bbae85f3743e982 100644
(file)
--- a/
src/be/nikiroo/jvcard/tui/windows/TuiContactWindow.java
+++ b/
src/be/nikiroo/jvcard/tui/windows/TuiContactWindow.java
@@
-1,28
+1,28
@@
package be.nikiroo.jvcard.tui.windows;
import jexer.TAction;
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 {
import jexer.TKeypress;
import jexer.TLabel;
import jexer.TWindow;
import be.nikiroo.jvcard.Contact;
public class TuiContactWindow extends TuiBasicWindow {
- public TuiContactWindow(final T
Application app
, final Contact contact) {
- super(
app
, "Contact view");
+ public TuiContactWindow(final T
uiBasicWindow parent
, final Contact contact) {
+ super(
parent
, "Contact view");
- addKeyBinding(TKeypress.kbQ, new TAction() {
+ addKeyBinding(TKeypress.kbQ,
"Quit",
new TAction() {
@Override
public void DO() {
@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")
@Override
public void DO() {
@SuppressWarnings("unused")
- TWindow w = new TuiRawContactWindow(app, contact);
+ TWindow w = new TuiRawContactWindow(TuiContactWindow.this,
+ contact);
}
});
}
});
diff --git
a/src/be/nikiroo/jvcard/tui/windows/TuiFileListWindow.java
b/src/be/nikiroo/jvcard/tui/windows/TuiFileListWindow.java
index f1feea5c021ead72fb6ae9c4c1f24694ed3eb76e..f354a1061c0c9bcbf36cd1fbb2addf2119149dfb 100644
(file)
--- a/
src/be/nikiroo/jvcard/tui/windows/TuiFileListWindow.java
+++ b/
src/be/nikiroo/jvcard/tui/windows/TuiFileListWindow.java
@@
-17,14
+17,13
@@
import be.nikiroo.jvcard.launcher.Main;
import be.nikiroo.jvcard.parsers.Format;
public class TuiFileListWindow extends TuiBrowserWindow {
import be.nikiroo.jvcard.parsers.Format;
public class TuiFileListWindow extends TuiBrowserWindow {
- private TApplication app;
private List<String> files;
private List<CardResult> cards;
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>();
this.files = files;
cards = new ArrayList<CardResult>();
@@
-41,7
+40,7
@@
public class TuiFileListWindow extends TuiBrowserWindow {
dataLines.add(listOfOneFile);
}
dataLines.add(listOfOneFile);
}
- addKeyBinding(TKeypress.kbQ, new TAction() {
+ addKeyBinding(TKeypress.kbQ,
"Quit",
new TAction() {
@Override
public void DO() {
close();
@Override
public void DO() {
close();
@@
-55,7
+54,8
@@
public class TuiFileListWindow extends TuiBrowserWindow {
public void onAction(int selectedLine, int selectedColumn) {
try {
@SuppressWarnings("unused")
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);
}
} catch (IOException e) {
setMessage("Fail to get file: " + e.getMessage(), true);
}
diff --git
a/src/be/nikiroo/jvcard/tui/windows/TuiRawContactWindow.java
b/src/be/nikiroo/jvcard/tui/windows/TuiRawContactWindow.java
index c784b8091704723f582bc2ae3b4f2c1e10d7c475..e69ee37a7497f14e9bd20365bc0f5b2bf50c92b6 100644
(file)
--- a/
src/be/nikiroo/jvcard/tui/windows/TuiRawContactWindow.java
+++ b/
src/be/nikiroo/jvcard/tui/windows/TuiRawContactWindow.java
@@
-11,8
+11,8
@@
import be.nikiroo.jvcard.Data;
public class TuiRawContactWindow extends TuiBrowserWindow {
public class TuiRawContactWindow extends TuiBrowserWindow {
- public TuiRawContactWindow(T
Application app
, Contact contact) {
- super(
app
, "Contact RAW mode", false);
+ public TuiRawContactWindow(T
uiBasicWindow parent
, Contact contact) {
+ super(
parent
, "Contact RAW mode", false);
List<String> headers = new ArrayList<String>();
headers.add("Name");
List<String> headers = new ArrayList<String>();
headers.add("Name");
@@
-29,7
+29,7
@@
public class TuiRawContactWindow extends TuiBrowserWindow {
dataLines.add(dataLine);
}
dataLines.add(dataLine);
}
- addKeyBinding(TKeypress.kbQ, new TAction() {
+ addKeyBinding(TKeypress.kbQ,
"Quit",
new TAction() {
@Override
public void DO() {
close();
@Override
public void DO() {
close();