Warning removal
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
185d19bfcf
commit
626f557aa0
@ -0,0 +1,16 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.swt;
|
||||
|
||||
/** The common interface for console display.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public interface ConsoleOutputDisplay {
|
||||
|
||||
/** Append a line to the display.
|
||||
*
|
||||
* @param m the line content */
|
||||
void appendLine(String m);
|
||||
|
||||
}
|
@ -4,34 +4,45 @@
|
||||
package net.bigeon.gclc.swt;
|
||||
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.swt.widgets.Widget;
|
||||
|
||||
import net.bigeon.gclc.utils.AOutputForwardRunnable;
|
||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
||||
|
||||
/** @author Emmanuel Bigeon */
|
||||
public final class ConsoleOutputManager {
|
||||
/** The local implementation of the forwarding runnable
|
||||
/** The manager for console output to insert in a text.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public final class ConsoleOutputManager implements ConsoleOutputDisplay {
|
||||
/** The local implementation of the forwarding runnable.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
private final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable {
|
||||
public static final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable {
|
||||
/** The running status */
|
||||
private boolean running = true;
|
||||
private final PipedConsoleOutput out;
|
||||
private boolean running = true;
|
||||
private final PipedConsoleOutput out;
|
||||
private final ConsoleOutputDisplay display;
|
||||
private final Widget element;
|
||||
|
||||
/** @param manager the manager */
|
||||
public ToSWTConsoleForwardRunnable(final PipedConsoleOutput manager) {
|
||||
/** @param manager the manager
|
||||
* @param display the display
|
||||
* @param element the composite */
|
||||
public ToSWTConsoleForwardRunnable(final PipedConsoleOutput manager,
|
||||
final ConsoleOutputDisplay display,
|
||||
final Widget element) {
|
||||
super(manager);
|
||||
out = manager;
|
||||
this.display = display;
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void forwardLine(final String m) {
|
||||
appendConsoleOutput(System.lineSeparator() + m);
|
||||
display.appendLine(m);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunning() {
|
||||
return running && !text.isDisposed();
|
||||
return running && !element.isDisposed();
|
||||
}
|
||||
|
||||
/** @param running the running to set */
|
||||
@ -57,11 +68,15 @@ public final class ConsoleOutputManager {
|
||||
}
|
||||
|
||||
/** @param next the next message */
|
||||
public void appendConsoleOutput(final String next) {
|
||||
@Override
|
||||
public void appendLine(final String next) {
|
||||
text.getDisplay().syncExec(new Runnable() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
if (!text.getText().isEmpty()) {
|
||||
text.append(System.lineSeparator());
|
||||
}
|
||||
text.append(next);
|
||||
}
|
||||
});
|
||||
@ -82,7 +97,7 @@ public final class ConsoleOutputManager {
|
||||
forwardThread = null;
|
||||
return;
|
||||
}
|
||||
forward = new ToSWTConsoleForwardRunnable(output);
|
||||
forward = new ToSWTConsoleForwardRunnable(output, this, text);
|
||||
forwardThread = new Thread(forward, "gclcToSWT"); //$NON-NLS-1$
|
||||
forwardThread.start();
|
||||
}
|
||||
|
@ -5,19 +5,42 @@ package net.bigeon.gclc.swt;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bigeon
|
||||
/** The runnable forwarding prompts from a buffered input to a label.
|
||||
*
|
||||
*/
|
||||
* @author Emmanuel Bigeon */
|
||||
public class PromptReadingRunnable implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = Logger
|
||||
.getLogger(PromptReadingRunnable.class.getName());
|
||||
private final BufferedReader reader;
|
||||
private final Label view;
|
||||
private boolean running = true;
|
||||
|
||||
private static class LabelUpdater implements Runnable {
|
||||
private final Label label;
|
||||
private final String content;
|
||||
|
||||
/** @param label the label
|
||||
* @param content the content */
|
||||
public LabelUpdater(final Label label, final String content) {
|
||||
super();
|
||||
this.label = label;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run() */
|
||||
@Override
|
||||
public void run() {
|
||||
label.setText(content);
|
||||
}
|
||||
}
|
||||
|
||||
/** @param reader the reader
|
||||
* @param view the view to update on lines. */
|
||||
public PromptReadingRunnable(final BufferedReader reader, final Label view) {
|
||||
@ -27,24 +50,16 @@ public class PromptReadingRunnable implements Runnable {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
* @see java.lang.Runnable#run() */
|
||||
@Override
|
||||
public void run() {
|
||||
String prompt;
|
||||
try {
|
||||
while (isRunning() && (prompt = reader.readLine()) != null) {
|
||||
final String curPrompt = prompt;
|
||||
view.getDisplay().syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
view.setText(curPrompt);
|
||||
}
|
||||
});
|
||||
view.getDisplay().syncExec(new LabelUpdater(view, prompt));
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
LOGGER.log(Level.INFO, "Prompt cannot be read, or was prematuraly closed", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user