@@ -0,0 +1,2439 @@
+package com.alexrnl.subtitlecorrector.gui.view;%0A%0Aimport java.io.PrintStream;%0Aimport java.util.Scanner;%0Aimport java.util.logging.Logger;%0A%0Aimport com.alexrnl.commons.utils.Word;%0Aimport com.alexrnl.subtitlecorrector.service.SessionParameters;%0Aimport com.alexrnl.subtitlecorrector.service.UserPrompt;%0Aimport com.alexrnl.subtitlecorrector.service.UserPromptAnswer;%0A%0A/**%0A * A console implementation for the %7B@link UserPrompt%7D interface.%0A * @author Alex%0A */%0Apublic class ConsoleUserPrompt implements UserPrompt %7B%0A%09/** Logger */%0A%09private static Logger%09%09lg%09= Logger.getLogger(ConsoleUserPrompt.class.getName());%0A%09%0A%09/** The scanner plugged on the console input */%0A%09private Scanner%09%09%09%09input;%0A%09/** The console output */%0A%09private final PrintStream%09output;%0A%09%0A%09/**%0A%09 * Constructor #1.%3Cbr /%3E%0A%09 */%0A%09public ConsoleUserPrompt () %7B%0A%09%09super();%0A%09%09input = null;%0A%09%09output = System.out;%0A%09%7D%0A%09%0A%09@Override%0A%09public void startSession (final SessionParameters parameters) %7B%0A%09%09if (input != null) %7B%0A%09%09%09throw new IllegalStateException(%22Session was not properly stop, input was not null%22);%0A%09%09%7D%0A%09%09input = new Scanner(System.in);%0A%09%7D%0A%0A%09@Override%0A%09public void stopSession () %7B%0A%09%09if (input == null) %7B%0A%09%09%09throw new IllegalStateException(%22Session was not properly started, input was null%22);%0A%09%09%7D%0A%09%09input = null;%0A%09%09%0A%09%7D%0A%0A%09@Override%0A%09public UserPromptAnswer confirm (final String context, final Word original, final String replacement) %7B%0A%09%09if (input == null) %7B%0A%09%09%09throw new IllegalStateException(%22Session was not properly started, input is null, %22 +%0A%09%09%09%09%09%22cannot confirm replacement%22);%0A%09%09%7D%0A%09%09String answer;%0A%09%09boolean cancelled = false;%0A%09%09boolean rememberChoice;%0A%09%09%0A%09%09// TODO translate%0A%09%09output.println(%22Replace '%22 + original + %22' by '%22 + replacement + %22'?%22);%0A%09%09if (context != null) %7B%0A%09%09%09output.println(%22Context:%5Cn%5Ct%22);%0A%09%09%09output.println(context);%0A%09%09%7D%0A%09%09output.println(%22y/n %3E%22);%0A%09%09final boolean keep = 'y' == input.nextLine().charAt(0);%0A%09%09if (keep) %7B%0A%09%09%09answer = replacement;%0A%09%09%7D else %7B%0A%09%09%09output.println(%22Type the replacement:%22);%0A%09%09%09answer = input.nextLine();%0A%09%09%09if (answer.isEmpty()) %7B%0A%09%09%09%09cancelled = true;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09output.println(%22Remember choice for the rest of the session?%22);%0A%09%09output.println(%22y/n %3E%22);%0A%09%09rememberChoice = 'y' == input.nextLine().charAt(0);%0A%09%09%0A%09%09return new UserPromptAnswer(answer, cancelled, rememberChoice);%0A%09%7D%0A%09%0A%09@Override%0A%09public UserPromptAnswer confirm (final Word original, final String replacement) %7B%0A%09%09return confirm(null, original, replacement);%0A%09%7D%0A%7D%0A

Add a ConsoleUserPrompt