|
From: Rashmi B. <ra...@us...> - 2005-04-26 17:34:24
|
Update of /cvsroot/pocolap/pocolap/src/com/pocolap/xtab/format In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22129 Added Files: ContemporaryFormat.java HtmlFormat.java PlainFormat.java SimpleGridFormat.java TableFormat.java Log Message: PDF related changes --- NEW FILE: TableFormat.java --- /* * Created on Apr 14, 2005 by Rashmi Banthia * Copyright (c) 2005 Rashmi Banthia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.pocolap.xtab.format ; import org.apache.log4j.Logger ; import com.lowagie.text.pdf.PdfPTable ; import com.lowagie.text.Rectangle; import com.lowagie.text.PageSize ; import com.pocolap.xtab.layout.SpreadSheet; public class TableFormat { static Logger logger = Logger.getLogger(TableFormat.class); public TableFormat(){} public Rectangle getPageSize(){ Rectangle psize = PageSize.A4.rotate(); //psize.setBackgroundColor(new java.awt.Color(204, 204, 255)); return psize ; } public PdfPTable formatTable(String[][] harr,String[][] newarr, SpreadSheet sheet){ return null ; } } --- NEW FILE: SimpleGridFormat.java --- /* * Created on Apr 14, 2005 by Rashmi Banthia * Copyright (c) 2005 Rashmi Banthia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.pocolap.xtab.format ; import org.apache.log4j.Logger ; import com.lowagie.text.pdf.PdfPTable ; import com.lowagie.text.pdf.PdfPCell ; import com.pocolap.xtab.layout.SpreadSheet; import java.awt.Color; import com.lowagie.text.Paragraph ; import com.lowagie.text.FontFactory; import com.lowagie.text.Element ; import com.lowagie.text.Font ; import com.lowagie.text.Rectangle; import com.lowagie.text.PageSize ; public class SimpleGridFormat extends TableFormat { static Logger logger = Logger.getLogger(SimpleGridFormat.class); public PdfPTable formatTable(String[][] harr,String[][] newarr, SpreadSheet sheet){ 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.setHorizontalAlignment(Element.ALIGN_LEFT) ; // Default is center for (int i=0;i<rows;i++){ for (int j=0;j<cols;j++){ if ((i<hrow) && (j<hcol)){ //Row/Column Selectors if (fixedcol==0){ if (i==hrow-1) table.addCell(applyStyleLastRowSelector(newarr[i][j])); else table.addCell(applyStyleRowSelector(newarr[i][j],hcol)); } else { if (fixedrow==0){ if (j==hcol-1) table.addCell(applyStyleLastColSelector(newarr[i][j])); else table.addCell(applyStyleColSelector(newarr[i][j])); } else { if ((j==hcol-1)&&(i!=hrow-1)) table.addCell(applyStyleRowSelector(newarr[i][j],hcol)); if (i==hrow-1){ if (j==hcol-1) table.addCell(applyStyleLastColSelector(newarr[i][j])); else table.addCell(applyStyleColSelector(newarr[i][j])); } } } } else { if ((i>=hrow) && (j<hcol)) //Column Headers { if (j==hcol-1){ if ((i%2)==0) table.addCell(applyStyleLastColumnHeader(newarr[i][j])); else table.addCell(applyStyleLastColumnHeaderAlt(newarr[i][j])); } else{ if ((i%2)==0) table.addCell(applyStyleColumnHeader(newarr[i][j])); else table.addCell(applyStyleColumnHeaderAlt(newarr[i][j])); } } else { if ((i<hrow) && (j>=hcol)) //Row Headers { if (i==hrow-1) table.addCell(applyStyleLastRowHeader(newarr[i][j])); else table.addCell(applyStyleRowHeader(newarr[i][j])); } else { //Data cells if ((i%2)==0) table.addCell(applyStyleData(newarr[i][j])); else table.addCell(applyStyleDataAlt(newarr[i][j])); } } } } } return table; } 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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(0.3f); border.setBorderWidthRight(0.3f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleRowSelector(String str, int colspan){ 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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(0.3f); border.setBorderWidthRight(2f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleLastRowSelector(String str){ 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_RIGHT); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(2f); border.setBorderWidthRight(2f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleColSelector(String str){ 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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(2f); border.setBorderWidthRight(0.3f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleLastColSelector(String str){ 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_RIGHT); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(2f); border.setBorderWidthRight(2f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleColumnHeader(String str){ //font bold color=#FFFFFF 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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(0.3f); border.setBorderWidthRight(0.3f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleColumnHeaderAlt(String str){ //font bold color=#FFFFFF 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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(0.3f); border.setBorderWidthRight(0.3f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleLastColumnHeaderAlt(String str){ //font bold color=#FFFFFF 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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(0.3f); border.setBorderWidthRight(2f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleLastColumnHeader(String str){ //font bold color=#FFFFFF 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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(0.3f); border.setBorderWidthRight(2f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleRowHeader(String str){ 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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(0.3f); border.setBorderWidthRight(0.3f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } private PdfPCell applyStyleLastRowHeader(String str){ 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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(2f); border.setBorderWidthRight(0.3f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(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); Rectangle border = new Rectangle(0f,0f); border.setBorderWidthLeft(0.3f); border.setBorderWidthBottom(0.3f); border.setBorderWidthRight(0.3f); border.setBorderWidthTop(0.3f); border.setBorderColor(Color.BLACK); cell.cloneNonPositionParameters(border); return cell ; } } --- NEW FILE: HtmlFormat.java --- /* * Created on Apr 14, 2005 by Rashmi Banthia * Copyright (c) 2005 Rashmi Banthia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.pocolap.xtab.format ; import org.apache.log4j.Logger ; import com.lowagie.text.pdf.PdfPTable ; import com.lowagie.text.pdf.PdfPCell ; import com.pocolap.xtab.layout.SpreadSheet; import java.awt.Color; import com.lowagie.text.Paragraph ; import com.lowagie.text.FontFactory; import com.lowagie.text.Element ; import com.lowagie.text.Font ; import com.lowagie.text.Rectangle ; import com.lowagie.text.PageSize ; public class HtmlFormat extends TableFormat { static Logger logger = Logger.getLogger(HtmlFormat.class); public Rectangle getPageSize(){ Rectangle psize = PageSize.A4.rotate(); psize.setBackgroundColor(new java.awt.Color(204, 204, 255)); return psize ; } public PdfPTable formatTable(String[][] harr,String[][] newarr, SpreadSheet sheet){ 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.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 ; } } --- NEW FILE: ContemporaryFormat.java --- /* * Created on Apr 14, 2005 by Rashmi Banthia * Copyright (c) 2005 Rashmi Banthia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.pocolap.xtab.format ; import org.apache.log4j.Logger ; import com.lowagie.text.pdf.PdfPTable ; import com.lowagie.text.pdf.PdfPCell ; import com.pocolap.xtab.layout.SpreadSheet; import java.awt.Color; import com.lowagie.text.Paragraph ; import com.lowagie.text.FontFactory; import com.lowagie.text.Element ; import com.lowagie.text.Font ; import com.lowagie.text.Rectangle; import com.lowagie.text.PageSize ; public class ContemporaryFormat extends TableFormat { static Logger logger = Logger.getLogger(ContemporaryFormat.class); public PdfPTable formatTable(String[][] harr,String[][] newarr, SpreadSheet sheet){ 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.setHorizontalAlignment(Element.ALIGN_LEFT) ; // Default is center for (int i=0;i<rows;i++){ for (int j=0;j<cols;j++){ if ((i<hrow) && (j<hcol)){ //Row/Column Selectors if (fixedcol==0){ if (i==hrow-1) table.addCell(applyStyleLastRowSelector(newarr[i][j])); else table.addCell(applyStyleRowSelector(newarr[i][j],hcol)); } else { if (fixedrow==0){ if (j==hcol-1) table.addCell(applyStyleLastColSelector(newarr[i][j])); else table.addCell(applyStyleColSelector(newarr[i][j])); } else { if ((j==hcol-1)&&(i!=hrow-1)) table.addCell(applyStyleRowSelector(newarr[i][j],hcol)); if (i==hrow-1){ if (j==hcol-1) table.addCell(applyStyleLastColSelector(newarr[i][j])); else table.addCell(applyStyleColSelector(newarr[i][j])); } } } } else { if ((i>=hrow) && (j<hcol)) //Column Headers { if (j==hcol-1){ if ((i%2)==0) table.addCell(applyStyleLastColumnHeader(newarr[i][j])); else table.addCell(applyStyleLastColumnHeaderAlt(newarr[i][j])); } else{ if ((i%2)==0) table.addCell(applyStyleColumnHeader(newarr[i][j])); else table.addCell(applyStyleColumnHeaderAlt(newarr[i][j])); } } else { if ((i<hrow) && (j>=hcol)) //Row Headers { if (i==hrow-1) table.addCell(applyStyleLastRowHeader(newarr[i][j])); else table.addCell(applyStyleRowHeader(newarr[i][j])); } else { //Data cells if ((i%2)==0) table.addCell(applyStyleData(newarr[i][j])); else table.addCell(applyStyleDataAlt(newarr[i][j])); } } } } } return table; } 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(217,217,217)); // #D9D9D9 *gray*; cell.setBorder(Rectangle.NO_BORDER); return cell ; } private PdfPCell applyStyleRowSelector(String str, int colspan){ 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(217,217,217)); // #D9D9D9 *gray*; cell.setBorder(Rectangle.RIGHT ); cell.setBorderWidth(2f); return cell ; } private PdfPCell applyStyleLastRowSelector(String str){ 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_RIGHT); cell.setBackgroundColor(new Color(217,217,217)); // #D9D9D9 *gray*; cell.setBorder(Rectangle.BOTTOM |Rectangle.RIGHT ); cell.setBorderWidth(2f); return cell ; } private PdfPCell applyStyleColSelector(String str){ 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_CENTER); cell.setBackgroundColor(new Color(217,217,217)); // #D9D9D9 *gray*; cell.setBorder(Rectangle.BOTTOM ); cell.setBorderWidth(2f); return cell ; } private PdfPCell applyStyleLastColSelector(String str){ 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(217,217,217)); // #D9D9D9 *gray*; cell.setBorder(Rectangle.BOTTOM | 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.BOLDITALIC, Color.black)); PdfPCell cell = new PdfPCell(new Paragraph(p)); cell.setHorizontalAlignment( Element.ALIGN_CENTER); cell.setBackgroundColor(new Color(217,217,217)); // #D9D9D9 *gray*; cell.setBorder(Rectangle.NO_BORDER); return cell ; } private PdfPCell applyStyleColumnHeaderAlt(String str){ //font bold color=#FFFFFF 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.setBorder(Rectangle.NO_BORDER); return cell ; } private PdfPCell applyStyleLastColumnHeaderAlt(String str){ //font bold color=#FFFFFF 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.setBorder(Rectangle.RIGHT); cell.setBorderWidth(2f); return cell ; } private PdfPCell applyStyleLastColumnHeader(String str){ //font bold color=#FFFFFF 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(217,217,217)); // #D9D9D9 *gray*; cell.setBorder(Rectangle.RIGHT); cell.setBorderWidth(2f); return cell ; } private PdfPCell applyStyleRowHeader(String str){ 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(217,217,217)); // #D9D9D9 *gray*; cell.setBorder(Rectangle.NO_BORDER); return cell ; } private PdfPCell applyStyleLastRowHeader(String str){ 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(217,217,217)); // #D9D9D9 *gray*; cell.setBorder(Rectangle.BOTTOM ); cell.setBorderWidth(2f); 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.setBorder(Rectangle.NO_BORDER); return cell ; } } --- NEW FILE: PlainFormat.java --- /* * Created on Apr 14, 2005 by Rashmi Banthia * Copyright (c) 2005 Rashmi Banthia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.pocolap.xtab.format ; import org.apache.log4j.Logger ; import com.lowagie.text.pdf.PdfPTable ; import com.lowagie.text.pdf.PdfPCell ; import com.pocolap.xtab.layout.SpreadSheet; import java.awt.Color; import com.lowagie.text.Paragraph ; import com.lowagie.text.FontFactory; import com.lowagie.text.Element ; import com.lowagie.text.Font ; public class PlainFormat extends TableFormat { static Logger logger = Logger.getLogger(PlainFormat.class); public PdfPTable formatTable(String[][] harr,String[][] newarr, SpreadSheet sheet){ 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.setHorizontalAlignment(Element.ALIGN_LEFT) ; // Default is center for (int i=0;i<rows;i++){ for (int j=0;j<cols;j++){ table.addCell(applyStyleData(newarr[i][j])); } } return table; } private PdfPCell applyStyleData(String str){ 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); return cell ; } } |