Source Code Listing for: Flight.java

  1. // ===================================================================

  2. //                File Name: Flight.java

  3. // ===================================================================

  4. /*****

  5. ** This code must be treated as an example pseudo code. This is just

  6. ** an example to teach the special "patent pending" methods of the

  7. ** Raju's GUI Class. This is intended for showing some new features.

  8. ** This code is not intended for use in any application. However,

  9. ** may be useful to build example web pages to learn the methods.

  10. *****/

  11. // Copyright(c) 2006 All Rights Reserved...Raju Chiluvuri  

  1. package com.agile.libtemplate;

  2.  

  3. import java.io.*;

  4. import java.util.*;

  5. import javax.servlet.http.HttpServletRequest;

  1. // BEGIN: Java Class to generate customized Flight-image
  2. public class Flight extends AgileTemplate {

  1. // SVG Paths to display the each Flight Models (e.g. Boeing7x7 or Airbus3x0)
  2. String B767 = "d=' M 50   0 L 40    -5 L -30   -5 L -50   0 \n" +

  3.           "M 15  -5 L -10  -50 L -15  -50 L  -5 -15 L -5 -5 \n" +

  4.           "M -35 -3 L -45  -20 L -50  -20 L -47  -1 \n" +

  5.           "M -50  0 L -30   -2 L -27    0 \n" +

  6.           "M 10 -15 L 15   -15 L 15   -21 L   6 -21 \n" +

  7.           "         \n" +

  8.           "M 50   0 L 40     5 L -30    5 L -50   0 \n" +

  9.           "M 15   5 L -10   50 L -15   50 L  -5  15 L -5  5 \n" +

  10.           "M -35  3 L -45   20 L -50   20 L -47   1 \n" +

  11.           "M -50  0 L -30    2 L -27    0 \n" +

  12.           "M 10  15 L 15   15 L 15    21 L   6  21'> \n";

  13.  

  14. String B757=  "d=' M 60 0 L 50 -4 L -45 -4 L -63 0 L -40 -1 L -37 0 \n" +

  15.           "M 15 -4 L -8 -48 L -12 -48 L -5 -20 L -5 -4 \n" +

  16.           "M -47 -4 L -58 -18 L -64 -18 L -58 -1 \n" +

  17.           "M 10 -13 L 15 -13 L 15 -19 L 7 -19 \n" +

  18.           "  \n" +

  19.           "M 60 0 L 50 4 L -45 4 L -63 0 L -40 1 L -37 0 \n" +

  20.           "M 15 4 L -8 48 L -12 48 L -5 20 L -5 4 \n" +

  21.           "M -47 4 L -58 18 L -64 18 L -58 1 \n" +

  22.           "M 10 13 L 15 13 L 15 19 L 7 19 '> \n";

  23.  

  24. String SF37 = "d=' M 40 0 L 30 -5 L -30 -5 L -52 0 L -38 -1 L -35 0 \n" +

  25.           "M -35 -4 L -40 -25 L -45 -25 L -48 -1 \n" +

  26.           "M 5 -5 L 0 -57 L -4 -57 L -9 -5 \n" +

  27.           "M 10 -26 L -8 -26 L -8 -30 L 10 -30 L 13 -28 L 10 -26 \n" +

  28.           "M 11 -20 L 11 -36 \n" +

  29.           " \n" +

  30.           "M 40 0 L 30 5 L -30 5 L -52 0 L -38 1 L -35 0 \n" +

  31.           "M -35 4 L -40 25 L -45 25 L -48 1 M 5 5 L 0 57 L -4 57 L -9 5 \n" +

  32.           "M 10 26 L -8 26 L -8 30 L 10 30 L 13 28 L 10 26 \n" +

  33.           "M 11 20 L 11 36 '> \n";

  34.  

  35. String SF34 = "d=' M 60 0 L 50 -5 L -30 -5 L -55 0 \n" +

  36.           "M 10 -5 L -10 -52 L -13 -52 L -5 -5 \n" +

  37.           "M -45 -2 L -54 -17 L -58 -17 L -52 0 \n" +

  38.           "M -55 0 L -33 -2 L -30 0 \n" +

  39.           "M -23 -5 L -23 -10 L -37 -10 L -37 -5 L -23 -5 \n" +

  40.           "M -37 -5 L -42 -3 \n" +

  41.           "    \n" +

  42.           "M 60 0 L 50 5 L -30 5 L -55 0 \n" +

  43.           "M 10 5 L -10 52 L -13 52 L -5 5 \n" +

  44.           "M -45 2 L -54 17 L -58 17 L -52 0 \n" +

  45.           "M -55 0 L -33 2 L -30 0 \n" +

  46.           "M -23 5 L -23 10 L -37 10 L -37 5 L -23 5 \n" +

  47.           "M -37 5 L -42 3 '> \n";

  48.  

  49. String DC10 = "d=' M 50 0 L 40 -5 L -20 -5 L -45 0 \n" +

  50.           "M 10 -5 L -10 -52 L -13 -52 L -5 -5 \n" +

  51.           "M -35 -2 L -44 -17 L -48 -17 L -42 0 L -23 -2 L -20 0 \n" +

  52.           "M -13 -5 L -13 -10 L -27 -10 L -27 -5 L -13 -5 \n" +

  53.           "M -27 -5 L -32 -3 \n" +

  54.           "    \n" +

  55.           "M 50 0 L 40 5 L -20 5 L -45 0 \n" +

  56.           "M 10 5 L -10 52 L -13 52 L -5 5 \n" +

  57.           "M -35 2 L -44 17 L -48 17 L -42 0 L -23 2 L -20 0 M -13 5 L -13 10 \n" +

  58.           "L -27 10 L -27 5 L -13 5 \n" +

  59.           "M -27 5 L -32 3 '>\n";

  60.  

  61. String B747 = "d=' M 60 0 L 50 -5 L 40 -7 L -30 -7 L -65 0 \n" +

  62.           "M 23 -7 L -22 -63 L -27 -63 L -7 -25 L -4 -7 \n" +

  63.           "M -45 -4 L -61 -22 L -65 -22 L -60 -1 \n" +

  64.           "M -65 0 L -40 -2 L -37 0 \n" +

  65.           "M 12 -20 L 18 -20 L 18 -25 L 8 -25 \n" +

  66.           "M -3 -38 L 3 -38 L 3 -43 L -7 -43 \n" +

  67.           "    \n" +

  68.           "M 60  0 L 50   5 L 40   7 L -30  7 L -65 0 \n" +

  69.           "M 23  7 L -22 63 L -27 63 L -7  25 L -4  7 \n" +

  70.           "M -45 4 L -61 22 L -65 22 L -60  1 \n" +

  71.           "M -65 0 L -40  2 L -37   0 \n" +

  72.           "M 12 20 L 18  20 L 18  25 L 8   25 \n" +

  73.           "M -3 38 L 3   38 L 3   43 L -7  43 '> \n";

  74.  

  75. String A330 = "d=' M 50 0 L -40 -5 L 35 -6 L -20 -6 L -55 0 L -33 -1 L -30 0 \n" +

  76.           "M 15 -6 L -15 -60 L -20 -60 L -6 -20 L -5 -6 \n" +

  77.           "M -15 -60 L -20 -64 L -22 -64 L -20 -60 \n" +

  78.           "M -41 -3 L -50 -20 L -55 -20 L -50 -1 \n" +

  79.           "M 9 -17 L 15 -17 L 15 -24 L 5 -24 \n" +

  80.           "    \n" +

  81.           "M 50 0 L -40 5 L 35 6 L -20 6 L -55 0 L -33 1 L -30 0 \n" +

  82.           "M 15 6 L -15 60 L -20 60 L -6 20 L -5 6 \n" +

  83.           "M -15 60 L -20 64 L -22 64 L -20 60 \n" +

  84.           "M -41 3 L -50 20 L -55 20 L -50 1 \n" +

  85.           "M 9 17 L 15 17 L 15 24 L 5 24 '> \n";

  86.  

  87. String A340 = "d=' M 50 0 L -40 -5 L 35 -6 L -20 -6 L -55 0 L -33 -1 L -30 0 \n" +

  88.           "M 15 -6 L -15 -60 L -20 -60 L -6 -20 L -5 -6 \n" +

  89.           "M -15 -60 L -20 -64 L -22 -64 L -20 -60 \n" +

  90.           "M -41 -3 L -50 -20 L -55 -20 L -50 -1 \n" +

  91.           "M 9 -17 L 15 -17 L 15 -24 L 5 -24 \n" +

  92.           "M -2 -37 L 4 -37 L 4 -44 L 6 -44 \n" +

  93.           "    \n" +

  94.           "M 50 0 L -40 5 L 35 6 L -20 6 L -55 0 L -33 1 L -30 0 \n" +

  95.           "M 15 6 L -15 60 L -20 60 L -6 20 L -5 6 \n" +

  96.           "M -15 60 L -20 64 L -22 64 L -20 60 \n" +

  97.           "M -41 3 L -50 20 L -55 20 L -50 1 \n" +

  98.           "M 9 17 L 15 17 L 15 24 L 5 24 \n" +

  99.           "M -2 37 L 4 37 L 4 44 L 6 44 '> \n";

  100.  

  101. String MD11 = "d=' M 50 0 L 40 -4 L 35 -5 L -20 -5 L -38 -3  \n" +

  102.           "M -25 0 L -25 -3 L -41 -3 L -41 0  \n" +

  103.           "M -41 -2 L -44 0 L -32 -1 L -30 0  \n" +

  104.           "M -29 -4 L -38 -15 L -42 -15 L -38 -3  \n" +

  105.           "M 12 -5 L -15 -45 L -19 -45 L -8 -19 L -7 -5  \n" +

  106.           "M 7 -12 L 13 -12 L 13 -18 L 3 -18  \n" +

  107.           "M -15 -45 L -20 -48 L -21 -48 L -19 -45  \n" +

  108.           "    \n" +

  109.           "M 50 0 L 40 4 L 35 5 L -20 5 L -38 3  \n" +

  110.           "M -25 0 L -25 3 L -41 3 L -41 0  \n" +

  111.           "M -41 2 L -44 0 L -32 1 L -30 0  \n" +

  112.           "M -29 4 L -38 15 L -42 15 L -38 3  \n" +

  113.           "M 12 5 L -15 45 L -19 45 L -8 19 L -7 5  \n" +

  114.           "M 7 12 L 13 12 L 13 18 L 3 18  \n" +

  115.           "M -15 45 L -20 48 L -21 48 L -19 45 '>  \n";

  116.  

  117. String B737 = "d=' M 50 0 L 40 -4 L 35 -5 L -20 -5 L -38 -3  \n" +

  118.           "M -25 0 L -25 -3 L -41 -3 L -41 0  \n" +

  119.           "M -41 -2 L -44 0 L -32 -1 L -30 0  \n" +

  120.           "M -29 -4 L -38 -15 L -42 -15 L -38 -3  \n" +

  121.           "M 12 -5 L -15 -45 L -19 -45 L -8 -19 L -7 -5  \n" +

  122.           "M 7 -12 L 13 -12 L 13 -18 L 3 -18   \n" +

  123.           "    \n" +

  124.           "M 50 0 L 40 4 L 35 5 L -20 5 L -38 3  \n" +

  125.           "M -25 0 L -25 3 L -41 3 L -41 0  \n" +

  126.           "M -41 2 L -44 0 L -32 1 L -30 0  \n" +

  127.           "M -29 4 L -38 15 L -42 15 L -38 3  \n" +

  128.           "M 12 5 L -15 45 L -19 45 L -8 19 L -7 5  \n" +

  129.           "M 7 12 L 13 12 L 13 18 L 3 18 '>  \n";

  1.      // Variable to store input customization data of Flight-image

  2.      String    Flight_num = null, Model = null;

  3.      String    img_path = null;

  4.      String    data_url = null;

  5.      String    loc_url = null;

  6.      double    dx = 0, dy = 0, dir = 0;

  7.      String    func_to_disply_info = null;

  8.      final     String    in_coming = "green";

  9.      final     String    out_going = "blue";

  10.      final     String    passing_thru  = "grey";

  11.      final     String    high_priority = "red";

  12.      final     String    neibouring_airport1 = "Light Yellow";

  13.      final     String    neibouring_airport2 = "lavender";

  14.      final     String    air_force = "Tan";

  15.      final     String    unidentified  = "Rose";

  16.  

  17.      String    flt_color =  in_coming;  // Default color of the Image  

  1.       // Constructor, which also initializes the Object's Variables/Data.
  2.      public Flight(AC_Info ACI, String flt_num,

  3.               String flt_model, int code, String url)  {

  4.  

  5.           super(ACI);

  6.  

  7.           Flight_num = flt_num;

  8.           Model = flt_model; // Flight model (e.g. B747 or DC11)

  9.           data_url = url; // URL to make Ajax call to get latest Flight-data

  10.  

  11.           if (code == 1)      flt_color = out_going;

  12.           else if (code == 2) flt_color = passing_thru;

  13.           else if (code == 3) flt_color = high_priority;

  14.           else if (code == 4) flt_color = neibouring_airport1;

  15.           else if (code == 5) flt_color = neibouring_airport2;

  16.           else if (code == 6) flt_color = air_force;

  17.           else if (code == 7) flt_color = unidentified;

  18.  

  19.           img_path = B747; // This determines the shape of Flight's Image.

  20.           if (Model.equalsIgnoreCase("B737"))        img_path = B737;

  21.           else if (Model.equalsIgnoreCase("MD11"))   img_path = MD11;

  22.           else if (Model.equalsIgnoreCase("A340"))   img_path = A340;

  23.           else if (Model.equalsIgnoreCase("A330"))   img_path = A330;

  24.           else if (Model.equalsIgnoreCase("DC10"))   img_path = DC10;

  25.           else if (Model.equalsIgnoreCase("SF34"))   img_path = SF34;

  26.           else if (Model.equalsIgnoreCase("SF37"))   img_path = SF37;

  27.           else if (Model.equalsIgnoreCase("B757"))   img_path = B757;

  28.           else if (Model.equalsIgnoreCase("B767"))   img_path = B767;

  29.       }

  30.  

  31.      // Method to set initial location of the Flight-image

  32.      public void set_location(double x, double y, double d, String location_url) {

  33.           dx   = x;

  34.           dy   = y;

  35.           dir  = d;

  36.           loc_url = location_url; // URL to make Ajax call to get latest location

  37.      }

  1.      // This Service Method of the CCG-Object that returns,

  2.      // The Service Method name of the Flight-image's JavaScrpt Object.

  3.      public String getUpdateLocationMethodName() {

  4.           return("airline_" + UNQ_ID + ".update_location");

  5.      }  

  1.      // Sets Function to be called, upon User-click to display Data

  2.      public void Set_func_to_disply_info (String Func_name) {

  3.           func_to_disply_info = Func_name;

  4.      } 

  1.      // Returns Object-name of the flight

  2.      public String Get_flight_obj_name () {

  3.           return("airline_" + UNQ_ID + "");

  4.      } 

  1. // This function Writes 'SECTION-1' of the code for the Flight-Image

  2. private int generate_class_def(PrintWriter out) {

  3.  

  4.      // Code Check, if the CLASS definition is already in the Web document.

  5.      if (this.aci.setJScriptClass("airplane_v1_1"))       return(0);

  6.  

  7.      // Include the SECTION-1 (JavaScript class code file for the Flight)

  8.      out.println("<script xlink:href='Flight_class.js' language='text/ecmascript' />");

  9.      return(0);

  10. }

  1. // This function Writes 'SECTION-2' of the code for the Flight-Image

  2. private int generate_object_init(PrintWriter out) {

  3.     out.println("//SECTION-2: Instantiation and Init Flight's JavaScript Object");

  4.     out.println("<script type='text/ecmascript'> ");

  5.     String tmp_str = "'" + Flight_num + "', '" + data_url + "', '" + UNQ_ID + "'";

  6.     out.println("var airline_" + UNQ_ID + " = new airline_v1_1("+tmp_str+" ); ");

  7.     out.println(" ");

  8.     if (func_to_disply_info != null)

  9.      out.println("airline_" +UNQ_ID+ ".set_info_table_func("+func_to_disply_info+"); ");

  10.     out.println("</script> ");

  11.     out.println(" ");

  12.     return(0);

  13. } // End of JavaScript-Object instantiation & Initialization section  

  1. // This function Writes 'SECTION-2' of the code for the Flight-Image

  2. private int generate_svg_code(PrintWriter out) {

  3.   out.println("// SECTION-3: SVG Instruction section to Draw the Flight-Image");

  4.   out.println("<g id='al_loc_" + UNQ_ID + "' transform='translate(" + dx + ", " + dy + ")'> ");

  5.   out.println("    <g id='al_grp_" + UNQ_ID + "' transform='scale(0.2)'  ");

  6.   out.println("         onmouseover='airline_" + UNQ_ID + ".highlight(1)' ");

  7.   out.println("         onmouseout='airline_" + UNQ_ID + ".highlight(0)'  ");

  8.   out.println("         onclick='airline_" + UNQ_ID + ".show_info()'> "); //Set Event listeners

  9.   out.println("    <path id='al_img_" + UNQ_ID + "' fill='" + flt_color + "' stroke='red' stroke-width='.5pt'  ");

  10.   out.println("              transform='rotate( " + dir + " )'  ");

  11.   out.println(" " + img_path + " "); // Use img_path to draw Airplane image

  12.   out.println("    </path>  ");

  13.   out.println("       <text font-family='Verdana' x='15' y='0' font-size='24' fill='black'> "+Flight_num+" </text> ");

  14.   out.println("       <text font-family='Verdana' x='15' y='25' font-size='24' fill='black'> " + Model + " </text> ");

  15.   out.println("       <circle id='al_clue_" + UNQ_ID + "' cx='0' cy='0' r='12' style = 'fill:red;opacity:.75;stroke:black;stroke-width:4;visibility:hidden;'/>  ");

  16.   out.println("    </g>  ");

  17.   out.println("</g> ");

  18.   return(0);

  19. } // End of XML-graphics section  

  1. // Code Generation Method-"CGM()": Writes all sections for the Image

  2. public int CGM (PrintWriter out) {

  3.      generate_class_def(out);     // Call method to write 'SECTION-1'

  4.      generate_object_init(out);   // Call method to write 'SECTION-2'

  5.      generate_svg_code (out);     // Call method to write 'SECTION-3'

  6.      return 0;

  7. }    // END of the CGM()

  1. }// END: Java Class to generate customized Flight-image