You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/08/14 12:09:33 UTC

svn commit: r804155 - in /myfaces/tobago/trunk/core/src: main/java/org/apache/myfaces/tobago/component/ main/java/org/apache/myfaces/tobago/layout/ main/java/org/apache/myfaces/tobago/layout/grid/ test/java/org/apache/myfaces/tobago/layout/grid/

Author: lofwyr
Date: Fri Aug 14 10:09:33 2009
New Revision: 804155

URL: http://svn.apache.org/viewvc?rev=804155&view=rev
Log:
TOBAGO-606: Layout-Manager
 - clean up and fix the Grid: There were 2 positions of holding information about the columns/rows like "*;*" in the LayoutManager, and the number of columns e.g. 2, the number grows automatically in the grid, but this value wasn't updated for the LayoutManager, so in could happen an ArrayIndexOutOfBoundsException.

Removed:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/grid/GridArray.java
    myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/grid/GridArrayUnitTest.java
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIGridLayout.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/grid/Grid.java
    myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/grid/GridUnitTest.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIGridLayout.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIGridLayout.java?rev=804155&r1=804154&r2=804155&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIGridLayout.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/AbstractUIGridLayout.java Fri Aug 14 10:09:33 2009
@@ -17,7 +17,6 @@
  * limitations under the License.
  */
 
-import org.apache.commons.lang.ClassUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.tobago.OnComponentCreated;
@@ -47,18 +46,8 @@
 
   private Grid grid;
 
