home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 9 / boot-disc-1997-05.iso / Media / backup / sun / GroovyBox.java < prev    next >
Text File  |  1997-03-11  |  10KB  |  284 lines

  1. /**
  2.  * This is a template.  You may modify this file.
  3.  *
  4.  * Runtime vendor: SunSoft, Inc.
  5.  * Runtime version: 1
  6.  *
  7.  * Visual vendor: SunSoft, Inc.
  8.  * Visual version: 1
  9.  */
  10.  
  11.  
  12. import sunsoft.jws.visual.rt.base.*;
  13. import sunsoft.jws.visual.rt.shadow.java.awt.*;
  14. import java.awt.*;
  15.  
  16. import java.applet.*;
  17.  
  18.  
  19. public class GroovyBox extends Group {
  20.   private GroovyBoxRoot gui;
  21.  
  22.   /**
  23.    * Sample method call ordering during a group's lifetime:
  24.    *
  25.    * Constructor
  26.    * initRoot
  27.    * initGroup
  28.    * (setOnGroup and getOnGroup may be called at any time in any
  29.    *  order after initGroup has been called)
  30.    * createGroup
  31.    * showGroup/hideGroup + startGroup/stopGroup
  32.    * destroyGroup
  33.    */
  34.  
  35.   /**
  36.    * All the attributes used by the group must be defined in the
  37.    * constructor.  setOnGroup is called at initialization for all
  38.    * the attributes.  If the attribute has not been set prior to
  39.    * initialization, setOnGroup is called with the default value.
  40.    */
  41.   public GroovyBox() {
  42.     /**
  43.      * Define the group's custom attributes here.
  44.      *
  45.      * For example:
  46.      *
  47.      * attributes.add("customString", "java.lang.String",
  48.      *              "Default String", 0);
  49.      */
  50.  
  51.     /**
  52.      * This method defines the attributes that will be forwarded to
  53.      * the main child (either a window or a panel).  All attributes
  54.      * defined by this method are marked with the FORWARD flag.
  55.      */
  56.     addForwardedAttributes();
  57.   }
  58.  
  59.   /**
  60.    * initRoot must be overridden in group subclasses to initialize
  61.    * the shadow tree.  The return value must be the root of the
  62.    * newly initialized shadow tree.
  63.    */
  64.   protected Root initRoot() {
  65.     /**
  66.      * Initialize the gui components
  67.      */
  68.     gui = new GroovyBoxRoot(this);
  69.  
  70.     /**
  71.      * This method registers an attribute manager with the group, such
  72.      * that attributes marked with the FORWARD flag will be sent to
  73.      * this attribute manager.
  74.      */
  75.     addAttributeForward(gui.getMainChild());
  76.  
  77.     return gui;
  78.   }
  79.  
  80.   /**
  81.    * initGroup is called during initialization.  It is called just after
  82.    * initRoot is called, but before the sub-groups are initialized and
  83.    * before the attributes are sent to the setOnGroup method.
  84.    *
  85.    * initGroup is only called once in the lifetime of the Group.
  86.    * This is because groups cannot be uninitialized.  Anything that
  87.    * needs to be cleaned up should be created in createGroup instead
  88.    * of initGroup, and then can be cleaned up in destroyGroup.
  89.    * createGroup and destroyGroup may be called multiple times during
  90.    * the lifetime of a group.
  91.    */
  92.   protected void initGroup() { }
  93.  
  94.   /**
  95.    * showGroup may be overridden by group subclasses that want
  96.    * to know when the group becomes visible.  It is called just before
  97.    * the group becomes visible.  The group will already be initialized
  98.    * and created at this point.
  99.    */
  100.   protected void showGroup() { }
  101.  
  102.   /**
  103.    * hideGroup may be overridden by group subclasses that want
  104.    * to know when the group becomes non-visible.  It is called just
  105.    * before the group becomes non-visible.
  106.    */
  107.   protected void hideGroup() { }
  108.  
  109.   /**
  110.    * createGroup is called during group creation.  Groups can be
  111.    * created and destroyed multiple times during their lifetime.
  112.    * Anything that is created in createGroup should be cleaned up
  113.    * in destroyGroup.  createGroup is called just after the group
  114.    * has been created.  Anything that needs to be done before the
  115.    * group is created should be done in initGroup.
  116.    */
  117.   protected void createGroup() { }
  118.  
  119.   /**
  120.    * destroyGroup is called during the destroy operation.  Groups can
  121.    * be created and destroyed multiple times during their lifetime.
  122.    * Anything that has been created in createGroup should be cleaned up
  123.    * in destroyGroup.  destroyGroup is called just before the group
  124.    * is destroyed.
  125.    */
  126.   protected void destroyGroup() { }
  127.  
  128.   /**
  129.    * This method may be overridden by group subclasses that want
  130.    * to be informed when the application is starting.  This method is
  131.    * only called after the entire application has been initialized and
  132.    * created.
  133.    *
  134.    * For applets, startGroup is called whenever start is called on the
  135.    * applet.
  136.    */
  137.   protected void startGroup() { }
  138.  
  139.   /**
  140.    * This method may be overridden by group subclasses that want
  141.    * to be informed when the application is stopping.  This method
  142.    * will be called before a destroy is done.
  143.    *
  144.    * For applets, stopGroup is called whenever stop is called on the
  145.    * applet.
  146.    */
  147.   protected void stopGroup() { }
  148.  
  149.   /**
  150.    * "getOnGroup" may be overridden by sub-groups that
  151.    * store attribute values themselves, and do not depend on the
  152.    * group superclass to store them.  This method should be overridden
  153.    * instead of "get".  Any attributes handled in setOnGroup where
  154.    * super.setOnGroup is not called must also be handled in getOnGroup.
  155.    *
  156.    * The default implementation of getOnGroup retrieves the value
  157.    * from the attribute table.
  158.    *
  159.    * The reason that "getOnGroup" should be overridden instead
  160.    * of "get" is that "getOnGroup" is guaranteed not to be called
  161.    * until the group class is initialized.  This means that initRoot
  162.    * will always be called before any calls to getOnGroup are made.
  163.    *
  164.    * Also, this method is only for attributes that are defined in the
  165.    * sub-groups.  It is not called for forwarded attributes.
  166.    */
  167.   protected Object getOnGroup(String key) {
  168.     return super.getOnGroup(key);
  169.   }
  170.  
  171.   /**
  172.    * "setOnGroup" may be overridden by sub-groups that
  173.    * want notification when attributes are changed.  This method
  174.    * should be overridden instead of "set".  Any attributes handled
  175.    * in setOnGroup where super.setOnGroup is not called must also be
  176.    * handled in getOnGroup.
  177.    *
  178.    * The default implementation of setOnGroup puts the value
  179.    * in the attribute table.
  180.    *
  181.    * The reason that "setOnGroup" should be overridden instead
  182.    * of "set" is that "setOnGroup" is guaranteed not to be called
  183.    * until the group class is initialized.  This means that initRoot
  184.    * will always be called before any calls to setOnGroup are made.
  185.    *
  186.    * During initialization, "setOnGroup" will be called for all
  187.    * the group's attributes even if they have not be changed from
  188.    * the default value.  But for attributes that have the DEFAULT
  189.    * flag set, "setOnGroup" will only be called if the value
  190.    * of the attribute has changed from the default.
  191.    *
  192.    * Also, this method is only called when attributes defined in the
  193.    * sub-groups are updated.  It is not called for forwarded attributes.
  194.    */
  195.   protected void setOnGroup(String key, Object value) {
  196.     super.setOnGroup(key, value);
  197.   }
  198.  
  199.   /**
  200.    * handleMessage may be overridden by subclasses that want to act
  201.    * on messages that are sent to the group.  Typically, messages are
  202.    * either AWT events that have been translated to messages, or they
  203.    * are messages that have been sent by other groups.
  204.    * super.handleMessage should be called for any messages that aren't
  205.    * handled.  If super.handleMessage is not called, then handleEvent
  206.    * will not be called.
  207.    *
  208.    * The default implementation of handleMessage returns "true".  This
  209.    * means that no events will be passed up the group tree, unless a
  210.    * subclass overrides this method to return "false".  AWT events are
  211.    * not propagated regardless of the return value from handleEvent.
  212.    *
  213.    * If you want a message to go to the parent group, override
  214.    * handleMessage to return false for that message.
  215.    *
  216.    * If you want an AWT event to go to the parent group, you need to
  217.    * call postMessageToParent() with the event message.
  218.    */
  219.   public boolean handleMessage(Message msg) {
  220.     return super.handleMessage(msg);
  221.   }
  222.  
  223.   /**
  224.    * handleEvent may be overridden by subclasses that want to get
  225.    * notified when AWT events that are sent by the gui components.
  226.    * The return value should be true for handled events, and
  227.    * super.handleEvent should be called for unhandled events.
  228.    * If super.handleEvent is not called, then the specific event
  229.    * handling methods will not be called.
  230.    *
  231.    * The message's target is set to the shadow that sent the event.
  232.    * The event's target is set to the AWT component that sent the event.
  233.    *
  234.    *
  235.    * The following specific event handling methods may also be overridden:
  236.    *
  237.    * public boolean mouseDown(Message msg, Event evt, int x, int y);
  238.    * public boolean mouseDrag(Message msg, Event evt, int x, int y);
  239.    * public boolean mouseUp(Message msg, Event evt, int x, int y);
  240.    * public boolean mouseMove(Message msg, Event evt, int x, int y);
  241.    * public boolean mouseEnter(Message msg, Event evt, int x, int y);
  242.    * public boolean mouseExit(Message msg, Event evt, int x, int y);
  243.    * public boolean keyDown(Message msg, Event evt, int key);
  244.    * public boolean keyUp(Message msg, Event evt, int key);
  245.    * public boolean action(Message msg, Event evt, Object what);
  246.    * public boolean gotFocus(Message msg, Event evt, Object what);
  247.    * public boolean lostFocus(Message msg, Event evt, Object what);
  248.    */
  249.   public boolean handleEvent(Message msg, Event evt) {
  250.     return super.handleEvent(msg, evt);
  251.   }
  252.  
  253.   public boolean mouseEnter(Message msg, Event evt, int x, int y)
  254.   {
  255.     Applet ourApplet = getApplet();
  256.     AudioClip clip;
  257.     String clipFilename = null;
  258.  
  259.     // If the mouse is entering any of our Image Labels, we play
  260.     // a sound that has nothing to do with the image.
  261.     // Confusion is Entertainment!
  262.     if (msg.target == gui.alien)
  263.         clipFilename = "mix.au";
  264.     else if (msg.target == gui.thatgirl)
  265.         clipFilename = "gEEk.au";
  266.     else if (msg.target == gui.disc)
  267.         clipFilename = "powerchord.au";
  268.     else if (msg.target == gui.mrbrad)
  269.         clipFilename = "hahaha.au";
  270.     else if (msg.target == gui.baby)
  271.         clipFilename = "picking.au";
  272.     else if (msg.target == gui.bootnet)
  273.         clipFilename = "whatEVer.au";
  274.  
  275.     if (clipFilename != null)
  276.     {
  277.         clip = ourApplet.getAudioClip(ourApplet.getDocumentBase(), clipFilename);
  278.         clip.play();
  279.     }
  280.  
  281.     return super.mouseEnter(msg, evt, x, y);
  282.   }
  283. }
  284.