// 
                                  Copyright(c) 2004 All Rights Reserved...Raju 
                                  Chiluvuri 
                                  package com.agile.libtemplate; 
                                   import 
                                  java.io.*; 
                                  import java.util.*; 
                                  import javax.servlet.http.HttpServletRequest; 
                                  public class RadioButtons extends 
                                  AgileTemplate  {
                                             
                                              int count = 0; 
                                              int first = 0; 
                                              String buttons[] = null; 
                                              String callback = null; 
                                              // Constructor, which also 
                                  initializes the Object. 
                                              public RadioButtons(AC_Info aci, 
                                  String list[], int num) 
                                  { 
                                                          super(aci); 
                                                          count = num; 
                                                          buttons = list; 
                                              }
  
                                           
                                // This method determines
                                the default selected Button. 
                                              public void setDefaultButton(int 
                                  def)  {
                                         
                                                                      first = 
                                  def; 
                                              }  
                                  //
                                The Following Three methods may be be Used by
                                "Integration Logic" to integrate the
                                AC 
                                              // This Get Method of
                                the GUI Class that Generates the Component AC 
                                              // This method
                                Returns, The Service Method name 
                                  of the generated AC. 
                                              public String getButtonSetMethodName()  {  
                                          
                                                           String name = "radio_" 
                                  + UNQ_ID + ".select_new_button"; 
                                                          return(name); 
                                              }
  
                                            
                                // CCG's Get-method to find the name of a
                                Service Method of the AC 
                                              public String getCB_AddMethodName()  { 
                                            
                                                           String name = "radio_" 
                                  + UNQ_ID + ".add_callback"; 
                                                          return(name); 
                                              }
  
                                           
                                // CCG's Set-method to INPUT external Callback
                                Function.  If the "callback !=
                                null", 
                                           
                                //  the CCG generates code such that,
                                the
                                AC calls the Callback upon new selection.  
                                            public void setCB_AddMethod(String 
                                  cb_name)  { 
                                  
                                                                      callback 
                                  = cb_name; 
                                              } 
  
                                              // The Code Generation Method 
                                  : CGM 
                                           public int CGM (PrintWriter out) 
                                  { 
                                              // Code Check, if the CLASS definition 
                                  is already in the Web document. 
                                              if (this.aci.setJScriptClass("radio_buttons_v1_0") 
                                  == false)    {
                                // Skip 
                                  the class code, If returns False 
                                               out.println("//SECTION-1:Copyright 
                                  (C) All Rights reserved...Raju Chiluvuri 
                                  "); 
                                              out.println("<script 
                                  type='text/ecmascript'> "); 
                                              out.println("<![CDATA[ 
                                  "); 
                                              out.println("function 
                                  radio_buttons_v1_0(rb_list, first) "); 
                                              out.println("{ 
                                  "); 
                                              out.println("    this.select_new_button = select_new_button; 
                                  "); 
                                              out.println("    this.add_callback = add_callback; "); 
                                              out.println("    var current_button = first; "); 
                                              out.println("    var button_list = rb_list; "); 
                                              out.println("    var callback_func = null; "); 
                                              out.println("    var radio_group_id = 'GROUP_ID'; "); 
                                              out.println(" 
                                  "); 
                                              out.println("    function add_callback( group_id, cb_name 
                                  ) { "); 
                                              out.println("                   
                                  radio_group_id 
                                  = group_id; "); 
                                              out.println("                   
                                  callback_func 
                                  = cb_name; "); 
                                              out.println("    } "); 
                                              out.println("     "); 
                                              
                                  out.println("  function select_new_button(new_button) {  
                                  "); 
                                              out.println("  if(current_button != new_button) { "); 
                                              out.println("  
                                  var svgobj = SVG_Document.getElementById(button_list[current_button]); 
                                  "); 
                                              out.println("  
                                  if (svgobj != 
                                  null) "); 
                                              out.println(" (svgobj.getStyle()).setProperty ('visibility', 
                                  'hidden'); "); 
                                              out.println(" 
                                  svgobj = SVG_Document.getElementById(button_list[new_button]); 
                                  "); 
                                              out.println(" 
                                  if (svgobj != null) "); 
                                              out.println("  (svgobj.getStyle()).setProperty ('visibility', 
                                  'visible'); "); 
                                              out.println(" 
                                  "); 
                                              out.println(" 
                                  current_button = new_button; "); 
                                              out.println("  
                                  if (callback_func != null)  "); 
                                              out.println(" callback_func(radio_group_id, new_button); "); 
                                              out.println("       } "); 
                                              out.println("    } "); 
                                              out.println("} 
                                  "); 
                                              out.println("]]> 
                                  "); 
                                              out.println("</script> 
                                  "); 
                                              out.println(" 
                                  "); 
                                              }//
                                END OF: If statement to skip the JScript Class Defenition 
                                 
                                               
                                  out.println("// SECTION-2: Instantiation 
                                  and Init section Radio-button Object 
                                  "); 
                                              out.println("<script 
                                  type='text/ecmascript'> "); 
                                              String   tmp_id = "rbutton_list_" + UNQ_ID; 
                                              out.print("var 
                                  " + tmp_id + " = new Array("); 
                                              for (int i = 0; i < count; i++) 
                                  { 
                                                          out.print("'rbutton" + i + "_" 
                                  + UNQ_ID + "'"); 
                                                        if(i < (count-1) ) 
                                   out.print(","); 
                                               } 
                                               out.println("); "); 
                                               out.println("var radio_" + UNQ_ID 
                                  + " = new radio_buttons_v1_0(" + tmp_id 
                                  + ", " + first + "); "); 
                                               out.println(" "); 
                                 
                                            
                                // If a Callback is INPUT to the CCG, then
                                include the following cods, so that, AC calls
                                the Callback. 
                                               if (callback != null) { 
                                                       out.println("radio_" 
                                  + UNQ_ID + ".add_callback( 'none', " 
                                  + callback + "); "); 
                                               } 
                                               out.println(" "); 
                                               out.println("</script> "); 
                                               out.println(" ");  
                                             out.println("//SECTION-3: Presentation 
                                  Section for the Rotate-Banner "); 
                                               out.println("<g> "); 
                                               for (int i = 0; i < count; i++) { 
                                                       int y = i*20 + 5; 
                                                       out.println(" <g transform='translate(5 " + y + ")' 
                                  onclick='radio_" + UNQ_ID + ".select_new_button(" 
                                  + i + ")'> "); 
                                                       out.println(" <text x='20' y='20'> " + buttons[i] 
                                  + " </text> "); 
                                                       out.println(" <circle cx='10' cy='15' r='5' stroke-width='1' 
                                  stroke='rgb(100,100,100)' fill='white'/> 
                                  "); 
                                                       out.println(" <circle cx='10' cy='15' r='3' id='rbutton" 
                                  + i + "_" + UNQ_ID + "' "); 
                                                       if( first == i) 
                                                                   out.println(" style='fill:black;visibility:visible;'/> 
                                  "); 
                                                       else 
                                                                   out.println(" style='fill:black;visibility:hidden;'/> "); 
                                                       out.println(" </g> "); 
                                                } 
                                                out.println("</g> "); 
                                                 return 0; 
                                              } 
                                  // END of 
                                  the CGM()  
                                  }   // END of the Class Definition. 
                                 |