home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / WFC / SimpleOCXControl / TestControlForm.java < prev   
Encoding:
Java Source  |  2000-05-04  |  8.3 KB  |  257 lines

  1. import com.ms.wfc.app.*;
  2. import com.ms.wfc.core.*;
  3. import com.ms.wfc.ui.*;
  4.  
  5. import java.util.Date ;
  6. import SimpComp.* ;
  7.  
  8. /**
  9.  * TestControlForm
  10.  * 
  11.  * A form to test the SimpleControl
  12.  * 
  13.  * The form hosts the control as a WFC Control - not as an ActiveX Control
  14.  * and allows various control properties to be set. 
  15.  * 
  16.  * It also hooks events from the control
  17.  * 
  18.  */
  19. public class TestControlForm extends Form { 
  20.     /**
  21.      * Initialise the form - called when the application is run
  22.      */
  23.     public TestControlForm() { 
  24.         super();
  25.  
  26.         // Required for Visual J++ Form Designer support
  27.         initForm();        
  28.     }
  29.     
  30.     /**
  31.      * Part of the demo/sample interface, this retrieves the HTML help text for
  32.      * the sample.
  33.      */
  34.     public String getHTML() {
  35.         return "";
  36.     }
  37.  
  38.     /**
  39.      * TestControlForm overrides dispose so it can clean up the
  40.      * component list.
  41.      */
  42.     public void dispose() { 
  43.         super.dispose();
  44.         components.dispose();
  45.     }
  46.     
  47.     /*
  48.     * This methods hooks to the changed event on the edit control
  49.     * feeding text into SimpleControl 
  50.     */
  51.     private void sleStringData_textChanged(Object source, Event e) { 
  52.         simpleControl1.setStringData (((Edit)source).getText()) ;
  53.     }
  54.  
  55.     /*
  56.     * This methods hooks to the number data changed event that is fired
  57.     * by SimpleControl whenever the numberDataProperty is changed. It sets 
  58.     * the value of the label control to the value of the SimpleControl 
  59.     * numberData property
  60.     */
  61.     private void simplecontrol1_numberDataChanged(Object source, Event e) { 
  62.         short numberValue = ((SimpleControl)source).getNumberData() ;
  63.         String textValue = (new Short(numberValue)).toString() ;
  64.         lblNumberValue.setText(textValue) ;
  65.     }
  66.  
  67.     /*
  68.     * This methods hooks to the click event for the Angry radiobutton
  69.     * It sets SimpleControl to Angry mode 
  70.     */
  71.     private void rbAngry_click(Object source, Event e) { 
  72.         simpleControl1.setDrawingMode(DrawingMode.ANGRY) ;                      
  73.     }
  74.  
  75.     /*
  76.     * This methods hooks to the click event for the Calm radiobutton
  77.     * It sets SimpleControl to Calm mode 
  78.     */
  79.     private void rbCalm_click(Object source, Event e) { 
  80.         simpleControl1.setDrawingMode(DrawingMode.CALM) ;                      
  81.     }
  82.  
  83.     /*
  84.     * This methods hooks to the click event for the Awkward radiobutton
  85.     * It sets SimpleControl to Awkward mode 
  86.     */
  87.     private void rbAwkward_click(Object source, Event e) { 
  88.         simpleControl1.setDrawingMode(DrawingMode.AWKWARD) ;                      
  89.     }
  90.     
  91.     /*
  92.     * This methods hooks to the click event for the Set Number Data button
  93.     * It sets the numberData property of SimpleControl to the time now 
  94.     * as seconds 
  95.     */
  96.     private void butSetNumberData_click(Object source, Event e) { 
  97.         Date now = new Date() ;
  98.         long secs = now.getTime() ;
  99.         simpleControl1.setNumberData((short)secs) ;
  100.     }
  101.  
  102.     private void rbCalm_checkedChanged(Object source, Event e)
  103.     {
  104.         
  105.     }
  106.  
  107.     /**
  108.      * NOTE: The following code is required by the Visual J++ form
  109.      * designer.  It can be modified using the form editor.  Do not
  110.      * modify it using the code editor.
  111.      */
  112.     Container components = new Container();
  113.     SimpleControl simpleControl1 = new SimpleControl();
  114.     Edit sleStringData = new Edit();
  115.     Label label1 = new Label();
  116.     RadioButton rbAngry = new RadioButton();
  117.     Button butSetNumberData = new Button();
  118.     Label lblNumberValue = new Label();
  119.     GroupBox groupBox1 = new GroupBox();
  120.     GroupBox groupBox2 = new GroupBox();
  121.     RadioButton rbCalm = new RadioButton();
  122.     RadioButton rbAwkward = new RadioButton();
  123.     GroupBox groupBox3 = new GroupBox();
  124.     GroupBox groupBox4 = new GroupBox();
  125.  
  126.     private void initForm()
  127.     {
  128.         this.setText("TestControlForm");
  129.         this.setAutoScaleBaseSize(new Point(5, 13));
  130.         this.setClientSize(new Point(617, 244));
  131.  
  132.         simpleControl1.setAnchor(ControlAnchor.ALL);
  133.         simpleControl1.setLocation(new Point(28, 30));
  134.         simpleControl1.setSize(new Point(223, 182));
  135.         simpleControl1.setTabIndex(4);
  136.         simpleControl1.setTabStop(false);
  137.         simpleControl1.setText("simpleControl1");
  138.         simpleControl1.setDrawingMode(DrawingMode.CALM);
  139.         simpleControl1.setNumberData((short)102);
  140.         simpleControl1.setStringData("sdfsdf");
  141.         simpleControl1.setMyOwnType(MyOwnType.TYPE1);
  142.         simpleControl1.addOnNumberDataChanged(new EventHandler(this.simplecontrol1_numberDataChanged));
  143.  
  144.         sleStringData.setAnchor(ControlAnchor.TOPRIGHT);
  145.         sleStringData.setLocation(new Point(381, 31));
  146.         sleStringData.setSize(new Point(200, 20));
  147.         sleStringData.setTabIndex(0);
  148.         sleStringData.setText("");
  149.         sleStringData.addOnTextChanged(new EventHandler(this.sleStringData_textChanged));
  150.  
  151.         label1.setAnchor(ControlAnchor.TOPRIGHT);
  152.         label1.setLocation(new Point(309, 28));
  153.         label1.setSize(new Point(64, 16));
  154.         label1.setTabIndex(6);
  155.         label1.setTabStop(false);
  156.         label1.setText("String Data");
  157.  
  158.         rbAngry.setAnchor(ControlAnchor.BOTTOMLEFT);
  159.         rbAngry.setBackColor(Color.CONTROL);
  160.         rbAngry.setLocation(new Point(16, 64));
  161.         rbAngry.setSize(new Point(85, 25));
  162.         rbAngry.setTabIndex(2);
  163.         rbAngry.setText("Angry");
  164.         rbAngry.addOnClick(new EventHandler(this.rbAngry_click));
  165.  
  166.         butSetNumberData.setAnchor(ControlAnchor.TOPRIGHT);
  167.         butSetNumberData.setLocation(new Point(429, 66));
  168.         butSetNumberData.setSize(new Point(144, 88));
  169.         butSetNumberData.setTabIndex(2);
  170.         butSetNumberData.setText("Change the number");
  171.         butSetNumberData.addOnClick(new EventHandler(this.butSetNumberData_click));
  172.  
  173.         lblNumberValue.setAnchor(ControlAnchor.TOPRIGHT);
  174.         lblNumberValue.setBackColor(Color.INFO);
  175.         lblNumberValue.setFont(new Font("Arial", 12.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  176.         lblNumberValue.setLocation(new Point(327, 200));
  177.         lblNumberValue.setSize(new Point(232, 24));
  178.         lblNumberValue.setTabIndex(7);
  179.         lblNumberValue.setTabStop(false);
  180.         lblNumberValue.setText("");
  181.         lblNumberValue.setTextAlign(HorizontalAlignment.CENTER);
  182.  
  183.         groupBox1.setAnchor(ControlAnchor.ALL);
  184.         groupBox1.setLocation(new Point(12, 6));
  185.         groupBox1.setSize(new Point(263, 222));
  186.         groupBox1.setTabIndex(3);
  187.         groupBox1.setTabStop(false);
  188.         groupBox1.setText("Control");
  189.  
  190.         groupBox2.setAnchor(ControlAnchor.TOPRIGHT);
  191.         groupBox2.setLocation(new Point(293, 7));
  192.         groupBox2.setSize(new Point(304, 168));
  193.         groupBox2.setTabIndex(1);
  194.         groupBox2.setTabStop(false);
  195.         groupBox2.setText("Set the control properties");
  196.  
  197.         rbCalm.setAnchor(ControlAnchor.BOTTOMLEFT);
  198.         rbCalm.setBackColor(Color.CONTROL);
  199.         rbCalm.setLocation(new Point(16, 16));
  200.         rbCalm.setSize(new Point(85, 25));
  201.         rbCalm.setTabIndex(0);
  202.         rbCalm.setTabStop(true);
  203.         rbCalm.setText("Calm");
  204.         rbCalm.setChecked(true);
  205.         rbCalm.addOnClick(new EventHandler(this.rbCalm_click));
  206.         rbCalm.addOnCheckedChanged(new EventHandler(this.rbCalm_checkedChanged));
  207.  
  208.         rbAwkward.setAnchor(ControlAnchor.BOTTOMLEFT);
  209.         rbAwkward.setBackColor(Color.CONTROL);
  210.         rbAwkward.setLocation(new Point(16, 40));
  211.         rbAwkward.setSize(new Point(85, 25));
  212.         rbAwkward.setTabIndex(1);
  213.         rbAwkward.setText("Awkward");
  214.         rbAwkward.addOnClick(new EventHandler(this.rbAwkward_click));
  215.  
  216.         groupBox3.setAnchor(ControlAnchor.BOTTOMLEFT);
  217.         groupBox3.setLocation(new Point(16, 56));
  218.         groupBox3.setSize(new Point(104, 104));
  219.         groupBox3.setTabIndex(0);
  220.         groupBox3.setTabStop(false);
  221.         groupBox3.setText("I am:");
  222.  
  223.         groupBox4.setAnchor(ControlAnchor.TOPRIGHT);
  224.         groupBox4.setLocation(new Point(295, 184));
  225.         groupBox4.setSize(new Point(304, 48));
  226.         groupBox4.setTabIndex(5);
  227.         groupBox4.setTabStop(false);
  228.         groupBox4.setText("Hooked to Number Change Event");
  229.  
  230.         this.setNewControls(new Control[] {
  231.                             lblNumberValue, 
  232.                             butSetNumberData, 
  233.                             label1, 
  234.                             sleStringData, 
  235.                             simpleControl1, 
  236.                             groupBox1, 
  237.                             groupBox2, 
  238.                             groupBox4});
  239.         groupBox2.setNewControls(new Control[] {
  240.                                  groupBox3});
  241.         groupBox3.setNewControls(new Control[] {
  242.                                  rbAngry, 
  243.                                  rbAwkward, 
  244.                                  rbCalm});
  245.     }
  246.  
  247.     /**
  248.      * The main entry point for the application. 
  249.      *
  250.      * @param args Array of parameters passed to the application
  251.      * via the command line.
  252.      */
  253.     public static void main(String args[]) { 
  254.         Application.run(new TestControlForm());
  255.     }
  256. }
  257.