1 package org.joshy.html.table; 2 3 import org.joshy.u; 4 5 public class CellGrid { 6 private Cell[][] grid; 7 8 private int height = 0; 9 private int width = 0; 10 11 public int getHeight() { 12 return height+1; 13 } 14 15 public int getWidth() { 16 return width+1; 17 } 18 19 public void addCell(int x, int y, int col_span, int row_span, Cell cell) { 20 for(int i=0; i<col_span; i++) { 22 for(int j=0; j<row_span; j++) { 23 setCell(x+i,y+j,cell); 24 } 25 } 26 } 27 28 private void setCell(int x, int y, Cell cell) { 29 grid[y][x] = cell; 32 if(y > height) { 33 height = y; 34 } 35 if(x > width) { 36 width = x; 37 } 38 } 39 40 public Cell getCell(int x, int y) { 41 if(x >= getWidth()) { 42 u.p("CellGrid.getCell("+x+","+y+") but width = " + getWidth()); 43 } 44 if(y >= getHeight()) { 45 u.p("CellGrid.getCell("+x+","+y+") but height = " + getHeight()); 46 } 47 if(grid[y][x] == null) { 48 u.p("CellGrid.getCell("+x+","+y+") is null"); 49 } 50 return grid[y][x]; 52 } 53 54 public boolean isReal(int x, int y) { 55 if(!isRowVirtual(x,y) && !isColVirtual(x,y)) { 56 return true; 57 } 58 return false; 59 } 60 61 62 private boolean isRowVirtual(int x, int y) { 63 if(y == 0) { 64 return false; 65 } 66 if(getCell(x,y-1) == getCell(x,y)) { 67 return true; 68 } 69 return false; 70 } 71 private boolean isColVirtual(int x, int y) { 72 if(x == 0) { 73 return false; 74 } 75 if(getCell(x-1,y) == getCell(x,y)) { 76 return true; 77 } 78 return false; 79 } 80 81 82 public CellGrid() { 83 grid = new Cell[20][20]; 84 } 85 86 } 87 | Popular Tags |