import java.util.ArrayList;\r
import java.util.List;\r
\r
-// BOZO - Support inserting cells/rows.\r
-\r
/** Base layout functionality.\r
* @author Nathan Sweet */\r
abstract public class BaseTableLayout<C, T extends C, L extends BaseTableLayout, K extends Toolkit<C, T, L>> {\r
private int columns, rows;\r
\r
private final ArrayList<Cell> cells = new ArrayList(4);\r
- private final Cell cellDefaults = Cell.defaults(this);\r
+ private final Cell cellDefaults;\r
private final ArrayList<Cell> columnDefaults = new ArrayList(2);\r
private Cell rowDefaults;\r
\r
\r
public BaseTableLayout (K toolkit) {\r
this.toolkit = toolkit;\r
+ cellDefaults = toolkit.obtainCell((L)this);\r
+ cellDefaults.defaults();\r
}\r
\r
/** Invalidates the layout. The cached min and pref sizes are recalculated the next time layout is done or the min or pref sizes\r
cell.widget = widget;\r
\r
if (cells.size() > 0) {\r
- // Set cell x and y.\r
+ // Set cell column and row.\r
Cell lastCell = cells.get(cells.size() - 1);\r
if (!lastCell.endRow) {\r
cell.column = lastCell.column + lastCell.colspan;\r
cell.row = lastCell.row;\r
- } else\r
+ } else {\r
+ cell.column = 0;\r
cell.row = lastCell.row + 1;\r
+ }\r
// Set the index of the cell above.\r
if (cell.row > 0) {\r
outer:\r
}\r
}\r
}\r
+ } else {\r
+ cell.column = 0;\r
+ cell.row = 0;\r
}\r
cells.add(cell);\r
\r
cell.set(cellDefaults);\r
if (cell.column < columnDefaults.size()) {\r
- Cell columnDefaults = this.columnDefaults.get(cell.column);\r
- if (columnDefaults != null) cell.merge(columnDefaults);\r
+ Cell columnCell = columnDefaults.get(cell.column);\r
+ if (columnCell != null) cell.merge(columnCell);\r
}\r
cell.merge(rowDefaults);\r
\r
* for all cells in the new row. */\r
public Cell row () {\r
if (cells.size() > 0) endRow();\r
+ if (rowDefaults != null) toolkit.freeCell(rowDefaults);\r
rowDefaults = toolkit.obtainCell((L)this);\r
+ rowDefaults.clear();\r
return rowDefaults;\r
}\r
\r
Cell cell = columnDefaults.size() > column ? columnDefaults.get(column) : null;\r
if (cell == null) {\r
cell = toolkit.obtainCell((L)this);\r
+ cell.clear();\r
if (column >= columnDefaults.size()) {\r
for (int i = columnDefaults.size(); i < column; i++)\r
columnDefaults.add(null);\r
align = CENTER;\r
if (debug != Debug.none) toolkit.clearDebugRectangles((L)this);\r
debug = Debug.none;\r
- cellDefaults.set(Cell.defaults(this));\r
+ cellDefaults.defaults();\r
+ for (int i = 0, n = columnDefaults.size(); i < n; i++) {\r
+ Cell columnCell = columnDefaults.get(i);\r
+ if (columnCell != null) toolkit.freeCell(columnCell);\r
+ }\r
columnDefaults.clear();\r
}\r
\r
/** Removes all widgets and cells from the table. */\r
public void clear () {\r
for (int i = cells.size() - 1; i >= 0; i--) {\r
- Object widget = cells.get(i).widget;\r
+ Cell cell = cells.get(i);\r
+ Object widget = cell.widget;\r
if (widget != null) toolkit.removeChild(table, (C)widget);\r
+ toolkit.freeCell(cell);\r
}\r
cells.clear();\r
rows = 0;\r
columns = 0;\r
+ if (rowDefaults != null) toolkit.freeCell(rowDefaults);\r
rowDefaults = null;\r
invalidate();\r
}\r
return layout;\r
}\r
\r
- static Cell defaults (BaseTableLayout layout) {\r
- Cell defaults = new Cell();\r
- defaults.layout = layout;\r
- defaults.minWidth = Value.minWidth;\r
- defaults.minHeight = Value.minHeight;\r
- defaults.prefWidth = Value.prefWidth;\r
- defaults.prefHeight = Value.prefHeight;\r
- defaults.maxWidth = Value.maxWidth;\r
- defaults.maxHeight = Value.maxHeight;\r
- defaults.spaceTop = Value.zero;\r
- defaults.spaceLeft = Value.zero;\r
- defaults.spaceBottom = Value.zero;\r
- defaults.spaceRight = Value.zero;\r
- defaults.padTop = Value.zero;\r
- defaults.padLeft = Value.zero;\r
- defaults.padBottom = Value.zero;\r
- defaults.padRight = Value.zero;\r
- defaults.fillX = 0f;\r
- defaults.fillY = 0f;\r
- defaults.align = CENTER;\r
- defaults.expandX = 0;\r
- defaults.expandY = 0;\r
- defaults.ignore = false;\r
- defaults.colspan = 1;\r
- return defaults;\r
+ /** Sets all constraint fields to null. */\r
+ public void clear () {\r
+ minWidth = null;\r
+ minHeight = null;\r
+ prefWidth = null;\r
+ prefHeight = null;\r
+ maxWidth = null;\r
+ maxHeight = null;\r
+ spaceTop = null;\r
+ spaceLeft = null;\r
+ spaceBottom = null;\r
+ spaceRight = null;\r
+ padTop = null;\r
+ padLeft = null;\r
+ padBottom = null;\r
+ padRight = null;\r
+ fillX = null;\r
+ fillY = null;\r
+ align = null;\r
+ expandX = null;\r
+ expandY = null;\r
+ ignore = null;\r
+ colspan = null;\r
+ uniformX = null;\r
+ uniformY = null;\r
+ }\r
+\r
+ /** Reset state so the cell can be reused. Doesn't reset the constraint fields. */\r
+ public void free () {\r
+ widget = null;\r
+ layout = null;\r
+ endRow = false;\r
+ cellAboveIndex = -1;\r
+ }\r
+\r
+ /** Set all constraints to cell default values. */\r
+ void defaults () {\r
+ minWidth = Value.minWidth;\r
+ minHeight = Value.minHeight;\r
+ prefWidth = Value.prefWidth;\r
+ prefHeight = Value.prefHeight;\r
+ maxWidth = Value.maxWidth;\r
+ maxHeight = Value.maxHeight;\r
+ spaceTop = Value.zero;\r
+ spaceLeft = Value.zero;\r
+ spaceBottom = Value.zero;\r
+ spaceRight = Value.zero;\r
+ padTop = Value.zero;\r
+ padLeft = Value.zero;\r
+ padBottom = Value.zero;\r
+ padRight = Value.zero;\r
+ fillX = 0f;\r
+ fillY = 0f;\r
+ align = CENTER;\r
+ expandX = 0;\r
+ expandY = 0;\r
+ ignore = false;\r
+ colspan = 1;\r
+ uniformX = null;\r
+ uniformY = null;\r
}\r
}\r