home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 13 / boot-disc-1997-09.iso / HyprWire / DATA.Z / ListPlugIn.java < prev    next >
Text File  |  1997-01-21  |  8KB  |  287 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. ListPlugIn:  List AWT Widget implemented in Hyperwire
  23.  
  24. Author:  Amalgamated YoYoDyne PlugIns, Inc.(Hyperwire demonstration file)
  25.  
  26. Version:  1.0
  27.  
  28. **************************************************************************/
  29.  
  30. import kinetix.hyperc1.runtime.*;
  31. import java.awt.*;
  32. import java.applet.Applet;
  33.  
  34.  
  35. /*** Class Declaration ***/
  36. public class ListPlugIn extends HwVisualUserPlugIn
  37. {
  38.     AWTList  mObject;
  39.     boolean    mCreatingAWTObject = false;
  40.     String s [] = new String [20];
  41.  
  42.  
  43.     /*** Instance methods ***/
  44.  
  45.     public void createAWTObject()
  46.         {  
  47.           if (mCreatingAWTObject) return; 
  48.  
  49.         mCreatingAWTObject = true;
  50.  
  51.         VisualRunService runService = piGetVisualRunService();
  52.         Applet theApplet = runService.siGetApplet();
  53.         Rectangle textRect = runService.siGetAbsRect();
  54.  
  55.         mObject = new AWTList(this);
  56.  
  57.         for ( int i=0; i < 20; i++ )
  58.             {
  59.             if ( !s[i].equals("") ) 
  60.                 mObject.addItem( s[i] );
  61.             }
  62.  
  63.         theApplet.add(mObject, 0);
  64.         mObject.reshape(textRect.x, textRect.y, textRect.width, textRect.height);
  65.         mObject.show();
  66.         mCreatingAWTObject = false;
  67.     }
  68.  
  69.  
  70.  
  71.     /*** VisualRunPlugIn Implementation ***/
  72.     /*                                        
  73.     /* The following 7 methods allow a 
  74.     /* PlugIn to draw an AWT Object (or a
  75.     /* sub-class thereof) to the Hyperwire
  76.     /* runtime.
  77.       /*                                    */ 
  78.     public void piEventAppletStart(Applet theApplet) throws HwException
  79.         {
  80.         if (mObject == null)
  81.             createAWTObject();
  82.         }
  83.  
  84.     public void piEventAboutToHide(int why) throws HwException
  85.         {
  86.         if (mObject != null)
  87.             {
  88.             if ( why == BasicRunPlugIn.E_THIS )
  89.                 mObject.nextFocus();
  90.             mObject.hide();
  91.             }
  92.         }        
  93.  
  94.     public void piEventAboutToShow(int why) throws HwException
  95.         {
  96.         if (mObject != null)
  97.             {
  98.             mObject.show();
  99.             }
  100.         }        
  101.  
  102.     public void piEventParentMovedBy(VisualRunPlugIn aParent, int xOffset, int yOffset) 
  103.     throws HwException
  104.         {
  105.         if (mObject != null)
  106.             {
  107.             Rectangle absRect = piGetVisualRunService().siGetAbsRect();
  108.             VisualRunRepresentation vRep = (VisualRunRepresentation) piGetVisualRunService();
  109.             mObject.reshape(absRect.x + xOffset, absRect.y + yOffset,
  110.                               absRect.width, absRect.height);
  111.             }
  112.         }
  113.  
  114.     public void piRestoreInitialRunState() throws HwException
  115.         {
  116. System.out.println("Restore");
  117.         piSetAbsRect(piGetVisualRunService().siGetAbsRect());
  118.         }
  119.         
  120.     public void piSetAbsRect(Rectangle aRect)    throws HwException
  121.         {
  122.         if (mObject != null)
  123.             {
  124.             mObject.reshape(aRect.x, aRect.y, aRect.width, aRect.height);
  125.             }
  126.         }
  127.  
  128.     /*** End VisualRunPlugIn Implementation ***/
  129.  
  130.     /*** Event Handler -- events from sub-class of AWT Object ***/
  131.  
  132.     public boolean handleEvent ( Event e ) throws HwException
  133.     {
  134.         switch (e.id)
  135.         {
  136.             case Event.LIST_SELECT:
  137.                 piGetVisualRunService().siPerformOutput("ListSelect",
  138.                             HwString.from(mObject.getSelectedItem()) );
  139.                 return true;
  140.         }
  141.  
  142.         return false;
  143.     }
  144.  
  145.  
  146.     /*** Properties Interface ***/
  147.  
  148.     public void fiSetListItem1 ( String item ) { s[0] = item; }
  149.     public void fiSetListItem2 ( String item ) { s[1] = item; }
  150.     public void fiSetListItem3 ( String item ) { s[2] = item; }
  151.     public void fiSetListItem4 ( String item ) { s[3] = item; }
  152.     public void fiSetListItem5 ( String item ) { s[4] = item; }
  153.     public void fiSetListItem6 ( String item ) { s[5] = item; }
  154.     public void fiSetListItem7 ( String item ) { s[6] = item; }
  155.     public void fiSetListItem8 ( String item ) { s[7] = item; }
  156.     public void fiSetListItem9 ( String item ) { s[8] = item; }
  157.     public void fiSetListItem10 ( String item ) { s[9] = item; }
  158.     public void fiSetListItem11 ( String item ) { s[10] = item;    }
  159.     public void fiSetListItem12 ( String item ) { s[11] = item; }
  160.     public void fiSetListItem13 ( String item ) { s[12] = item; }
  161.     public void fiSetListItem14 ( String item ) { s[13] = item; }
  162.     public void fiSetListItem15 ( String item ) { s[14] = item; }
  163.     public void fiSetListItem16 ( String item ) { s[15] = item; }
  164.     public void fiSetListItem17 ( String item ) { s[16] = item; }
  165.     public void fiSetListItem18 ( String item ) { s[17] = item; }
  166.     public void fiSetListItem19 ( String item ) { s[18] = item; }
  167.     public void fiSetListItem20 ( String item ) { s[19] = item;    }
  168.  
  169.  
  170.     /*** Wire Interface ***/
  171.     /* These are all calls to methods in the AWT Object */
  172.  
  173.     public int wiCountItems()
  174.         {
  175.         return mObject.countItems();
  176.         }
  177.  
  178.     public String wiGetItem( int i )
  179.         {
  180.         return mObject.getItem( i );
  181.         }
  182.  
  183.     public void wiAddItem( String item )
  184.         {
  185.         mObject.addItem( item );
  186.         }
  187.  
  188.     public void wiAddItemAtIndex( String item, int i )
  189.         {
  190.         mObject.addItem( item, i );
  191.         }
  192.  
  193.     public void wiClear()
  194.         {
  195.         mObject.clear();
  196.         }
  197.  
  198.     public void wiDelItem( int i )
  199.         {
  200.         mObject.delItem( i );
  201.         }
  202.  
  203.     public void wiDelItems( int i, int j )
  204.         {
  205.         mObject.delItems( i, j );
  206.         }
  207.  
  208.     public void wiReplaceItem( String item, int i)
  209.         {
  210.         mObject.replaceItem( item, i );
  211.         }
  212.  
  213.     public int wiGetSelectedIndex()
  214.         {
  215.         return mObject.getSelectedIndex();
  216.         }
  217.  
  218.     public void wiSelect( int i )
  219.         {
  220.         mObject.select( i );
  221.         }
  222.  
  223.     public void wiDeselect( int i )
  224.         {
  225.         mObject.deselect( i );
  226.         }
  227.  
  228.     public boolean wiIsSelected( int i )
  229.         {
  230.         return mObject.isSelected( i );
  231.         }
  232.  
  233.     public int wiGetRows()
  234.         {
  235.         return mObject.getRows();
  236.         }
  237.  
  238.     public void wiMakeVisible( int i )
  239.         {
  240.         mObject.makeVisible( i );
  241.         }
  242.  
  243. }
  244.  
  245. /*** End ListPlugIn ***/
  246.  
  247.  
  248.  
  249. /***********************************************************************
  250. AWTScrollBar:  Sub-class of AWT Scrollbar widget, with event handler
  251.  
  252. Author:  Amalgamated YoYoDyne PlugIns, Inc.(Hyperwire demonstraton file)
  253.  
  254. Version:  1.0
  255.  
  256. ***********************************************************************/
  257.  
  258. class AWTList extends List 
  259.     {
  260.     ListPlugIn mPlugIn;
  261.  
  262.     /*** Constructor ***/
  263.     public AWTList(ListPlugIn aPlugIn) 
  264.         {
  265.         super();
  266.         mPlugIn = aPlugIn;
  267.         }
  268.  
  269.     /*** Pass Events back to the PlugIn ***/
  270.     public boolean handleEvent ( Event evt ) 
  271.         {
  272.         try 
  273.             {
  274.             return mPlugIn.handleEvent( evt );
  275.             } 
  276.         catch(Exception e) 
  277.             {
  278.             HwException oe = mPlugIn.piGetRunService().siProcessException(e, "List Widget Error");
  279.             mPlugIn.piGetRunService().siLogException(oe);
  280.             }
  281.         return false;
  282.         }
  283.     }
  284.  
  285. /*** End AWTList ***/
  286.  
  287.