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