home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / JPopupMenu$PanelPopup.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  4.0 KB  |  159 lines

  1. package com.sun.java.swing;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Graphics;
  7. import java.awt.Panel;
  8. import java.awt.Point;
  9. import java.awt.Rectangle;
  10. import java.awt.Window;
  11. import java.io.Serializable;
  12.  
  13. class JPopupMenu$PanelPopup extends Panel implements JPopupMenu.Popup, Serializable {
  14.    // $FF: synthetic field
  15.    private final JPopupMenu this$0;
  16.    int desiredLocationX;
  17.    int desiredLocationY;
  18.  
  19.    public JPopupMenu$PanelPopup(JPopupMenu var1) {
  20.       this.this$0 = var1;
  21.       this.this$0 = var1;
  22.       ((Container)this).setLayout(new BorderLayout());
  23.    }
  24.  
  25.    public int getWidth() {
  26.       return ((Component)this).getBounds().width;
  27.    }
  28.  
  29.    public int getHeight() {
  30.       return ((Component)this).getBounds().height;
  31.    }
  32.  
  33.    public Component getComponent() {
  34.       return this;
  35.    }
  36.  
  37.    public void addComponent(Component var1, Object var2) {
  38.       ((Container)this).add(var1, var2);
  39.    }
  40.  
  41.    public void removeComponent(Component var1) {
  42.       ((Container)this).remove(var1);
  43.    }
  44.  
  45.    public void update(Graphics var1) {
  46.       ((Container)this).paint(var1);
  47.    }
  48.  
  49.    public void pack() {
  50.       ((Component)this).setSize(((Container)this).getPreferredSize());
  51.    }
  52.  
  53.    public void show(Component var1) {
  54.       Object var2 = var1.getParent();
  55.       Object var3 = null;
  56.  
  57.       for(Object var4 = var2; var4 != null; var4 = ((Component)var4).getParent()) {
  58.          if (var4 instanceof JRootPane) {
  59.             var2 = ((JRootPane)var4).getLayeredPane();
  60.  
  61.             for(var8 = ((Component)var2).getParent(); var8 != null && !(var8 instanceof Window); var8 = ((Component)var8).getParent()) {
  62.             }
  63.  
  64.             Window var7 = (Window)var8;
  65.             break;
  66.          }
  67.  
  68.          if (var4 instanceof Window) {
  69.             var2 = var4;
  70.             Window var6 = (Window)var4;
  71.             break;
  72.          }
  73.       }
  74.  
  75.       Point var5 = this.convertScreenLocationToParent((Container)var2, this.desiredLocationX, this.desiredLocationY);
  76.       ((Component)this).setLocation(var5.x, var5.y);
  77.       if (var2 instanceof JLayeredPane) {
  78.          ((JLayeredPane)var2).add(this, JLayeredPane.POPUP_LAYER, 0);
  79.       } else {
  80.          ((Container)var2).add(this);
  81.       }
  82.    }
  83.  
  84.    public void hide() {
  85.       Container var1 = ((Component)this).getParent();
  86.       Rectangle var2 = ((Component)this).getBounds();
  87.       if (var1 != null) {
  88.          var1.remove(this);
  89.       }
  90.  
  91.       ((Component)var1).repaint(var2.x, var2.y, var2.width, var2.height);
  92.    }
  93.  
  94.    public Rectangle getBoundsOnScreen() {
  95.       Container var1 = ((Component)this).getParent();
  96.       if (var1 != null) {
  97.          Rectangle var2 = ((Component)this).getBounds();
  98.          Point var3 = this.convertParentLocationToScreen(var1, var2.x, var2.y);
  99.          var2.x = var3.x;
  100.          var2.y = var3.y;
  101.          return var2;
  102.       } else {
  103.          throw new Error("getBoundsOnScreen called on an invisible popup");
  104.       }
  105.    }
  106.  
  107.    Point convertParentLocationToScreen(Container var1, int var2, int var3) {
  108.       Window var4 = null;
  109.  
  110.       for(Object var6 = this; var6 != null; var6 = ((Component)var6).getParent()) {
  111.          if (var6 instanceof Window) {
  112.             var4 = (Window)var6;
  113.             break;
  114.          }
  115.       }
  116.  
  117.       if (var4 != null) {
  118.          Rectangle var5 = ((Component)var4).getBounds();
  119.          Point var7 = new Point(var2, var3);
  120.          var7 = SwingUtilities.convertPoint(var1, var7, (Component)null);
  121.          var7.x += var5.x;
  122.          var7.y += var5.y;
  123.          return var7;
  124.       } else {
  125.          throw new Error("convertParentLocationToScreen: no window ancestor found");
  126.       }
  127.    }
  128.  
  129.    Point convertScreenLocationToParent(Container var1, int var2, int var3) {
  130.       Window var4 = null;
  131.  
  132.       for(Container var5 = var1; var5 != null; var5 = ((Component)var5).getParent()) {
  133.          if (var5 instanceof Window) {
  134.             var4 = (Window)var5;
  135.             break;
  136.          }
  137.       }
  138.  
  139.       if (var4 != null) {
  140.          Point var6 = new Point(var2, var3);
  141.          SwingUtilities.convertPointFromScreen(var6, var1);
  142.          return var6;
  143.       } else {
  144.          throw new Error("convertScreenLocationToParent: no window ancestor found");
  145.       }
  146.    }
  147.  
  148.    public void setLocationOnScreen(int var1, int var2) {
  149.       Container var3 = ((Component)this).getParent();
  150.       if (var3 != null) {
  151.          Point var4 = this.convertScreenLocationToParent(var3, var1, var2);
  152.          ((Component)this).setLocation(var4.x, var4.y);
  153.       } else {
  154.          this.desiredLocationX = var1;
  155.          this.desiredLocationY = var2;
  156.       }
  157.    }
  158. }
  159.