|
From: Rashmi B. <ra...@us...> - 2005-04-26 17:33:48
|
Update of /cvsroot/pocolap/pocolap/src/com/pocolap/xtab/format In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21728 Modified Files: FormatPDF.java Log Message: PDF related changes Index: FormatPDF.java =================================================================== RCS file: /cvsroot/pocolap/pocolap/src/com/pocolap/xtab/format/FormatPDF.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FormatPDF.java 19 Apr 2005 00:39:58 -0000 1.2 --- FormatPDF.java 26 Apr 2005 17:33:39 -0000 1.3 *************** *** 45,48 **** --- 45,50 ---- import java.io.ByteArrayOutputStream; import java.lang.Math; + import com.pocolap.schema.SupplementalItem ; + import com.pocolap.schema.FormatTypeItem; public class FormatPDF { *************** *** 87,92 **** if (flist!=null) TOP_MARGIN = TOP_MARGIN + (flist.length * 14); ! Rectangle psize = PageSize.A4.rotate(); ! psize.setBackgroundColor(new java.awt.Color(204, 204, 255)); //CCCCFF Document document = new Document(psize, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN); //(PageSize,left,right,top,margin) try{ --- 89,95 ---- if (flist!=null) TOP_MARGIN = TOP_MARGIN + (flist.length * 14); ! ! TableFormat tableformat = getTableFormat(); ! Rectangle psize = tableformat.getPageSize(); Document document = new Document(psize, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN); //(PageSize,left,right,top,margin) try{ *************** *** 97,104 **** writer.setPageEvent(new HeaderEvent(currdefinition,flist)); document.open(); ! createTable(writer,document); } catch(DocumentException de) { ! System.err.println(de.getMessage()); } document.close(); --- 100,107 ---- writer.setPageEvent(new HeaderEvent(currdefinition,flist)); document.open(); ! createTable(writer,document, tableformat); } catch(DocumentException de) { ! logger.error(errclass + de.getMessage()); } document.close(); *************** *** 116,120 **** } ! private void createTable(PdfWriter writer,Document document) { String errclass = getClass().getName()+".createTable(PdfWriter,Document): "; logger.debug(errclass+ "Creating table .."); --- 119,123 ---- } ! private void createTable(PdfWriter writer,Document document , TableFormat tableformat) { String errclass = getClass().getName()+".createTable(PdfWriter,Document): "; logger.debug(errclass+ "Creating table .."); *************** *** 130,134 **** } catch(DocumentException de) { ! System.err.println(de.getMessage()); } return ; --- 133,137 ---- } catch(DocumentException de) { ! logger.error(errclass+de.getMessage()); } return ; *************** *** 140,144 **** //Decide how many cols on a page int totalpoints = (int)PageSize.A4.rotate().right() - LEFT_MARGIN - RIGHT_MARGIN ; //left and right margins ! // logger.debug("Totalpoints on this page: " + totalpoints); float[] maxlen; //contains the points required for each column in newarr[][]. maxlen = new float[newarr[0].length]; --- 143,147 ---- //Decide how many cols on a page int totalpoints = (int)PageSize.A4.rotate().right() - LEFT_MARGIN - RIGHT_MARGIN ; //left and right margins ! // logger.debug("Totalpoints on this page: " + totalpoints); float[] maxlen; //contains the points required for each column in newarr[][]. maxlen = new float[newarr[0].length]; *************** *** 156,162 **** } ! // for(int i=0;i<maxlen.length;i++){ ! // logger.debug("i=" + i + " Col length:" + maxlen[i]); ! // } //Calculate the no. of points required for header columns --- 159,165 ---- } ! // for(int i=0;i<maxlen.length;i++){ ! // logger.debug("i=" + i + " Col length:" + maxlen[i]); ! // } //Calculate the no. of points required for header columns *************** *** 166,174 **** } ! // logger.debug("Header column points : " + hcolpoints); int totaltables = 0,sum=0; //Calculate no. of tables ! // logger.debug("Calculate no. of tables"); for (int i=0,j=harr[0].length ;j<maxlen.length;totaltables = i,i++){ sum = hcolpoints ; --- 169,177 ---- } ! // logger.debug("Header column points : " + hcolpoints); int totaltables = 0,sum=0; //Calculate no. of tables ! // logger.debug("Calculate no. of tables"); for (int i=0,j=harr[0].length ;j<maxlen.length;totaltables = i,i++){ sum = hcolpoints ; *************** *** 178,182 **** sum = sum + (int)maxlen[j]; } ! // logger.debug("i="+i+" sum="+sum); } totaltables ++ ; --- 181,185 ---- sum = sum + (int)maxlen[j]; } ! // logger.debug("i="+i+" sum="+sum); } totaltables ++ ; *************** *** 232,236 **** PdfPTable table ; ! table = formatTable(harr,smallarr); table.setLockedWidth(true); try{ --- 235,239 ---- PdfPTable table ; ! table = tableformat.formatTable(harr,smallarr,sheet); table.setLockedWidth(true); try{ *************** *** 240,244 **** } catch(DocumentException de) { ! System.err.println(de.getMessage()); } } --- 243,247 ---- } catch(DocumentException de) { ! logger.error(errclass+de.getMessage()); } } *************** *** 316,541 **** } ! private PdfPTable formatTable(String[][] harr,String[][] newarr){ ! int fixedrow = sheet.getFixedRowCount() ; ! int fixedcol = sheet.getFixedColumnCount() ; ! int rows = newarr.length; ! int cols = newarr[0].length ; ! int hrow = harr.length ; ! int hcol = harr[0].length; ! ! PdfPTable table = null ; ! table = new PdfPTable(cols); ! ! table.setHeaderRows(hrow); ! //table.setWidthPercentage(100); //Default width is 80% ! table.setHorizontalAlignment(Element.ALIGN_LEFT) ; // Default is center ! ! ! for(int i=0;i<rows;i++){ ! for(int j=0;j<cols;j++){ ! if ( (( i<hrow-1 && j==hcol-1) && (!(fixedcol==0))) || ! (( i<hrow && j==hcol-1) && ((fixedcol==0))) ) ! table.addCell(applyStyleColumnSelector(newarr[i][j],hcol)); ! ! else if (i==hrow-1 && j<hcol) ! table.addCell(applyStyleRowSelector(newarr[i][j])); ! ! else if ( (( i<hrow-1 && j>hcol-1) && (!(fixedcol==0))) || ! (( i<hrow && j>hcol-1) && ((fixedcol==0))) ) ! table.addCell(applyStyleColumnHeader(newarr[i][j])); ! ! else if (i>hrow-1 && j<hcol && (!(newarr[i][j].equalsIgnoreCase("Totals")))) ! table.addCell(applyStyleRowHeader(newarr[i][j])); ! ! else if (i==hrow-1 && (!(fixedcol==0)) && (!(i==0)) ) ! table.addCell(applyStyleSeparator(" ")); ! ! else if ( ((fixedcol==0) && (i==hrow) && (j==hcol-1))|| ! ((fixedrow==0) && (j==hcol) && i==hrow-1) ) ! table.addCell(applyStyleTotal(newarr[i][j])); ! ! else if ((newarr[i][j]!=null)&&((i%2)==0)) ! table.addCell(applyStyleData(newarr[i][j])); ! ! else if ((newarr[i][j]!=null)&&((i%2)==1)) ! table.addCell(applyStyleDataAlt(newarr[i][j])); ! ! } ! } ! ! return table; ! } ! ! //#D9D9D9 nice gray ! private PdfPCell applyStyleColumnSelector(String str, int colspan){ ! //white bold times_roman font ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, Color.white)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setColspan(colspan); ! cell.setHorizontalAlignment( Element.ALIGN_RIGHT); ! cell.setBackgroundColor(new Color(0,102,204)); //#0066CC *blue*; ! return cell ; ! } ! ! private PdfPCell applyStyleRowSelector(String str){ ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, Color.white)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! cell.setBackgroundColor(new Color(102,153,255)); //#6699FF *bluish*; ! return cell ; ! } ! ! private PdfPCell applyStyleColumnHeader(String str){ ! //font bold color=#FFFFFF ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, new Color(255,255,255))); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! cell.setBackgroundColor(new Color(0,102,204)); // #0066CC *blue*; ! return cell ; ! } ! ! private PdfPCell applyStyleRowHeader(String str){ ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, Color.white)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! cell.setBackgroundColor(new Color(102,153,255)); // #6699FF *bluish*; ! return cell ; ! } ! ! private PdfPCell applyStyleSeparator(String str){ ! //font bold color=#CCCCCC ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, new Color(204,204,204))); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setBackgroundColor(new Color(153,153,153)); // 999999 *light gray*; ! return cell ; ! } ! ! private PdfPCell applyStyleTotal(String str){ ! //font bold color=#FFFFFF ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC, new Color(255,255,255))); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! cell.setBackgroundColor(new Color(0,0,102)); // #000066 *mint green*; ! return cell ; ! } ! ! private PdfPCell applyStyleData(String str){ ! //font bold color=#FFFFFF ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.NORMAL, Color.black)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! cell.setBackgroundColor(new Color(204,204,204)); // CCCCCC *white*; ! return cell ; ! } ! ! private PdfPCell applyStyleDataAlt(String str){ ! //font bold color=#FFFFFF ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.NORMAL, Color.black)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! cell.setBackgroundColor(new Color(204,204,255)); // #CCCCFF; ! return cell ; ! } ! ! ! /* ! //#D9D9D9 nice gray ! private PdfPCell applyStyleColumnSelector(String str, int colspan){ ! //white bold times_roman font ! // Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, Color.white)); ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC, Color.black)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setColspan(colspan); ! cell.setHorizontalAlignment( Element.ALIGN_RIGHT); ! //cell.setBackgroundColor(new Color(0,102,204)); //#0066CC *blue*; ! cell.setBackgroundColor(new Color(217,217,217)); // #D9D9D9 *gray*; ! cell.setBorder(Rectangle.RIGHT ); ! cell.setBorderWidth(2f); ! return cell ; ! } ! ! private PdfPCell applyStyleRowSelector(String str){ ! //Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, Color.white)); ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC, Color.black)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! //cell.setBackgroundColor(new Color(102,153,255)); //#6699FF *bluish*; ! cell.setBackgroundColor(new Color(217,217,217)); // #D9D9D9 *gray*; ! cell.setBorder(Rectangle.BOTTOM |Rectangle.RIGHT ); ! //cell.setBorder(Rectangle.RIGHT); ! cell.setBorderWidth(2f); ! return cell ; ! } ! ! private PdfPCell applyStyleColumnHeader(String str){ ! //font bold color=#FFFFFF ! //Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, new Color(255,255,255))); ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC, Color.black)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! //cell.setBackgroundColor(new Color(0,102,204)); // #0066CC *blue*; ! cell.setBackgroundColor(new Color(217,217,217)); // #D9D9D9 *gray*; ! cell.setBorder(Rectangle.NO_BORDER); ! ! return cell ; ! } ! ! private PdfPCell applyStyleRowHeader(String str){ ! //Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, Color.white)); ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC, Color.black)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! //cell.setBackgroundColor(new Color(102,153,255)); // #6699FF *bluish*; ! cell.setBackgroundColor(new Color(217,217,217)); // #D9D9D9 *gray*; ! cell.setBorder(Rectangle.RIGHT); ! cell.setBorderWidth(2f); ! return cell ; ! } ! ! private PdfPCell applyStyleSeparator(String str){ ! //font bold color=#CCCCCC ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD, new Color(204,204,204))); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! //cell.setBackgroundColor(new Color(153,153,153)); // 999999 *light gray*; ! cell.setBackgroundColor(new Color(217,217,217)); // #D9D9D9 *gray*; ! cell.setBorder(Rectangle.BOTTOM); ! cell.setBorderWidth(2f); ! return cell ; ! } ! ! private PdfPCell applyStyleTotal(String str){ ! //font bold color=#FFFFFF ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC, new Color(255,255,255))); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! cell.setBackgroundColor(new Color(0,0,102)); // #000066 *mint green*; ! cell.setBorder(Rectangle.NO_BORDER); ! return cell ; ! } ! ! private PdfPCell applyStyleData(String str){ ! //font bold color=#FFFFFF ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.NORMAL, Color.black)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! //cell.setBackgroundColor(new Color(204,204,204)); // CCCCCC *white*; ! cell.setBackgroundColor(new Color(217,217,217)); // #D9D9D9 *gray*; ! cell.setBorder(Rectangle.NO_BORDER); ! return cell ; ! } ! ! private PdfPCell applyStyleDataAlt(String str){ ! //font bold color=#FFFFFF ! Paragraph p = new Paragraph(str,FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.NORMAL, Color.black)); ! PdfPCell cell = new PdfPCell(new Paragraph(p)); ! cell.setHorizontalAlignment( Element.ALIGN_CENTER); ! //cell.setBackgroundColor(new Color(204,204,255)); // #CCCCFF; ! cell.setBorder(Rectangle.NO_BORDER); ! return cell ; ! } ! */ } ! /* Here's some documentation to understand this class: (X denotes empty cell) --- 319,355 ---- } ! private TableFormat getTableFormat(){ ! TableFormat t = null ; ! SupplementalItem sitem = currdefinition.getCrossTabDef().getRept().getSupplementalItem() ; ! if ((sitem!=null) && ! (sitem.getPdfConfigItem()!=null) && ! (sitem.getPdfConfigItem().getPdfFormatItem()!=null) ! ){ ! switch (sitem.getPdfConfigItem().getPdfFormatItem().getFormatTypeItem().intValue()){ ! case FormatTypeItem.INT_HTML: ! t = new HtmlFormat(); ! break; ! case FormatTypeItem.INT_CONTEMPORARY: ! t = new ContemporaryFormat(); ! break; ! case FormatTypeItem.INT_SIMPLE_GRID: ! t = new SimpleGridFormat(); ! break; ! case FormatTypeItem.INT_PLAIN: ! t = new PlainFormat(); ! break; ! default: ! t = new ContemporaryFormat(); ! break; ! } ! } ! else ! t = new ContemporaryFormat(); ! return t ; ! } ! } ! /*c Here's some documentation to understand this class: (X denotes empty cell) |