home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 13 / boot-disc-1997-09.iso / HyprWire / DATA.Z / ScrollbarPlugIn.java < prev    next >
Text File  |  1997-01-21  |  8KB  |  298 lines

  1. package kinetix.hyperc1.userPlugIns;
  2.  
  3. /********************************************************************************\
  4. **                                                                              **
  5. **  (C) Copyright 1997 by Autodesk, Inc.                                        **
  6. **                                                                              **
  7. **  This program is copyrighted by Autodesk, Inc. and is licensed to you under  **
  8. **  the following conditions.  You may not distribute or publish the source     **
  9. **  code of this program in any form.  You may incorporate this code in object  **
  10. **  form in derivative works provided such derivative works are (i.) are de-    **
  11. **  signed and intended to work solely with Autodesk, Inc. products, and (ii.)  **
  12. **  contain Autodesk's copyright notice "(C) Copyright 1997 by Autodesk, Inc."  **
  13. **                                                                              **
  14. **  AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  AUTODESK SPE-  **
  15. **  CIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR  **
  16. **  A PARTICULAR USE.  AUTODESK, INC.  DOES NOT WARRANT THAT THE OPERATION OF   **
  17. **  THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.                            **
  18. **                                                                              **
  19. \********************************************************************************/
  20.  
  21. /**************************************************************************
  22. ScrollBarPlugIn:  Scrollbar AWT Widget implemented in Hyperwire
  23.  
  24. Author:  Hyperwire demonstration file
  25.  
  26. Version:  1.0
  27.  
  28. Note:  This PlugIn is used for both Horizontal and Vertical Scrollbars
  29.  
  30. **************************************************************************/
  31.  
  32. import kinetix.hyperc1.runtime.*;
  33. import java.awt.*;
  34. import java.applet.Applet;
  35.  
  36. /*** Class Declaration ***/
  37. public class ScrollbarPlugIn extends HwVisualUserPlugIn
  38.     {
  39.  
  40.     /*** Custom Object ***/
  41.     AWTScrollbar AWTObject;
  42.     public boolean mCreatingAWTObject = false;
  43.  
  44.  
  45.     /*** Persistent Properties ***/
  46.     int value, visible, minimum, maximum, type;
  47.  
  48.  
  49.     /*** Class Methods ***/
  50.     private void createAWTObject() 
  51.         {  
  52.         if (mCreatingAWTObject) return; 
  53.  
  54.         mCreatingAWTObject = true;
  55.  
  56.         VisualRunService runService = piGetVisualRunService();
  57.         Applet theApplet = runService.siGetApplet();
  58.         Rectangle textRect = runService.siGetAbsRect();
  59.  
  60.         // Create the AWT Object
  61.         if ( type == 1 )
  62.             {
  63.             AWTObject = new AWTScrollbar(this, Scrollbar.HORIZONTAL);
  64.             }
  65.         else
  66.             {
  67.             AWTObject = new AWTScrollbar(this, Scrollbar.VERTICAL);
  68.             }
  69.  
  70.         // Add it to the Applet and set the size to the PlugIn's size
  71.         theApplet.add(AWTObject, 0);
  72.         AWTObject.reshape(textRect.x, textRect.y, textRect.width, textRect.height);
  73.  
  74.         // Set and object-specific values
  75.         AWTObject.setLineIncrement(1);
  76.         AWTObject.setPageIncrement(10);
  77.         AWTObject.setValues(value,visible,minimum,maximum);
  78.  
  79.         // And away we go!
  80.         AWTObject.show();
  81.         mCreatingAWTObject = false;
  82.         }
  83.  
  84.  
  85.  
  86.     /*** VisualRunPlugIn Implementation ***/
  87.     /*                                        
  88.     /* The following 7 methods allow a 
  89.     /* PlugIn to draw an AWT Object (or a
  90.     /* sub-class thereof) to the Hyperwire
  91.     /* runtime.
  92.       /*                                    */ 
  93.     public void piEventAppletStart(Applet theApplet) throws HwException 
  94.         {
  95.         if (AWTObject == null) createAWTObject();
  96.         }
  97.  
  98.     public void piEventAboutToHide(int why) throws HwException 
  99.         {
  100.         if (AWTObject != null) 
  101.             {
  102.             if ( why == BasicRunPlugIn.E_THIS ) AWTObject.nextFocus();
  103.             AWTObject.hide();
  104.             }
  105.         }        
  106.  
  107.     public void piEventAboutToShow(int why) throws HwException 
  108.         {
  109.         if (AWTObject != null) AWTObject.show();
  110.         }        
  111.  
  112.     public void piEventParentMovedBy(VisualRunPlugIn aParent, int xOffset, int yOffset) throws HwException 
  113.         {
  114.         if (AWTObject != null) 
  115.             {
  116.             Rectangle absRect = piGetVisualRunService().siGetAbsRect();
  117.             VisualRunRepresentation vRep = (VisualRunRepresentation) piGetVisualRunService();
  118.             AWTObject.reshape(absRect.x + xOffset, absRect.y + yOffset, absRect.width, absRect.height);
  119.             }
  120.         }
  121.  
  122.     public void piRestoreInitialRunState() throws HwException 
  123.         {
  124.         piSetAbsRect(piGetVisualRunService().siGetAbsRect());
  125.         }
  126.         
  127.     public void piSetAbsRect(Rectangle aRect) throws HwException 
  128.         {
  129.         if (AWTObject != null) AWTObject.reshape(aRect.x, aRect.y, aRect.width, aRect.height);
  130.         }
  131.  
  132.     /*** End VisualRunPlugIn Implementation ***/
  133.  
  134.  
  135.     /*** Event Handler -- events from sub-class of AWT Object ***/
  136.  
  137.     public boolean handleEvent( Event e ) throws HwException 
  138.         {
  139.         switch (e.id) 
  140.             {
  141.             case Event.SCROLL_ABSOLUTE:
  142.                 piGetVisualRunService().siPerformOutput("Absolute", 
  143.                             HwInt.from(AWTObject.getValue()));
  144.                 piGetVisualRunService().siPerformOutput("Changed", 
  145.                             HwInt.from(AWTObject.getValue()));
  146.                 return true;
  147.  
  148.             case Event.SCROLL_LINE_UP:
  149.                 piGetVisualRunService().siPerformOutput("LineUp", 
  150.                             HwInt.from(AWTObject.getValue()));
  151.                 piGetVisualRunService().siPerformOutput("Changed", 
  152.                             HwInt.from(AWTObject.getValue()));
  153.                 return true;
  154.  
  155.             case Event.SCROLL_LINE_DOWN:
  156.                 piGetVisualRunService().siPerformOutput("LineDown", 
  157.                             HwInt.from(AWTObject.getValue()));
  158.                 piGetVisualRunService().siPerformOutput("Changed", 
  159.                             HwInt.from(AWTObject.getValue()));
  160.                 return true;
  161.  
  162.             case Event.SCROLL_PAGE_UP:
  163.                 piGetVisualRunService().siPerformOutput("PageUp", 
  164.                             HwInt.from(AWTObject.getValue()));
  165.                 piGetVisualRunService().siPerformOutput("Changed", 
  166.                             HwInt.from(AWTObject.getValue()));
  167.                 return true;
  168.  
  169.             case Event.SCROLL_PAGE_DOWN:
  170.                 piGetVisualRunService().siPerformOutput("PageDown", 
  171.                             HwInt.from(AWTObject.getValue()));
  172.                 piGetVisualRunService().siPerformOutput("Changed", 
  173.                             HwInt.from(AWTObject.getValue()));
  174.                 return true;
  175.  
  176.             }
  177.  
  178.         return false;
  179.         }
  180.  
  181.  
  182.     /*** Properties Interface ***/
  183.  
  184.     public void fiSetValue( int i) { value = i; }
  185.     public void fiSetVisible( int i) { visible = i;    }
  186.     public void fiSetMinimum( int i) { minimum = i; }
  187.     public void fiSetMaximum( int i) { maximum = i;    }
  188.     public void fiSetType( int i ) { type = i; }
  189.  
  190.     /*** Wire Interface ***/
  191.     /* These are all calls to methods in the AWT Object */
  192.     
  193.     public int wiSetValue( int i) 
  194.         {
  195.         AWTObject.setValue(i);
  196.         return i;
  197.         }
  198.  
  199.     public int wiGetValue() 
  200.         {
  201.         return AWTObject.getValue();
  202.         }
  203.  
  204.     public int wiSetVisible( int i) 
  205.         {
  206.         AWTObject.setValues(AWTObject.getValue(), i, minimum, maximum);
  207.         return i;
  208.         }
  209.  
  210.     public int wiGetVisible() 
  211.         {
  212.         return AWTObject.getVisible();
  213.         }
  214.  
  215.     public int wiSetMinimum( int i) 
  216.         {
  217.         AWTObject.setValues(AWTObject.getValue(), visible, i, maximum);
  218.         return i;
  219.         }
  220.  
  221.     public int wiGetMinimum() 
  222.         {
  223.         return AWTObject.getMinimum();
  224.         }
  225.  
  226.     public int wiSetMaximum( int i) 
  227.         {
  228.         AWTObject.setValues(AWTObject.getValue(), visible, minimum, i);
  229.         return i;
  230.         }
  231.  
  232.     public int wiGetMaximum() 
  233.         {
  234.         return AWTObject.getMaximum();
  235.         }
  236.  
  237.     public int wiSetPageIncrement( int i) 
  238.         {
  239.         AWTObject.setPageIncrement(i);
  240.         return i;
  241.         }    
  242.  
  243.     public int wiGetPageIncrement() 
  244.         {
  245.         return AWTObject.getPageIncrement();
  246.         }
  247.  
  248.     public int wiSetLineIncrement( int i) 
  249.         {
  250.         AWTObject.setLineIncrement(i);
  251.         return i;
  252.         }
  253.  
  254.     public int wiGetLineIncrement() 
  255.         {
  256.         return AWTObject.getLineIncrement();
  257.         }
  258.     }
  259.  
  260. /*** End ScrollbarPlugIn ***/
  261.  
  262. /***********************************************************************
  263. AWTScrollBar:  Sub-class of AWT Scrollbar widget, with event handler
  264.  
  265. Author:  Amalgamated YoYoDyne PlugIns, Inc.(Hyperwire demonstraton file)
  266.  
  267. Version:  1.0
  268.  
  269. ***********************************************************************/
  270.  
  271. class AWTScrollbar extends Scrollbar 
  272.     {
  273.     ScrollbarPlugIn mPlugIn;
  274.  
  275.     /*** Constructor ***/
  276.     public AWTScrollbar(ScrollbarPlugIn aPlugIn, int type) 
  277.         {
  278.         super(type);
  279.         mPlugIn = aPlugIn;
  280.         }
  281.  
  282.     /*** Pass Events back to the PlugIn ***/
  283.     public boolean handleEvent ( Event evt ) 
  284.         {
  285.         try 
  286.             {
  287.             return mPlugIn.handleEvent( evt );
  288.             } 
  289.         catch(Exception e) 
  290.             {
  291.             HwException oe = mPlugIn.piGetRunService().siProcessException(e, "Scrollbar Widget Error");
  292.             mPlugIn.piGetRunService().siLogException(oe);
  293.             }
  294.         return false;
  295.         }
  296.     }
  297.  
  298. /*** End AWTScrollbar ***/