001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.export.oasis;
029:
030: import java.io.IOException;
031: import java.io.Writer;
032:
033: import net.sf.jasperreports.engine.JRAlignment;
034: import net.sf.jasperreports.engine.JRElement;
035: import net.sf.jasperreports.engine.JRPrintElement;
036: import net.sf.jasperreports.engine.util.JRColorUtil;
037:
038: /**
039: * @author Teodor Danciu (teodord@users.sourceforge.net)
040: * @version $Id: CellStyle.java 1664 2007-03-26 09:48:03Z lucianc $
041: */
042: public class CellStyle extends BorderStyle {
043: /**
044: *
045: */
046: private static final String VERTICAL_ALIGN_TOP = "top";
047: private static final String VERTICAL_ALIGN_MIDDLE = "middle";
048: private static final String VERTICAL_ALIGN_BOTTOM = "bottom";
049:
050: //private String fill = null;
051: private String backcolor = null;
052:
053: private String verticalAlignment = null;
054:
055: /**
056: *
057: */
058: public CellStyle(Writer styleWriter, JRPrintElement element) {
059: super (styleWriter, element);
060:
061: if (element.getMode() == JRElement.MODE_OPAQUE) {
062: //fill = "solid";
063: backcolor = JRColorUtil
064: .getColorHexa(element.getBackcolor());
065: } else {
066: //fill = "none";
067: }
068:
069: if (element instanceof JRAlignment) {
070: switch (((JRAlignment) element).getVerticalAlignment()) {
071: case JRAlignment.VERTICAL_ALIGN_BOTTOM: {
072: verticalAlignment = VERTICAL_ALIGN_BOTTOM;
073: break;
074: }
075: case JRAlignment.VERTICAL_ALIGN_MIDDLE: {
076: verticalAlignment = VERTICAL_ALIGN_MIDDLE;
077: break;
078: }
079: case JRAlignment.VERTICAL_ALIGN_TOP:
080: default: {
081: verticalAlignment = VERTICAL_ALIGN_TOP;
082: }
083: }
084: }
085: }
086:
087: /**
088: *
089: */
090: public String getId() {
091: return backcolor
092: + super .getId()
093: + (verticalAlignment != null ? "" : "|"
094: + verticalAlignment);
095: }
096:
097: /**
098: *
099: */
100: public void write(String cellStyleName) throws IOException {
101: styleWriter.write("<style:style style:name=\"");
102: styleWriter.write(cellStyleName);
103: styleWriter.write("\"");
104: styleWriter.write(" style:family=\"table-cell\">\n");
105: styleWriter.write(" <style:table-cell-properties");
106: styleWriter.write(" fo:wrap-option=\"wrap\"");
107: styleWriter.write(" style:shrink-to-fit=\"false\"");
108: if (backcolor != null) {
109: styleWriter.write(" fo:background-color=\"#");
110: styleWriter.write(backcolor);
111: styleWriter.write("\"");
112: }
113:
114: writeBorder(TOP_BORDER);
115: writeBorder(LEFT_BORDER);
116: writeBorder(BOTTOM_BORDER);
117: writeBorder(RIGHT_BORDER);
118:
119: if (verticalAlignment != null) {
120: styleWriter.write(" style:vertical-align=\"");
121: styleWriter.write(verticalAlignment);
122: styleWriter.write("\"");
123: }
124:
125: styleWriter.write("/>\n");
126: styleWriter.write("</style:style>\n");
127: }
128:
129: }
|