home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 September / dppcpro0998.iso / Rwc / Sybase / Install.exe / samples.z / Form_SortableVector.wxf < prev    next >
Encoding:
Text File  |  1998-03-25  |  16.5 KB  |  652 lines

  1. Save Format v2.3(19971110)
  2. @begin Form "Form_SortableVector"
  3.  
  4.  @begin Object "Powersoft Java AWT 1.10::java.awt.Frame"
  5.   DesignName Form_SortableVector;
  6.   @begin ClassProperties
  7. @begin-code BaseClassList
  8.  
  9. extends java.awt.Frame
  10.  
  11. @end-code;
  12.    @begin CPMethod "loadVector"
  13.     @begin CPPrototype "Prototype for LoadVectorMethod"
  14. @begin-code SourceCode "Prototype for LoadVectorMethod"
  15.  
  16.         // Not used for Java classes
  17.  
  18. @end-code;
  19.     @end;
  20.     @begin CPDefinition "LoadVectorMethod"
  21. @begin-code SourceCode "LoadVectorMethod"
  22.  
  23.     //
  24.     // LoadVectorMethod
  25.     //
  26.  
  27.     void loadVector()
  28.     {
  29.         _nameVector.clear();
  30.         for ( int t = 0; t<ELEMENTS; t += 1 )
  31.             _nameVector.append( _nameList[t] );
  32.     }
  33.  
  34. @end-code;
  35.     @end;
  36.    @end;
  37.    @begin CPMethod "sequentialSearch"
  38.     @begin CPPrototype "Prototype for SequentialSearchMethod"
  39. @begin-code SourceCode "Prototype for SequentialSearchMethod"
  40.  
  41.         // Not used for Java classes
  42.  
  43. @end-code;
  44.     @end;
  45.     @begin CPDefinition "SequentialSearchMethod"
  46. @begin-code SourceCode "SequentialSearchMethod"
  47.  
  48.     //
  49.     // SequentialSearchMethod
  50.     //
  51.  
  52.     public int sequentialSearch(String searchName)
  53.     {
  54.         Enumeration     e;
  55.         int             count = 0;
  56.         
  57.         e = _nameVector.getElements();
  58.  
  59.         while ( e.hasMoreElements() )
  60.         {
  61.             String currentElement = ( String ) e.nextElement();
  62.             if ( currentElement.equals( searchName ) )
  63.             {
  64.                 return count;
  65.             }
  66.             count++;
  67.         }
  68.         return -1;
  69.     }
  70.  
  71. @end-code;
  72.     @end;
  73.    @end;
  74.    @begin CPMethod "updateListbox"
  75.     @begin CPPrototype "Prototype for updateListboxMethod"
  76. @begin-code SourceCode "Prototype for updateListboxMethod"
  77.  
  78.         // Not used for Java classes
  79.  
  80. @end-code;
  81.     @end;
  82.     @begin CPDefinition "updateListboxMethod"
  83. @begin-code SourceCode "updateListboxMethod"
  84.  
  85.     //
  86.     // updateListboxMethod
  87.     //
  88.  
  89.     public void updateListbox()
  90.     {
  91.         Enumeration     e;
  92.  
  93.         lb_nameList.clear();
  94.  
  95.         e = _nameVector.getElements();
  96.  
  97.         while ( e.hasMoreElements () )
  98.             {
  99.                 String currentElement = ( String ) e.nextElement();
  100.                 lb_nameList.addItem( currentElement );
  101.             }
  102.     }
  103.  
  104. @end-code;
  105.     @end;
  106.    @end;
  107.   @end;
  108.   @begin Properties
  109.    @begin DesignProperties
  110.     Style "cf0000";
  111.     ResID 0;
  112.     DesignRect 59,36,293,224;
  113.    @end;
  114.    @begin ObjectProperties
  115.     font "Dialog-Plain-12";
  116.     LayoutManager "powersoft.powerj.ui.ResizePercentageLayout";
  117.     FormPositionType "DesignTime";
  118.     foreground "java.awt.Color.black";
  119.     background "java.awt.Color.lightGray";
  120.     SerializationData "";
  121.     title "Sortable Vector";
  122.    @end;
  123.   @end;
  124.   @begin Events
  125.    @begin Event "powersoft.powerj.event.Object.objectCreated"
  126. @begin-code SourceCode "powersoft.powerj.event.Object.objectCreated"
  127.  
  128.     public boolean Form_SortableVector_objectCreated(powersoft.powerj.event.EventData event)
  129.     {
  130.         loadVector();
  131.         updateListbox();
  132.  
  133.         return false;
  134.     }
  135.  
  136. @end-code;
  137.    @end;
  138.    @begin Event "java.awt.event.Window.windowClosing"
  139. @begin-code SourceCode "java.awt.event.Window.windowClosing"
  140.  
  141.     public void Form_SortableVector_windowClosing(java.awt.event.WindowEvent event)
  142.     {
  143.         setVisible( false );
  144.         destroy();
  145.     }
  146.  
  147. @end-code;
  148.    @end;
  149.   @end;
  150.   @begin UserFunctions
  151.    @begin UserFunction "Form_SortableVector()"
  152.     @begin Definition
  153. @begin-code SourceCode "Form_SortableVector()"
  154.  
  155.     public Form_SortableVector()
  156.     {
  157.         super();
  158.     }
  159.  
  160. @end-code;
  161.     @end;
  162.    @end;
  163.    @begin UserFunction "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
  164.     @begin Prototype
  165.      FunctionScope 1;
  166. @begin-code SourceCode "Prototype for unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
  167.  
  168. // Placeholder for Prototype for unhandledEvent( String listenerName, String methodName, java.lang.Object event )
  169. //     you should move the prototype here from the Class Contents section
  170.  
  171. @end-code;
  172.     @end;
  173.     @begin Definition
  174. @begin-code SourceCode "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
  175.  
  176.     public void unhandledEvent( String listenerName, String methodName, java.lang.Object event )
  177.     {
  178.  
  179.     }
  180.  
  181. @end-code;
  182.     @end;
  183.    @end;
  184.    @begin UserFunction "processEvent(java.awt.AWTEvent event)"
  185.     @begin Definition
  186. @begin-code SourceCode "processEvent(java.awt.AWTEvent event)"
  187.  
  188.     public void processEvent(java.awt.AWTEvent event)
  189.     {
  190.  
  191.         defaultProcessEvent(event);
  192.     }
  193.  
  194. @end-code;
  195.     @end;
  196.    @end;
  197.    @begin UserFunction "getContentPane()"
  198.     @begin Definition
  199. @begin-code SourceCode "getContentPane()"
  200.  
  201.     public java.awt.Container getContentPane()
  202.     {
  203.         return this;
  204.     }
  205.  
  206. @end-code;
  207.     @end;
  208.    @end;
  209.   @end;
  210.   @begin CodeBlocks
  211.    @begin CodeBlock "HppPrefix"
  212.     FunctionScope 1;
  213. @begin-code SourceCode "Imports()"
  214.  
  215. // add your custom import statements here
  216. import java.util.Enumeration;
  217. import powersoft.powerj.util.SortableVector;      
  218. import powersoft.powerj.util.StringUtility;          
  219. import powersoft.powerj.util.CompareRoutine;          
  220.  
  221. @end-code;
  222.    @end;
  223.    @begin CodeBlock "ClassContents"
  224.     FunctionScope 1;
  225. @begin-code SourceCode "Data Members()"
  226.  
  227.     // add your data members here
  228.     final int ELEMENTS = 28;
  229.     SortableVector      _nameVector = new SortableVector();
  230.     String              _sortType = new String( "none" );
  231.     String[]            _nameList =
  232.     {
  233.         "John",
  234.         "Brad",
  235.         "Jim",
  236.         "Greg",
  237.         "Dan",
  238.         "Dave",
  239.         "Wesley",
  240.         "Eric",
  241.         "Chris",
  242.         "Geno",
  243.         "Rob",
  244.         "David",
  245.         "Ivan",
  246.         "Waldo",
  247.         "Mark",
  248.         "Kevin",
  249.         "Paul",
  250.         "Bill",
  251.         "Eugene",
  252.         "Tim",
  253.         "Asif",
  254.         "Michael",
  255.         "Thorsten",
  256.         "Graham",
  257.         "Jack",
  258.         "Lisa",
  259.         "Anthony",
  260.         "Brian"
  261.     };
  262.  
  263. @end-code;
  264.    @end;
  265.    @begin CodeBlock "GeneratedClassContents"
  266.     FunctionScope 1;
  267. @begin-code SourceCode "GeneratedClassContents()"
  268.  
  269.  
  270. @end-code;
  271.    @end;
  272.    @begin CodeBlock "CppPrefix"
  273.     FunctionScope 6;
  274.     GeneratedFunction 1;
  275. @begin-code SourceCode "Not Applicable for Java()"
  276.  
  277.  
  278. @end-code;
  279.    @end;
  280.   @end;
  281.   @begin Objects
  282.    @begin Object "Powersoft Java AWT 1.10::java.awt.MenuBar"
  283.     DesignName menu_SortableVector;
  284.     @begin Properties
  285.      @begin DesignProperties
  286.       Style "50000103";
  287.       ResID 0;
  288.       DesignRect 219,195,16,15;
  289.      @end;
  290.      @begin ObjectProperties
  291.       SerializationData "";
  292.      @end;
  293.     @end;
  294.     @begin Objects
  295.      @begin Object "Powersoft Java AWT 1.10::java.awt.Menu"
  296.       DesignName Sort;
  297.       @begin Properties
  298.        @begin DesignProperties
  299.         ResID 0;
  300.         DesignRect 0,0,0,0;
  301.        @end;
  302.        @begin ObjectProperties
  303.         label "Sort";
  304.         SerializationData "";
  305.        @end;
  306.       @end;
  307.       @begin Objects
  308.        @begin Object "Powersoft Java AWT 1.10::java.awt.MenuItem"
  309.         DesignName AlphaSort;
  310.         @begin Properties
  311.          @begin DesignProperties
  312.           ResID 0;
  313.           DesignRect 0,0,0,0;
  314.          @end;
  315.          @begin ObjectProperties
  316.           label "Alpha Sort";
  317.           SerializationData "";
  318.          @end;
  319.         @end;
  320.         @begin Events
  321.          @begin Event "java.awt.event.Action.actionPerformed"
  322. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  323.  
  324.     public void menu_SortableVector_AlphaSort_actionPerformed(java.awt.event.ActionEvent event)
  325.     {
  326.         CompareRoutine routine = StringUtility.getCompareRoutine( false );
  327.         _nameVector.setCompareRoutine( routine );
  328.  
  329.         _sortType = "alpha";
  330.         _nameVector.sort();
  331.         updateListbox();
  332.     }
  333.  
  334. @end-code;
  335.          @end;
  336.         @end;
  337.        @end;
  338.        @begin Object "Powersoft Java AWT 1.10::java.awt.MenuItem"
  339.         DesignName NameLengthSort;
  340.         @begin Properties
  341.          @begin DesignProperties
  342.           ResID 0;
  343.           DesignRect 0,0,0,0;
  344.          @end;
  345.          @begin ObjectProperties
  346.           label "Name Length Sort";
  347.           SerializationData "";
  348.          @end;
  349.         @end;
  350.         @begin Events
  351.          @begin Event "java.awt.event.Action.actionPerformed"
  352. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  353.  
  354.     public void menu_SortableVector_NameLengthSort_actionPerformed(java.awt.event.ActionEvent event)
  355.     {
  356.         //  use our own StringLengthSort Class
  357.         _nameVector.setCompareRoutine( new StringLengthSort() );
  358.         _sortType = "namelength";
  359.         _nameVector.sort();
  360.         updateListbox();        
  361.     }
  362.  
  363. @end-code;
  364.          @end;
  365.         @end;
  366.        @end;
  367.        @begin Object "Powersoft Java AWT 1.10::java.awt.MenuItem"
  368.         DesignName Scramble;
  369.         @begin Properties
  370.          @begin DesignProperties
  371.           ResID 0;
  372.           DesignRect 0,0,0,0;
  373.          @end;
  374.          @begin ObjectProperties
  375.           label "Scramble";
  376.           SerializationData "";
  377.          @end;
  378.         @end;
  379.         @begin Events
  380.          @begin Event "java.awt.event.Action.actionPerformed"
  381. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  382.  
  383.     public void menu_SortableVector_Scramble_actionPerformed(java.awt.event.ActionEvent event)
  384.     {
  385.         _nameVector = new SortableVector();
  386.         loadVector();
  387.         updateListbox();
  388.         _sortType = "none";            
  389.     }
  390.  
  391. @end-code;
  392.          @end;
  393.         @end;
  394.        @end;
  395.       @end;
  396.      @end;
  397.      @begin Object "Powersoft Java AWT 1.10::java.awt.Menu"
  398.       DesignName Name;
  399.       @begin Properties
  400.        @begin DesignProperties
  401.         ResID 0;
  402.         DesignRect 0,0,0,0;
  403.        @end;
  404.        @begin ObjectProperties
  405.         label "Name";
  406.         SerializationData "";
  407.        @end;
  408.       @end;
  409.       @begin Objects
  410.        @begin Object "Powersoft Java AWT 1.10::java.awt.MenuItem"
  411.         DesignName AddWaldo;
  412.         @begin Properties
  413.          @begin DesignProperties
  414.           ResID 0;
  415.           DesignRect 0,0,0,0;
  416.          @end;
  417.          @begin ObjectProperties
  418.           label "Add Waldo";
  419.           SerializationData "";
  420.          @end;
  421.         @end;
  422.         @begin Events
  423.          @begin Event "java.awt.event.Action.actionPerformed"
  424. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  425.  
  426.     public void menu_SortableVector_AddWaldo_actionPerformed(java.awt.event.ActionEvent event)
  427.     {
  428.         if ( _sortType.equals( "none" ) )
  429.         {
  430.             _nameVector.insert( 
  431.                 ( int )( Math.random() * _nameVector.getCount() ),
  432.                 "Waldo"
  433.                 );
  434.         }
  435.         else
  436.         {
  437.             _nameVector.insert( "Waldo" );
  438.         }
  439.         updateListbox();        
  440.     }
  441.  
  442. @end-code;
  443.          @end;
  444.         @end;
  445.        @end;
  446.        @begin Object "Powersoft Java AWT 1.10::java.awt.MenuItem"
  447.         DesignName RemoveWaldo;
  448.         @begin Properties
  449.          @begin DesignProperties
  450.           ResID 0;
  451.           DesignRect 0,0,0,0;
  452.          @end;
  453.          @begin ObjectProperties
  454.           label "Remove Waldo";
  455.           SerializationData "";
  456.          @end;
  457.         @end;
  458.         @begin Events
  459.          @begin Event "java.awt.event.Action.actionPerformed"
  460. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  461.  
  462.     public void menu_SortableVector_RemoveWaldo_actionPerformed(java.awt.event.ActionEvent event)
  463.     {
  464.         int             position = -1;
  465.  
  466.         if ( !_sortType.equals( "alpha" ) )
  467.         {
  468.             position = sequentialSearch( "Waldo" );
  469.         }
  470.         else
  471.         {
  472.             position = _nameVector.binarySearch( "Waldo" );
  473.         }
  474.  
  475.         if ( position > -1 )
  476.         {
  477.             _nameVector.removeAt(position);
  478.             updateListbox();
  479.         }
  480.     }
  481.  
  482. @end-code;
  483.          @end;
  484.         @end;
  485.        @end;
  486.        @begin Object "Powersoft Java AWT 1.10::java.awt.MenuItem"
  487.         DesignName FindWaldo;
  488.         @begin Properties
  489.          @begin DesignProperties
  490.           ResID 0;
  491.           DesignRect 0,0,0,0;
  492.          @end;
  493.          @begin ObjectProperties
  494.           label "Find Waldo";
  495.           SerializationData "";
  496.          @end;
  497.         @end;
  498.         @begin Events
  499.          @begin Event "java.awt.event.Action.actionPerformed"
  500. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  501.  
  502.     public void menu_SortableVector_FindWaldo_actionPerformed(java.awt.event.ActionEvent event)
  503.     {
  504.         int             position = 0;
  505.  
  506.         if ( !_sortType.equals( "alpha" ) )
  507.         {
  508.             position = sequentialSearch( "Waldo" ) + 1;
  509.         }
  510.         else
  511.         {
  512.             position = ( _nameVector.binarySearch( "Waldo" ) + 1 );
  513.         }
  514.  
  515.         if ( position != 0 )
  516.         {
  517.             textf_messages.setText( "Waldo found at position " + position + "." );
  518.         }
  519.         else
  520.         {
  521.             textf_messages.setText( "Waldo not found." );
  522.         }
  523.     }
  524.  
  525. @end-code;
  526.          @end;
  527.         @end;
  528.        @end;
  529.        @begin Object "Powersoft Java AWT 1.10::java.awt.MenuItem"
  530.         DesignName RemoveThirdName;
  531.         @begin Properties
  532.          @begin DesignProperties
  533.           ResID 0;
  534.           DesignRect 0,0,0,0;
  535.          @end;
  536.          @begin ObjectProperties
  537.           label "Remove Third Name";
  538.           SerializationData "";
  539.          @end;
  540.         @end;
  541.         @begin Events
  542.          @begin Event "java.awt.event.Action.actionPerformed"
  543. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  544.  
  545.     public void menu_SortableVector_RemoveThirdName_actionPerformed(java.awt.event.ActionEvent event)
  546.     {
  547.         if ( _nameVector.getCount() > 2 )
  548.         {
  549.             _nameVector.removeAt( 2 );
  550.             updateListbox();
  551.         }            
  552.     }
  553.  
  554. @end-code;
  555.          @end;
  556.         @end;
  557.        @end;
  558.       @end;
  559.      @end;
  560.     @end;
  561.    @end;
  562.    @begin Object "Powersoft Java AWT 1.10::java.awt.List"
  563.     DesignName lb_nameList;
  564.     @begin Properties
  565.      @begin DesignProperties
  566.       ResID 0;
  567.       TabIndex 1;
  568.       DesignRect 5,40,275,135;
  569.      @end;
  570.      @begin ObjectProperties
  571.       font "Dialog-Plain-12";
  572.       dataTrackRow "0";
  573.       foreground "java.awt.Color.black";
  574.       background "java.awt.Color.white";
  575.       SerializationData "";
  576.      @end;
  577.      @begin ComponentProperties "lb_nameList"
  578.      @end;
  579.     @end;
  580.    @end;
  581.    @begin Object "Powersoft Java AWT 1.10::java.awt.TextField"
  582.     DesignName textf_messages;
  583.     @begin Properties
  584.      @begin DesignProperties
  585.       Style "800";
  586.       ResID 0;
  587.       TabIndex 2;
  588.       DesignRect 5,180,275,13;
  589.      @end;
  590.      @begin ObjectProperties
  591.       font "Dialog-Plain-12";
  592.       foreground "java.awt.Color.black";
  593.       background "java.awt.Color.white";
  594.       SerializationData "";
  595.      @end;
  596.     @end;
  597.    @end;
  598.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  599.     DesignName label_1;
  600.     @begin Properties
  601.      @begin DesignProperties
  602.       ResID 100;
  603.       TabIndex 3;
  604.       DesignRect 5,5,275,10;
  605.      @end;
  606.      @begin ObjectProperties
  607.       font "Dialog-Plain-12";
  608.       text "This sample demonstrates some of the use of the SortableVector class.";
  609.       foreground "java.awt.Color.black";
  610.       background "java.awt.Color.lightGray";
  611.       SerializationData "";
  612.      @end;
  613.     @end;
  614.    @end;
  615.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  616.     DesignName label_2;
  617.     @begin Properties
  618.      @begin DesignProperties
  619.       ResID 100;
  620.       TabIndex 4;
  621.       DesignRect 5,15,275,10;
  622.      @end;
  623.      @begin ObjectProperties
  624.       font "Dialog-Plain-12";
  625.       text "The menu items perform operations on the vector and display the results";
  626.       foreground "java.awt.Color.black";
  627.       background "java.awt.Color.lightGray";
  628.       SerializationData "";
  629.      @end;
  630.     @end;
  631.    @end;
  632.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  633.     DesignName label_3;
  634.     @begin Properties
  635.      @begin DesignProperties
  636.       ResID 100;
  637.       TabIndex 5;
  638.       DesignRect 5,25,275,10;
  639.      @end;
  640.      @begin ObjectProperties
  641.       font "Dialog-Plain-12";
  642.       text "in the list box below.";
  643.       foreground "java.awt.Color.black";
  644.       background "java.awt.Color.lightGray";
  645.       SerializationData "";
  646.      @end;
  647.     @end;
  648.    @end;
  649.   @end;
  650.  @end;
  651. @end;
  652.