Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2018-11-30 22:02:44 -05:00
parent bb06b2a799
commit 0562faad70
3 changed files with 57 additions and 18 deletions

View File

@ -9,19 +9,24 @@ import org.eclipse.swt.widgets.Text;
import net.bigeon.gclc.utils.PipedConsoleInput;
/** @author Emmanuel Bigeon */
/** The object managing the console input.
*
* @author Emmanuel Bigeon */
public final class ConsoleInputManager implements ConsoleDelayIO {
private final Text text;
private PipedConsoleInput input;
/** @param text the text */
/** Create a managing object.
*
* @param text the text */
public ConsoleInputManager(final Text text) {
super();
this.text = text;
}
/** @param string the text */
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#setInput(java.lang.String) */
@Override
public void setInput(final String string) {
text.setText(string);
@ -35,19 +40,23 @@ public final class ConsoleInputManager implements ConsoleDelayIO {
return text.getText();
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#validateInput() */
@Override
public void validateInput() throws IOException {
input.type(text.getText());
}
/** Set the input to control
/** Set the input to control.
*
* @param input the input */
public void setManager(final PipedConsoleInput input) {
this.input = input;
}
/** @return the text */
/** Get the text component containing the currently set input.
*
* @return the text */
public Text getText() {
return text;
}

View File

@ -7,25 +7,36 @@ import java.io.BufferedReader;
import org.eclipse.swt.widgets.Label;
/** @author Emmanuel Bigeon */
/** The manager for the console prompt updates.
*
* @author Emmanuel Bigeon */
public final class ConsolePromptManager {
private final Label label;
/** The label to set the prompts at. */
private final Label label;
/** The current prompt reading runnable. */
private PromptReadingRunnable promptRead;
/** @param label the label to update */
/** Create the manager.
*
* @param label the label to update with prompts */
public ConsolePromptManager(final Label label) {
super();
this.label = label;
}
/** @param string the text */
/** Set the prompt.
* <p>
* This method sets the prompt on the label as requested, without changing the
* actual prompt of the console input.
*
* @param string the text */
public void setPrompt(final String string) {
label.setText(string);
}
/** Set the input to control
/** Set the input to control.
*
* @param promptStream the input */
public void setStream(final BufferedReader promptStream) {
@ -39,8 +50,7 @@ public final class ConsolePromptManager {
promptRead = null;
return;
}
promptRead = new PromptReadingRunnable(promptStream,
label);
promptRead = new PromptReadingRunnable(promptStream, label);
final Thread th = new Thread(promptRead, "Prompt To Label");
th.start();
}

View File

@ -15,17 +15,29 @@ import org.eclipse.swt.widgets.Label;
* @author Emmanuel Bigeon */
public class PromptReadingRunnable implements Runnable {
private static final Logger LOGGER = Logger
/** The logger for this class. */
private static final Logger LOGGER = Logger
.getLogger(PromptReadingRunnable.class.getName());
/** The reader providing the succession of prompts */
private final BufferedReader reader;
/** The label. */
private final Label view;
/** The running status. */
private boolean running = true;
/** The updating runnable implementation.
*
* @author Emmanuel Bigeon */
private static class LabelUpdater implements Runnable {
/** The label to update. */
private final Label label;
/** The text to set. */
private final String content;
/** @param label the label
/** Create the updating runnable.
*
* @param label the label
* @param content the content */
public LabelUpdater(final Label label, final String content) {
super();
@ -41,7 +53,9 @@ public class PromptReadingRunnable implements Runnable {
}
}
/** @param reader the reader
/** Create the prompt flow updating runnable.
*
* @param reader the reader
* @param view the view to update on lines. */
public PromptReadingRunnable(final BufferedReader reader, final Label view) {
super();
@ -63,17 +77,23 @@ public class PromptReadingRunnable implements Runnable {
}
}
/** @return the running */
/** Get the running state.
*
* @return the running */
public synchronized boolean isRunning() {
return running;
}
/** @param running the running to set */
/** Set the running state.
*
* @param running the running to set */
public synchronized void setRunning(final boolean running) {
this.running = running;
}
/** @return the reader */
/** Get the prompt flow.
*
* @return the reader */
public BufferedReader getReader() {
return reader;
}