Mercurial > projects > dwt-addons
diff dwtx/ui/forms/widgets/TableWrapLayout.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 56fea7e5f0f9 |
children | 8df1d4193877 |
line wrap: on
line diff
--- a/dwtx/ui/forms/widgets/TableWrapLayout.d Sun Aug 03 17:01:51 2008 +0200 +++ b/dwtx/ui/forms/widgets/TableWrapLayout.d Thu Aug 07 15:01:33 2008 +0200 @@ -25,8 +25,7 @@ import dwt.widgets.Layout; import dwt.dwthelper.utils; -import tango.util.collection.ArraySeq; -import tango.util.collection.HashMap; +import dwtx.dwtxhelper.Collection; /** * This implementation of the layout algorithm attempts to position controls in @@ -101,9 +100,9 @@ private bool initialLayout = true; - private ArraySeq!(Object) grid = null; + private Vector grid = null; - private HashMap!(Object,Object) rowspans; + private Hashtable rowspans; private int[] minColumnWidths, maxColumnWidths; @@ -179,7 +178,7 @@ } if (grid is null || changed) { changed = true; - grid = new ArraySeq!(Object); + grid = new Vector(); createGrid(parent); } if (minColumnWidths is null) @@ -211,7 +210,7 @@ } if (grid is null || changed) { changed = true; - grid = new ArraySeq!(Object); + grid = new Vector(); createGrid(parent); } if (maxColumnWidths is null) @@ -247,7 +246,7 @@ } if (grid is null || changed) { changed = true; - grid = new ArraySeq!(Object); + grid = new Vector(); createGrid(parent); } resetColumnWidths(); @@ -299,7 +298,7 @@ for (int i = 0; i < grid.size(); i++) { int rowHeight = rowHeights[i]; int x = leftMargin+clientArea.x; - TableWrapData[] row = (cast(ArrayWrapperT!(TableWrapData)) grid.get(i)).array; + TableWrapData[] row = arrayFromObject!(TableWrapData)( grid.elementAt(i)); for (int j = 0; j < numColumns; j++) { TableWrapData td = row[j]; if (td.isItemData) { @@ -318,7 +317,7 @@ bool changed) { int[] rowHeights = new int[grid.size()]; for (int i = 0; i < grid.size(); i++) { - TableWrapData[] row = (cast(ArrayWrapperT!(TableWrapData)) grid.get(i)).array; + TableWrapData[] row = arrayFromObject!(TableWrapData)( grid.elementAt(i)); rowHeights[i] = 0; for (int j = 0; j < numColumns; j++) { TableWrapData td = row[j]; @@ -339,7 +338,7 @@ size = new Point(size.x, td.heightHint); } td.compSize = size; - RowSpan rowspan = rowspans.containsKey(child) ? cast(RowSpan) rowspans.get(child) : null; + RowSpan rowspan = cast(RowSpan) rowspans.get(child); if (rowspan is null) { rowHeights[i] = Math.max(rowHeights[i], size.y); } else @@ -347,8 +346,8 @@ } updateRowSpans(i, rowHeights[i]); } - foreach( k, v; rowspans ){ - RowSpan rowspan = cast(RowSpan) v; + for (Enumeration enm = rowspans.elements(); enm.hasMoreElements();) { + RowSpan rowspan = cast(RowSpan) enm.nextElement(); int increase = rowspan.getRequiredHeightIncrease(); if (increase is 0) continue; @@ -431,7 +430,7 @@ int width = td.compSize.x-td.indent; width = Math.min(width, colWidth); int slotHeight = rowHeights[row]; - RowSpan rowspan = rowspans.containsKey(control) ? cast(RowSpan) rowspans.get(control) : null; + RowSpan rowspan = cast(RowSpan) rowspans.get(control); if (rowspan !is null) { slotHeight = 0; for (int i = row; i < row + td.rowspan; i++) { @@ -463,15 +462,15 @@ int row, column, rowFill, columnFill; Control[] children; TableWrapData spacerSpec; - ArraySeq!(Object) growingCols = new ArraySeq!(Object); - ArraySeq!(Object) growingRows = new ArraySeq!(Object); - rowspans = new HashMap!(Object,Object); + Vector growingCols = new Vector(); + Vector growingRows = new Vector(); + rowspans = new Hashtable(); // children = composite.getChildren(); if (children.length is 0) return; // - grid.append( new ArrayWrapperT!(TableWrapData)(createEmptyRow())); + grid.addElement( new ArrayWrapperObject(createEmptyRow())); row = 0; column = 0; // Loop through the children and place their associated layout specs in @@ -481,13 +480,13 @@ // Find the first available spot in the grid. Control child = children[i]; TableWrapData spec = cast(TableWrapData) child.getLayoutData(); - while ((cast(ArrayWrapperT!(TableWrapData)) grid.get(row)).array[column] !is null) { + while (arrayFromObject!(TableWrapData)( grid.elementAt(row))[column] !is null) { column = column + 1; if (column >= numColumns) { row = row + 1; column = 0; if (row >= grid.size()) { - grid.append(new ArrayWrapperT!(TableWrapData)(createEmptyRow())); + grid.addElement(new ArrayWrapperObject(createEmptyRow())); } } } @@ -495,25 +494,25 @@ // not, go to the // next row. if (column + spec.colspan - 1 >= numColumns) { - grid.append(new ArrayWrapperT!(TableWrapData)(createEmptyRow())); + grid.addElement(new ArrayWrapperObject(createEmptyRow())); row = row + 1; column = 0; } // The vertical span for the item will be at least 1. If it is > 1, // add other rows to the grid. if (spec.rowspan > 1) { - rowspans.add(child, new RowSpan(child, column, row)); + rowspans.put(child, new RowSpan(child, column, row)); } for (int j = 2; j <= spec.rowspan; j++) { if (row + j > grid.size()) { - grid.append(new ArrayWrapperT!(TableWrapData)(createEmptyRow())); + grid.addElement(new ArrayWrapperObject(createEmptyRow())); } } // Store the layout spec. Also cache the childIndex. NOTE: That we // assume the children of a // composite are maintained in the order in which they are created // and added to the composite. - (cast(ArrayWrapperT!(TableWrapData)) grid.get(row)).array[column] = spec; + arrayFromObject!(TableWrapData)( grid.elementAt(row))[column] = spec; spec.childIndex = i; if (spec.grabHorizontal) { updateGrowingColumns(growingCols, spec, column); @@ -530,14 +529,14 @@ for (int c = 0; c < spec.colspan; c++) { spacerSpec = new TableWrapData(); spacerSpec.isItemData = false; - (cast(ArrayWrapperT!(TableWrapData)) grid.get(row + r)).array[column + c] = spacerSpec; + arrayFromObject!(TableWrapData)( grid.elementAt(row + r))[column + c] = spacerSpec; } } for (int c = 1; c <= columnFill; c++) { for (int r = 0; r < spec.rowspan; r++) { spacerSpec = new TableWrapData(); spacerSpec.isItemData = false; - (cast(ArrayWrapperT!(TableWrapData)) grid.get(row + r)).array[column + c] = spacerSpec; + arrayFromObject!(TableWrapData)( grid.elementAt(row + r))[column + c] = spacerSpec; } } column = column + spec.colspan - 1; @@ -546,12 +545,12 @@ for (int k = column + 1; k < numColumns; k++) { spacerSpec = new TableWrapData(); spacerSpec.isItemData = false; - (cast(ArrayWrapperT!(TableWrapData)) grid.get(row)).array[k] = spacerSpec; + arrayFromObject!(TableWrapData)( grid.elementAt(row))[k] = spacerSpec; } for (int k = row + 1; k < grid.size(); k++) { spacerSpec = new TableWrapData(); spacerSpec.isItemData = false; - (cast(ArrayWrapperT!(TableWrapData)) grid.get(k)).array[column] = spacerSpec; + arrayFromObject!(TableWrapData)( grid.elementAt(k))[column] = spacerSpec; } growingColumns = new int[growingCols.size()]; for (int i = 0; i < growingCols.size(); i++) { @@ -563,7 +562,7 @@ } } - private void updateGrowingColumns(ArraySeq!(Object) growingColumns, + private void updateGrowingColumns(Vector growingColumns, TableWrapData spec, int column) { int affectedColumn = column + spec.colspan - 1; for (int i = 0; i < growingColumns.size(); i++) { @@ -571,10 +570,10 @@ if (col.intValue() is affectedColumn) return; } - growingColumns.append(new Integer(affectedColumn)); + growingColumns.add(new Integer(affectedColumn)); } - private void updateGrowingRows(ArraySeq!(Object) growingRows, TableWrapData spec, + private void updateGrowingRows(Vector growingRows, TableWrapData spec, int row) { int affectedRow = row + spec.rowspan - 1; for (int i = 0; i < growingRows.size(); i++) { @@ -582,7 +581,7 @@ if (irow.intValue() is affectedRow) return; } - growingRows.append(new Integer(affectedRow)); + growingRows.add(new Integer(affectedRow)); } private TableWrapData[] createEmptyRow() { @@ -615,7 +614,7 @@ } if (grid is null || changed) { changed = true; - grid = new ArraySeq!(Object); + grid = new Vector(); createGrid(parent); } resetColumnWidths(); @@ -666,7 +665,7 @@ int innerHeight = 0; // compute widths for (int i = 0; i < grid.size(); i++) { - TableWrapData[] row = (cast(ArrayWrapperT!(TableWrapData)) grid.get(i)).array; + TableWrapData[] row = arrayFromObject!(TableWrapData)( grid.elementAt(i)); // assign widths, calculate heights int rowHeight = 0; for (int j = 0; j < numColumns; j++) { @@ -687,7 +686,7 @@ Point size = computeSize(td.childIndex, cwidth, td.indent, td.maxWidth, td.maxHeight); cy = size.y; } - RowSpan rowspan = rowspans.containsKey(child) ? cast(RowSpan) rowspans.get(child) : null; + RowSpan rowspan = cast(RowSpan) rowspans.get(child); if (rowspan !is null) { // don't take the height of this child into acount // because it spans multiple rows @@ -701,7 +700,7 @@ innerHeight += verticalSpacing; innerHeight += rowHeight; } - if (!rowspans.drained()) + if (!rowspans.isEmpty()) innerHeight = compensateForRowSpans(innerHeight); totalHeight = topMargin + innerHeight + bottomMargin; return new Point(tableWidth, totalHeight); @@ -710,15 +709,15 @@ private void updateRowSpans(int row, int rowHeight) { if (rowspans is null || rowspans.size() is 0) return; - foreach( k, v; rowspans ){ - RowSpan rowspan = cast(RowSpan) v; + for (Enumeration enm = rowspans.elements(); enm.hasMoreElements();) { + RowSpan rowspan = cast(RowSpan) enm.nextElement(); rowspan.update(row, rowHeight); } } private int compensateForRowSpans(int totalHeight) { - foreach( k, v; rowspans ){ - RowSpan rowspan = cast(RowSpan) v; + for (Enumeration enm = rowspans.elements(); enm.hasMoreElements();) { + RowSpan rowspan = cast(RowSpan) enm.nextElement(); totalHeight += rowspan.getRequiredHeightIncrease(); } return totalHeight; @@ -780,7 +779,7 @@ void calculateColumnWidths(Composite parent, int [] columnWidths, bool max, bool changed) { bool secondPassNeeded=false; for (int i = 0; i < grid.size(); i++) { - TableWrapData[] row = (cast(ArrayWrapperT!(TableWrapData)) grid.get(i)).array; + TableWrapData[] row = arrayFromObject!(TableWrapData)( grid.elementAt(i)); for (int j = 0; j < numColumns; j++) { TableWrapData td = row[j]; if (td.isItemData is false) @@ -808,7 +807,7 @@ // Second pass for controls with multi-column horizontal span for (int i = 0; i < grid.size(); i++) { - TableWrapData[] row = (cast(ArrayWrapperT!(TableWrapData)) grid.get(i)).array; + TableWrapData[] row = arrayFromObject!(TableWrapData)( grid.elementAt(i)); for (int j = 0; j < numColumns; j++) { TableWrapData td = row[j]; if (td.isItemData is false || td.colspan is 1)