summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/gui/Console.java
diff options
context:
space:
mode:
Diffstat (limited to 'source/com/c2kernel/gui/Console.java')
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/gui/Console.java93
1 files changed, 56 insertions, 37 deletions
diff --git a/source/com/c2kernel/gui/Console.java b/source/com/c2kernel/gui/Console.java
index 370413a..a16e6f6 100755..100644
--- a/source/com/c2kernel/gui/Console.java
+++ b/source/com/c2kernel/gui/Console.java
@@ -6,12 +6,22 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.InterruptedIOException;
+import java.io.PrintWriter;
import java.net.Socket;
-import java.util.Iterator;
import java.util.Properties;
-import javax.swing.*;
+import javax.swing.Box;
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.FileStringUtility;
@@ -32,12 +42,12 @@ public class Console extends JFrame {
JScrollPane scroll;
JTextField input;
JButton sendButton;
- JButton toFileButton;
+ JButton toFileButton;
FileWriter logFile;
ConsoleConnection connection;
JFileChooser scriptLoader = new JFileChooser();
static int bufferSize = Integer.parseInt(Gateway.getProperty("Console.bufferSize", "200"));
-
+
public Console(String host, int port) {
super("Cristal Console - "+host);
GridBagLayout gridbag = new GridBagLayout();
@@ -48,13 +58,15 @@ public class Console extends JFrame {
setSize(400, 600);
sendButton = new JButton("Send");
sendButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
submit();
}
});
JButton clearButton = new JButton("Clear");
clearButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
synchronized (output) {
output.setText("");
}
@@ -62,7 +74,8 @@ public class Console extends JFrame {
});
toFileButton = new JButton("Save");
toFileButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
if (logFile == null) {
int returnValue = scriptLoader.showSaveDialog(null);
switch (returnValue)
@@ -93,8 +106,8 @@ public class Console extends JFrame {
}
}
});
-
-
+
+
input.addKeyListener(new EnterListener(this));
scroll = new JScrollPane(output);
@@ -104,7 +117,7 @@ public class Console extends JFrame {
c.weightx=1.0;c.weighty=1.0;
gridbag.setConstraints(scroll, c);
getContentPane().add(scroll);
-
+
Box inputBox = Box.createHorizontalBox();
inputBox.add(input);
inputBox.add(Box.createHorizontalStrut(5));
@@ -115,47 +128,50 @@ public class Console extends JFrame {
c.weighty=0;
gridbag.setConstraints(inputBox, c);
getContentPane().add(inputBox);
-
+
try {
Properties utilProps = FileStringUtility.loadConfigFile( Resource.getDomainResourceURL("ScriptUtils.conf").toString());
Box utilBox = Box.createHorizontalBox();
- for (Iterator utilIter = utilProps.keySet().iterator(); utilIter.hasNext();) {
- String name = (String) utilIter.next();
+ for (Object name2 : utilProps.keySet()) {
+ String name = (String) name2;
String value = utilProps.getProperty(name);
JButton newUtil = new JButton(name);
newUtil.setActionCommand(value);
newUtil.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
processUtil(e.getActionCommand());
}
});
utilBox.add(newUtil);
utilBox.add(Box.createHorizontalStrut(5));
}
-
+
c.gridy++;
gridbag.setConstraints(utilBox, c);
getContentPane().add(utilBox);
} catch (Exception ex) { // no domain utils
}
-
-
+
+
validate();
connection = new ConsoleConnection(host, port, this);
new Thread(connection).start();
addWindowListener(new java.awt.event.WindowAdapter() {
- public void windowClosing(java.awt.event.WindowEvent evt) {
+ @Override
+ public void windowClosing(java.awt.event.WindowEvent evt) {
if (connection!=null) connection.shutdown();
dispose();
}
});
}
-
- public void setVisible(boolean visible) {
+
+ @Override
+ public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) input.requestFocus();
}
-
+
public void processUtil(String command) {
int replace;
String text = input.getText();
@@ -164,12 +180,12 @@ public class Console extends JFrame {
}
connection.sendCommand(command);
}
-
+
public void submit() {
connection.sendCommand(input.getText());
input.setText("");
}
-
+
public void print(String line) {
synchronized (output) {
String currentText = output.getText()+line+"\n";
@@ -187,8 +203,9 @@ public class Console extends JFrame {
}
}
}
-
- public void disable() {
+
+ @Override
+ public void disable() {
synchronized (output) {
output.append("Lost connection");
}
@@ -196,14 +213,15 @@ public class Console extends JFrame {
input.setEnabled(false);
sendButton.setEnabled(false);
}
-
+
private class EnterListener extends KeyAdapter
{
Console parent;
public EnterListener(Console parent) {
this.parent = parent;
}
- public void keyPressed(KeyEvent e) {
+ @Override
+ public void keyPressed(KeyEvent e) {
if (e.getKeyCode()==10) {
parent.submit();
}
@@ -213,16 +231,17 @@ public class Console extends JFrame {
private class ConsoleConnection implements Runnable {
String host; int port; Console parent; boolean keepConnected = true;
Socket conn; PrintWriter consoleOutput; BufferedReader consoleInput;
-
-
+
+
public ConsoleConnection(String host, int port, Console parent) {
Thread.currentThread().setName("Console Client to "+host+":"+port);
this.host = host;
this.port = port;
this.parent = parent;
}
-
- public void run() {
+
+ @Override
+ public void run() {
connect();
while (keepConnected) {
try {
@@ -239,20 +258,20 @@ public class Console extends JFrame {
keepConnected = false;
}
}
-
+
try {
conn.close();
} catch (IOException ex) { }
}
-
+
public void sendCommand(String command) {
consoleOutput.println(command);
}
-
+
public void shutdown() {
keepConnected = false;
}
-
+
public void connect() {
parent.print("Connecting to "+host+":"+port);
try {
@@ -262,7 +281,7 @@ public class Console extends JFrame {
consoleOutput = new PrintWriter(conn.getOutputStream(), true);
consoleInput = new BufferedReader(new InputStreamReader(conn.getInputStream()));
} catch (Exception ex) {
-
+
}
}
}