+ /**
+ * Show a question to the user and switch to "ask for answer" mode see
+ * {@link MainWindow#handleQuestion}. The user will be asked to enter some
+ * answer and confirm with ENTER.
+ *
+ * @param action
+ * the related action
+ * @param question
+ * the question to ask
+ * @param initial
+ * the initial answer if any (to be edited by the user)
+ */
+ public void setQuestion(KeyAction action, String question, String initial) {
+ setQuestion(action, question, initial, false);
+ }
+
+ /**
+ * Show a question to the user and switch to "ask for answer" mode see
+ * {@link MainWindow#handleQuestion}. The user will be asked to hit one key
+ * as an answer.
+ *
+ * @param action
+ * the related action
+ * @param question
+ * the question to ask
+ */
+ public void setQuestion(KeyAction action, String question) {
+ setQuestion(action, question, null, true);
+ }
+
+ /**
+ * Show a question to the user and switch to "ask for answer" mode see
+ * {@link MainWindow#handleQuestion}.
+ *
+ * @param action
+ * the related action
+ * @param question
+ * the question to ask
+ * @param initial
+ * the initial answer if any (to be edited by the user)
+ * @param oneKey
+ * TRUE for a one-key answer, FALSE for a text answer validated
+ * by ENTER
+ */
+ private void setQuestion(KeyAction action, String question, String initial,
+ boolean oneKey) {
+ userQuestion = new UserQuestion(action, oneKey);
+
+ messagePanel.removeAllComponents();
+
+ Panel hpanel = new Panel();
+ LinearLayout llayout = new LinearLayout(Direction.HORIZONTAL);
+ llayout.setSpacing(0);
+ hpanel.setLayoutManager(llayout);
+
+ Label lbl = UiColors.createLabel(ColorOption.LINE_MESSAGE_QUESTION, " "
+ + question + " ");
+ text = new TextBox(new TerminalSize(getSize().getColumns()
+ - lbl.getSize().getColumns(), 1));
+
+ if (initial != null) {
+ // add all chars one by one so the caret is at the end
+ for (int index = 0; index < initial.length(); index++) {
+ text.handleInput(new KeyStroke(initial.charAt(index), false,
+ false));
+ }
+ }
+
+ 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();
+ }
+
+ /**
+ * Refresh the window and the empty-space handling. You should call this
+ * method when the window size changed.
+ *
+ * @param size
+ * the new size of the window
+ */
+ public void refresh(TerminalSize size) {
+ if (size == null)
+ return;
+
+ if (getSize() == null || !getSize().equals(size))
+ setSize(size);
+
+ setTitle();
+
+ if (actions != null)
+ setActions(new ArrayList<KeyAction>(actions), false);
+
+ invalidate();