home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / AWTComponentView.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  2.8 KB  |  97 lines  |  [TEXT/CWIE]

  1. // AWTComponentView.java
  2. // By Ned Etcode
  3. // Copyright 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import java.awt.Component;
  8. import netscape.util.*;
  9.  
  10.  
  11. /* ALERT!
  12.     - Can't add components to the panel using index other than 0.
  13.     - Focus events come in when clicking on AWT things and then ours
  14.     */
  15.  
  16. /** View subclass that supports the embedding of an AWT Component in an IFC
  17.   * application. The component will not be clipped by other IFC Views,
  18.   * including the AWTComponentView itself, or any of its ancestors.
  19.   */
  20. public class AWTComponentView extends View {
  21.     Component component;
  22.     // This will go away when we changed the semantics of
  23.     // ancestorWasRemovedFromViewHierarchy.
  24.     RootView rootView;
  25.  
  26.     /** Constructs an AWTComponentView with origin (0, 0) and zero width and
  27.       * height.
  28.       */
  29.     public AWTComponentView() {
  30.         this(0, 0, 0, 0);
  31.     }
  32.  
  33.     /** Constructs an AWTComponentView with bounds <B>rect</B>.
  34.       */
  35.     public AWTComponentView(Rect rect) {
  36.         this(rect.x, rect.y, rect.width, rect.height);
  37.     }
  38.  
  39.     /** Constructs an AWTComponentView with
  40.       * bounds (<B>x</B>, <B>y</B>, <B>width</B>, <B>height</B>).
  41.       */
  42.     public AWTComponentView(int x, int y, int width, int height) {
  43.         super(x, y, width, height);
  44.     }
  45.  
  46.     void setComponentBounds() {
  47.         Rect cBounds = _superview.convertRectToView(null, bounds);
  48.  
  49.         component.reshape(cBounds.x, cBounds.y, cBounds.width, cBounds.height);
  50.     }
  51.  
  52.     void addComponent() {
  53.         if (rootView != null) {
  54.             rootView.addComponentView(this);
  55.         }
  56.     }
  57.  
  58.     void removeComponent() {
  59.         if (component != null && rootView != null) {
  60.             rootView.removeComponentView(this);
  61.         }
  62.     }
  63.  
  64.     /** Sets the AWT component that will be embedded in the AWTComponentView.
  65.       */
  66.     public void setAWTComponent(Component aComponent) {
  67.         removeComponent();
  68.         component = aComponent;
  69.         addComponent();
  70.     }
  71.  
  72.     /** Returns the AWT component.
  73.       * @see #setComponent
  74.       */
  75.     public Component awtComponent() {
  76.         return component;
  77.     }
  78.  
  79.     /** Overridden to take special action when the AWTComponentView or an
  80.       * ancestor leaves the Application's View hierarchy.
  81.       * @see View#ancestorWillRemoveFromViewHierarchy
  82.       */
  83.     protected void ancestorWillRemoveFromViewHierarchy(View removedView) {
  84.         removeComponent();
  85.         rootView = null;
  86.     }
  87.  
  88.     /** Overridden to take special action when the AWTComponentView or an
  89.       * ancestor becomes part of the Application's View hierarchy.
  90.       * @see View#ancestorWasAddedToViewHierarchy
  91.       */
  92.     protected void ancestorWasAddedToViewHierarchy(View addedView) {
  93.         rootView = rootView();
  94.         addComponent();
  95.     }
  96. }
  97.