-  // XXX columns and columnTokens are double/redundant
-  private LayoutTokens columnTokens;
-
-  // XXX rows and rowTokens are double/redundant
-  private LayoutTokens rowTokens;
-
   public void onComponentCreated(FacesContext context, UIComponent component) {
-
-    columnTokens = LayoutTokens.parse(getColumns());
-    rowTokens = LayoutTokens.parse(getRows());
-
-    grid = new Grid(columnTokens.getSize(), rowTokens.getSize());
+    grid = new Grid(LayoutTokens.parse(getColumns()), LayoutTokens.parse(getRows()));
   }
 
   /**
@@ -69,15 +58,14 @@
     // horizontal
     EquationManager horizontal = layoutContext.getHorizontal();
     int[] horizontalIndices = horizontal.partition(
-        horizontalIndex, columnTokens.getSize(),
-        getColumnSpacing(), container.getLeftOffset(), container.getRightOffset(),
-        container.getClass().getSimpleName());
+        horizontalIndex, grid.getColumns().getSize(),
+        getColumnSpacing(), container.getLeftOffset(), container.getRightOffset(), container);
 
     // vertical
     EquationManager vertical = layoutContext.getVertical();
     int[] verticalIndices = vertical.partition(
-        verticalIndex, rowTokens.getSize(), getRowSpacing(),
-        container.getTopOffset(), container.getBottomOffset(), container.getClass().getSimpleName());
+        verticalIndex, grid.getRows().getSize(), getRowSpacing(),
+        container.getTopOffset(), container.getBottomOffset(), container);
 
     List<LayoutComponent> components = container.getComponents();
     for (LayoutComponent c : components) {
@@ -90,21 +78,19 @@
     addPixelConstraints(layoutContext, horizontalIndex + 1, verticalIndex + 1);
     addRelativeConstraints(layoutContext, horizontalIndex + 1, verticalIndex + 1);
 
-    for (int j = 0; j < grid.getRowCount(); j++) {
-      for (int i = 0; i < grid.getColumnCount(); i++) {
-        Cell temp = grid.get(i, j);
+    for (int j = 0; j < grid.getRows().getSize(); j++) {
+      for (int i = 0; i < grid.getColumns().getSize(); i++) {
+        Cell temp = grid.getCell(i, j);
         if (temp instanceof OriginCell) {
           OriginCell cell = (OriginCell) temp;
           LayoutComponent component = temp.getComponent();
 
           // horizontal
-          int hIndex = horizontal.combine(horizontalIndices[i], cell.getColumnSpan(), getColumnSpacing(),
-              component.getClass().getSimpleName());
+          int hIndex = horizontal.combine(horizontalIndices[i], cell.getColumnSpan(), getColumnSpacing(), component);
           cell.getComponent().setHorizontalIndex(hIndex);
 
           // vertical
-          int vIndex = vertical.combine(verticalIndices[j], cell.getRowSpan(), getRowSpacing(),
-              component.getClass().getSimpleName());
+          int vIndex = vertical.combine(verticalIndices[j], cell.getRowSpan(), getRowSpacing(), component);
           cell.getComponent().setVerticalIndex(vIndex);
 
           if (component instanceof LayoutContainer) {
@@ -116,11 +102,11 @@
 
             Measure preferredWidth = component.getPreferredWidth();
             if (preferredWidth != null) {
-              horizontal.setFixedLength(hIndex, preferredWidth, component.getClass().getSimpleName());
+              horizontal.setFixedLength(hIndex, preferredWidth, component);
             }
             Measure preferredHeight = component.getPreferredHeight();
             if (preferredHeight != null) {
-              vertical.setFixedLength(vIndex, preferredHeight, component.getClass().getSimpleName());
+              vertical.setFixedLength(vIndex, preferredHeight, component);
             }
           }
         }
@@ -139,9 +125,9 @@
 
   private void distributeSizes(LayoutContext layoutContext) {
 
-    for (int j = 0; j < grid.getRowCount(); j++) {
-      for (int i = 0; i < grid.getColumnCount(); i++) {
-        Cell temp = grid.get(i, j);
+    for (int j = 0; j < grid.getRows().getSize(); j++) {
+      for (int i = 0; i < grid.getColumns().getSize(); i++) {
+        Cell temp = grid.getCell(i, j);
         if (temp instanceof OriginCell) {
           OriginCell cell = (OriginCell) temp;
           LayoutComponent component = temp.getComponent();
@@ -176,10 +162,10 @@
   private void distributePositions(LayoutContainer container) {
 
     // find the "left" positions
-    for (int j = 0; j < grid.getRowCount(); j++) {
+    for (int j = 0; j < grid.getRows().getSize(); j++) {
       PixelMeasure left = (PixelMeasure) container.getLeftOffset();
-      for (int i = 0; i < grid.getColumnCount(); i++) {
-        Cell cell = grid.get(i, j);
+      for (int i = 0; i < grid.getColumns().getSize(); i++) {
+        Cell cell = grid.getCell(i, j);
         if (cell == null) {
           continue; // XXX why this can happen?
         }
@@ -197,10 +183,10 @@
     }
 
     // find the "top" positions
-    for (int i = 0; i < grid.getColumnCount(); i++) {
+    for (int i = 0; i < grid.getColumns().getSize(); i++) {
       PixelMeasure top = (PixelMeasure) container.getTopOffset();
-      for (int j = 0; j < grid.getRowCount(); j++) {
-        Cell cell = grid.get(i, j);
+      for (int j = 0; j < grid.getRows().getSize(); j++) {
+        Cell cell = grid.getCell(i, j);
         if (cell == null) {
           continue; // XXX why this can happen?
         }
@@ -220,12 +206,12 @@
 
   private void addPixelConstraints(LayoutContext layoutContext, int horizontalIndexOffset, int verticalIndexOffset) {
     // horizontal
+    LayoutTokens columnTokens = grid.getColumns();
     for (int i = 0; i < columnTokens.getSize(); i++) {
       LayoutToken layoutToken = columnTokens.get(i);
       if (layoutToken instanceof PixelLayoutToken) {
         Measure pixel = new PixelMeasure(((PixelLayoutToken) layoutToken).getPixel());
-        layoutContext.getHorizontal().setFixedLength(i + horizontalIndexOffset, pixel,
-            ClassUtils.getShortClassName(getParent(), "null"));
+        layoutContext.getHorizontal().setFixedLength(i + horizontalIndexOffset, pixel, this);
       }
 /*
       if (layoutToken instanceof AutoLayoutToken) {
@@ -236,13 +222,13 @@
 */
     }
     // vertical
