00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import javax.swing.*;
00036 import java.awt.event.*;
00037 import java.net.*;
00038 import java.io.*;
00039 import gov.lanl.isr.sensix.*;
00040
00041
00042 public class SenseApplet extends JApplet implements Runnable
00043 {
00044 static public boolean gui_on = true;
00045 static public boolean in_browser = true;
00046 static public JFrame parent = null;
00047
00048 public SenseGui gui;
00049 public Socket socket;
00050 public String host;
00051 public PrintWriter out;
00052
00053 private BufferedReader in;
00054 private Thread t;
00055
00056 private boolean running;
00057 private boolean shutdown;
00058
00059
00060 public void init()
00061 {
00062 BufferedReader std_in = null;
00063 socket = null;
00064 out = null;
00065
00066 try {
00067 if (in_browser)
00068 host = getCodeBase().getHost();
00069 else
00070 host = "127.0.0.1";
00071
00072 socket = new Socket(host, SenseCorba.SERVER_PORT);
00073
00074 out = new PrintWriter(socket.getOutputStream(), true);
00075 in = new BufferedReader(
00076 new InputStreamReader(socket.getInputStream()));
00077
00078 std_in = new BufferedReader(new InputStreamReader(System.in));
00079 } catch (Exception e) {
00080 System.err.println("Exception creating socket to CORBA at " + host);
00081 e.printStackTrace(System.err);
00082 System.exit(1);
00083 }
00084
00085 running = true;
00086 shutdown = false;
00087 t = new Thread(this);
00088 t.start();
00089
00090 if (gui_on) {
00091 int width = SenseGui.FIELD_WIDTH;
00092
00093 if (in_browser) {
00094 try {
00095 width = Integer.parseInt(getParameter("FieldWidth"));
00096 if (width < 300 || width > 1000)
00097 width = SenseGui.FIELD_WIDTH;
00098 } catch (NullPointerException e) {
00099 width = SenseGui.FIELD_WIDTH;
00100 } catch (NumberFormatException e) {
00101 width = SenseGui.FIELD_WIDTH;
00102 }
00103 }
00104
00105 gui = new SenseGui(width, this, parent, in_browser);
00106 getContentPane().add(gui);
00107 }
00108 else {
00109 System.out.println("Enter a SENSIX task specification: " +
00110 " (or 'help')");
00111 while (running) {
00112 String input = null;
00113 try {
00114 input = std_in.readLine().trim();
00115 }
00116 catch(java.io.IOException e) {
00117 continue;
00118 }
00119
00120 out.println(input);
00121 if (input.equalsIgnoreCase("quit") ||
00122 input.equalsIgnoreCase("exit"))
00123 running = false;
00124 }
00125 try {
00126 out.close();
00127 } catch (Exception e) {}
00128 shutdown = true;
00129 }
00130 }
00131
00132
00133 public void run() {
00134 while (running) {
00135 try {
00136 if (in.ready()) {
00137 String data;
00138 data = in.readLine().trim();
00139
00140 if (gui_on)
00141 gui.ctl_panel.results_txt.append("\t" + data + "\n");
00142 else
00143 System.out.println("\t" + data);
00144 }
00145 else
00146 Thread.sleep(10);
00147 }
00148 catch(Exception e) {
00149 e.printStackTrace(System.err);
00150 continue;
00151 }
00152 }
00153 try {
00154 while (!shutdown)
00155 Thread.sleep(10);
00156 in.close();
00157 socket.close();
00158 } catch (Exception e) {}
00159 }
00160
00161
00162 public String[][] getParameterInfo()
00163 {
00164 String pinfo[][] = {
00165 {"FieldWidth", "300 - 1000", "deployment field width"}
00166 };
00167 return pinfo;
00168 }
00169
00170
00171 public static void main(String args[])
00172 {
00173 gui_on = true;
00174 in_browser = false;
00175
00176 for (int i = 0; i < args.length; i++) {
00177 if (args[i].equalsIgnoreCase("--nogui"))
00178 gui_on = false;
00179 }
00180
00181 final JFrame frame = new JFrame("SENSIX control");
00182 if (gui_on)
00183 parent = frame;
00184
00185 final SenseApplet applet = new SenseApplet();
00186
00187 if (gui_on) {
00188 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
00189 frame.getContentPane().add(applet);
00190
00191 int width = SenseGui.FIELD_WIDTH + 10;
00192 int height = SenseGui.GetHeight(SenseGui.FIELD_WIDTH) + 10;
00193 frame.setSize(width, height);
00194 frame.addWindowListener(new WindowAdapter() {
00195 public void windowClosing(WindowEvent e) {
00196 if (applet != null && applet.gui != null)
00197 applet.gui.quit();
00198 }
00199 });
00200 }
00201
00202 try {
00203 applet.init();
00204 }
00205 catch (java.lang.Exception e) {
00206 System.out.println("Exception: " + e);
00207 frame.dispose();
00208 System.exit(-1);
00209 }
00210
00211 if (gui_on)
00212 frame.setVisible(true);
00213 else
00214 frame.dispose();
00215 }
00216 }