package kcg.faics.cmmn.excel;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/** 
 * ExcelStyle.java
 * @author 임새미 
 * @since 2016. 10. 14.
 *
 *  	 수정일                     수정자                                       수정내용
 *  -------------	--------	---------------------------
 *  2016. 10. 14. 	    임새미				       최초생성
 * 
 */
public class ExcelStyle {
	
	private XSSFFont normalFont;
	private XSSFFont boldFont;
	private XSSFFont titleFont;
	
	private XSSFColor yellowColor = new XSSFColor(new java.awt.Color(255, 255, 238));
	private XSSFColor grayColor = new XSSFColor(new java.awt.Color(238, 238, 238));
	private XSSFColor cyanColor = new XSSFColor(new java.awt.Color(238, 255, 255));

	private DataFormat numericFormat; 
	
	public XSSFCellStyle titleStyle;
	public XSSFCellStyle headerStyle;
	public XSSFCellStyle firstRowTextStyle;
	public XSSFCellStyle firstRowNumericStyle;
	public XSSFCellStyle normalTextStyle;
	public XSSFCellStyle normalLeftBoldTextStyle;
	public XSSFCellStyle normalNumericStyle;
	
	
	public ExcelStyle(XSSFWorkbook wb) {
		defindeStyle(wb);
	}
	
	private void defindeStyle(XSSFWorkbook wb) {
		
		numericFormat = wb.createDataFormat();
		
		titleStyle = (XSSFCellStyle) wb.createCellStyle();
		headerStyle = (XSSFCellStyle) wb.createCellStyle();
		firstRowTextStyle = (XSSFCellStyle) wb.createCellStyle();
		firstRowNumericStyle = (XSSFCellStyle) wb.createCellStyle();
		normalTextStyle = (XSSFCellStyle) wb.createCellStyle();
		normalLeftBoldTextStyle = (XSSFCellStyle) wb.createCellStyle();
		normalNumericStyle = (XSSFCellStyle) wb.createCellStyle();
		
		normalFont = (XSSFFont) wb.createFont();
		normalFont.setFontName("돋음");
		normalFont.setFontHeightInPoints((short) 9);
		normalFont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
		
		boldFont = (XSSFFont) wb.createFont();
		boldFont.setFontName("돋음");
		boldFont.setFontHeightInPoints((short) 9);
		boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		
		titleFont = (XSSFFont) wb.createFont();
		titleFont.setFontName("돋음");
		titleFont.setFontHeightInPoints((short) 12);
		titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		
		titleStyle.setFont(titleFont);
		titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		
		headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
		headerStyle.setFont(boldFont);
		headerStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		headerStyle.setBorderTop(BorderStyle.HAIR);
		headerStyle.setBorderLeft(BorderStyle.HAIR);
		headerStyle.setBorderRight(BorderStyle.HAIR);
		headerStyle.setBorderBottom(BorderStyle.HAIR);
		headerStyle.setFillForegroundColor(grayColor);
		headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
		
		firstRowTextStyle.setAlignment(CellStyle.ALIGN_CENTER);
		firstRowTextStyle.setFont(normalFont);
		firstRowTextStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		firstRowTextStyle.setBorderTop(BorderStyle.HAIR);
		firstRowTextStyle.setBorderLeft(BorderStyle.HAIR);
		firstRowTextStyle.setBorderRight(BorderStyle.HAIR);
		firstRowTextStyle.setBorderBottom(BorderStyle.HAIR);
		firstRowTextStyle.setFillForegroundColor(yellowColor);
		firstRowTextStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
		
		firstRowNumericStyle.setAlignment(CellStyle.ALIGN_CENTER);
		firstRowNumericStyle.setFont(normalFont);
		firstRowNumericStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		firstRowNumericStyle.setBorderTop(BorderStyle.HAIR);
		firstRowNumericStyle.setBorderLeft(BorderStyle.HAIR);
		firstRowNumericStyle.setBorderRight(BorderStyle.HAIR);
		firstRowNumericStyle.setBorderBottom(BorderStyle.HAIR);
		firstRowNumericStyle.setFillForegroundColor(yellowColor);
		firstRowNumericStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
		firstRowNumericStyle.setDataFormat(numericFormat.getFormat("#,###"));
		
		normalTextStyle.setAlignment(CellStyle.ALIGN_CENTER);
		normalTextStyle.setFont(normalFont);
		normalTextStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		normalTextStyle.setBorderTop(BorderStyle.HAIR);
		normalTextStyle.setBorderLeft(BorderStyle.HAIR);
		normalTextStyle.setBorderRight(BorderStyle.HAIR);
		normalTextStyle.setBorderBottom(BorderStyle.HAIR);
		
				
		normalNumericStyle.setAlignment(CellStyle.ALIGN_CENTER);
		normalNumericStyle.setFont(normalFont);
		normalNumericStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		normalNumericStyle.setBorderTop(BorderStyle.HAIR);
		normalNumericStyle.setBorderLeft(BorderStyle.HAIR);
		normalNumericStyle.setBorderRight(BorderStyle.HAIR);
		normalNumericStyle.setBorderBottom(BorderStyle.HAIR);
		normalNumericStyle.setDataFormat(numericFormat.getFormat("#,###"));
		
	}
	
}
