X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2FMainWindow.java;h=aa996353c9b2b8d292dfa92761f763c94bd98a09;hp=7f438d918a717792f2686d6a86379c8949d74dd2;hb=9c8baf0c360173b864683176c567757429c4fb12;hpb=fae07ea7af01c64ca1a858db75a615555318d5e2 diff --git a/src/be/nikiroo/jvcard/tui/MainWindow.java b/src/be/nikiroo/jvcard/tui/MainWindow.java index 7f438d9..aa99635 100644 --- a/src/be/nikiroo/jvcard/tui/MainWindow.java +++ b/src/be/nikiroo/jvcard/tui/MainWindow.java @@ -1,5 +1,6 @@ package be.nikiroo.jvcard.tui; +import java.io.File; import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -122,13 +123,30 @@ public class MainWindow extends BasicWindow { actions = content.getKeyBindings(); contentPanel.addComponent(content, BorderLayout.Location.CENTER); this.content.add(content); + + Interactable focus = content.nextFocus(null); + if (focus != null) + focus.takeFocus(); } setTitle(title); setActions(actions, true, true); + invalidate(); } + public MainContent popContent() { + MainContent removed = null; + MainContent prev = null; + if (content.size() > 0) + removed = content.remove(content.size() - 1); + if (content.size() > 0) + prev = content.remove(content.size() - 1); + pushContent(prev); + + return removed; + } + /** * Set the application title. * @@ -152,6 +170,52 @@ public class MainWindow extends BasicWindow { .createLayoutData(LinearLayout.Alignment.Center)); } + /** + * Show the given message on screen. It will disappear at the next action. + * + * @param mess + * the message to display + * @param error + * TRUE for an error message, FALSE for an information message + */ + public void setMessage(String mess, boolean error) { + messagePanel.removeAllComponents(); + if (mess != null) { + Element element = (error ? UiColors.Element.LINE_MESSAGE_ERR + : UiColors.Element.LINE_MESSAGE); + Label lbl = element.createLabel(" " + mess + " "); + messagePanel.addComponent(lbl, LinearLayout + .createLayoutData(LinearLayout.Alignment.Center)); + } + } + + public void setQuestion(String mess, boolean oneKey) { + messagePanel.removeAllComponents(); + if (mess != null) { + waitForOneKeyAnswer = oneKey; + + Panel hpanel = new Panel(); + LinearLayout llayout = new LinearLayout(Direction.HORIZONTAL); + llayout.setSpacing(0); + hpanel.setLayoutManager(llayout); + + Label lbl = UiColors.Element.LINE_MESSAGE_QUESTION.createLabel(" " + + mess + " "); + text = new TextBox(new TerminalSize(getSize().getColumns() + - lbl.getSize().getColumns(), 1)); + + hpanel.addComponent(lbl, LinearLayout + .createLayoutData(LinearLayout.Alignment.Beginning)); + hpanel.addComponent(text, LinearLayout + .createLayoutData(LinearLayout.Alignment.Fill)); + + messagePanel.addComponent(hpanel, LinearLayout + .createLayoutData(LinearLayout.Alignment.Beginning)); + + text.takeFocus(); + } + } + @Override public void draw(TextGUIGraphics graphics) { setTitle(title); @@ -165,24 +229,12 @@ public class MainWindow extends BasicWindow { super.draw(graphics); } - public MainContent popContent() { - MainContent removed = null; - MainContent prev = null; - if (content.size() > 0) - removed = content.remove(content.size() - 1); - if (content.size() > 0) - prev = content.remove(content.size() - 1); - pushContent(prev); - - return removed; - } - private void setActions(List actions, boolean allowKeys, boolean enableDefaultactions) { this.actions.clear(); actionsPadded = false; - + if (enableDefaultactions) this.actions.addAll(defaultActions); @@ -233,52 +285,6 @@ public class MainWindow extends BasicWindow { } } - /** - * Show the given message on screen. It will disappear at the next action. - * - * @param mess - * the message to display - * @param error - * TRUE for an error message, FALSE for an information message - */ - public void setMessage(String mess, boolean error) { - messagePanel.removeAllComponents(); - if (mess != null) { - Element element = (error ? UiColors.Element.LINE_MESSAGE_ERR - : UiColors.Element.LINE_MESSAGE); - Label lbl = element.createLabel(" " + mess + " "); - messagePanel.addComponent(lbl, LinearLayout - .createLayoutData(LinearLayout.Alignment.Center)); - } - } - - public void setQuestion(String mess, boolean oneKey) { - messagePanel.removeAllComponents(); - if (mess != null) { - waitForOneKeyAnswer = oneKey; - - Panel hpanel = new Panel(); - LinearLayout llayout = new LinearLayout(Direction.HORIZONTAL); - llayout.setSpacing(0); - hpanel.setLayoutManager(llayout); - - Label lbl = UiColors.Element.LINE_MESSAGE_QUESTION.createLabel(" " - + mess + " "); - text = new TextBox(new TerminalSize(getSize().getColumns() - - lbl.getSize().getColumns(), 1)); - - hpanel.addComponent(lbl, LinearLayout - .createLayoutData(LinearLayout.Alignment.Beginning)); - hpanel.addComponent(text, LinearLayout - .createLayoutData(LinearLayout.Alignment.Fill)); - - messagePanel.addComponent(hpanel, LinearLayout - .createLayoutData(LinearLayout.Alignment.Beginning)); - - text.takeFocus(); - } - } - private String handleQuestion(KeyStroke key) { String answer = null;