1 32 33 package it.businesslogic.ireport.crosstab; 34 import it.businesslogic.ireport.Box; 35 import it.businesslogic.ireport.BoxElement; 36 import it.businesslogic.ireport.CrosstabReportElement; 37 import it.businesslogic.ireport.ReportElement; 38 import it.businesslogic.ireport.Style; 39 import it.businesslogic.ireport.util.Java2DUtil; 40 import java.awt.Color ; 41 import java.awt.Font ; 42 import java.awt.Graphics2D ; 43 import java.awt.Rectangle ; 44 import java.awt.Stroke ; 45 46 50 public class CrosstabCell implements BoxElement { 51 52 53 public static final int HEADER_CELL = 1; public static final int CT_HEADER_CELL = 3; public static final int DETAIL_CELL = 0; public static final int NODATA_CELL = 2; 58 private int type = DETAIL_CELL; 59 private String name = null; 60 private int top = 0; 61 private int left = 0; 62 private int width = 0; 63 private int height = 0; 64 private String mode = "Transparent"; 65 66 private boolean paintSelection = false; 67 68 private Style style = null; 69 70 73 private int topIndex = 0; 74 75 78 private int bottomIndex = 0; 79 80 83 private int leftIndex = 0; 84 85 88 private int rightIndex = 0; 89 90 91 private String rowTotalGroup = ""; 92 private String columnTotalGroup = ""; 93 94 private CrosstabReportElement parent = null; 95 96 private java.awt.Color backcolor = null; 97 98 private Box box = new Box(); 99 100 103 private double zoomFactor = 1.0; 104 105 106 public CrosstabCell() { 107 } 108 109 public String getName() { 110 111 if (name == null) 112 { 113 if (getType() == NODATA_CELL) 114 { 115 setName("When no data"); 116 } 117 else if (getType() == DETAIL_CELL) 118 { 119 setName( ((getRowTotalGroup().equals("")) ? "Detail" : getRowTotalGroup()) + " / " + ((getColumnTotalGroup().equals("")) ? "Detail" : getColumnTotalGroup()) ); 120 } 121 else if (getType() == CT_HEADER_CELL) 122 { 123 setName("Crosstab header"); 124 } 125 } 126 127 return name; 128 } 129 130 public void setName(String name) { 131 this.name = name; 132 } 133 134 public int getTop() { 135 return top; 136 } 137 138 public void setTop(int top) { 139 this.top = top; 140 } 141 142 public int getLeft() { 143 return left; 144 } 145 146 public void setLeft(int left) { 147 this.left = left; 148 } 149 150 public int getWidth() { 151 return width; 152 } 153 154 public void setWidth(int width) { 155 this.width = width; 156 } 157 158 public int getHeight() { 159 return height; 160 } 161 162 public void setHeight(int height) { 163 this.height = height; 164 } 165 166 public Box getBox() { 167 return box; 168 } 169 170 public void setBox(Box box) { 171 this.box = box; 172 } 173 174 public int getType() { 175 return type; 176 } 177 178 public void setType(int type) { 179 this.type = type; 180 } 181 182 public String getRowTotalGroup() { 183 return rowTotalGroup; 184 } 185 186 public void setRowTotalGroup(String rowTotalGroup) { 187 this.rowTotalGroup = rowTotalGroup; 188 } 189 190 public String getColumnTotalGroup() { 191 return columnTotalGroup; 192 } 193 194 public void setColumnTotalGroup(String columnTotalGroup) { 195 this.columnTotalGroup = columnTotalGroup; 196 } 197 198 public java.awt.Color getBackcolor() { 199 return backcolor; 200 } 201 202 public void setBackcolor(java.awt.Color backcolor) { 203 this.backcolor = backcolor; 204 } 205 206 public CrosstabReportElement getParent() { 207 return parent; 208 } 209 210 public void setParent(CrosstabReportElement parent) { 211 this.parent = parent; 212 } 213 214 public Rectangle getBounds() 215 { 216 return new Rectangle (left,top,width,height); 217 } 218 219 220 public void drawCell(Graphics2D g, double zoom_factor) 221 { 222 this.zoomFactor = zoom_factor; 223 224 225 Color bgcolor = (this.getBackcolor() == null || getMode().equals("Transparent")) ? Color.WHITE : this.getBackcolor(); 226 227 228 if (getType() == NODATA_CELL) 229 { 230 g.setColor(new Color ( bgcolor.getRed(), bgcolor.getGreen(), bgcolor.getBlue(), 200 )); 231 } 232 else 233 { 234 g.setColor( bgcolor ); 235 } 236 g.fillRect(10 + getZoomedDim(this.getLeft()), 10 + getZoomedDim(this.getTop()), 237 getZoomedDim(this.getWidth())-1, getZoomedDim(this.getHeight())-1); 238 239 240 241 g.setFont( new Font ( "Arial", Font.BOLD, 12)); int txt_height = g.getFontMetrics().getHeight(); 245 txt_height -= g.getFontMetrics().getMaxDescent(); 246 Color c = (getBackcolor() == null) ? Color.WHITE : getBackcolor(); 247 g.setColor(new Color (255-c.getRed(),255 - c.getGreen(),255-c.getBlue(),32)); 248 249 Java2DUtil.setClip(g, 250 (Math.max(2,getZoomedDim(2))) + 10 + getZoomedDim(this.getLeft()), 251 (Math.max(2,getZoomedDim(2))) + 10 + getZoomedDim(this.getTop()), 252 getZoomedDim(this.getWidth())-1-(Math.max(2,getZoomedDim(2))), 253 getZoomedDim(this.getHeight())-1-(Math.max(2,getZoomedDim(2)))); 254 255 g.drawString( this.getName(), 256 (Math.max(2,getZoomedDim(2))) + 10 + getZoomedDim(this.getLeft()), 257 (Math.max(2,getZoomedDim(2))) + 10 + getZoomedDim(this.getTop()) + g.getFontMetrics().getAscent()); 258 259 260 c = (getBackcolor() == null) ? Color.WHITE : getBackcolor(); 261 g.setColor(new Color (255-c.getRed(),255 - c.getGreen(),255-c.getBlue(),200)); 262 263 Java2DUtil.resetClip(g); 264 265 if (isPaintSelection()) 266 { 267 for (int j=1; j<=20; ++j) 268 { 269 g.setColor(new Color (255,168,0,j)); 270 int i=10; 271 g.fillRect(getZoomedDim(this.getLeft())-i+10, getZoomedDim(this.getTop())-i+10, 272 getZoomedDim(this.getWidth())+(i*2), i); 273 274 g.fillRect(getZoomedDim(this.getLeft())-i+10, getZoomedDim(this.getTop())+10, 275 i, getZoomedDim(this.getHeight())); 276 277 g.fillRect(getZoomedDim(this.getLeft())+10-i, getZoomedDim(this.getTop())+getZoomedDim(this.getHeight())+10, 278 getZoomedDim(this.getWidth())+(i*2), i); 279 280 g.fillRect(getZoomedDim(this.getLeft())+getZoomedDim(this.getWidth())+10, getZoomedDim(this.getTop())+10, 281 i, getZoomedDim(this.getHeight())); 282 } 283 } 284 285 } 286 287 288 293 public void drawCellBox(Graphics2D g, double zoom_factor, boolean isFirstInColumn, boolean isFirstInRow) 294 { 295 this.zoomFactor = zoom_factor; 296 298 Stroke oldStroke = g.getStroke(); 299 Color oldColor = g.getColor(); 300 301 if (box != null) 302 { 303 int ax = getZoomedDim(getLeft())+10; 305 int ay = getZoomedDim(getTop())+10; 306 int bx = ax + getZoomedDim(getWidth()); 307 int by = ay + getZoomedDim(getHeight()); 308 309 Stroke newBoxStroke = null; 310 311 if (box.getLeftBorderColor() != null && (newBoxStroke = ReportElement.getPenStroke(box.getLeftBorder(), zoom_factor)) != null) 312 { 313 g.setColor(box.getLeftBorderColor()); 314 if ((newBoxStroke = ReportElement.getPenStroke(box.getLeftBorder(), zoom_factor)) != null) 315 { 316 g.setStroke(newBoxStroke); 317 g.drawLine(ax, ay, ax, by); 318 } 319 320 newBoxStroke = null; 321 } 322 else if (isFirstInRow && box.getRightBorderColor() != null) 323 { 324 g.setColor(box.getRightBorderColor()); 325 if ((newBoxStroke = ReportElement.getPenStroke(box.getRightBorder(), zoom_factor)) != null) 326 { 327 g.setStroke(newBoxStroke); 328 g.drawLine(ax, ay, ax, by); 329 } 330 } 331 332 if (box.getTopBorderColor() != null && (newBoxStroke = ReportElement.getPenStroke(box.getTopBorder(), zoom_factor)) != null) 333 { 334 g.setColor(box.getTopBorderColor()); 335 g.setStroke(newBoxStroke); 336 g.drawLine(ax, ay, bx, ay); 337 } 338 else if (isFirstInColumn && box.getBottomBorderColor() != null) 339 { 340 g.setColor(box.getBottomBorderColor()); 341 if ((newBoxStroke = ReportElement.getPenStroke(box.getBottomBorder(), zoom_factor)) != null) 342 { 343 g.setStroke(newBoxStroke); 344 g.drawLine(ax, ay, bx, ay); 345 } 346 } 347 348 if (box.getRightBorderColor() != null) 349 { 350 g.setColor(box.getRightBorderColor()); 351 if ((newBoxStroke = ReportElement.getPenStroke(box.getRightBorder(), zoom_factor)) != null) 352 { 353 g.setStroke(newBoxStroke); 354 g.drawLine(bx, ay, bx, by); 355 } 356 } 357 358 if (box.getBottomBorderColor() != null) 359 { 360 g.setColor(box.getBottomBorderColor()); 361 if ((newBoxStroke = ReportElement.getPenStroke(box.getBottomBorder(), zoom_factor)) != null) 362 { 363 g.setStroke(newBoxStroke); 364 g.drawLine(ax, by, bx, by); 365 } 366 } 367 } 368 g.setStroke(oldStroke); 369 } 370 371 374 public int getZoomedDim(int dim) { 375 if (getZoomFactor() == 1.0) return dim; 376 return (int)((double)dim*getZoomFactor()); 377 } 378 379 383 public CrosstabCell cloneMe() 384 { 385 CrosstabCell cell = new CrosstabCell(); 386 cell.setTop( this.getTop()); 387 cell.setLeft( this.getLeft()); 388 cell.setHeight( this.getHeight()); 389 cell.setWidth( this.getWidth()); 390 cell.setBox( this.getBox().cloneMe()); 391 cell.setBackcolor( this.getBackcolor()); 392 cell.setColumnTotalGroup( this.getColumnTotalGroup() ); 393 cell.setRowTotalGroup( this.getRowTotalGroup() ); 394 cell.setParent( this.getParent()); 395 cell.setType( this.getType()); 396 397 return cell; 398 } 399 400 public double getZoomFactor() { 401 return zoomFactor; 402 } 403 404 public void setZoomFactor(double zoomFactor) { 405 this.zoomFactor = zoomFactor; 406 } 407 408 public int getTopIndex() { 409 return topIndex; 410 } 411 412 public void setTopIndex(int topIndex) { 413 this.topIndex = topIndex; 414 } 415 416 public int getBottomIndex() { 417 return bottomIndex; 418 } 419 420 public void setBottomIndex(int bottomIndex) { 421 this.bottomIndex = bottomIndex; 422 } 423 424 public int getLeftIndex() { 425 return leftIndex; 426 } 427 428 public void setLeftIndex(int leftIndex) { 429 this.leftIndex = leftIndex; 430 } 431 432 public int getRightIndex() { 433 return rightIndex; 434 } 435 436 public void setRightIndex(int rightIndex) { 437 this.rightIndex = rightIndex; 438 } 439 440 public String toString() 441 { 442 return getName(); 443 } 444 445 public boolean isPaintSelection() { 446 return paintSelection; 447 } 448 449 public void setPaintSelection(boolean paintSelection) { 450 this.paintSelection = paintSelection; 451 } 452 453 public String getMode() { 454 return mode; 455 } 456 457 public void setMode(String mode) { 458 this.mode = mode; 459 } 460 461 public Style getStyle() { 462 return style; 463 } 464 465 public void setStyle(Style style) { 466 if (this.style != style) 467 { 468 this.style = style; 469 if (style != null) 470 { 471 this.setBackcolor( style.getAttributeColor( style.ATTRIBUTE_backcolor,getBackcolor(), true) ); 472 this.setMode( style.getAttributeString( style.ATTRIBUTE_mode, getMode(), true) ); 473 474 475 if (style.getAttributeString(style.ATTRIBUTE_border, null, true) != null) 477 this.getBox().setBorder( style.getAttributeString(style.ATTRIBUTE_border, null, true) ); 478 if (style.getAttributeColor(style.ATTRIBUTE_borderColor, null, true) != null) 479 this.getBox().setBorderColor( style.getAttributeColor(style.ATTRIBUTE_borderColor, null, true)); 480 if (style.getAttributeString(style.ATTRIBUTE_padding, null, true) != null) 481 this.getBox().setPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_padding, null, true) )); 482 483 if (style.getAttributeString(style.ATTRIBUTE_topBorder, null, true) != null) 484 this.getBox().setTopBorder( style.getAttributeString(style.ATTRIBUTE_topBorder, null, true) ); 485 if (style.getAttributeColor(style.ATTRIBUTE_topBorderColor, null, true) != null) 486 this.getBox().setTopBorderColor( style.getAttributeColor(style.ATTRIBUTE_topBorderColor, null, true)); 487 if (style.getAttributeString(style.ATTRIBUTE_topPadding, null, true) != null) 488 this.getBox().setTopPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_topPadding, null, true) )); 489 490 if (style.getAttributeString(style.ATTRIBUTE_leftBorder, null, true) != null) 491 this.getBox().setLeftBorder( style.getAttributeString(style.ATTRIBUTE_leftBorder, null, true) ); 492 if (style.getAttributeColor(style.ATTRIBUTE_leftBorderColor, null, true) != null) 493 this.getBox().setLeftBorderColor( style.getAttributeColor(style.ATTRIBUTE_leftBorderColor, null, true)); 494 if (style.getAttributeString(style.ATTRIBUTE_leftPadding, null, true) != null) 495 this.getBox().setLeftPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_leftPadding, null, true) )); 496 497 if (style.getAttributeString(style.ATTRIBUTE_rightBorder, null, true) != null) 498 this.getBox().setRightBorder( style.getAttributeString(style.ATTRIBUTE_rightBorder, null, true) ); 499 if (style.getAttributeColor(style.ATTRIBUTE_rightBorderColor, null, true) != null) 500 this.getBox().setRightBorderColor( style.getAttributeColor(style.ATTRIBUTE_rightBorderColor, null, true)); 501 if (style.getAttributeString(style.ATTRIBUTE_rightPadding, null, true) != null) 502 this.getBox().setRightPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_rightPadding, null, true) )); 503 504 if (style.getAttributeString(style.ATTRIBUTE_bottomBorder, null, true) != null) 505 this.getBox().setBottomBorder( style.getAttributeString(style.ATTRIBUTE_bottomBorder, null, true) ); 506 if (style.getAttributeColor(style.ATTRIBUTE_bottomBorderColor, null, true) != null) 507 this.getBox().setBottomBorderColor( style.getAttributeColor(style.ATTRIBUTE_bottomBorderColor, null, true)); 508 if (style.getAttributeString(style.ATTRIBUTE_bottomPadding, null, true) != null) 509 this.getBox().setBottomPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_bottomPadding, null, true) )); 510 } 511 } 512 } 513 } 514 | Popular Tags |