+    LayoutTokens rowTokens = grid.getRows();
     for (int i = 0; i < rowTokens.getSize(); i++) {
       LayoutToken layoutToken = rowTokens.get(i);
       if (layoutToken instanceof PixelLayoutToken) {
         // XXX PixelLayoutToken might be removed/changed
         Measure pixel = new PixelMeasure(((PixelLayoutToken) layoutToken).getPixel());
-        layoutContext.getVertical().setFixedLength(i + verticalIndexOffset, pixel,
-            ClassUtils.getShortClassName(getParent(), "null"));
+        layoutContext.getVertical().setFixedLength(i + verticalIndexOffset, pixel, this);
       }
 /*
       if (layoutToken instanceof AutoLayoutToken) {
@@ -258,6 +244,7 @@
     // horizontal
     Integer first = null;
     Integer firstIndex = null;
+    LayoutTokens columnTokens = grid.getColumns();
     for (int i = 0; i < columnTokens.getTokens().size(); i++) {
       LayoutToken token = columnTokens.getTokens().get(i);
       if (token instanceof RelativeLayoutToken) {
@@ -267,13 +254,14 @@
           firstIndex = i + horizontalIndexOffset;
         } else {
           layoutContext.getHorizontal().proportionate(
-              firstIndex, i + horizontalIndexOffset, first, factor, ClassUtils.getShortClassName(getParent(), "null"));
+              firstIndex, i + horizontalIndexOffset, first, factor, getParent());
         }
       }
     }
     // vertical
     first = null;
     firstIndex = null;
+    LayoutTokens rowTokens = grid.getRows();
     for (int i = 0; i < rowTokens.getTokens().size(); i++) {
       LayoutToken token = rowTokens.getTokens().get(i);
       if (token instanceof RelativeLayoutToken) {
@@ -283,7 +271,7 @@
           firstIndex = i + verticalIndexOffset;
         } else {
           layoutContext.getVertical().proportionate(
-              firstIndex, i + verticalIndexOffset, first, factor, ClassUtils.getShortClassName(getParent(), "null"));
+              firstIndex, i + verticalIndexOffset, first, factor, getParent());
         }
       }
     }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java?rev=804155&r1=804154&r2=804155&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java Fri Aug 14 10:09:33 2009
@@ -25,16 +25,15 @@
 import java.util.List;
 import java.util.StringTokenizer;
 
-/*
- * Date: May 2, 2007
- * Time: 1:11:25 PM
- */
 public final class LayoutTokens {
 
   private static final Log LOG = LogFactory.getLog(LayoutTokens.class);
 
   private List<LayoutToken> tokens = new ArrayList<LayoutToken>();
 
+  public LayoutTokens() {
+  }
+
   public int getSize() {
     return tokens.size();
   }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/grid/Grid.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/grid/Grid.java?rev=804155&r1=804154&r2=804155&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/grid/Grid.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/layout/grid/Grid.java Fri Aug 14 10:09:33 2009
@@ -19,32 +19,40 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.tobago.layout.PixelMeasure;
+import org.apache.myfaces.tobago.layout.AutoLayoutToken;
+import org.apache.myfaces.tobago.layout.LayoutTokens;
 
 import java.util.ArrayList;
 import java.util.List;
 
-/*
- * Date: 24.01.2008 16:31:58
- */
 public class Grid {
 
   private static final Log LOG = LogFactory.getLog(Grid.class);
 
-  private GridArray grid;
-
-  private PixelMeasure[] columns;
-  private PixelMeasure[] rows;
+  // TODO: check if it is faster with arrays.
+  /**
+   * The rectangular data as a 1-dim list;
+   */
+  private List<Cell> cells;
+  private LayoutTokens columns;
+  private LayoutTokens rows;
 
   private List<Integer> errorIndexes;
 
   private int columnCursor;
   private int rowCursor;
 
-  public Grid(int columnCount, int rowCount) {
-    grid = new GridArray(columnCount, rowCount);
-    columns = new PixelMeasure[columnCount];
-    rows = new PixelMeasure[rowCount];
+  public Grid(LayoutTokens columns, LayoutTokens rows) {
+    assert columns.getSize() > 0;
+    assert rows.getSize() > 0;
+
+    this.columns = columns;
+    this.rows = rows;
+    int size = columns.getSize() * rows.getSize();
+    this.cells = new ArrayList<Cell>(size);
+    for (int i = 0; i < size; i++) {
+      this.cells.add(null);
+    }
   }
 
   public void add(OriginCell cell, int columnSpan, int rowSpan) {
@@ -54,10 +62,10 @@
 
     boolean error = false;
 
-    if (columnSpan + columnCursor > grid.getColumnCount()) {
+    if (columnSpan + columnCursor > columns.getSize()) {
       LOG.warn("The columnSpan is to large for the actual position in the grid. Will be fixed. "
-          + "columnSpan=" + columnSpan + " columnCursor=" + columnCursor + " columnCount=" + grid.getColumnCount());
-      columnSpan = grid.getColumnCount() - columnCursor;
+          + "columnSpan=" + columnSpan + " columnCursor=" + columnCursor + " columnCount=" + columns.getSize());
+      columnSpan = columns.getSize() - columnCursor;
       error = true;
     }
 
@@ -65,9 +73,9 @@
     cell.setRowSpan(rowSpan);
 
     for (int i = 1; i < columnSpan; i++) {
-      if (grid.get(i + columnCursor, rowCursor) != null) {
+      if (getCell(i + columnCursor, rowCursor) != null) {
         LOG.warn("The columnSpan is to large for the actual position in the grid. Will be fixed. "
-            + "columnSpan=" + columnSpan + " columnCursor=" + columnCursor + " columnCount=" + grid.getColumnCount());
+            + "columnSpan=" + columnSpan + " columnCursor=" + columnCursor + " columnCount=" + columns.getSize());
         columnSpan = i - 1;
         error = true;
       }
@@ -81,8 +89,8 @@
         } else {
           actualCell = new SpanCell(cell, i == 0, j == 0);
         }
-        assert grid.get(i + columnCursor, j + rowCursor) == null : "Position in the cell must be free.";
-        grid.set(i + columnCursor, j + rowCursor, actualCell);
+        assert getCell(i + columnCursor, j + rowCursor) == null : "Position in the cell must be free.";
+        setCell(i + columnCursor, j + rowCursor, actualCell);
         if (error) {
           addError(i + columnCursor, j + rowCursor);
         }
@@ -92,14 +100,28 @@
     findNextFreeCell();
   }
 
-  public Cell get(int column, int row) {
-    return grid.get(column, row);
+  public Cell getCell(int column, int row) {
+    assert column >= 0 && column < columns.getSize() : "column=" + column + " columnCount=" + columns.getSize();
+    assert row >= 0 : "row=" + row;
+
+    if (row >= rows.getSize()) {
+      return null;
+    } else {
+      return cells.get(column + row * columns.getSize());
+    }
+  }
+
+  public void setCell(int column, int row, Cell cell) {
+    if (row >= rows.getSize()) {
+      enlarge(row - rows.getSize() + 1);
+    }
+    cells.set(column + row * columns.getSize(), cell);
   }
 
   private void findNextFreeCell() {
-    for (; rowCursor < grid.getRowCount(); rowCursor++) {
-      for (; columnCursor < grid.getColumnCount(); columnCursor++) {
-        if (grid.get(columnCursor, rowCursor) == null) {
+    for (; rowCursor < rows.getSize(); rowCursor++) {
+      for (; columnCursor < columns.getSize(); columnCursor++) {
+        if (getCell(columnCursor, rowCursor) == null) {
           return;
         }
       }
@@ -107,34 +129,35 @@
     }
   }
 
-  public int getColumnCount() {
-    return grid.getColumnCount();
+  public LayoutTokens getColumns() {
+    return columns;
+  }
+
+  public LayoutTokens getRows() {
+    return rows;
   }
 
-  public int getRowCount() {
-    return grid.getRowCount();
+  private void enlarge(int newRows) {
+    for (int i = 0; i < newRows; i++) {
+      for (int j = 0; j < columns.getSize(); j++) {
+        cells.add(null);
+      }
+      rows.addToken(AutoLayoutToken.INSTANCE);
+    }
   }
 
   public void addError(int i, int j) {
     if (errorIndexes == null) {
       errorIndexes = new ArrayList<Integer>();
     }
-    errorIndexes.add(j * grid.getColumnCount() + i);
+    errorIndexes.add(j * columns.getSize() + i);
   }
 
   public boolean hasError(int i, int j) {
     if (errorIndexes == null) {
       return false;
     }
-    return errorIndexes.contains(j * grid.getColumnCount() + i);
-  }
-
-  public PixelMeasure[] getColumns() {
-    return columns;
-  }
-
-  public PixelMeasure[] getRows() {
-    return rows;
+    return errorIndexes.contains(j * columns.getSize() + i);
   }
 
   /**
@@ -157,16 +180,16 @@
     StringBuilder builder = new StringBuilder();
 
     // top of grid
-    for (int i = 0; i < grid.getColumnCount(); i++) {
+    for (int i = 0; i < columns.getSize(); i++) {
       if (i == 0) {
-        if (grid.get(i, 0) != null) {
+        if (getCell(i, 0) != null) {
           builder.append("┏");
         } else {
           builder.append("┌");
         }
       } else {
-        Cell c = grid.get(i - 1, 0);
-        Cell d = grid.get(i, 0);
+        Cell c = getCell(i - 1, 0);
+        Cell d = getCell(i, 0);
         if (c == null && d == null) {
           builder.append("┬");
         } else {
@@ -183,28 +206,28 @@
           }
         }
       }
-      if (grid.get(i, 0) != null) {
+      if (getCell(i, 0) != null) {
         builder.append("━");
       } else {
         builder.append("─");
       }
 
     }
-    if (grid.get(grid.getColumnCount() - 1, 0) != null) {
+    if (getCell(columns.getSize() - 1, 0) != null) {
       builder.append("┓");
     } else {
       builder.append("┐");
     }
     builder.append("\n");
 
-    for (int j = 0; j < grid.getRowCount(); j++) {
+    for (int j = 0; j < rows.getSize(); j++) {
 
       // between the cells
       if (j != 0) {
-        for (int i = 0; i < grid.getColumnCount(); i++) {
+        for (int i = 0; i < columns.getSize(); i++) {
           if (i == 0) {
-            Cell b = grid.get(0, j - 1);
-            Cell d = grid.get(0, j);
+            Cell b = getCell(0, j - 1);
+            Cell d = getCell(0, j);
             if (b == null && d == null) {
               builder.append("├");
             } else {
@@ -221,10 +244,10 @@
               }
             }
           } else {
-            Cell a = grid.get(i - 1, j - 1);
-            Cell b = grid.get(i, j - 1);
-            Cell c = grid.get(i - 1, j);
-            Cell d = grid.get(i, j);
+            Cell a = getCell(i - 1, j - 1);
+            Cell b = getCell(i, j - 1);
+            Cell c = getCell(i - 1, j);
+            Cell d = getCell(i, j);
 //            a│b
 //            ─┼─
 //            c│d
@@ -264,16 +287,16 @@
               }
             }
           }
-          Cell a = grid.get(i, j - 1);
-          Cell c = grid.get(i, j);
+          Cell a = getCell(i, j - 1);
+          Cell c = getCell(i, j);
           if (connected(a, c)) {
             builder.append("─");
           } else {
             builder.append("━");
           }
         }
-        Cell a = grid.get(grid.getColumnCount() - 1, j - 1);
-        Cell c = grid.get(grid.getColumnCount() - 1, j);
+        Cell a = getCell(columns.getSize() - 1, j - 1);
+        Cell c = getCell(columns.getSize() - 1, j);
         if (a == null && c == null) {
           builder.append("┤");
         } else {
@@ -293,16 +316,16 @@
       }
 
       // cell
-      for (int i = 0; i < grid.getColumnCount(); i++) {
+      for (int i = 0; i < columns.getSize(); i++) {
         if (i == 0) {
-          if (grid.get(i, j) != null) {
+          if (getCell(i, j) != null) {
             builder.append("┃");
           } else {
             builder.append("│");
           }
         } else {
-          Cell c = grid.get(i - 1, j);
-          Cell d = grid.get(i, j);
+          Cell c = getCell(i - 1, j);
+          Cell d = getCell(i, j);
           if (connected(c, d)) {
             builder.append("│");
           } else {
@@ -312,14 +335,14 @@
         if (hasError(i, j)) {
           builder.append("✖"); //↯
         } else {
-          if (grid.get(i, j) instanceof OriginCell) {
+          if (getCell(i, j) instanceof OriginCell) {
             builder.append("█");
-          } else if (grid.get(i, j) instanceof SpanCell) {
+          } else if (getCell(i, j) instanceof SpanCell) {
             if (j == 0) {
               builder.append("➞");
             } else {
-              Cell a = grid.get(i, j - 1);
-              Cell c = grid.get(i, j);
+              Cell a = getCell(i, j - 1);
+              Cell c = getCell(i, j);
               if (connected(a, c)) {
                 builder.append("⬇");
               } else {
@@ -331,7 +354,7 @@
           }
         }
       }
-      if (grid.get(grid.getColumnCount() - 1, j) != null) {
+      if (getCell(columns.getSize() - 1, j) != null) {
         builder.append("┃");
       } else {
         builder.append("│");
@@ -340,16 +363,16 @@
     }
 
     //last bottom
-    for (int i = 0; i < grid.getColumnCount(); i++) {
+    for (int i = 0; i < columns.getSize(); i++) {
       if (i == 0) {
-        if (grid.get(0, grid.getRowCount() - 1) != null) {
+        if (getCell(0, rows.getSize() - 1) != null) {
           builder.append("┗");
         } else {
           builder.append("└");
         }
       } else {
-        Cell a = grid.get(i - 1, grid.getRowCount() - 1);
-        Cell b = grid.get(i, grid.getRowCount() - 1);
+        Cell a = getCell(i - 1, rows.getSize() - 1);
+        Cell b = getCell(i, rows.getSize() - 1);
         if (a == null && b == null) {
           builder.append("┴");
         } else {
@@ -366,13 +389,13 @@
           }
         }
       }
-      if (grid.get(i, grid.getRowCount() - 1) != null) {
+      if (getCell(i, rows.getSize() - 1) != null) {
         builder.append("━");
       } else {
         builder.append("─");
       }
     }
-    if (grid.get(grid.getColumnCount() - 1, grid.getRowCount() - 1) != null) {
+    if (getCell(columns.getSize() - 1, rows.getSize() - 1) != null) {
       builder.append("┛");
     } else {
       builder.append("┘");

Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/grid/GridUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/grid/GridUnitTest.java?rev=804155&r1=804154&r2=804155&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/grid/GridUnitTest.java (original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/layout/grid/GridUnitTest.java Fri Aug 14 10:09:33 2009
@@ -17,6 +17,7 @@
  * limitations under the License.
  */
 
+import org.apache.myfaces.tobago.layout.LayoutTokens;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -25,25 +26,25 @@
   @Test
   public void test1x1() {
 
-    Grid grid = new Grid(1, 1);
-    Assert.assertEquals(1, grid.getColumnCount());
-    Assert.assertEquals(1, grid.getRowCount());
+    Grid grid = new Grid(LayoutTokens.parse("*"), LayoutTokens.parse("*"));
+    Assert.assertEquals(1, grid.getColumns().getSize());
+    Assert.assertEquals(1, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┌─┐\n"
         + "│◌│\n"
         + "└─┘\n", grid.toString());
 
     grid.add(new OriginCell(null), 1, 1);
-    Assert.assertEquals(1, grid.getColumnCount());
-    Assert.assertEquals(1, grid.getRowCount());
+    Assert.assertEquals(1, grid.getColumns().getSize());
+    Assert.assertEquals(1, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┓\n"
         + "┃█┃\n"
         + "┗━┛\n", grid.toString());
 
     grid.add(new OriginCell(null), 1, 1);
-    Assert.assertEquals(1, grid.getColumnCount());
-    Assert.assertEquals(2, grid.getRowCount());
+    Assert.assertEquals(1, grid.getColumns().getSize());
+    Assert.assertEquals(2, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┓\n"
         + "┃█┃\n"
@@ -52,8 +53,8 @@
         + "┗━┛\n", grid.toString());
 
     grid.add(new OriginCell(null), 1, 2);
-    Assert.assertEquals(1, grid.getColumnCount());
-    Assert.assertEquals(4, grid.getRowCount());
+    Assert.assertEquals(1, grid.getColumns().getSize());
+    Assert.assertEquals(4, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┓\n"
         + "┃█┃\n"
@@ -67,8 +68,8 @@
 
     // with warning
     grid.add(new OriginCell(null), 2, 1);
-    Assert.assertEquals(1, grid.getColumnCount());
-    Assert.assertEquals(5, grid.getRowCount());
+    Assert.assertEquals(1, grid.getColumns().getSize());
+    Assert.assertEquals(5, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┓\n"
         + "┃█┃\n"
@@ -86,33 +87,33 @@
   @Test
   public void test2x1() {
 
-    Grid grid = new Grid(2, 1);
-    Assert.assertEquals(2, grid.getColumnCount());
-    Assert.assertEquals(1, grid.getRowCount());
+    Grid grid = new Grid(LayoutTokens.parse("*;*"), LayoutTokens.parse("*"));
+    Assert.assertEquals(2, grid.getColumns().getSize());
+    Assert.assertEquals(1, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┌─┬─┐\n"
         + "│◌│◌│\n"
         + "└─┴─┘\n", grid.toString());
 
     grid.add(new OriginCell(null), 1, 1);
-    Assert.assertEquals(2, grid.getColumnCount());
-    Assert.assertEquals(1, grid.getRowCount());
+    Assert.assertEquals(2, grid.getColumns().getSize());
+    Assert.assertEquals(1, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┱─┐\n"
         + "┃█┃◌│\n"
         + "┗━┹─┘\n", grid.toString());
 
     grid.add(new OriginCell(null), 1, 1);
-    Assert.assertEquals(2, grid.getColumnCount());
-    Assert.assertEquals(1, grid.getRowCount());
+    Assert.assertEquals(2, grid.getColumns().getSize());
+    Assert.assertEquals(1, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┳━┓\n"
         + "┃█┃█┃\n"
         + "┗━┻━┛\n", grid.toString());
 
     grid.add(new OriginCell(null), 2, 2);
-    Assert.assertEquals(2, grid.getColumnCount());
-    Assert.assertEquals(3, grid.getRowCount());
+    Assert.assertEquals(2, grid.getColumns().getSize());
+    Assert.assertEquals(3, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┳━┓\n"
         + "┃█┃█┃\n"
@@ -123,8 +124,8 @@
         + "┗━┷━┛\n", grid.toString());
 
     grid.add(new OriginCell(null), 1, 2);
-    Assert.assertEquals(2, grid.getColumnCount());
-    Assert.assertEquals(5, grid.getRowCount());
+    Assert.assertEquals(2, grid.getColumns().getSize());
+    Assert.assertEquals(5, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┳━┓\n"
         + "┃█┃█┃\n"
@@ -139,8 +140,8 @@
         + "┗━┹─┘\n", grid.toString());
 
     grid.add(new OriginCell(null), 1, 1);
-    Assert.assertEquals(2, grid.getColumnCount());
-    Assert.assertEquals(5, grid.getRowCount());
+    Assert.assertEquals(2, grid.getColumns().getSize());
+    Assert.assertEquals(5, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┳━┓\n"
         + "┃█┃█┃\n"
@@ -155,8 +156,8 @@
         + "┗━┹─┘\n", grid.toString());
 
     grid.add(new OriginCell(null), 1, 2);
-    Assert.assertEquals(2, grid.getColumnCount());
-    Assert.assertEquals(6, grid.getRowCount());
+    Assert.assertEquals(2, grid.getColumns().getSize());
+    Assert.assertEquals(6, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┳━┓\n"
         + "┃█┃█┃\n"
@@ -174,16 +175,16 @@
 
     grid.add(new OriginCell(null), 2, 1);
     // fehler
-    Assert.assertEquals(2, grid.getColumnCount());
-    Assert.assertEquals(6, grid.getRowCount());
+    Assert.assertEquals(2, grid.getColumns().getSize());
+    Assert.assertEquals(6, grid.getRows().getSize());
   }
 
   @Test
   public void test5x5() {
 
-    Grid grid = new Grid(5, 5);
-    Assert.assertEquals(5, grid.getColumnCount());
-    Assert.assertEquals(5, grid.getRowCount());
+    Grid grid = new Grid(LayoutTokens.parse("*;*;*;*;*"), LayoutTokens.parse("*;*;*;*;*"));
+    Assert.assertEquals(5, grid.getColumns().getSize());
+    Assert.assertEquals(5, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┌─┬─┬─┬─┬─┐\n"
         + "│◌│◌│◌│◌│◌│\n"
@@ -210,8 +211,8 @@
     grid.add(new OriginCell(null), 1, 2);
     grid.add(new OriginCell(null), 2, 1);
     grid.add(new OriginCell(null), 1, 1);
-    Assert.assertEquals(5, grid.getColumnCount());
-    Assert.assertEquals(5, grid.getRowCount());
+    Assert.assertEquals(5, grid.getColumns().getSize());
+    Assert.assertEquals(5, grid.getRows().getSize());
     Assert.assertEquals(""
         + "┏━┳━┳━┳━┯━┓\n"
         + "┃█┃█┃█┃█│➞┃\n"