1 25 26 package org.joshy.html; 27 28 import java.awt.Point ; 29 import java.awt.Rectangle ; 30 31 import java.util.*; 32 33 import org.joshy.html.box.*; 34 import org.joshy.html.table.*; 35 36 import org.joshy.u; 37 38 import org.w3c.dom.*; 39 40 41 public class TableLayout2 42 extends TableLayout { 43 public Box createBox(Context c, Node node) { 44 45 TableBox table = new TableBox(); 46 table.node = node; 47 48 getMargin(c, table); 50 getPadding(c, table); 51 getBorder(c, table); 52 53 return table; 54 } 55 56 public Box layout(Context c, Element elem) { 57 58 try { 59 60 TableBox table_box = (TableBox)createBox(c, elem); 63 64 float border_spacing = c.css.getFloatProperty(elem, 66 "border-spacing"); 67 table_box.spacing = new Point ((int)border_spacing, 68 (int)border_spacing); 69 70 int fixed_width = c.getExtents().width; 72 73 if (c.css.hasProperty(elem, "width", false)) { 74 fixed_width = (int)c.css.getFloatProperty(elem, "width", false); 75 } 76 77 int orig_fixed_width = fixed_width; 78 79 fixed_width -= table_box.margin.left + table_box.border.left + 81 table_box.padding.left + table_box.spacing.x + 82 table_box.padding.right + table_box.border.right + table_box.margin.right; 83 84 Table table = new Table(); 86 table.addTable(elem); 87 88 table.calculateWidths(fixed_width, c); 90 91 Box bx = calculateBoxes(fixed_width, table_box, c, table); 93 bx.width += table_box.margin.left + table_box.border.left + table_box.padding.left 94 + table_box.margin.right + table_box.border.right + table_box.padding.right; 95 bx.height += table_box.margin.top + table_box.border.top + table_box.padding.top + 96 table_box.margin.bottom + table_box.border.bottom + table_box.padding.bottom; 97 98 return bx; 100 } catch (Exception ex) { 101 u.p(ex); 102 103 return null; 104 } 105 } 106 107 108 public Box calculateBoxes(int avail_width, TableBox box, Context c, Table table) { 109 110 box.width = avail_width; 111 box.height = 100; 112 box.x = 5; 113 box.y = 5; 114 115 RowBox prev_row = new RowBox(0,0,0,0); 117 int max_width = 0; 118 119 CellGrid grid = table.getCellGrid(); 121 for(int y=0; y<grid.getHeight(); y++) { 122 RowBox row_box = new RowBox(0,0,0,0); 124 box.rows.add(row_box); 126 127 int row_height = 0; 128 int column_count = 0; 129 130 for(int x=0; x<grid.getWidth(); x++) { 132 u.p("x = " + x); 133 if(grid.isReal(x,y)) { 135 u.p("it's real"); 136 137 Cell cell = grid.getCell(x,y); 138 139 CellBox cell_box = new CellBox(0,0,10,10); 141 cell.cb = cell_box; 142 cell_box.rb = row_box; 143 cell_box.x = table.calcColumnX(column_count); 145 cell_box.width = table.calcColumnWidth(column_count, cell.col_span); 148 cell_box.node = cell.node; 149 150 Rectangle oe = c.getExtents(); 153 c.setExtents(new Rectangle (c.getExtents().x,c.getExtents().y, 154 cell_box.width, 100)); 155 Layout layout = LayoutFactory.getLayout(cell.node); 157 Box cell_contents = layout.layout(c,(Element)cell_box.node); 158 cell_box.sub_box = cell_contents; 159 cell_box.height = cell_box.sub_box.height; 160 column_count += cell.col_span; 161 c.setExtents(oe); 163 164 165 cell_box.y = 0; 167 row_box.cells.add(cell_box); 169 170 171 if(cell.row_span == 1) { 174 if(cell_box.height > row_box.height) { 175 row_box.height = cell_box.height; 176 } 177 } 178 row_box.width += cell_box.width; 179 180 } else { 181 u.p("it's virtual"); 182 Cell cell = grid.getCell(x,y); 183 CellBox cell_box = CellBox.createVirtual(cell.cb); 185 row_box.cells.add(cell_box); 187 } 191 } 193 195 row_height = 0; 197 row_box.y = prev_row.y + prev_row.height; 198 prev_row = row_box; 199 if(row_box.width > max_width) { 201 max_width = row_box.width; 202 } 203 204 for(int k=0; k<row_box.cells.size(); k++) { 207 CellBox cb = (CellBox)row_box.cells.get(k); 208 if(cb.isReal()) { 209 cb.height = row_box.height; 210 cb.sub_box.height = row_box.height; 211 } else { 212 CellBox real = cb.getReal(); 215 RowBox orig_row = real.rb; 217 RowBox cur_row = row_box; 219 221 real.height = cur_row.y - orig_row.y + cur_row.height; 222 real.sub_box.height = real.height; 223 } 225 u.p("cell = " + cb); 226 } 227 228 229 } 230 231 box.height = prev_row.y + prev_row.height; 232 box.width = max_width; 233 return box; 234 235 } 236 237 } 238 239 269 270 271 | Popular Tags |