home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / VNR967 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  7.2 KB  |  311 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Insets;
  7. import java.awt.LayoutManager2;
  8. import java.io.Serializable;
  9.  
  10. public class BasicSplitPaneUI$BasicHorizontalLayoutManager implements LayoutManager2, Serializable {
  11.    // $FF: synthetic field
  12.    BasicSplitPaneUI this$0;
  13.    protected int[] sizes;
  14.    protected Component[] components;
  15.    protected int dividerLocation;
  16.  
  17.    // $FF: synthetic method
  18.    BasicSplitPaneUI$BasicHorizontalLayoutManager(BasicSplitPaneUI this$0) {
  19.       this.this$0 = this$0;
  20.       this.components = new Component[3];
  21.       this.components[0] = this.components[1] = this.components[2] = null;
  22.       this.sizes = new int[3];
  23.       this.dividerLocation = -1;
  24.    }
  25.  
  26.    protected void resetSizeAt(int index) {
  27.       this.sizes[index] = -1;
  28.    }
  29.  
  30.    protected void setSizes(int[] newSizes) {
  31.       System.arraycopy(newSizes, 0, this.sizes, 0, 3);
  32.    }
  33.  
  34.    protected int[] getSizes() {
  35.       int[] retSizes = new int[3];
  36.       System.arraycopy(this.sizes, 0, retSizes, 0, 3);
  37.       return retSizes;
  38.    }
  39.  
  40.    protected int getPreferredSizeOfComponent(Component c) {
  41.       return c.getPreferredSize().width;
  42.    }
  43.  
  44.    protected int getSizeOfComponent(Component c) {
  45.       return c.getSize().width;
  46.    }
  47.  
  48.    protected int getAvailableSize(Dimension containerSize, Insets insets) {
  49.       return insets == null ? containerSize.width : containerSize.width - (insets.left + insets.right + 2 * this.this$0.getDividerBorderSize());
  50.    }
  51.  
  52.    protected int getInitialLocation(Insets insets) {
  53.       return insets != null ? insets.left : 0;
  54.    }
  55.  
  56.    protected void setComponentToSize(Component c, int size, int location, Insets insets, Dimension containerSize) {
  57.       if (insets != null) {
  58.          c.setBounds(location, insets.top, size, containerSize.height - (insets.top + insets.bottom));
  59.       } else {
  60.          c.setBounds(location, 0, size, containerSize.height);
  61.       }
  62.  
  63.    }
  64.  
  65.    public void layoutContainer(Container container) {
  66.       Dimension containerSize = ((Component)container).getSize();
  67.       if (containerSize.height != 0 && containerSize.width != 0) {
  68.          int totalSize = 0;
  69.          Insets insets = this.this$0.splitPane.getInsets();
  70.          int availableSize = this.getAvailableSize(containerSize, insets);
  71.          int beginLocation = this.this$0.splitPane.getDividerLocation();
  72.  
  73.          for(int counter = 0; counter < 3; ++counter) {
  74.             if (this.components[counter] != null) {
  75.                if (this.sizes[counter] == -1) {
  76.                   this.sizes[counter] = Math.min(availableSize, this.getPreferredSizeOfComponent(this.components[counter]));
  77.                } else {
  78.                   int newSize = this.getSizeOfComponent(this.components[counter]);
  79.                   if (this.sizes[counter] != newSize) {
  80.                      if (counter == 0) {
  81.                         if (this.components[1] != null) {
  82.                            this.sizes[1] = Math.max(0, this.sizes[1] + (this.sizes[counter] - newSize));
  83.                         }
  84.                      } else if (counter == 1 && this.components[0] != null) {
  85.                         this.sizes[0] = Math.max(0, this.sizes[0] + (this.sizes[counter] - newSize));
  86.                      }
  87.  
  88.                      this.sizes[counter] = newSize;
  89.                      if (counter == 0) {
  90.                         counter = 1;
  91.                      }
  92.                   }
  93.                }
  94.             }
  95.          }
  96.  
  97.          for(int var11 = 0; var11 < 3; ++var11) {
  98.             totalSize += this.sizes[var11];
  99.          }
  100.  
  101.          if (totalSize != availableSize) {
  102.             int toDiff = availableSize - totalSize;
  103.             if (this.components[1] != null) {
  104.                int var13 = Math.max(0, this.sizes[1] + toDiff);
  105.                if (var13 == 0) {
  106.                   toDiff += this.sizes[1];
  107.                   this.sizes[1] = 0;
  108.                   if (this.components[0] != null) {
  109.                      this.sizes[0] = Math.max(0, this.sizes[0] + toDiff);
  110.                   }
  111.                } else {
  112.                   this.sizes[1] = var13;
  113.                }
  114.             } else if (this.components[0] != null) {
  115.                this.sizes[0] = Math.max(0, this.sizes[0] + toDiff);
  116.             }
  117.          }
  118.  
  119.          int nextLocation = this.getInitialLocation(insets);
  120.          int bdSize = this.this$0.getDividerBorderSize();
  121.          int var12 = 0;
  122.  
  123.          while(var12 < 3) {
  124.             if (this.components[var12] != null) {
  125.                this.setComponentToSize(this.components[var12], this.sizes[var12], nextLocation, insets, containerSize);
  126.                nextLocation += this.sizes[var12];
  127.             }
  128.  
  129.             switch (var12) {
  130.                case 0:
  131.                   var12 = 2;
  132.                   nextLocation += bdSize;
  133.                   break;
  134.                case 1:
  135.                   var12 = 3;
  136.                   break;
  137.                case 2:
  138.                   var12 = 1;
  139.                   nextLocation += bdSize;
  140.             }
  141.          }
  142.  
  143.          if (beginLocation != this.this$0.splitPane.getDividerLocation()) {
  144.             this.this$0.splitPane.setLastDividerLocation(beginLocation);
  145.          }
  146.  
  147.       }
  148.    }
  149.  
  150.    public void addLayoutComponent(String place, Component component) {
  151.       boolean isValid = true;
  152.       if (place != null) {
  153.          if (place.equals("divider")) {
  154.             this.components[2] = component;
  155.             this.sizes[2] = -1;
  156.          } else if (!place.equals("left") && !place.equals("top")) {
  157.             if (!place.equals("right") && !place.equals("bottom")) {
  158.                if (!place.equals("nonContinuousDivider")) {
  159.                   isValid = false;
  160.                }
  161.             } else {
  162.                this.components[1] = component;
  163.                this.sizes[1] = -1;
  164.             }
  165.          } else {
  166.             this.components[0] = component;
  167.             this.sizes[0] = -1;
  168.          }
  169.       } else {
  170.          isValid = false;
  171.       }
  172.  
  173.       if (!isValid) {
  174.          throw new IllegalArgumentException("cannot add to layout: unknown constraint: " + place);
  175.       }
  176.    }
  177.  
  178.    public Dimension minimumLayoutSize(Container container) {
  179.       Insets insets = this.this$0.splitPane.getInsets();
  180.       int minY = 0;
  181.       int minX = 0;
  182.  
  183.       for(int counter = 0; counter < 3; ++counter) {
  184.          if (this.components[counter] != null) {
  185.             Dimension minSize = this.components[counter].getMinimumSize();
  186.             minX += minSize.width;
  187.             if (minSize.height > minY) {
  188.                minY = minSize.height;
  189.             }
  190.          }
  191.       }
  192.  
  193.       if (insets != null) {
  194.          minX += insets.left + insets.right;
  195.          minY += insets.bottom + insets.top;
  196.       }
  197.  
  198.       return new Dimension(minX, minY);
  199.    }
  200.  
  201.    public Dimension preferredLayoutSize(Container container) {
  202.       Insets insets = this.this$0.splitPane.getInsets();
  203.       int preY = 0;
  204.       int preX = 0;
  205.  
  206.       for(int counter = 0; counter < 3; ++counter) {
  207.          if (this.components[counter] != null) {
  208.             Dimension preSize = this.components[counter].getPreferredSize();
  209.             preX += preSize.width;
  210.             if (preSize.height > preY) {
  211.                preY = preSize.height;
  212.             }
  213.          }
  214.       }
  215.  
  216.       if (insets != null) {
  217.          preX += insets.left + insets.right;
  218.          preY += insets.bottom + insets.top;
  219.       }
  220.  
  221.       return new Dimension(preX, preY);
  222.    }
  223.  
  224.    public void removeLayoutComponent(Component component) {
  225.       for(int counter = 0; counter < 3; ++counter) {
  226.          if (this.components[counter] == component) {
  227.             this.components[counter] = null;
  228.             this.sizes[counter] = 0;
  229.          }
  230.       }
  231.  
  232.    }
  233.  
  234.    public void addLayoutComponent(Component comp, Object constraints) {
  235.       if (constraints != null && !(constraints instanceof String)) {
  236.          throw new IllegalArgumentException("cannot add to layout: constraint must be a string (or null)");
  237.       } else {
  238.          this.addLayoutComponent((String)constraints, comp);
  239.       }
  240.    }
  241.  
  242.    public float getLayoutAlignmentX(Container target) {
  243.       return 0.0F;
  244.    }
  245.  
  246.    public float getLayoutAlignmentY(Container target) {
  247.       return 0.0F;
  248.    }
  249.  
  250.    public void invalidateLayout(Container c) {
  251.    }
  252.  
  253.    public Dimension maximumLayoutSize(Container target) {
  254.       return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  255.    }
  256.  
  257.    public void resetToPreferredSizes() {
  258.       for(int counter = 0; counter < 3; ++counter) {
  259.          this.sizes[counter] = -1;
  260.       }
  261.  
  262.    }
  263.  
  264.    protected void updateComponents() {
  265.       Component comp = this.this$0.splitPane.getLeftComponent();
  266.       if (this.components[0] != comp) {
  267.          this.components[0] = comp;
  268.          if (comp == null) {
  269.             this.sizes[0] = 0;
  270.          } else {
  271.             this.sizes[0] = -1;
  272.          }
  273.       }
  274.  
  275.       comp = this.this$0.splitPane.getRightComponent();
  276.       if (this.components[1] != comp) {
  277.          this.components[1] = comp;
  278.          if (comp == null) {
  279.             this.sizes[1] = 0;
  280.          } else {
  281.             this.sizes[1] = -1;
  282.          }
  283.       }
  284.  
  285.       Component[] children = this.this$0.splitPane.getComponents();
  286.       Component oldDivider = this.components[2];
  287.       this.components[2] = null;
  288.  
  289.       for(int counter = children.length - 1; counter >= 0; --counter) {
  290.          if (children[counter] != this.components[0] && children[counter] != this.components[1] && children[counter] != this.this$0.nonContinuousLayoutDivider) {
  291.             if (oldDivider != children[counter]) {
  292.                this.components[2] = children[counter];
  293.                if (children[counter] == null) {
  294.                   this.sizes[2] = 0;
  295.                } else {
  296.                   this.sizes[2] = -1;
  297.                }
  298.             } else {
  299.                this.components[2] = oldDivider;
  300.             }
  301.             break;
  302.          }
  303.       }
  304.  
  305.       if (this.components[2] == null) {
  306.          this.sizes[2] = 0;
  307.       }
  308.  
  309.    }
  310. }
  311.