1 /*******************************************************************************
\r
2 * Copyright (c) 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics;
\r
14 import java.io.IOException;
\r
16 import org.simantics.databoard.util.binary.InputStreamReadable;
\r
19 * @author Tuukka Lehtonen
\r
21 public class ConsoleUserAgent implements PlatformUserAgent {
\r
24 public int showPrompt(String title, String message, String[] options, int defaultChoice) {
\r
28 System.out.println("== " + title + " ==\n");
\r
29 System.out.println(message + "\n");
\r
30 for (int i = 0; i < options.length; ++i)
\r
31 System.out.println("[" + i + "] " + options[i]);
\r
32 System.out.print("Select [");
\r
33 for (int i = 0; i < options.length; ++i)
\r
34 System.out.print(i);
\r
35 System.out.println("] (default = " + defaultChoice + ") ? ");
\r
37 InputStreamReadable rdr = new InputStreamReadable(System.in, 1);
\r
38 String str = rdr.readLine();
\r
39 //System.out.println("READ: '" + str + "'");
\r
41 int choice = Integer.parseInt(str);
\r
42 if (choice >= 0 && choice < options.length) {
\r
46 } catch (NumberFormatException e) {
\r
47 // Just repeat the question if input is unintelligible
\r
50 } catch (IOException e) {
\r
51 e.printStackTrace();
\r
53 return defaultChoice;
\r