git://git.nikiroo.be
/
jvcard.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add more warnings source to 1.6) and fix warnings
[jvcard.git]
/
src
/
be
/
nikiroo
/
jvcard
/
tui
/
MainWindow.java
diff --git
a/src/be/nikiroo/jvcard/tui/MainWindow.java
b/src/be/nikiroo/jvcard/tui/MainWindow.java
index 8dc860dcb3f75212de68187a778cc183e94bc888..617d8a521eb692e17f103f56ddb9bf9f6ba0ab4f 100644
(file)
--- a/
src/be/nikiroo/jvcard/tui/MainWindow.java
+++ b/
src/be/nikiroo/jvcard/tui/MainWindow.java
@@
-1,18
+1,21
@@
package be.nikiroo.jvcard.tui;
package be.nikiroo.jvcard.tui;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-import be.nikiroo.jvcard.i18n.Trans;
-import be.nikiroo.jvcard.i18n.Trans.StringId;
+import be.nikiroo.jvcard.launcher.Main;
+import be.nikiroo.jvcard.resources.ColorOption;
+import be.nikiroo.jvcard.resources.StringId;
import be.nikiroo.jvcard.tui.KeyAction.Mode;
import be.nikiroo.jvcard.tui.KeyAction.Mode;
-import be.nikiroo.jvcard.tui.UiColors.Element;
import be.nikiroo.jvcard.tui.panes.ContactDetails;
import be.nikiroo.jvcard.tui.panes.ContactDetailsRaw;
import be.nikiroo.jvcard.tui.panes.ContactList;
import be.nikiroo.jvcard.tui.panes.MainContent;
import be.nikiroo.jvcard.tui.panes.ContactDetails;
import be.nikiroo.jvcard.tui.panes.ContactDetailsRaw;
import be.nikiroo.jvcard.tui.panes.ContactList;
import be.nikiroo.jvcard.tui.panes.MainContent;
+import be.nikiroo.utils.StringUtils;
+import be.nikiroo.utils.Version;
import com.googlecode.lanterna.TerminalSize;
import com.googlecode.lanterna.gui2.BasicWindow;
import com.googlecode.lanterna.TerminalSize;
import com.googlecode.lanterna.gui2.BasicWindow;
@@
-52,7
+55,7
@@
public class MainWindow extends BasicWindow {
* Information about a question to ask the user and its answer.
*
* @author niki
* Information about a question to ask the user and its answer.
*
* @author niki
- *
+ *
*/
private class UserQuestion {
private boolean oneKeyAnswer;
*/
private class UserQuestion {
private boolean oneKeyAnswer;
@@
-220,6
+223,16
@@
public class MainWindow extends BasicWindow {
if (contentStack.size() > 0)
prev = contentStack.remove(contentStack.size() - 1);
if (contentStack.size() > 0)
prev = contentStack.remove(contentStack.size() - 1);
+ if (prev != null) {
+ try {
+ String mess = prev.wakeup();
+ if (mess != null)
+ setMessage(mess, false);
+ } catch (IOException e) {
+ setMessage(e.getMessage(), true);
+ }
+ }
+
pushContent(prev);
return removed;
pushContent(prev);
return removed;
@@
-239,9
+252,9
@@
public class MainWindow extends BasicWindow {
if (mess != null || messagePanel.getChildCount() > 0) {
messagePanel.removeAllComponents();
if (mess != null) {
if (mess != null || messagePanel.getChildCount() > 0) {
messagePanel.removeAllComponents();
if (mess != null) {
-
Element element = (error ? UiColors.Element
.LINE_MESSAGE_ERR
- :
UiColors.Element
.LINE_MESSAGE);
- Label lbl =
element.createLabel(
" " + mess + " ");
+
ColorOption element = (error ? ColorOption
.LINE_MESSAGE_ERR
+ :
ColorOption
.LINE_MESSAGE);
+ Label lbl =
UiColors.createLabel(element,
" " + mess + " ");
messagePanel.addComponent(lbl, LinearLayout
.createLayoutData(LinearLayout.Alignment.Center));
}
messagePanel.addComponent(lbl, LinearLayout
.createLayoutData(LinearLayout.Alignment.Center));
}
@@
-306,7
+319,7
@@
public class MainWindow extends BasicWindow {
llayout.setSpacing(0);
hpanel.setLayoutManager(llayout);
llayout.setSpacing(0);
hpanel.setLayoutManager(llayout);
- Label lbl = UiColors.
Element.LINE_MESSAGE_QUESTION.createLabel(
" "
+ Label lbl = UiColors.
createLabel(ColorOption.LINE_MESSAGE_QUESTION,
" "
+ question + " ");
text = new TextBox(new TerminalSize(getSize().getColumns()
- lbl.getSize().getColumns(), 1));
+ question + " ");
text = new TextBox(new TerminalSize(getSize().getColumns()
- lbl.getSize().getColumns(), 1));
@@
-392,7
+405,7
@@
public class MainWindow extends BasicWindow {
*/
private void setTitle() {
String prefix = " " + Main.APPLICATION_TITLE + " (version "
*/
private void setTitle() {
String prefix = " " + Main.APPLICATION_TITLE + " (version "
- +
Main.APPLICATION_VERSION
+ ")";
+ +
Version.getCurrentVersion()
+ ")";
String title = null;
int count = -1;
String title = null;
int count = -1;
@@
-408,8
+421,7
@@
public class MainWindow extends BasicWindow {
if (title.length() > 0) {
prefix = prefix + ": ";
if (title.length() > 0) {
prefix = prefix + ": ";
- title = StringUtils.sanitize(title, UiColors.getInstance()
- .isUnicode());
+ title = StringUtils.sanitize(title, Main.isUnicode());
}
String countStr = "";
}
String countStr = "";
@@
-440,27
+452,24
@@
public class MainWindow extends BasicWindow {
super.setTitle(prefix);
Label lblPrefix = new Label(prefix);
super.setTitle(prefix);
Label lblPrefix = new Label(prefix);
- UiColors.
Element.TITLE_MAIN.themeLabel(
lblPrefix);
+ UiColors.
themeLabel(ColorOption.TITLE_MAIN,
lblPrefix);
Label lblTitle = null;
if (title.length() > 0) {
lblTitle = new Label(title);
Label lblTitle = null;
if (title.length() > 0) {
lblTitle = new Label(title);
- UiColors.
Element.TITLE_VARIABLE.themeLabel(
lblTitle);
+ UiColors.
themeLabel(ColorOption.TITLE_VARIABLE,
lblTitle);
}
}
- Label lblCount = null;
- if (countStr != null) {
- lblCount = new Label(countStr);
- UiColors.Element.TITLE_COUNT.themeLabel(lblCount);
- }
+ Label lblCount = new Label(countStr);
+ UiColors.themeLabel(ColorOption.TITLE_COUNT, lblCount);
titlePanel.removeAllComponents();
titlePanel.addComponent(lblPrefix, BorderLayout.Location.LEFT);
titlePanel.removeAllComponents();
titlePanel.addComponent(lblPrefix, BorderLayout.Location.LEFT);
- if (lblTitle != null)
+ if (lblTitle != null)
{
titlePanel.addComponent(lblTitle, BorderLayout.Location.CENTER);
titlePanel.addComponent(lblTitle, BorderLayout.Location.CENTER);
- if (lblCount != null)
-
titlePanel.addComponent(lblCount, BorderLayout.Location.RIGHT);
+ }
+ titlePanel.addComponent(lblCount, BorderLayout.Location.RIGHT);
}
}
}
}
@@
-497,21
+506,22
@@
public class MainWindow extends BasicWindow {
actionPanel.removeAllComponents();
for (KeyAction action : this.actions) {
actionPanel.removeAllComponents();
for (KeyAction action : this.actions) {
- String trans = " " +
action.getStringId().trans(
) + " ";
+ String trans = " " +
Main.trans(action.getStringId()
) + " ";
if (" ".equals(trans))
continue;
if (" ".equals(trans))
continue;
- String keyTrans =
Trans.getInstance()
.trans(action.getKey());
+ String keyTrans =
KeyAction
.trans(action.getKey());
Panel kPane = new Panel();
LinearLayout layout = new LinearLayout(Direction.HORIZONTAL);
layout.setSpacing(0);
kPane.setLayoutManager(layout);
Panel kPane = new Panel();
LinearLayout layout = new LinearLayout(Direction.HORIZONTAL);
layout.setSpacing(0);
kPane.setLayoutManager(layout);
- kPane.addComponent(UiColors.Element.ACTION_KEY
- .createLabel(keyTrans));
- kPane.addComponent(UiColors.Element.ACTION_DESC.createLabel(trans));
+ kPane.addComponent(UiColors.createLabel(ColorOption.ACTION_KEY,
+ keyTrans));
+ kPane.addComponent(UiColors.createLabel(ColorOption.ACTION_DESC,
+ trans));
actionPanel.addComponent(kPane);
}
actionPanel.addComponent(kPane);
}
@@
-523,8
+533,8
@@
public class MainWindow extends BasicWindow {
}
if (width > 0) {
}
if (width > 0) {
- actionPanel.addComponent(UiColors.
Element.ACTION_DESC
-
.createLabel(
StringUtils.padString("", width)));
+ actionPanel.addComponent(UiColors.
createLabel(
+
ColorOption.ACTION_DESC,
StringUtils.padString("", width)));
}
}
}
}
@@
-593,8
+603,6
@@
public class MainWindow extends BasicWindow {
*
* @param key
* the key that was pressed
*
* @param key
* the key that was pressed
- * @param answer
- * the answer given for this key
*
* @return if the window handled the input
*/
*
* @return if the window handled the input
*/
@@
-610,7
+618,13
@@
public class MainWindow extends BasicWindow {
handled = true;
handled = true;
- if (action.onAction()) {
+ action.getObject(); // see {@link KeyAction#getMessage()}
+ String mess = action.getMessage();
+ if (mess != null) {
+ setMessage(mess, action.isError());
+ }
+
+ if (!action.isError() && action.onAction()) {
handleAction(action, null);
}
handleAction(action, null);
}
@@
-623,12
+637,11
@@
public class MainWindow extends BasicWindow {
/**
* Handle the input in case of "normal" (not "ask for answer") mode.
*
/**
* Handle the input in case of "normal" (not "ask for answer") mode.
*
- * @param
key
- * the key that was pressed
+ * @param
action
+ * the key that was pressed
and the action to take
* @param answer
* the answer given for this key
*
* @param answer
* the answer given for this key
*
- * @return if the window handled the input
*/
private void handleAction(KeyAction action, String answer) {
MainContent content = getContent();
*/
private void handleAction(KeyAction action, String answer) {
MainContent content = getContent();
@@
-658,6
+671,10
@@
public class MainWindow extends BasicWindow {
case CONTACT_LIST:
if (action.getCard() != null) {
pushContent(new ContactList(action.getCard()));
case CONTACT_LIST:
if (action.getCard() != null) {
pushContent(new ContactList(action.getCard()));
+ } else if (action.getObject() != null
+ && action.getObject() instanceof MainContent) {
+ MainContent mergeContent = (MainContent) action.getObject();
+ pushContent(mergeContent);
}
break;
case CONTACT_DETAILS:
}
break;
case CONTACT_DETAILS: