1 package com.calipso.reportgenerator.userinterface; 2 3 import com.calipso.reportgenerator.common.DimensionValueNode; 4 5 import javax.swing.*; 6 import java.awt.*; 7 import java.util.Vector ; 8 import java.util.Iterator ; 9 10 14 15 public class RowHeaderTableUI extends HeaderTableUI{ 16 17 private static final double ESTIMATED_MARGIN = 0.01; 19 private static final int ROWS_ERROR_MARGIN = 4; 20 21 25 protected int getVisibleCellCount() { 26 return (table.getParent().getParent().getHeight()/table.getRowHeight()) + ROWS_ERROR_MARGIN; 27 } 28 29 33 protected int getFromCell(){ 34 int result = ((JScrollPane)table.getParent().getParent()).getVerticalScrollBar().getValue(); 35 return (int)Math.floor(result / (table.getRowHeight() + ESTIMATED_MARGIN)); } 37 38 42 protected int getToCell() { 43 int from = ((JScrollPane)table.getParent().getParent()).getVerticalScrollBar().getValue(); 44 from = (int)Math.floor(from/table.getRowHeight()); 45 int to = from + getVisibleCellCount(); 46 if((getModel().getRowCount() - to) <= 0){ 47 to = getModel().getRowCount(); 48 }else{ 49 if(getModel().getDimensionCount() == 1){ 50 return to; 51 }else{ 52 int rows = to; 53 to = getLastRowForGroup(from); 54 while(to < rows){ 55 to = getLastRowForGroup(to + 1); 56 } 57 } 58 } 59 return ++to; 60 } 61 62 68 private int getLastRowForGroup(int from) { 69 DimensionValueNode node = getModel().getDimensionValueNode(); 70 if(!node.getSubNodesList().isEmpty()){ 71 if(node.getDimensionCount()==1){ 72 return from + getVisibleCellCount(); 74 }else{ 75 Vector endings = getEndingsVector(); 76 int i=0; 77 while(i<endings.size() && ((Integer )endings.elementAt(i)).intValue() < from){ 78 i++; 79 } 80 return ((Integer )endings.elementAt(i)).intValue(); 81 } 82 87 }else{ 88 return from + getVisibleCellCount(); 89 } 90 } 91 92 93 94 95 100 protected void paintCells(Graphics g) { 101 super.paintCells(g); 102 if (getModel().getDimensionCount() == 0){ 103 DimensionValueNode root = getModel().getDimensionValueNode(); 104 int[] cell = new int[] {0, 0}; 105 Rectangle rect = table.getCellRect(cell[0], cell[0], true); 106 paintRectangle(rect, g, getGroupFooterCaption(root), false, false); 107 } 108 } 109 110 116 protected void fillEndingCellForGroups(Vector endings,boolean withTotals, DimensionValueNode node){ 117 if(node.getSubNodesList().isEmpty() || node.getCollapsed()){ 118 iterations++; 119 if(node.getCollapsed()){ 120 endings.add(new Integer (iterations)); 121 } 122 return; 123 } 124 Iterator iterator = node.getSubNodesList().iterator(); 125 while (iterator.hasNext()) { 126 DimensionValueNode current = (DimensionValueNode) iterator.next(); 127 fillEndingCellForGroups(endings, withTotals, current); 128 } 129 if(withTotals){ 130 iterations++; 131 if(node.getDimesionIndex() == 0){ 132 endings.add(new Integer (iterations)); 133 } 134 }else{ 135 if(!endings.isEmpty()){ 136 if(node.getDimesionIndex() == 0){ 137 if(((Integer )endings.lastElement()).intValue() != iterations){ 138 endings.add(new Integer (iterations)); 139 } 140 } 141 }else if(node.getDimesionIndex() == 0){ 142 endings.add(new Integer (iterations)); 143 } 144 } 145 } 146 147 157 protected void doPaintNode(DimensionValueNode node, Graphics g, int[] rowIndexes, int[] rowSizes, int from, int to) { 158 Rectangle rect = null; 159 int nodeDimIndex = node.getDimesionIndex(); 160 int dimCount = getModel().getDimensionCount(); 161 boolean isLastDim = nodeDimIndex == dimCount - 1; 162 if (isLastDim) { 163 for (int i = 0; i < dimCount - 1; i++) { 164 rowSizes[i]++; 165 } 166 } 167 if (getModel().getWithTotals() && !isLastDim) { 168 if (node.getCollapsed()) { 169 for (int i = 0; i <= nodeDimIndex; i++) { 170 rowSizes[i]++; 171 } 172 for (int i = nodeDimIndex + 1; i < dimCount; i++) { 173 rowIndexes[i]++; 174 } 175 count++; 176 } 177 else { 178 int index = rowIndexes[nodeDimIndex + 1]; 179 rect = getTotalRectangleFromNode(node, index); 180 getAllSubNodes().put(new Integer (index), node); 181 if ((count >= from) && (count <= to)){ 182 paintRectangle(rect, g, getGroupFooterCaption(node), false, false); 183 } 184 count++; 185 for (int i = 0; i <= nodeDimIndex; i++) { 186 rowSizes[i]++; 187 } 188 for (int i = nodeDimIndex + 1; i < dimCount; i++) { 189 rowIndexes[i]++; 190 } 191 } 192 } 193 if (nodeDimIndex >= 0) { 194 int size = Math.max(rowSizes[nodeDimIndex], 1); 195 int index = rowIndexes[nodeDimIndex]; 196 rect = getRectangleFromNode(node, index, size); 197 if ((count >= from) && (count <= to)){ 198 paintRectangle(rect, g, node.getValue(), getNodeIsCollapsable(node), node.getCollapsed()); 199 } 200 if (isLastDim) { 201 getAllSubNodes().put(new Integer (index), node); 202 count++; 203 } 204 rowIndexes[nodeDimIndex] += size; 205 } 206 } 207 208 } 209 | Popular Tags |