Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: emc/gui/NCapplet.java


1   //******************************************************************************
2   // NCapplet.java:  Applet
3   //
4   //******************************************************************************/
5   
6   package emc.gui;
7   
8   import java.io.*;
9   import java.util.*;
10  import java.net.*;
11  import java.applet.*;
12  import java.awt.*;
13  import java.awt.event.*;
14  
15  import emc.gui.NCappletFrame;
16  import emc.nml.*;
17  
18  import rcs.*;
19  import rcs.nml.*;
20  import rcs.utils.*;
21  import rcs.posemath.*;
22  import jftp.*;
23  
24  
25  //==============================================================================
26  // Main Class for applet NCapplet
27  //
28  //==============================================================================
29  public class NCapplet extends Applet implements Runnable, ActionListener, ItemListener, AdjustmentListener, KeyListener
30  {
31    // NML Objects
32    NMLConnection NCStatusChannel = null;
33    NMLConnection NCCommandChannel = null;
34    NMLConnection NCErrlogChannel = null;
35    EMC_STAT ncStatus = null;
36    EMC_STAT ncStatusOld = null;
37    int nc_serial_number = 0;
38    public boolean read_errlog = true;
39    public boolean repaint_needed = true;
40    double cycle_time = 0.5;
41  
42    
43  
44    // Display Controls
45    FlowLayout mainLayout = null;
46    Panel mainInnerPanel = null;
47    GridBagLayout mainInnerLayout = null;
48    Label titleBarLabel = null;
49    Button newWindowButton = null;
50    Button initButton = null;
51    QueryDialog initQueryDialog = null;
52    Button abortButton = null;
53    Panel choiceStatusPanel = null;
54    GridBagLayout choiceStatusLayout = null;
55    Panel choicePanel = null;
56    CardLayout choiceLayout = null;
57    PositionDisplayPanel positionPanel = null;
58    Panel programPanel = null;
59    FlowLayout programLayout = null;
60    Panel programInnerPanel = null;
61    GridBagLayout programInnerLayout = null;
62    java.awt.List programList = null;
63    TextField programTextField = null;
64    Button loadProgramButton = null;
65    Button browseLocalButton = null;
66    Button browseRemoteButton = null;
67    Button runButton = null;
68    Button haltButton = null;
69    Button holdButton = null;
70    Button resumeButton = null;
71    Button singleStepButton = null;
72    Label XProgPosLabel = null;
73    Label YProgPosLabel = null;
74    Label ZProgPosLabel = null;
75    Label XProgOffsetLabel = null;
76    Label YProgOffsetLabel = null;
77    Label ZProgOffsetLabel = null;
78    Label GCodesLabel1 = null;
79    Label GCodesLabel2 = null;
80    Label MCodesLabel1 = null;
81    Label MCodesLabel2 = null;
82    Label mdiLabel = null;
83    TextArea mdiOldCommandsArea = null;
84    TextField mdiExecField = null;
85    Button mdiExecButton = null;
86    Panel toolTablePanel = null;    
87    FlowLayout toolTableLayout = null;
88    Panel toolTableInnerPanel = null;
89    GridBagLayout toolTableInnerLayout = null;
90    TextField toolTableTextField = null;
91    Button toolTableLoadButton = null;
92    java.awt.List toolTableList = null;
93    Panel errlogPanel = null;
94    FlowLayout errlogLayout = null;
95    Panel errlogInnerPanel = null;
96    GridBagLayout errlogInnerLayout = null;
97    Checkbox readErrlogCheckbox = null;
98    Button clearErrlogButton = null;
99    TextArea errlogTextArea = null;
100   Panel cpanelPanel = null;
101   FlowLayout cpanelLayout = null;
102   Panel cpanelInnerPanel = null;
103   GridBagLayout cpanelInnerLayout = null;
104   Button estopResetButton = null;
105   Button estopButton = null;
106   Button machineOnButton = null;
107   Button machineOffButton = null;
108   Label modeLabel = null;
109   Button autoButton = null;
110   Button manualButton = null;
111   Button mdiButton = null;
112   Checkbox autoSetModeCheckbox = null;
113   Label jogTypeLabel = null;
114   Choice jogTypeChoice = null;
115   Label jogSpeedLabel = null;
116   Scrollbar jogSpeedSlider =null;
117   Label axisControlLabel = null;
118   JogButton XJogPlusButton = null;
119   JogButton YJogPlusButton = null;
120   JogButton ZJogPlusButton = null;
121   JogButton XJogMinusButton = null;
122   JogButton YJogMinusButton = null;
123   JogButton ZJogMinusButton = null;
124   Button XHomeButton = null;
125   Button YHomeButton = null;
126   Button ZHomeButton = null;
127   Label XPositionLabel = null;
128   Label YPositionLabel = null;
129   Label ZPositionLabel = null;
130   Checkbox XEnableCheckbox = null;
131   Checkbox YEnableCheckbox = null;
132   Checkbox ZEnableCheckbox = null;
133   Checkbox XLocalOffsetCheckbox = null;
134   Checkbox YLocalOffsetCheckbox = null;
135   Checkbox ZLocalOffsetCheckbox = null;
136   double x_local_offset = 0;
137   double y_local_offset = 0;
138   double z_local_offset = 0;
139   Label feedrateOverrideLabel = null;
140   Scrollbar feedrateOverrideSlider = null;
141   Label spindleOverrideLabel = null;
142   Scrollbar spindleOverrideSlider = null;
143   Label spindleControlLabel = null;
144   Button spindleCCWButton = null;
145   Button spindleOffButton = null;
146   Button spindleCWButton = null;
147   Checkbox spindleBrakeCheckbox = null;
148   JogButton spindleIncrButton = null;
149   JogButton spindleDecrButton = null;
150   Label userNameLabel = null;
151   TextField userNameField = null;
152   Label userPasswdLabel = null;
153   TextField userPasswdField = null;
154   Checkbox connectedCheckbox = null;
155   Checkbox debugCheckbox = null;
156   Label NMLfileLabel = null;
157   TextField NMLfileTextField = null;
158   Checkbox relativePositionCheckbox = null;
159   CheckboxGroup unitsGroup = null;
160   Checkbox inchesCheckbox = null;
161   Checkbox mmCheckbox = null;
162   Button memCleanCheckButton = null;
163   Label cycleTimeLabel = null;
164   Scrollbar cycleTimeScrollbar = null;
165   Label HeartBeatLabel = null;
166   Label TaskHeartBeatLabel = null;
167   Label IoHeartBeatLabel = null;
168   Label MotionHeartBeatLabel = null;
169   Label GuiHeartBeatLabel = null;
170 
171   Panel statusPanel = null;
172   GridLayout statusLayout = null;
173   Label estopStatusLabel = null;
174   Label powerStatusLabel = null;
175   Label programStatusLabel = null;
176   Label execStatusLabel = null;
177   Label inposStatusLabel = null;
178   Label errlogStatusLabel = null;
179   Label modeStatusLabel = null;
180   Label feedrateStatusLabel = null;
181   Label spindleStatusLabel = null;
182   Label homingStatusLabel = null;
183   Label homedStatusLabel = null;
184   Label loginStatusLabel = null;
185 
186   Panel buttonPanel = null;
187   GridLayout buttonPanelLayout = null;
188   Button positionButton = null;
189   Button programButton = null;
190   Button toolTableButton = null;
191   Button cpanelButton = null;
192   Button errlogButton = null;
193 
194 
195   // Miscellaneous variables
196   boolean relative_position = false;
197   int num_errors = 0;
198   int num_new_errors = 0;
199   int num_stat_updates = 0;
200   boolean load_program_requested = false;
201   boolean browse_remote_requested = false;
202   boolean browse_local_requested = false;
203   double jog_scale = 1.0;
204   int jog_speed = 25;
205   static public final int INCH_UNITS = 1;
206   static public final int MILLIMETER_UNITS = 2;
207   static public final double MILLIMETERS_TO_INCHES = (1/25.4);
208   static public final double INCHES_TO_MILLIMETERS = 25.4;
209   int unit_type = INCH_UNITS;
210   int old_unit_type = INCH_UNITS;
211   Vector old_mdi_commands = new Vector();
212   int current_mdi_command_index = 0;
213   boolean is_connected = false;
214   static public int nc_applet_count = 0;
215   static public boolean debug_on = false;
216 
217   String choice_layout_selection = "position";
218 
219   static public String newline = "\n";
220   static {
221     try
222       {
223   String temp_newline = System.getProperty("line.separator");
224   if(null != temp_newline)
225     {
226       newline = temp_newline;
227     }
228       }
229     catch(Exception e)
230       {
231   e.printStackTrace();
232       }
233   }    
234 
235   // THREAD SUPPORT:
236   //    m_NCapplet  is the Thread object for the applet
237   //--------------------------------------------------------------------------
238   Thread   m_NCapplet = null;
239 
240   // STANDALONE APPLICATION SUPPORT:
241   //    m_fStandAlone will be set to true if applet is run standalone
242   //--------------------------------------------------------------------------
243   boolean m_fStandAlone = false;
244 
245   // PARAMETER SUPPORT:
246   //    Parameters allow an HTML author to pass information to the applet;
247   // the HTML author specifies them using the <PARAM> tag within the <APPLET>
248   // tag.  The following variables are used to store the values of the
249   // parameters.
250   //--------------------------------------------------------------------------
251 
252   // Members for applet parameters
253   // <type>       <MemberVar>    = <Default Value>
254   //--------------------------------------------------------------------------
255   private static String m_NMLfile = "emc.nml";
256   private String m_InitFile = "nce.ini";
257   private String m_ToolTable = "tool.tbl";
258   private String m_NCProgBase = "ftp://isdftp.cme.nist.gov/users/shackle/emc/";
259   private boolean m_UseColor = true;
260   private String m_InterpreterDialect = "RS274NGC";
261   private String m_InchCode = "G20";
262   private String m_MilliMeterCode = "G21";
263   private double m_MCodeFactor = 0.1;
264   private double m_GCodeFactor = 0.1;
265   private String m_UserPasswd = "";
266   private String m_UserName = "";
267   private boolean run_local = false;
268 
269 
270   // Parameter names.  To change a name of a parameter, you need only make
271   // a single change.  Simply modify the value of the parameter string below.
272   //--------------------------------------------------------------------------
273 private final String PARAM_NMLfile = "NMLfile";
274 private final String PARAM_InitFile = "InitFile";
275 private final String PARAM_ToolTable = "ToolTable";
276 private final String PARAM_NCProgBase = "NCProgBase";
277 private final String PARAM_UseColor = "UseColor";
278 private final String PARAM_InterpreterDialect = "InterpreterDialect";
279 private final String PARAM_InchCode = "InchCode";
280 private final String PARAM_MilliMeterCode = "MilliMeterCode";
281 private final String PARAM_MCodeFactor = "MCodeFactor";
282 private final String PARAM_GCodeFactor = "GCodeFactor";
283 private final String PARAM_UserPasswd = "UserPasswd";
284 private final String PARAM_UserName = "UserName";
285 private final String PARAM_DebugOn = "DebugOn";
286 private final String PARAM_RunLocal = "RunLocal";
287 
288 
289 
290   // Create Some messages here to avoid too much allocation/garbage collection
291   EMC_AXIS_ABORT axis_stop_msg = new EMC_AXIS_ABORT();
292   EMC_AXIS_ENABLE axis_enable_msg = new EMC_AXIS_ENABLE();
293   EMC_AXIS_DISABLE axis_disable_msg = new EMC_AXIS_DISABLE();
294   EMC_AXIS_HOME homeMsg = new EMC_AXIS_HOME();
295   EMC_AXIS_INCR_JOG incr_jog_msg = new EMC_AXIS_INCR_JOG();
296   EMC_AXIS_JOG jog_msg = new EMC_AXIS_JOG();
297   EMC_TASK_SET_MODE modeMsg = new EMC_TASK_SET_MODE();
298   EMC_TASK_ABORT abortMsg = new EMC_TASK_ABORT();
299   EMC_TASK_PLAN_EXECUTE exec_msg = new EMC_TASK_PLAN_EXECUTE();
300   EMC_TASK_ABORT haltMsg = new EMC_TASK_ABORT();
301   EMC_TASK_PLAN_PAUSE pauseMsg = new EMC_TASK_PLAN_PAUSE();
302   EMC_TASK_PLAN_RESUME resumeMsg = new EMC_TASK_PLAN_RESUME();
303   EMC_TASK_SET_STATE stateMsg = new EMC_TASK_SET_STATE();
304   EMC_TASK_PLAN_STEP stepMsg = new EMC_TASK_PLAN_STEP();
305   EMC_SPINDLE_OFF spindleOffMsg = new EMC_SPINDLE_OFF();
306   EMC_SPINDLE_ON spindleOnMsg = new EMC_SPINDLE_ON();
307   EMC_SPINDLE_INCREASE spindleIncrMsg = new EMC_SPINDLE_INCREASE();
308   EMC_SPINDLE_DECREASE spindleDecrMsg = new EMC_SPINDLE_DECREASE();
309   EMC_SPINDLE_CONSTANT spindleConstMsg = new EMC_SPINDLE_CONSTANT();
310   EMC_TRAJ_SET_SCALE scaleMsg = new EMC_TRAJ_SET_SCALE();
311   EMC_TASK_PLAN_RUN runMsg = new EMC_TASK_PLAN_RUN();
312   EMC_SPINDLE_BRAKE_RELEASE brake_release_msg = new EMC_SPINDLE_BRAKE_RELEASE();
313   EMC_SPINDLE_BRAKE_ENGAGE brake_engage_msg = new EMC_SPINDLE_BRAKE_ENGAGE();
314   EMC_TOOL_LOAD_TOOL_TABLE load_tool_table_msg = new EMC_TOOL_LOAD_TOOL_TABLE();
315   EMC_TASK_INIT task_init_msg = new EMC_TASK_INIT();
316 
317   boolean jog_started = false;
318 
319   void StartJog(int axis, int jog_type, int dir)
320   {
321     try 
322       {
323   jog_started = true;
324   positionPanel.selected_axis = axis;
325   if(null != cmdToSend)
326     {
327       System.err.println("Don't start jog while another command pending.");
328       return;
329     }
330   if(dir > 0)
331     {
332       dir = +1;
333     }
334   else
335     {
336       dir = -1;
337     }
338   jog_scale = 0.0;
339   if(jog_speed < 0.0)
340     {
341       System.err.println("Invalid jog_speed = "+jog_speed);
342       return;
343     }
344   if(null != ncStatus)
345     {
346       jog_scale =  ncStatus.motion.axis[axis].units;
347     }
348   else if(null != ncStatusOld)
349     {
350       jog_scale = ncStatusOld.motion.axis[axis].units;
351     }
352   else
353     {
354       System.err.println("Can't get units for jog.\n");
355       return;
356     }
357   if(jog_scale < 1E-6  || jog_scale > 1E4)
358     {
359       System.err.println("Invalid jog_scale = "+jog_scale);
360       return;
361     }
362   if(debug_on)
363     {
364       System.out.println("jog_scale = "+jog_scale+" units/mm");
365       System.out.println("jog_speed = "+jog_speed+" mm/s");
366       System.out.println("dir = "+dir);
367       System.out.println("jog_type = "+jog_type);
368     }
369   switch(jog_type)
370     {
371     case 0:
372       jog_msg.axis = axis;
373       jog_msg.vel = jog_scale * ((double) jog_speed*dir);
374       NCCommandChannel.write(jog_msg);
375       break;
376           
377     case 1:     // 0.1 mm
378       incr_jog_msg.axis = axis;
379       incr_jog_msg.incr = jog_scale * 0.1;
380       incr_jog_msg.vel = jog_scale * ((double) jog_speed*dir);
381       SetCmdToSend(incr_jog_msg,nml_emc.EMC_TASK_MODE_MANUAL);
382       break;
383     case 2:    // 1.0 mm
384       incr_jog_msg.axis = axis;
385       incr_jog_msg.incr = jog_scale * 1.0;
386       incr_jog_msg.vel = jog_scale * ((double) jog_speed*dir);
387       SetCmdToSend(incr_jog_msg,nml_emc.EMC_TASK_MODE_MANUAL);
388       break;
389     case 3:    // 10.0 mm
390       incr_jog_msg.axis = axis;
391       incr_jog_msg.incr = jog_scale * 10.0;
392       incr_jog_msg.vel = jog_scale * ((double) jog_speed*dir);
393       SetCmdToSend(incr_jog_msg,nml_emc.EMC_TASK_MODE_MANUAL);
394       break;
395     case 4:    // 0.0001 inch
396       incr_jog_msg.axis = axis;
397       incr_jog_msg.incr = jog_scale * 0.00254;
398       incr_jog_msg.vel = jog_scale * ((double) jog_speed*dir);
399       SetCmdToSend(incr_jog_msg,nml_emc.EMC_TASK_MODE_MANUAL);
400       break;
401     case 5:    // 0.001 inch
402       incr_jog_msg.axis = axis;
403       incr_jog_msg.incr = jog_scale * 0.0254;
404       incr_jog_msg.vel = jog_scale * ((double) jog_speed*dir);
405       SetCmdToSend(incr_jog_msg,nml_emc.EMC_TASK_MODE_MANUAL);
406       break;
407     case 6:    // 0.01 inch
408       incr_jog_msg.axis = axis;
409       incr_jog_msg.incr = jog_scale * 0.254;
410       incr_jog_msg.vel = jog_scale * ((double) jog_speed*dir);
411       SetCmdToSend(incr_jog_msg,nml_emc.EMC_TASK_MODE_MANUAL);
412       break;
413     case 7:    // 0.1 inch
414       incr_jog_msg.axis = axis;
415       incr_jog_msg.incr = jog_scale * 2.54;
416       incr_jog_msg.vel = jog_scale * ((double) jog_speed*dir);
417       SetCmdToSend(incr_jog_msg,nml_emc.EMC_TASK_MODE_MANUAL);
418       break;
419     case 8:    // 1 inch
420       incr_jog_msg.axis = axis;
421       incr_jog_msg.incr = jog_scale * 25.4;
422       incr_jog_msg.vel = jog_scale * ((double) jog_speed*dir);
423       SetCmdToSend(incr_jog_msg,nml_emc.EMC_TASK_MODE_MANUAL);
424       break;
425     }
426       }
427     catch(Exception e)
428       {
429   e.printStackTrace();
430       }
431   }
432 
433 
434   // STANDALONE APPLICATION SUPPORT
435   //   The GetParameter() method is a replacement for the getParameter() method
436   // defined by Applet. This method returns the value of the specified parameter;
437   // unlike the original getParameter() method, this method works when the applet
438   // is run as a standalone application, as well as when run within an HTML page.
439   // This method is called by GetParameters().
440   //---------------------------------------------------------------------------
441   String GetParameter(String strName, String args[])
442   {
443     String strValue = null;
444 
445     try
446       {
447   if(null == strName)
448     {
449       return null;
450     }
451 
452   if (args == null)
453     {
454       // Running within an HTML page, so call original getParameter().
455       //-------------------------------------------------------------------
456       strValue = getParameter(strName);
457       if(null != strValue)
458         {
459     System.out.println("GetParameter: "+strName+"="+strValue);
460         }
461       return strValue;
462     }
463 
464   // Running as standalone application, so parameter values are obtained from
465   // the command line. The user specifies them as follows:
466   //
467   //  JView NCapplet param1=<val> param2=<"val with spaces"> ...
468   //-----------------------------------------------------------------------
469   int    i;
470   String strArg  = strName + "=";
471       
472   for (i = 0; i < args.length; i++)
473     {
474       if(args[i] != null)
475         {
476     if(args[i].indexOf("=") < 0)
477       {
478         continue;
479       }
480 
481     if(args[i].length() > strArg.length())
482       {
483         if (strArg.equalsIgnoreCase(args[i].substring(0, strArg.length())))
484           {
485       // Found matching parameter on command line, so extract its value.
486       // If in double quotes, remove the quotes.
487       //---------------------------------------------------------------
488       strValue= args[i].substring(strArg.length());
489       if (strValue.startsWith("\""))
490         {
491           strValue = strValue.substring(1);
492           if (strValue.endsWith("\""))
493             strValue = strValue.substring(0, strValue.length() - 1);
494         }
495           }
496       }
497         }
498     }
499   if(null != strValue)
500     {
501       System.out.println("GetParameter: "+strName+"="+strValue);
502     }
503         
504       }
505     catch(Exception e)
506       {
507   e.printStackTrace();
508       }
509 
510     return strValue;
511   }
512 
513   // STANDALONE APPLICATION SUPPORT
514   //   The GetParameters() method retrieves the values of each of the applet's
515   // parameters and stores them in variables. This method works both when the
516   // applet is run as a standalone application and when it's run within an HTML
517   // page.  When the applet is run as a standalone application, this method is
518   // called by the main() method, which passes it the command-line arguments.
519   // When the applet is run within an HTML page, this method is called by the
520   // init() method with args == null.
521   //---------------------------------------------------------------------------
522   void GetParameters(String args[])
523   {
524     try
525       {
526   // Query values of all Parameters
527   //--------------------------------------------------------------
528   String param;
529 
530   // NMLfile: URL or File Name for the NML configuration file.
531   //--------------------------------------------------------------
532   param = GetParameter(PARAM_NMLfile, args);
533   if (param != null)
534     m_NMLfile = param;
535 
536   // InitFile: URL or File Name for the Initialization File
537   //--------------------------------------------------------------
538   param = GetParameter(PARAM_InitFile, args);
539   if (param != null)
540     m_InitFile = param;
541 
542   // ToolTable: URL or File Name for the text file containing the tool table.
543   //--------------------------------------------------------------
544   param = GetParameter(PARAM_ToolTable, args);
545   if (param != null)
546     m_ToolTable = param;
547 
548   // NCProgBase: Directory or Base URL where the NC programs will be stored.
549   //--------------------------------------------------------------
550   param = GetParameter(PARAM_NCProgBase, args);
551   if (param != null)
552     {
553       m_NCProgBase = param;
554       if(m_NCProgBase.length() > 1 &&
555          !m_NCProgBase.endsWith("\\") &&
556          !m_NCProgBase.endsWith("/"))
557         {
558     if(m_NCProgBase.startsWith("http:"))
559       {
560         m_NCProgBase = m_NCProgBase+"/";
561       }
562     else
563       {
564         m_NCProgBase = m_NCProgBase+File.separatorChar;
565       }
566         }
567     }
568 
569   // UseColor: Allows color to displays to be just as limited as B&W
570   //--------------------------------------------------------------
571   param = GetParameter(PARAM_UseColor, args);
572   if (param != null)
573     {
574       if(param.equals("false"))
575         {
576     m_UseColor = false;
577         }
578     }
579 
580   // InterpreterDialect: Dialect used by the Part Program Interpreter
581   //--------------------------------------------------------------
582   param = GetParameter(PARAM_InterpreterDialect, args);
583   if(param != null)
584     m_InterpreterDialect = param;
585 
586   // InchCode: G or M code used by the interpreter to indicate using inches.
587   //--------------------------------------------------------------
588   param = GetParameter(PARAM_InchCode, args);
589   if(param != null)
590     m_InchCode = param;
591 
592   // MilliMeterCode: G or M code used by the interpreter to indicate using MilliMeters.
593   //--------------------------------------------------------------
594   param = GetParameter(PARAM_MilliMeterCode, args);
595   if(param != null)
596     m_MilliMeterCode = param;
597 
598   // GCodeFactor: Multiplication factor used for displaying G codes, ussually 1 or 0.1
599   //--------------------------------------------------------------
600   param = GetParameter(PARAM_GCodeFactor, args);
601   if(param != null)
602     m_GCodeFactor = Double.valueOf(param).doubleValue();
603 
604 
605   // MCodeFactor: Multiplication factor used for displaying M codes, ussually 1 or 0.1
606   //--------------------------------------------------------------
607   param = GetParameter(PARAM_MCodeFactor, args);
608   if(param != null)
609     m_MCodeFactor = Double.valueOf(param).doubleValue();
610 
611       
612   // UserName: Default User Name used for connecting to NML, FTP, etc.
613   //--------------------------------------------------------------
614   param = GetParameter(PARAM_UserName, args);
615   if(param != null)
616     m_UserName = param;
617 
618   // UserPasswd: Default User Passwd used for connecting to NML, FTP, etc.
619   //--------------------------------------------------------------
620   param = GetParameter(PARAM_UserPasswd, args);
621   if(param != null)
622     m_UserPasswd = param;
623 
624   // DebugOn: URL or File Name for the NML configuration file.
625   //--------------------------------------------------------------
626   param = GetParameter(PARAM_DebugOn, args);
627   if (param != null)
628     {
629       debug_on = Boolean.valueOf(param).booleanValue();;
630       NCappletFrame.debug_on = debug_on;
631     }
632 
633 
634   // Assume all files stored locally can be accessed directly by the controller, so there is no need to upload them with ftp.
635   //--------------------------------------------------------------
636   param = GetParameter(PARAM_RunLocal, args);
637   if (param != null)
638     {
639       run_local = Boolean.valueOf(param).booleanValue();;
640     }
641 
642       }
643     catch(Exception e)
644       {
645   e.printStackTrace();
646       }
647   }
648 
649 public String []CreateArgs()
650   {
651     String args[] = new String[5];
652 
653     try
654       {
655   args[0] = "NMLfile="+m_NMLfile;
656   args[1] = "InitFile="+m_InitFile;
657   args[2] = "ToolTable="+m_ToolTable;
658   args[3] = "NCProgBase="+m_NCProgBase;
659   args[4] = "UseColor="+m_UseColor;
660       }
661     catch(Exception e)
662       {
663   e.printStackTrace();
664       }
665     return args;
666   }
667 
668    public static final String ident = "$Id: NCapplet.java,v 1.1.1.1 2000/06/14 19:37:10 wshackle Exp $";
669 
670 
671   // STANDALONE APPLICATION SUPPORT
672   //   The main() method acts as the applet's entry point when it is run
673   // as a standalone application. It is ignored if the applet is run from
674   // within an HTML page.
675   //--------------------------------------------------------------------------
676 public static void main(String args[])
677   {
678     String version = "   ";
679      
680     try
681     {
682       int version_index = ident.indexOf(",v")+2;
683       if(version_index >0)
684       {
685   int space_index = ident.indexOf(" ", version_index+6);
686   version = ident.substring(version_index, space_index);
687       }
688     }
689     catch(Exception e)
690       {
691   e.printStackTrace();
692       }
693     System.out.println("");
694     System.out.println(" *****************************************");    
695     System.out.println(" *** Java Graphical User Interface     ***");
696     System.out.println(" *** Version: "+version+"         ***");
697     System.out.println(" ***         for the                   ***");
698     System.out.println(" *** Enhanced Machine Controller       ***");
699     System.out.println(" *****************************************");
700     System.out.println("");
701     
702     if(args.length > 0)
703       {
704   String first_arg = args[0].toUpperCase();
705   //System.out.println("first_arg = "+first_arg);
706   if(first_arg.indexOf("HELP") > -1 ||
707      first_arg.indexOf('?') > -1)
708     {
709       try
710         {
711     NCapplet temp_applet = new NCapplet();
712     System.out.println(temp_applet.getAppletInfo());
713     String param_info[][] = temp_applet.getParameterInfo();
714     System.out.println("Usage: [Parameter=value]");
715     System.out.println("Parameter \tType \tDescription");
716     for(int i = 0; i < param_info.length; i++)
717       {
718         for(int ii = 0; ii < param_info[i].length; ii++)
719           {
720       System.out.print(param_info[i][ii]+" \t");
721           }
722         System.out.println("");
723       }
724     //Thread.sleep(5000);
725         }
726       catch(Exception e)
727         {
728     e.printStackTrace();
729         }
730       System.exit(0);
731     }
732   else if(args[0].equalsIgnoreCase("-nml") && args.length > 1)
733     {
734       m_NMLfile = args[1];
735       System.out.println("Using "+m_NMLfile+" as the NML configuration file.");
736       
737     }
738   for(int i = 0; i < args.length; i++)
739     {
740       String argCaps = args[i].toUpperCase();
741       System.out.println("argCaps = "+argCaps);
742       if(argCaps.indexOf("DEBUG") >= 0 )
743         {
744     debug_on = true;
745     System.out.println("Debug Mode ON.");
746         }
747     }
748       }
749 
750     CreateNewWindow(args, true);
751   }
752 
753 public static void CreateNewWindow(String args[], boolean stand_alone)
754   {
755     try
756       {
757   if(debug_on)
758     {
759       System.out.println("Create new Frame");
760     }
761   // Create Toplevel Window to contain applet NCapplet
762   //-----------------------------------------------------------------
763   NCappletFrame frame = new NCappletFrame("NCapplet",null);
764   NCappletFrame.in_an_applet = !stand_alone;
765 
766   int frame_width = 775;
767   int frame_height = 575;
768   if(debug_on)
769     {
770       System.out.println("Get Screensize");
771     }
772   try
773     {
774       Toolkit tk = frame.getToolkit();
775       if(null != tk)
776         {
777     Dimension d = tk.getScreenSize();
778     if(null != d)
779       {
780         frame_width = d.width - 35;
781         frame_height = d.height -35;
782       }
783         }
784     }
785   catch(Exception e)
786     {
787       e.printStackTrace();
788     }
789   if(frame_width > 1075)
790     {
791       frame_width = 1075;
792     }
793   if(frame_height > 775)
794     {
795       frame_height = 775;
796     }  
797   
798   
799   frame.setVisible(false);
800   frame.setSize(frame_width, frame_height);
801   Point p = frame.getLocation();
802   Insets is = frame.getInsets();
803   if(is.left < 10)
804     {
805       is.left = 10;
806     }
807   if(is.top < 10)
808     {
809       is.top = 10;
810     }
811   if(p.x < is.left || p.y < is.top)
812     {
813       p.x = is.left+1;
814       p.y = is.top+1;
815       frame.setLocation(p);
816     }
817   
818 
819   // The following code starts the applet running within the frame window.
820   // It also calls GetParameters() to retrieve parameter values from the
821   // command line, and sets m_fStandAlone to true to prevent init() from
822   // trying to get them from the HTML page.
823   //----------------------------------------------------------------------
824   if(debug_on)
825     {
826       System.out.println("Create new Applet");
827     }
828   NCapplet applet_NCapplet = new NCapplet();
829   frame.innerApplet =   applet_NCapplet;
830   frame.addKeyListener(applet_NCapplet);
831   applet_NCapplet.in_resizable_window = true;
832   if(stand_alone)
833     {
834       applet_NCapplet.m_fStandAlone = true;
835       applet_NCapplet.GetParameters(args);
836     }
837   frame.resizeInnerApplet();
838 
839   frame.add("Center", applet_NCapplet);
840   
841   if(debug_on)
842     {
843       System.out.println("Initialize Applet");
844     }
845   applet_NCapplet.init();
846   if(debug_on)
847     {
848       System.out.println("Show Frame");
849     }
850   frame.show();
851   if(debug_on)
852     {
853       System.out.println("Start  Applet");
854     }
855   applet_NCapplet.start();
856       }
857     catch(Exception e)
858       {
859   e.printStackTrace();
860       }
861   }
862 
863   // NCapplet Class Constructor
864   //--------------------------------------------------------------------------
865   public NCapplet()
866   {
867     // Mark this as a non JDK 1.1 or better applet and then,
868     // Disable any unneccessary EVENTS
869     enableEvents(AWTEvent.ACTION_EVENT_MASK | 
870      AWTEvent.ADJUSTMENT_EVENT_MASK |
871      AWTEvent.ADJUSTMENT_EVENT_MASK |
872      AWTEvent.COMPONENT_EVENT_MASK |
873      AWTEvent.CONTAINER_EVENT_MASK |
874      AWTEvent.FOCUS_EVENT_MASK |
875      AWTEvent.ITEM_EVENT_MASK |
876      AWTEvent.KEY_EVENT_MASK |
877      AWTEvent.MOUSE_EVENT_MASK |
878      AWTEvent.MOUSE_MOTION_EVENT_MASK |
879      AWTEvent.TEXT_EVENT_MASK |
880      AWTEvent.WINDOW_EVENT_MASK);
881 
882     disableEvents(AWTEvent.ACTION_EVENT_MASK | 
883      AWTEvent.ADJUSTMENT_EVENT_MASK |
884      AWTEvent.ADJUSTMENT_EVENT_MASK |
885      AWTEvent.COMPONENT_EVENT_MASK |
886      AWTEvent.CONTAINER_EVENT_MASK |
887      AWTEvent.FOCUS_EVENT_MASK |
888      AWTEvent.ITEM_EVENT_MASK |
889      AWTEvent.KEY_EVENT_MASK |
890      AWTEvent.MOUSE_EVENT_MASK |
891      AWTEvent.MOUSE_MOTION_EVENT_MASK |
892      AWTEvent.TEXT_EVENT_MASK |
893      AWTEvent.WINDOW_EVENT_MASK);
894 
895     addKeyListener(this);
896     nc_applet_count++;
897   }
898 
899   // APPLET INFO SUPPORT:
900   //    The getAppletInfo() method returns a string describing the applet's
901   // author, copyright date, or miscellaneous information.
902   //--------------------------------------------------------------------------
903 public String getAppletInfo()
904   {
905     return "Name: NCapplet\r\n" +
906       "Author: Will Shackleford\r\n" +
907       "Created with Microsoft Visual J++ Version 1.0\r\n" +
908       "\r\n" +
909       "";
910   }
911 
912   // PARAMETER SUPPORT
913   //    The getParameterInfo() method returns an array of strings describing
914   // the parameters understood by this applet.
915   //
916   // NCapplet Parameter Information:
917   //  { "Name", "Type", "Description" },
918   //--------------------------------------------------------------------------
919 public String[][] getParameterInfo()
920   {
921     String[][] info =
922     {
923       { PARAM_NMLfile, "String", "URL or File Name for the NML configuration file." },
924       { PARAM_InitFile, "String", "URL or File Name for the Initialization File" },
925       { PARAM_ToolTable, "String", "URL or File Name for the text file containing the tool table." },
926       { PARAM_NCProgBase, "String", "Directory or Base URL where the NC programs will be stored." },
927       { PARAM_InterpreterDialect, "String", "Dialect used by the Part Program Interpreter." },
928       { PARAM_InchCode, "String", "G or M code used by the interpreter to indicate using inches." },
929       { PARAM_MilliMeterCode, "String", "G or M code used by the interpreter to indicate using MilliMeters." },
930       { PARAM_GCodeFactor, "double", "Multiplication factor used for displaying G codes, ussually 1 or 0.1" },
931       { PARAM_MCodeFactor, "double", "Multiplication factor used for displaying M codes, ussually 1 or 0.1" }  ,
932       { PARAM_UserName, "String", "Default User Name used for connecting to NML, FTP etc." },
933       { PARAM_UserPasswd, "String", "Default User Passwd used for connecting to NML, FTP etc." },
934       { PARAM_DebugOn, "boolean", "Turn on additional debug messages. (Printed to stdout/JavaConsole)" },
935       { PARAM_RunLocal, "boolean", "Assume all local files can be accessed directly by the controller, so there is no need to upload them." }
936     };
937     return info;    
938   }
939 
940   RCS_CMD_MSG cmdToSend = null;
941   int mode_for_command = -1;
942 
943 public void SetCmdToSend(RCS_CMD_MSG cmdMsg, int mode)
944   {
945     if(null != cmdToSend)
946       {
947   System.err.println("Attempt to send 2 commands in the same cycle. "+cmdMsg.type + " and "+ cmdToSend.type);
948       }
949     cmdToSend = cmdMsg;
950     mode_for_command = mode;
951   }
952 
953 
954   long start_waitfordone_millis = System.currentTimeMillis();
955   boolean WaitForDoneNeeded = false;
956   double WaitForDoneTimeout = 5.0;
957   
958   public boolean IsDone() 
959   {
960     long timeout_millis = (long) (WaitForDoneTimeout*1000.0);
961     try
962       {
963   ncStatus = (EMC_STAT) NCStatusChannel.read();
964       }
965     catch(NMLException e)
966       {
967   e.printStackTrace();
968   is_connected = false;
969   connectedCheckbox.setState(false);
970   Alert("Can't read NC Status NML Channel.\n"+e.getMessage());
971   WaitForDoneNeeded = false;
972   reconnect_needed = true;
973   consecutive_nulls = 0;
974   return false;
975       }
976     if(null != ncStatus)
977       {
978   consecutive_nulls = 0;
979   if((
980       ncStatus.status == nml_emc.RCS_DONE ||
981       ncStatus.status == nml_emc.UNINITIALIZED_STATUS )  &&
982      ncStatus.echo_serial_number == nc_serial_number)
983     {
984       start_waitfordone_millis = System.currentTimeMillis();
985       WaitForDoneNeeded = false;
986       return true;
987     }
988       }
989     if(System.currentTimeMillis() - start_waitfordone_millis > timeout_millis)
990       {
991   System.err.println("WaitForDone Timed-Out");
992   start_waitfordone_millis = System.currentTimeMillis();
993   WaitForDoneNeeded = false;
994   return true;
995       }
996     return false;
997   }
998   
999   
1000
1001public void SendCommand()
1002  {
1003    int i = 0;
1004    try
1005      {
1006  if(null == cmdToSend)
1007    {
1008      return;
1009    }
1010  //rcs.nml.NMLFormatConverterBase.debug_on = true;
1011  if(null == cmdToSend)
1012    {
1013      return;
1014    }
1015  try
1016    {
1017      if(autoSetModeCheckbox.getState() && null != NCStatusChannel && mode_for_command > 0)
1018        {
1019    if(null == ncStatus)
1020      {
1021        ncStatus = ncStatusOld;
1022      }
1023    if(null != ncStatus )
1024      {
1025      setmode:        {  
1026        if(mode_for_command != ncStatus.task.mode)
1027          {
1028      if(debug_on)
1029        {
1030          System.out.println("Setting mode to "+mode_for_command);
1031        }
1032      modeMsg.mode = mode_for_command;
1033      nc_serial_number++;
1034      modeMsg.serial_number = nc_serial_number;
1035      NCCommandChannel.write(modeMsg);
1036      for( i = 0; i < 10; i++)
1037        {
1038          try
1039            {
1040        ncStatus = (EMC_STAT) NCStatusChannel.read();
1041            }
1042          catch(NMLException e)
1043            {
1044        e.printStackTrace();
1045        consecutive_nulls = 0;
1046        is_connected = false;
1047        connectedCheckbox.setState(false);
1048        Alert("Can't read NC Status NML Channel.\n"+e.getMessage());
1049        break setmode;
1050            }
1051          if(null != ncStatus)
1052            {
1053        consecutive_nulls = 0;
1054        if(ncStatus.task.mode == mode_for_command)
1055          {
1056            break setmode;
1057          }
1058        if(ncStatus.echo_serial_number == nc_serial_number)
1059          {
1060            break setmode;
1061          }
1062            }
1063          Thread.sleep(100);
1064        }
1065          }
1066      }
1067      if(debug_on)
1068        {
1069          System.out.println("Mode changed after "+i+" cycles.");
1070        }
1071      first_stat_display = true;
1072      }
1073    if(ncStatus == ncStatusOld)
1074      {
1075        ncStatus = null;
1076      }
1077    else
1078      {
1079        ncStatusOld.task.mode = ncStatus.task.mode;
1080        ncStatusOld.echo_serial_number = ncStatus.echo_serial_number;
1081      }
1082        }
1083    }
1084  catch(Exception e)
1085    {
1086      e.printStackTrace();
1087    }
1088  nc_serial_number++;
1089  cmdToSend.serial_number = nc_serial_number;
1090  NCCommandChannel.write(cmdToSend);  
1091      }
1092    catch(Exception e)
1093      {
1094  e.printStackTrace();
1095      }
1096    //rcs.nml.NMLFormatConverterBase.debug_on = false;
1097    cmdToSend = null;
1098    mode_for_command = -1;
1099
1100  }
1101
1102  public void itemStateChanged(ItemEvent evt)
1103  {
1104    try
1105      {
1106  if(inside_init || loading_tool_table)
1107    {
1108      return;
1109    }
1110
1111      if(evt.getSource() ==  readErrlogCheckbox)
1112    {
1113      read_errlog =  readErrlogCheckbox.getState();
1114      return;
1115    }
1116
1117  //NMLConnection.write_debug_on = true;
1118  if(evt.getSource() == connectedCheckbox)
1119    {
1120      synchronized(this)
1121        {
1122    boolean new_is_connected = connectedCheckbox.getState();
1123    if(new_is_connected != is_connected)
1124      {
1125        is_connected = new_is_connected;
1126        if(is_connected)
1127          {
1128      InitializeNML();
1129          }
1130        else
1131          {
1132      DisconnectNML();
1133          }
1134      }
1135        }
1136      return;
1137    }
1138
1139  if(evt.getSource() == debugCheckbox)
1140    {
1141      synchronized(this)
1142        {
1143    debug_on = debugCheckbox.getState();
1144        }
1145      return;
1146    }
1147  if(evt.getSource() == relativePositionCheckbox)
1148    {
1149      synchronized(this)
1150        {
1151    relative_position = relativePositionCheckbox.getState();
1152    XLocalOffsetCheckbox.setState(false);
1153    x_local_offset = 0;
1154    XLocalOffsetCheckbox.setLabel("Offset: "+x_local_offset);
1155    YLocalOffsetCheckbox.setState(false);
1156    y_local_offset = 0;
1157    YLocalOffsetCheckbox.setLabel("Offset: "+y_local_offset);
1158    ZLocalOffsetCheckbox.setState(false);
1159    z_local_offset = 0;
1160    ZLocalOffsetCheckbox.setLabel("Offset: "+z_local_offset);
1161        }
1162      return;
1163    }
1164
1165  if(evt.getSource() == spindleBrakeCheckbox)
1166    {
1167      synchronized(this)
1168        {
1169    boolean engage_brake = spindleBrakeCheckbox.getState();
1170    if(engage_brake)
1171      {
1172        SetCmdToSend(brake_engage_msg, -1);
1173      }
1174    else
1175      {
1176        SetCmdToSend(brake_release_msg, -1);
1177      }
1178        }
1179      return;
1180    }
1181
1182  if(evt.getSource() ==  mmCheckbox)
1183     {
1184       synchronized(this)
1185         {
1186     if(!mmCheckbox.getState())
1187       {
1188         unit_type = INCH_UNITS;
1189         jogSpeedLabel.setText("Jog Speed: "+FormatDouble(((double)jog_speed*MILLIMETERS_TO_INCHES),7)+" inch/s");
1190       }
1191     else
1192       {
1193         unit_type = MILLIMETER_UNITS;
1194         jogSpeedLabel.setText("Jog Speed: "+FormatDouble(((double)jog_speed),7)+" mm/s");
1195       }
1196         }
1197       return;
1198     }
1199
1200  if(evt.getSource() ==  inchesCheckbox)
1201     {
1202       synchronized(this)
1203         {
1204     if(inchesCheckbox.getState())
1205       {
1206         unit_type = INCH_UNITS;
1207         jogSpeedLabel.setText("Jog Speed: "+FormatDouble(((double)jog_speed*MILLIMETERS_TO_INCHES),7)+" inch/s");
1208       }
1209     else
1210       {
1211         unit_type = MILLIMETER_UNITS;
1212         jogSpeedLabel.setText("Jog Speed: "+FormatDouble(((double)jog_speed),7)+" mm/s");
1213       }
1214         }
1215       return;
1216     }
1217
1218  if(evt.getSource() == XEnableCheckbox)
1219    {
1220      synchronized(this)
1221         {
1222     boolean enable_axis = XEnableCheckbox.getState();
1223     if(enable_axis)
1224       {
1225         axis_enable_msg.axis = 0;
1226         SetCmdToSend(axis_enable_msg, -1);
1227       }
1228     else
1229       {
1230         axis_disable_msg.axis = 0;
1231         SetCmdToSend(axis_disable_msg, -1);
1232       }
1233         }
1234      return;
1235    }
1236
1237  if(evt.getSource() == XLocalOffsetCheckbox)
1238    {
1239      synchronized(this)
1240        {
1241    boolean set_offset = XLocalOffsetCheckbox.getState();
1242    if(set_offset)
1243      {
1244        x_local_offset = ncStatusOld.motion.traj.position.tran.x;
1245      }
1246    else
1247      {
1248        x_local_offset = 0;
1249      }
1250    XLocalOffsetCheckbox.setLabel("Offset:"+x_local_offset);
1251        }
1252      return;
1253    }
1254
1255  if(evt.getSource() == YEnableCheckbox)
1256    {
1257      synchronized(this)
1258        {
1259    boolean enable_axis = YEnableCheckbox.getState();
1260    if(enable_axis)
1261      {
1262        axis_enable_msg.axis = 1;
1263        SetCmdToSend(axis_enable_msg, -1);
1264      }
1265    else
1266      {
1267        axis_disable_msg.axis = 1;
1268        SetCmdToSend(axis_disable_msg, -1);
1269      }
1270        }
1271      return;
1272    }
1273
1274  if(evt.getSource() == YLocalOffsetCheckbox)
1275    {
1276      synchronized(this)
1277        {
1278    boolean set_offset = YLocalOffsetCheckbox.getState();
1279    if(set_offset)
1280      {
1281        y_local_offset = ncStatusOld.motion.traj.position.tran.y;
1282      }
1283    else
1284      {
1285        y_local_offset = 0;
1286      }
1287    YLocalOffsetCheckbox.setLabel("Offset:"+y_local_offset);
1288        }
1289      return;
1290    }
1291
1292
1293  if(evt.getSource() == ZEnableCheckbox)
1294    {
1295      synchronized(this)
1296        {
1297    boolean enable_axis = ZEnableCheckbox.getState();
1298    if(enable_axis)
1299      {
1300        axis_enable_msg.axis = 2;
1301        SetCmdToSend(axis_enable_msg, nml_emc.EMC_TASK_MODE_MANUAL);
1302      }
1303    else
1304      {
1305        axis_disable_msg.axis = 2;
1306        SetCmdToSend(axis_disable_msg, nml_emc.EMC_TASK_MODE_MANUAL);
1307      }
1308        }
1309      return;
1310    }
1311  
1312  if(evt.getSource() == ZLocalOffsetCheckbox)
1313    {
1314      synchronized(this)
1315        {
1316    boolean set_offset = ZLocalOffsetCheckbox.getState();
1317    if(set_offset)
1318      {
1319        z_local_offset = ncStatusOld.motion.traj.position.tran.z;
1320      }
1321    else
1322      {
1323        z_local_offset = 0;
1324      }
1325    ZLocalOffsetCheckbox.setLabel("Offset:"+z_local_offset);
1326        }
1327      return;
1328    }
1329      }
1330    catch(Exception e)
1331      {
1332  e.printStackTrace();
1333      }
1334  }
1335
1336
1337
1338
1339  // Called any time the user presses a button or uses a control.
1340public void actionPerformed(ActionEvent  evt)
1341  {
1342    try
1343      {
1344  if(inside_init || loading_tool_table)
1345    {
1346      return;
1347    }
1348
1349  if(evt.getSource() == NMLfileTextField)
1350    {
1351      m_NMLfile = NMLfileTextField.getText();
1352    }
1353  
1354  if(!NMLInitialized)
1355    {
1356      return;
1357    }
1358
1359  if(debug_on)
1360    {
1361      System.out.println("NCapplet.actionPerformed("+evt+")");
1362    }
1363
1364  if(evt.getSource() == memCleanCheckButton)
1365    {
1366      synchronized(this)
1367        {
1368    System.out.println("Memory state before garbage collection:");
1369    Runtime rt = Runtime.getRuntime();
1370    System.out.println("\tTotal Memory: "+rt.totalMemory());
1371    System.out.println("\tFree Memory: "+rt.freeMemory());
1372    long start_time = System.currentTimeMillis();
1373    rt.runFinalization();
1374    rt.gc();
1375    long gc_time = System.currentTimeMillis() - start_time;
1376    System.out.println("Garbage collection took "+gc_time+" ms.");
1377    System.out.println("Memory state after garbage collection:");
1378    System.out.println("\tTotal Memory: "+rt.totalMemory());
1379    System.out.println("\tFree Memory: "+rt.freeMemory());
1380        }
1381      return;
1382    }
1383      
1384  if(evt.getSource() == (newWindowButton))
1385    {
1386      synchronized(this)
1387        {
1388    CreateNewWindow(CreateArgs(), m_fStandAlone);
1389        }
1390      return;
1391    }
1392  if(evt.getSource() == (abortButton))
1393    {
1394      synchronized(this)
1395        {
1396    nc_serial_number++;
1397    abortMsg.serial_number = nc_serial_number;
1398    cmdToSend = null;
1399    NCCommandChannel.write(abortMsg);
1400        }
1401      return;
1402    }
1403  if(evt.getSource() == initButton)
1404    {
1405      initQueryDialog = Query("Re-initialize Controller?");
1406      return;
1407    }
1408  if(evt.getSource() == (positionButton))
1409    {
1410      synchronized(this)
1411        {
1412    choiceLayout.show(choicePanel, "position");
1413    titleBarLabel.setText(". . .  NC Position  . . .");
1414    choice_layout_selection = "position";
1415    positionPanel.requestFocus();
1416        }
1417      return;
1418    }
1419  if(evt.getSource() == (programButton))
1420    {
1421      synchronized(this)
1422        {
1423    choiceLayout.show(choicePanel, "program");
1424    titleBarLabel.setText(". . .  NC Program  . . .");
1425    choice_layout_selection = "program";
1426        }
1427      return;
1428    }
1429  if(evt.getSource() == (loadProgramButton))
1430    {
1431      load_program_requested = true;