home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import netscape.util.ClassInfo;
- import netscape.util.Codable;
- import netscape.util.CodingException;
- import netscape.util.Decoder;
- import netscape.util.Encoder;
- import netscape.util.InconsistencyException;
- import netscape.util.Vector;
-
- public class GridLayout implements LayoutManager, Codable {
- int rowCount;
- int columnCount;
- int horizGap;
- int vertGap;
- int flowDirection;
- public static final int FLOW_ACROSS = 0;
- public static final int FLOW_DOWN = 1;
- static final String ROWCOUNT_KEY = "rowCount";
- static final String COLUMNCOUNT_KEY = "columnCount";
- static final String HORIZGAP_KEY = "horizGap";
- static final String VERTGAP_KEY = "vertGap";
- static final String FLOWDIRECTION_KEY = "flowDirection";
-
- public GridLayout() {
- this(0, 0, 0, 0, 0);
- }
-
- public GridLayout(int var1, int var2) {
- this(var1, var2, 0, 0, 0);
- }
-
- public GridLayout(int var1, int var2, int var3, int var4, int var5) {
- this.setRowCount(var1);
- this.setColumnCount(var2);
- this.horizGap = var3;
- this.vertGap = var4;
- this.setFlowDirection(var5);
- }
-
- public void setRowCount(int var1) {
- this.rowCount = var1 >= 0 ? var1 : 0;
- }
-
- public int rowCount() {
- return this.rowCount;
- }
-
- public void setColumnCount(int var1) {
- this.columnCount = var1 >= 0 ? var1 : 0;
- }
-
- public int columnCount() {
- return this.columnCount;
- }
-
- public void setHorizGap(int var1) {
- this.horizGap = var1;
- }
-
- public int horizGap() {
- return this.horizGap;
- }
-
- public void setVertGap(int var1) {
- this.vertGap = var1;
- }
-
- public int vertGap() {
- return this.vertGap;
- }
-
- public void setFlowDirection(int var1) {
- if (var1 != 0 && var1 != 1) {
- throw new InconsistencyException(this + "Invalid Flow direction specified: " + var1);
- } else {
- this.flowDirection = var1;
- }
- }
-
- public int flowDirection() {
- return this.flowDirection;
- }
-
- public void addSubview(View var1) {
- }
-
- public void removeSubview(View var1) {
- }
-
- public void layoutView(View var1, int var2, int var3) {
- Vector var4 = var1.subviews();
- int var6 = var4.count();
- if (var6 >= 1) {
- Size var16 = this.gridSize(var1);
- int var15 = var16.width;
- int var14 = var16.height;
- int var7 = (var1.bounds.width - this.horizGap * var15 - this.horizGap) / var15;
- int var8 = (var1.bounds.height - this.vertGap * var14 - this.vertGap) / var14;
- int var12 = 0;
- int var13 = 0;
- if (this.flowDirection == 1) {
- for(int var17 = 0; var17 < var6; ++var17) {
- int var18 = var7 * var13 + this.horizGap * (var13 + 1);
- int var19 = var8 * var12 + this.vertGap * (var12 + 1);
- View var20 = (View)var4.elementAt(var17);
- var20.setBounds(var18, var19, var7, var8);
- ++var12;
- if (var14 > 0 && var12 >= var14) {
- ++var13;
- var12 = 0;
- }
- }
-
- } else {
- for(int var5 = 0; var5 < var6; ++var5) {
- int var9 = var7 * var13 + this.horizGap * (var13 + 1);
- int var10 = var8 * var12 + this.vertGap * (var12 + 1);
- View var11 = (View)var4.elementAt(var5);
- var11.setBounds(var9, var10, var7, var8);
- ++var13;
- if (var15 > 0 && var13 >= var15) {
- ++var12;
- var13 = 0;
- }
- }
-
- }
- }
- }
-
- public Size gridSize(View var1) {
- int var2 = var1.subviews().count();
- if (var2 < 1) {
- return new Size();
- } else {
- int var3;
- int var4;
- if (this.rowCount == 0) {
- if (this.columnCount == 0) {
- var4 = (int)Math.ceil(Math.sqrt((double)((float)var2)));
- var3 = var4;
- } else {
- var4 = this.columnCount;
- var3 = (int)Math.ceil((double)((float)var2 / (float)var4));
- }
- } else if (this.columnCount == 0) {
- if (this.rowCount == 0) {
- var4 = (int)Math.ceil(Math.sqrt((double)((float)var2)));
- var3 = var4;
- } else {
- var3 = this.rowCount;
- var4 = (int)Math.ceil((double)((float)var2 / (float)var3));
- }
- } else {
- var3 = this.rowCount;
- var4 = this.columnCount;
- }
-
- return new Size(var4, var3);
- }
- }
-
- public void describeClassInfo(ClassInfo var1) {
- var1.addClass("netscape.application.GridLayout", 1);
- var1.addField("rowCount", (byte)8);
- var1.addField("columnCount", (byte)8);
- var1.addField("horizGap", (byte)8);
- var1.addField("vertGap", (byte)8);
- var1.addField("flowDirection", (byte)8);
- }
-
- public void decode(Decoder var1) throws CodingException {
- this.rowCount = var1.decodeInt("rowCount");
- this.columnCount = var1.decodeInt("columnCount");
- this.horizGap = var1.decodeInt("horizGap");
- this.vertGap = var1.decodeInt("vertGap");
- this.flowDirection = var1.decodeInt("flowDirection");
- }
-
- public void encode(Encoder var1) throws CodingException {
- var1.encodeInt("rowCount", this.rowCount);
- var1.encodeInt("columnCount", this.columnCount);
- var1.encodeInt("horizGap", this.horizGap);
- var1.encodeInt("vertGap", this.vertGap);
- var1.encodeInt("flowDirection", this.flowDirection);
- }
-
- public void finishDecoding() throws CodingException {
- }
- }
-