home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / awt / ScrollPane.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.6 KB  |  289 lines

  1. package java.awt;
  2.  
  3. import java.awt.peer.LightweightPeer;
  4. import java.awt.peer.ScrollPanePeer;
  5. import javax.accessibility.Accessible;
  6. import javax.accessibility.AccessibleContext;
  7.  
  8. public class ScrollPane extends Container implements Accessible {
  9.    public static final int SCROLLBARS_AS_NEEDED = 0;
  10.    public static final int SCROLLBARS_ALWAYS = 1;
  11.    public static final int SCROLLBARS_NEVER = 2;
  12.    private int scrollbarDisplayPolicy;
  13.    private ScrollPaneAdjustable vAdjustable;
  14.    private ScrollPaneAdjustable hAdjustable;
  15.    private static final String base = "scrollpane";
  16.    private static int nameCounter;
  17.    private static final long serialVersionUID = 7956609840827222915L;
  18.  
  19.    private static native void initIDs();
  20.  
  21.    public ScrollPane() {
  22.       this(0);
  23.    }
  24.  
  25.    public ScrollPane(int var1) {
  26.       super.layoutMgr = null;
  27.       super.width = 100;
  28.       super.height = 100;
  29.       switch (var1) {
  30.          case 0:
  31.          case 1:
  32.          case 2:
  33.             this.scrollbarDisplayPolicy = var1;
  34.             this.vAdjustable = new ScrollPaneAdjustable(this, new PeerFixer(this, this), 1);
  35.             this.hAdjustable = new ScrollPaneAdjustable(this, new PeerFixer(this, this), 0);
  36.             return;
  37.          default:
  38.             throw new IllegalArgumentException("illegal scrollbar display policy");
  39.       }
  40.    }
  41.  
  42.    String constructComponentName() {
  43.       Class var1 = this.getClass();
  44.       synchronized(var1) {
  45.          String var2 = "scrollpane" + nameCounter++;
  46.          return var2;
  47.       }
  48.    }
  49.  
  50.    protected final void addImpl(Component var1, Object var2, int var3) {
  51.       Object var4 = ((Component)this).getTreeLock();
  52.       synchronized(var4) {
  53.          if (((Container)this).getComponentCount() > 0) {
  54.             ((Container)this).remove(0);
  55.          }
  56.  
  57.          if (var3 > 0) {
  58.             throw new IllegalArgumentException("position greater than 0");
  59.          } else {
  60.             super.addImpl(var1, var2, var3);
  61.          }
  62.       }
  63.    }
  64.  
  65.    public int getScrollbarDisplayPolicy() {
  66.       return this.scrollbarDisplayPolicy;
  67.    }
  68.  
  69.    public Dimension getViewportSize() {
  70.       Insets var1 = ((Container)this).getInsets();
  71.       return new Dimension(super.width - var1.right - var1.left, super.height - var1.top - var1.bottom);
  72.    }
  73.  
  74.    public int getHScrollbarHeight() {
  75.       int var1 = 0;
  76.       if (this.scrollbarDisplayPolicy != 2) {
  77.          ScrollPanePeer var2 = (ScrollPanePeer)super.peer;
  78.          if (var2 != null) {
  79.             var1 = var2.getHScrollbarHeight();
  80.          }
  81.       }
  82.  
  83.       return var1;
  84.    }
  85.  
  86.    public int getVScrollbarWidth() {
  87.       int var1 = 0;
  88.       if (this.scrollbarDisplayPolicy != 2) {
  89.          ScrollPanePeer var2 = (ScrollPanePeer)super.peer;
  90.          if (var2 != null) {
  91.             var1 = var2.getVScrollbarWidth();
  92.          }
  93.       }
  94.  
  95.       return var1;
  96.    }
  97.  
  98.    public Adjustable getVAdjustable() {
  99.       return this.vAdjustable;
  100.    }
  101.  
  102.    public Adjustable getHAdjustable() {
  103.       return this.hAdjustable;
  104.    }
  105.  
  106.    public void setScrollPosition(int var1, int var2) {
  107.       Object var3 = ((Component)this).getTreeLock();
  108.       synchronized(var3) {
  109.          if (super.ncomponents <= 0) {
  110.             throw new NullPointerException("child is null");
  111.          } else {
  112.             this.hAdjustable.setValue(var1);
  113.             this.vAdjustable.setValue(var2);
  114.          }
  115.       }
  116.    }
  117.  
  118.    public void setScrollPosition(Point var1) {
  119.       this.setScrollPosition(var1.x, var1.y);
  120.    }
  121.  
  122.    public Point getScrollPosition() {
  123.       if (super.ncomponents <= 0) {
  124.          throw new NullPointerException("child is null");
  125.       } else {
  126.          return new Point(this.hAdjustable.getValue(), this.vAdjustable.getValue());
  127.       }
  128.    }
  129.  
  130.    public final void setLayout(LayoutManager var1) {
  131.       throw new AWTError("ScrollPane controls layout");
  132.    }
  133.  
  134.    public void doLayout() {
  135.       this.layout();
  136.    }
  137.  
  138.    Dimension calculateChildSize() {
  139.       Dimension var1 = ((Component)this).getSize();
  140.       Insets var2 = ((Container)this).getInsets();
  141.       int var3 = var1.width - var2.left * 2;
  142.       int var4 = var1.height - var2.top * 2;
  143.       Component var7 = ((Container)this).getComponent(0);
  144.       Dimension var8 = new Dimension(var7.getPreferredSize());
  145.       boolean var5;
  146.       boolean var6;
  147.       if (this.scrollbarDisplayPolicy == 0) {
  148.          var5 = var8.height > var4;
  149.          var6 = var8.width > var3;
  150.       } else if (this.scrollbarDisplayPolicy == 1) {
  151.          var6 = true;
  152.          var5 = true;
  153.       } else {
  154.          var6 = false;
  155.          var5 = false;
  156.       }
  157.  
  158.       int var9 = this.getVScrollbarWidth();
  159.       int var10 = this.getHScrollbarHeight();
  160.       if (var5) {
  161.          var3 -= var9;
  162.       }
  163.  
  164.       if (var6) {
  165.          var4 -= var10;
  166.       }
  167.  
  168.       if (var8.width < var3) {
  169.          var8.width = var3;
  170.       }
  171.  
  172.       if (var8.height < var4) {
  173.          var8.height = var4;
  174.       }
  175.  
  176.       return var8;
  177.    }
  178.  
  179.    public void layout() {
  180.       if (super.ncomponents > 0) {
  181.          Component var1 = ((Container)this).getComponent(0);
  182.          Point var2 = this.getScrollPosition();
  183.          Dimension var3 = this.calculateChildSize();
  184.          Dimension var4 = this.getViewportSize();
  185.          Insets var5 = ((Container)this).getInsets();
  186.          var1.reshape(var5.left - var2.x, var5.top - var2.y, var3.width, var3.height);
  187.          ScrollPanePeer var6 = (ScrollPanePeer)super.peer;
  188.          if (var6 != null) {
  189.             var6.childResized(var3.width, var3.height);
  190.          }
  191.  
  192.          var4 = this.getViewportSize();
  193.          this.hAdjustable.setSpan(0, var3.width, var4.width);
  194.          this.vAdjustable.setSpan(0, var3.height, var4.height);
  195.       }
  196.  
  197.    }
  198.  
  199.    public void printComponents(Graphics var1) {
  200.       if (super.ncomponents > 0) {
  201.          Component var2 = super.component[0];
  202.          Point var3 = var2.getLocation();
  203.          Dimension var4 = this.getViewportSize();
  204.          Insets var5 = ((Container)this).getInsets();
  205.          Graphics var6 = var1.create();
  206.  
  207.          try {
  208.             var6.clipRect(var5.left, var5.top, var4.width, var4.height);
  209.             var6.translate(var3.x, var3.y);
  210.             var2.printAll(var6);
  211.          } finally {
  212.             var6.dispose();
  213.          }
  214.       }
  215.  
  216.    }
  217.  
  218.    public void addNotify() {
  219.       Object var1 = ((Component)this).getTreeLock();
  220.       synchronized(var1) {
  221.          int var2 = 0;
  222.          int var3 = 0;
  223.          if (((Container)this).getComponentCount() > 0) {
  224.             var2 = this.vAdjustable.getValue();
  225.             var3 = this.hAdjustable.getValue();
  226.             this.vAdjustable.setValue(0);
  227.             this.hAdjustable.setValue(0);
  228.          }
  229.  
  230.          if (super.peer == null) {
  231.             super.peer = ((Component)this).getToolkit().createScrollPane(this);
  232.          }
  233.  
  234.          super.addNotify();
  235.          if (((Container)this).getComponentCount() > 0) {
  236.             this.vAdjustable.setValue(var2);
  237.             this.hAdjustable.setValue(var3);
  238.          }
  239.  
  240.          if (((Container)this).getComponentCount() > 0) {
  241.             Component var4 = ((Container)this).getComponent(0);
  242.             if (var4.peer instanceof LightweightPeer) {
  243.                ((Container)this).remove(0);
  244.                Panel var5 = new Panel();
  245.                ((Container)var5).setLayout(new BorderLayout());
  246.                ((Container)var5).add(var4);
  247.                ((Container)this).add(var5);
  248.             }
  249.          }
  250.  
  251.       }
  252.    }
  253.  
  254.    public String paramString() {
  255.       String var1;
  256.       switch (this.scrollbarDisplayPolicy) {
  257.          case 0:
  258.             var1 = "as-needed";
  259.             break;
  260.          case 1:
  261.             var1 = "always";
  262.             break;
  263.          case 2:
  264.             var1 = "never";
  265.             break;
  266.          default:
  267.             var1 = "invalid display policy";
  268.       }
  269.  
  270.       Point var2 = super.ncomponents > 0 ? this.getScrollPosition() : new Point(0, 0);
  271.       Insets var3 = ((Container)this).getInsets();
  272.       return super.paramString() + ",ScrollPosition=(" + var2.x + "," + var2.y + ")" + ",Insets=(" + var3.top + "," + var3.left + "," + var3.bottom + "," + var3.right + ")" + ",ScrollbarDisplayPolicy=" + var1;
  273.    }
  274.  
  275.    public AccessibleContext getAccessibleContext() {
  276.       if (super.accessibleContext == null) {
  277.          super.accessibleContext = new AccessibleAWTScrollPane(this);
  278.       }
  279.  
  280.       return super.accessibleContext;
  281.    }
  282.  
  283.    static {
  284.       Toolkit.loadLibraries();
  285.       initIDs();
  286.       nameCounter = 0;
  287.    }
  288. }
  289.