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