home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / samples.z / VectorSample.wxf < prev    next >
Text File  |  1997-01-28  |  12KB  |  504 lines

  1. Save Format v2.0(1)
  2. @begin Form "Sortable_Vector_Form"
  3.  Exported 0;
  4.  Abstract 0;
  5.  Interface 0;
  6.  PackageName "";
  7.  
  8.  @begin Object "powersoft.jcm.ui.Form"
  9.   Font "Dialog-Plain-8";
  10.   ControlScope "Private";
  11.   BackColor "Color.lightGray";
  12.   ForeColor "Color.black";
  13.   Text "Sortable Vector";
  14.   Visible "1";
  15.   DataSource "NULL";
  16.   DataColumns "";
  17.   BoundControl "0";
  18.   @begin Event "powersoft.jcm.event.Create"
  19.    GencodeSrcLine 169;
  20.    FunctionName "Sortable_Vector_Form_Create";
  21.   @end;
  22.   @begin UserFunction "Form1()"
  23.    Compiler 1;
  24.    GencodeSrcLine 114;
  25.    FunctionName "Sortable_Vector_Form::Form1()";
  26.   @end;
  27.   @begin UserFunction "updateListbox()"
  28.    GencodeSrcLine 153;
  29.    FunctionName "Sortable_Vector_Form::updateListbox()";
  30.   @end;
  31.   @begin UserFunction "Prototype for updateListbox()"
  32.    Private 1;
  33.    GencodeSrcLine -1;
  34.    FunctionName "Sortable_Vector_Form::Prototype for updateListbox()";
  35.   @end;
  36.   @begin UserFunction "loadVector()"
  37.    GencodeSrcLine 125;
  38.    FunctionName "Sortable_Vector_Form::loadVector()";
  39.   @end;
  40.   @begin UserFunction "Prototype for loadVector()"
  41.    Private 1;
  42.    GencodeSrcLine -1;
  43.    FunctionName "Sortable_Vector_Form::Prototype for loadVector()";
  44.   @end;
  45.   @begin UserFunction "sequentialSearch(String inName)"
  46.    GencodeSrcLine 134;
  47.    FunctionName "Sortable_Vector_Form::sequentialSearch(String inName)";
  48.   @end;
  49.   @begin UserFunction "Prototype for sequentialSearch(String inName)"
  50.    Private 1;
  51.    GencodeSrcLine -1;
  52.    FunctionName "Sortable_Vector_Form::Prototype for sequentialSearch(String inName)";
  53.   @end;
  54.   ResID 103;
  55.   DesignName Sortable_Vector_Form;
  56.   TabIndex 0;
  57.   DesignRect 130,135,298,232;
  58.  @end;
  59.  
  60.  @begin Menu
  61.   DesignName "menu_1";
  62.   IsDefault 1;
  63.   DesignRect 250,165,19,17;
  64.   @begin Popup
  65.    Name "Sort";
  66.    Caption "&Sort";
  67.    @begin Item
  68.     Name "AlphaSort";
  69.     Caption "&Alpha Sort";
  70.     @begin Event "powersoft.jcm.event.Click"
  71.      GencodeSrcLine 200;
  72.      FunctionName "menu_1_AlphaSort_Click";
  73.     @end;
  74.    @end;
  75.    @begin Item
  76.     Name "NameLengthSort";
  77.     Caption "&Name Length Sort";
  78.     @begin Event "powersoft.jcm.event.Click"
  79.      GencodeSrcLine 231;
  80.      FunctionName "menu_1_NameLengthSort_Click";
  81.     @end;
  82.    @end;
  83.    @begin Item
  84.     Name "Scramble";
  85.     Caption "&Scramble";
  86.     @begin Event "powersoft.jcm.event.Click"
  87.      GencodeSrcLine 275;
  88.      FunctionName "menu_1_Scramble_Click";
  89.     @end;
  90.    @end;
  91.   @end;
  92.   @begin Popup
  93.    Name "Name";
  94.    Caption "&Name";
  95.    @begin Item
  96.     Name "AddWaldo";
  97.     Caption "&Add Waldo";
  98.     @begin Event "powersoft.jcm.event.Click"
  99.      GencodeSrcLine 188;
  100.      FunctionName "menu_1_AddWaldo_Click";
  101.     @end;
  102.    @end;
  103.    @begin Item
  104.     Name "RemoveWaldo";
  105.     Caption "&Remove Waldo";
  106.     @begin Event "powersoft.jcm.event.Click"
  107.      GencodeSrcLine 255;
  108.      FunctionName "menu_1_RemoveWaldo_Click";
  109.     @end;
  110.    @end;
  111.    @begin Item
  112.     Name "FindWaldo";
  113.     Caption "&Find Waldo";
  114.     @begin Event "powersoft.jcm.event.Click"
  115.      GencodeSrcLine 213;
  116.      FunctionName "menu_1_FindWaldo_Click";
  117.     @end;
  118.    @end;
  119.    @begin Item
  120.     Name "RemoveThirdName";
  121.     Caption "&Remove Third Name";
  122.     @begin Event "powersoft.jcm.event.Click"
  123.      GencodeSrcLine 243;
  124.      FunctionName "menu_1_RemoveThirdName_Click";
  125.     @end;
  126.    @end;
  127.   @end;
  128.  @end;
  129.  
  130.  @begin Object "powersoft.jcm.ui.ListBox"
  131.   Font "<Inherited>";
  132.   Sort "0";
  133.   DataTrackRow "0";
  134.   DataBindAsLookup "0";
  135.   DataLookupSource "NULL";
  136.   DataLookupColumns "";
  137.   BackColor "Color.lightGray";
  138.   ForeColor "Color.black";
  139.   ResizePercentages "[ 0 0 50 100 ]";
  140.   Text "";
  141.   Visible "1";
  142.   DataSource "NULL";
  143.   DataColumns "";
  144.   BoundControl "0";
  145.   ResID 100;
  146.   DesignName lb_1;
  147.   TabIndex 1;
  148.   DesignRect 0,5,140,175;
  149.   @begin ComponentData "lb_1"
  150.   @end;
  151.  @end;
  152.  
  153.  @begin Object "powersoft.jcm.ui.Label"
  154.   Font "<Inherited>";
  155.   BackColor "Color.lightGray";
  156.   ForeColor "Color.black";
  157.   ResizePercentages "[ 0 100 0 0 ]";
  158.   Text "";
  159.   Visible "1";
  160.   DataSource "NULL";
  161.   DataColumns "";
  162.   BoundControl "0";
  163.   ResID 109;
  164.   DesignName label_messages;
  165.   TabIndex 2;
  166.   DesignRect 0,185,290,15;
  167.  @end;
  168.  
  169.  @begin Object "powersoft.jcm.ui.TextBox"
  170.   WTextBoxMultiLine 1;
  171.   WTextBoxReadOnly 1;
  172.   Font "<Inherited>";
  173.   PasswordCharacter "0";
  174.   BackColor "Color.white";
  175.   ForeColor "Color.black";
  176.   ResizePercentages "[ 50 0 50 100 ]";
  177.   Text "";
  178.   Visible "1";
  179.   DataSource "NULL";
  180.   DataColumns "";
  181.   BoundControl "0";
  182.   ResID 101;
  183.   DesignName textb_info;
  184.   TabIndex 3;
  185.   DesignRect 145,5,145,175;
  186.  @end;
  187.  
  188.  @begin HPPPrefixBlock
  189. @begin-code HPPPrefix
  190.  
  191. // add your custom import statements here
  192. import java.util.Enumeration;
  193. import powersoft.jcm.util.*;
  194.  
  195. @end-code;
  196.   GencodeSrcLine 15;
  197.  @end;
  198.  
  199.  @begin CPPPrefixBlock
  200. @begin-code CPPPrefix
  201.  
  202.  
  203. @end-code;
  204.   GencodeSrcLine 15;
  205.  @end;
  206.  
  207.  @begin ClassContentsBlock
  208. @begin-code ClassContents
  209.  
  210.     // add your data members here
  211.     SortableVector _nameVector = new SortableVector();
  212.     String _sortType = new String("none");
  213.     final int ELEMENTS = 29;
  214.     String[] _nameList =
  215.     {
  216.     "John",
  217.     "Brad",
  218.     "Jim",
  219.     "Greg",
  220.     "Dan",
  221.     "Dave",
  222.     "Wesley",
  223.     "Eric",
  224.     "Chris",
  225.     "Geno",
  226.     "Rob",
  227.     "David",
  228.     "Ivan",
  229.     "Waldo",
  230.     "Mark",
  231.     "Kevin",
  232.     "Paul",
  233.     "Bill",
  234.     "Eugene",
  235.     "Tim",
  236.     "Asif",
  237.     "Michael",
  238.     "Thorsten",
  239.     "Graham",
  240.     "Jim",
  241.     "Jack",
  242.     "Lisa",
  243.     "Anthony",
  244.     "Brian",
  245.     };
  246.  
  247. @end-code;
  248.   GencodeSrcLine 305;
  249.  @end;
  250.  
  251. @begin-code BaseClassList
  252.  
  253. extends powersoft.jcm.ui.Form
  254.  
  255. @end-code;
  256.  
  257. @begin-code GeneratedClassContents
  258.  
  259.         VectorSample();
  260.  
  261. @end-code;
  262.  
  263. @begin-code Code "Sortable_Vector_Form::Form1()"
  264.  
  265. //****************************
  266. /**
  267.  * This class displays the form and components.  It also
  268.  * handles the user generated events.
  269.  */
  270.     public @CLASSNAME@()
  271.     //****************************
  272.     {
  273.         super();
  274.     }
  275.  
  276. @end-code;
  277.  
  278. @begin-code Code "Sortable_Vector_Form::updateListbox()"
  279.  
  280.     public void updateListbox()
  281.     //****************************
  282.     {
  283.         Enumeration e;
  284.  
  285.         lb_1.deleteAll();
  286.  
  287.         e = _nameVector.getElements();
  288.  
  289.         while (e.hasMoreElements () )
  290.             {
  291.                 String currentElement = (String) e.nextElement();
  292.                 lb_1.add(currentElement);
  293.             }
  294.     }
  295.  
  296. @end-code;
  297.  
  298. @begin-code Code "Sortable_Vector_Form::Prototype for updateListbox()"
  299.  
  300.     public:
  301.         void updateListbox();
  302.  
  303. @end-code;
  304.  
  305. @begin-code Code "Sortable_Vector_Form::loadVector()"
  306.  
  307.     public void loadVector()
  308.     //****************************
  309.     {
  310.         _nameVector.clear();
  311.         for (int t = 0; t<ELEMENTS; t++)
  312.             _nameVector.append(_nameList[t]);
  313.  
  314.     }
  315.  
  316. @end-code;
  317.  
  318. @begin-code Code "Sortable_Vector_Form::Prototype for loadVector()"
  319.  
  320.     public:
  321.         void loadVector();
  322.  
  323. @end-code;
  324.  
  325. @begin-code Code "Sortable_Vector_Form::sequentialSearch(String inName)"
  326.  
  327.     public int sequentialSearch(String inName)
  328.     //****************************
  329.     {
  330.         Enumeration e;
  331.         int count = 0;
  332.         e = _nameVector.getElements();
  333.  
  334.         while (e.hasMoreElements() )
  335.         {
  336.             String currentElement = (String) e.nextElement();
  337.             if (currentElement.equals(inName))
  338.             {
  339.                 return count;
  340.             }
  341.             count++;
  342.         }
  343.         return -1;
  344.     }
  345.  
  346. @end-code;
  347.  
  348. @begin-code Code "Sortable_Vector_Form::Prototype for sequentialSearch(String inName)"
  349.  
  350.     public:
  351.         int sequentialSearch(String inName);
  352.  
  353. @end-code;
  354.  
  355. @begin-code Code "Sortable_Vector_Form_Create"
  356.  
  357.     public boolean Sortable_Vector_Form_Create(powersoft.jcm.event.CreateEvent event)
  358.     //****************************
  359.     {
  360.         loadVector();
  361.         updateListbox();
  362.         String info = "This example demonstrates the use\n" +
  363.                       "of the SortableVector class.  The list\n" +
  364.                       "of names displayed in the listbox is\n" +
  365.                       "sorted in a SortableVector called\n" +
  366.                       "_nameVector.  The various menu items\n" +
  367.                       "perform operations on this vector and\n" +
  368.                       "update the listbox to visually display\n" +
  369.                       "the results of the operation.  The\n" +
  370.                       "relevant code can be found in the menu\n" +
  371.                       "item click event handlers.";
  372.         textb_info.setText(info);
  373.         return false;
  374.     }
  375.  
  376. @end-code;
  377.  
  378. @begin-code Code "menu_1_AlphaSort_Click"
  379.  
  380.     public boolean menu_1_AlphaSort_Click(powersoft.jcm.event.ClickEvent event)
  381.     //****************************
  382.     {
  383.         CompareRoutine routine = StringUtility.getCompareRoutine( false );
  384.         _nameVector.setCompareRoutine( routine );
  385.  
  386.         _sortType = "alpha";
  387.         _nameVector.sort();
  388.         updateListbox();
  389.  
  390.         return false;
  391.     }
  392.  
  393. @end-code;
  394.  
  395. @begin-code Code "menu_1_NameLengthSort_Click"
  396.  
  397.     public boolean menu_1_NameLengthSort_Click(powersoft.jcm.event.ClickEvent event)
  398.     //****************************
  399.     {
  400.         _nameVector.setCompareRoutine( new StringLengthSort() );
  401.  
  402.         _sortType = "namelength";
  403.         _nameVector.sort();
  404.         updateListbox();        
  405.  
  406.         return false;
  407.     }
  408.  
  409. @end-code;
  410.  
  411. @begin-code Code "menu_1_Scramble_Click"
  412.  
  413.     public boolean menu_1_Scramble_Click(powersoft.jcm.event.ClickEvent event)
  414.     //****************************
  415.     {
  416.         _nameVector = new SortableVector();
  417.         loadVector();
  418.         updateListbox();
  419.         _sortType = "none";        
  420.  
  421.         return false;
  422.     }
  423.  
  424. @end-code;
  425.  
  426. @begin-code Code "menu_1_AddWaldo_Click"
  427.  
  428.     public boolean menu_1_AddWaldo_Click(powersoft.jcm.event.ClickEvent event)
  429.     //****************************
  430.     {
  431.         if (_sortType.equals("none"))
  432.             _nameVector.insert((int)(Math.random()*_nameVector.getCount()), "Waldo");  
  433.         else
  434.             _nameVector.insert("Waldo");
  435.         updateListbox();        
  436.  
  437.         return false;
  438.     }
  439.  
  440. @end-code;
  441.  
  442. @begin-code Code "menu_1_RemoveWaldo_Click"
  443.  
  444.     public boolean menu_1_RemoveWaldo_Click(powersoft.jcm.event.ClickEvent event)
  445.     //****************************
  446.     {
  447.         int position = -1;
  448.  
  449.         if (!_sortType.equals("alpha"))
  450.             position = sequentialSearch("Waldo");
  451.         else
  452.             position = _nameVector.binarySearch("Waldo");
  453.  
  454.         if (position > -1)
  455.         {
  456.             _nameVector.removeAt(position);
  457.             updateListbox();
  458.         }
  459.  
  460.  
  461.         return false;
  462.     }
  463.  
  464. @end-code;
  465.  
  466. @begin-code Code "menu_1_FindWaldo_Click"
  467.  
  468.     public boolean menu_1_FindWaldo_Click(powersoft.jcm.event.ClickEvent event)
  469.     //****************************
  470.     {
  471.         int position = 0;
  472.  
  473.         if (!_sortType.equals("alpha"))
  474.             position = sequentialSearch("Waldo") + 1;
  475.         else
  476.             position = (_nameVector.binarySearch("Waldo") + 1);
  477.  
  478.         if (position != 0)
  479.             label_messages.setText("Waldo found at position " + position + ".");
  480.         else
  481.             label_messages.setText("Waldo not found.");
  482.  
  483.         return false;
  484.     }
  485.  
  486. @end-code;
  487.  
  488. @begin-code Code "menu_1_RemoveThirdName_Click"
  489.  
  490.     public boolean menu_1_RemoveThirdName_Click(powersoft.jcm.event.ClickEvent event)
  491.     //****************************
  492.     {
  493.         if (_nameVector.getCount() > 2)
  494.         {
  495.             _nameVector.removeAt(2);
  496.             updateListbox();
  497.         }        
  498.  
  499.         return false;
  500.     }
  501.  
  502. @end-code;
  503. @end;
  504.