home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / netscape / application / GridLayout.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  4.3 KB  |  192 lines

  1. package netscape.application;
  2.  
  3. import netscape.util.ClassInfo;
  4. import netscape.util.Codable;
  5. import netscape.util.CodingException;
  6. import netscape.util.Decoder;
  7. import netscape.util.Encoder;
  8. import netscape.util.InconsistencyException;
  9. import netscape.util.Vector;
  10.  
  11. public class GridLayout implements LayoutManager, Codable {
  12.    int rowCount;
  13.    int columnCount;
  14.    int horizGap;
  15.    int vertGap;
  16.    int flowDirection;
  17.    public static final int FLOW_ACROSS = 0;
  18.    public static final int FLOW_DOWN = 1;
  19.    static final String ROWCOUNT_KEY = "rowCount";
  20.    static final String COLUMNCOUNT_KEY = "columnCount";
  21.    static final String HORIZGAP_KEY = "horizGap";
  22.    static final String VERTGAP_KEY = "vertGap";
  23.    static final String FLOWDIRECTION_KEY = "flowDirection";
  24.  
  25.    public GridLayout() {
  26.       this(0, 0, 0, 0, 0);
  27.    }
  28.  
  29.    public GridLayout(int var1, int var2) {
  30.       this(var1, var2, 0, 0, 0);
  31.    }
  32.  
  33.    public GridLayout(int var1, int var2, int var3, int var4, int var5) {
  34.       this.setRowCount(var1);
  35.       this.setColumnCount(var2);
  36.       this.horizGap = var3;
  37.       this.vertGap = var4;
  38.       this.setFlowDirection(var5);
  39.    }
  40.  
  41.    public void setRowCount(int var1) {
  42.       this.rowCount = var1 >= 0 ? var1 : 0;
  43.    }
  44.  
  45.    public int rowCount() {
  46.       return this.rowCount;
  47.    }
  48.  
  49.    public void setColumnCount(int var1) {
  50.       this.columnCount = var1 >= 0 ? var1 : 0;
  51.    }
  52.  
  53.    public int columnCount() {
  54.       return this.columnCount;
  55.    }
  56.  
  57.    public void setHorizGap(int var1) {
  58.       this.horizGap = var1;
  59.    }
  60.  
  61.    public int horizGap() {
  62.       return this.horizGap;
  63.    }
  64.  
  65.    public void setVertGap(int var1) {
  66.       this.vertGap = var1;
  67.    }
  68.  
  69.    public int vertGap() {
  70.       return this.vertGap;
  71.    }
  72.  
  73.    public void setFlowDirection(int var1) {
  74.       if (var1 != 0 && var1 != 1) {
  75.          throw new InconsistencyException(this + "Invalid Flow direction specified: " + var1);
  76.       } else {
  77.          this.flowDirection = var1;
  78.       }
  79.    }
  80.  
  81.    public int flowDirection() {
  82.       return this.flowDirection;
  83.    }
  84.  
  85.    public void addSubview(View var1) {
  86.    }
  87.  
  88.    public void removeSubview(View var1) {
  89.    }
  90.  
  91.    public void layoutView(View var1, int var2, int var3) {
  92.       Vector var4 = var1.subviews();
  93.       int var6 = var4.count();
  94.       if (var6 >= 1) {
  95.          Size var16 = this.gridSize(var1);
  96.          int var15 = var16.width;
  97.          int var14 = var16.height;
  98.          int var7 = (var1.bounds.width - this.horizGap * var15 - this.horizGap) / var15;
  99.          int var8 = (var1.bounds.height - this.vertGap * var14 - this.vertGap) / var14;
  100.          int var12 = 0;
  101.          int var13 = 0;
  102.          if (this.flowDirection == 1) {
  103.             for(int var17 = 0; var17 < var6; ++var17) {
  104.                int var18 = var7 * var13 + this.horizGap * (var13 + 1);
  105.                int var19 = var8 * var12 + this.vertGap * (var12 + 1);
  106.                View var20 = (View)var4.elementAt(var17);
  107.                var20.setBounds(var18, var19, var7, var8);
  108.                ++var12;
  109.                if (var14 > 0 && var12 >= var14) {
  110.                   ++var13;
  111.                   var12 = 0;
  112.                }
  113.             }
  114.  
  115.          } else {
  116.             for(int var5 = 0; var5 < var6; ++var5) {
  117.                int var9 = var7 * var13 + this.horizGap * (var13 + 1);
  118.                int var10 = var8 * var12 + this.vertGap * (var12 + 1);
  119.                View var11 = (View)var4.elementAt(var5);
  120.                var11.setBounds(var9, var10, var7, var8);
  121.                ++var13;
  122.                if (var15 > 0 && var13 >= var15) {
  123.                   ++var12;
  124.                   var13 = 0;
  125.                }
  126.             }
  127.  
  128.          }
  129.       }
  130.    }
  131.  
  132.    public Size gridSize(View var1) {
  133.       int var2 = var1.subviews().count();
  134.       if (var2 < 1) {
  135.          return new Size();
  136.       } else {
  137.          int var3;
  138.          int var4;
  139.          if (this.rowCount == 0) {
  140.             if (this.columnCount == 0) {
  141.                var4 = (int)Math.ceil(Math.sqrt((double)((float)var2)));
  142.                var3 = var4;
  143.             } else {
  144.                var4 = this.columnCount;
  145.                var3 = (int)Math.ceil((double)((float)var2 / (float)var4));
  146.             }
  147.          } else if (this.columnCount == 0) {
  148.             if (this.rowCount == 0) {
  149.                var4 = (int)Math.ceil(Math.sqrt((double)((float)var2)));
  150.                var3 = var4;
  151.             } else {
  152.                var3 = this.rowCount;
  153.                var4 = (int)Math.ceil((double)((float)var2 / (float)var3));
  154.             }
  155.          } else {
  156.             var3 = this.rowCount;
  157.             var4 = this.columnCount;
  158.          }
  159.  
  160.          return new Size(var4, var3);
  161.       }
  162.    }
  163.  
  164.    public void describeClassInfo(ClassInfo var1) {
  165.       var1.addClass("netscape.application.GridLayout", 1);
  166.       var1.addField("rowCount", (byte)8);
  167.       var1.addField("columnCount", (byte)8);
  168.       var1.addField("horizGap", (byte)8);
  169.       var1.addField("vertGap", (byte)8);
  170.       var1.addField("flowDirection", (byte)8);
  171.    }
  172.  
  173.    public void decode(Decoder var1) throws CodingException {
  174.       this.rowCount = var1.decodeInt("rowCount");
  175.       this.columnCount = var1.decodeInt("columnCount");
  176.       this.horizGap = var1.decodeInt("horizGap");
  177.       this.vertGap = var1.decodeInt("vertGap");
  178.       this.flowDirection = var1.decodeInt("flowDirection");
  179.    }
  180.  
  181.    public void encode(Encoder var1) throws CodingException {
  182.       var1.encodeInt("rowCount", this.rowCount);
  183.       var1.encodeInt("columnCount", this.columnCount);
  184.       var1.encodeInt("horizGap", this.horizGap);
  185.       var1.encodeInt("vertGap", this.vertGap);
  186.       var1.encodeInt("flowDirection", this.flowDirection);
  187.    }
  188.  
  189.    public void finishDecoding() throws CodingException {
  190.    }
  191. }
  192.