From 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 Mon Sep 17 00:00:00 2001 From: abranson Date: Thu, 4 Aug 2011 00:42:34 +0200 Subject: More code cleanup: Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class --- source/com/c2kernel/gui/Console.java | 93 ++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 37 deletions(-) mode change 100755 => 100644 source/com/c2kernel/gui/Console.java (limited to 'source/com/c2kernel/gui/Console.java') diff --git a/source/com/c2kernel/gui/Console.java b/source/com/c2kernel/gui/Console.java old mode 100755 new mode 100644 index 370413a..a16e6f6 --- 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) { - + } } } -- cgit v1.2.3