package org.zilonis.tool.ui.shell;
import java.awt.BorderLayout;
import java.awt.Font;
import java.io.DataInputStream;
import java.io.PrintStream;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.zilonis.tool.ext.aerith.ui.AerithScrollbarUI;
public class ShellComponent extends JPanel implements Runnable {
private JScrollPane scrollPanel;
private Plugin plugin;
private DataInputStream stdin;
private PrintStream stdout;
private PrintStream stderr;
private Thread linkingThread = null;
protected JLabel statusLabel = new JLabel();
private final InterpreterTextArea interpreterTextArea;
public ShellComponent(Plugin plugin) {
if (null == plugin)
throw new IllegalArgumentException("Require interpreter.");
this.plugin = plugin;
interpreterTextArea = new InterpreterTextArea();
stdin = interpreterTextArea.getInputStreamFromUI();
stdout = interpreterTextArea.getOutputStreamToUI();
stderr = interpreterTextArea.getErrorConsole();
initComponents();
scrollPanel.getVerticalScrollBar().setUI(new AerithScrollbarUI());
scrollPanel.getHorizontalScrollBar().setUI(new AerithScrollbarUI());
scrollPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 6,
1));
scrollPanel
.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPanel
.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
}
public void initComponents() {
setLayout(new BorderLayout());
scrollPanel = new JScrollPane(interpreterTextArea);
add(scrollPanel, BorderLayout.CENTER);
statusLabel.setFont(new Font("SansSerif", Font.PLAIN, 10));
add(statusLabel, BorderLayout.SOUTH);
}
public String getPluginVersion() {
return plugin.userVersion();
}
/**
* Send the argument statement to be evaluated in the interpreter.
*/
/*public void println(String statement) throws IOException {
if (statement != null)
interpreterTextArea.println(statement);
}*/
/**
* Run the interpreter.
*/
public void run() {
statusReset();
while (true) {
try {
plugin.console(stdin, stdout, stderr);
statusReset();
} catch (Exception exc) {
if (!plugin.exception(exc, stdout, stderr))
return;
}
}
}
/**
* Get status label text.
*/
public String getStatus() {
return statusLabel.getText();
}
/**
* Set status label text.
*/
public void setStatus(String msg) {
statusLabel.setText(msg);
}
/**
* Set status label to interp user version string.
*/
public void statusReset() {
statusLabel.setText(plugin.userVersion());
}
/**
* Create and start thread for this shell.
*/
public void start() {
if (linkingThread == null) {
linkingThread = new Thread(this);
linkingThread.start();
}
}
public void stop() {
if (linkingThread != null) {
linkingThread.stop();
linkingThread = null;
}
}
}
|