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.JRPrintText;
035:
036: /**
037: * @author Teodor Danciu (teodord@users.sourceforge.net)
038: * @version $Id: ParagraphStyle.java 1664 2007-03-26 09:48:03Z lucianc $
039: */
040: public class ParagraphStyle extends Style {
041: /**
042: *
043: */
044: protected static final String HORIZONTAL_ALIGN_LEFT = "start";
045: protected static final String HORIZONTAL_ALIGN_RIGHT = "end";
046: protected static final String HORIZONTAL_ALIGN_CENTER = "center";
047: protected static final String HORIZONTAL_ALIGN_JUSTIFY = "justified";
048:
049: /**
050: *
051: */
052: private static final String VERTICAL_ALIGN_TOP = "top";
053: private static final String VERTICAL_ALIGN_MIDDLE = "middle";
054: private static final String VERTICAL_ALIGN_BOTTOM = "bottom";
055:
056: private String verticalAlignment = null;
057: private String horizontalAlignment = null;
058: private String runDirection = null;
059:
060: /**
061: *
062: */
063: public ParagraphStyle(Writer styleWriter, JRPrintText text) {
064: super (styleWriter);
065:
066: verticalAlignment = VERTICAL_ALIGN_TOP;
067: switch (text.getVerticalAlignment()) {
068: case JRAlignment.VERTICAL_ALIGN_BOTTOM: {
069: verticalAlignment = VERTICAL_ALIGN_BOTTOM;
070: break;
071: }
072: case JRAlignment.VERTICAL_ALIGN_MIDDLE: {
073: verticalAlignment = VERTICAL_ALIGN_MIDDLE;
074: break;
075: }
076: case JRAlignment.VERTICAL_ALIGN_TOP:
077: default: {
078: verticalAlignment = VERTICAL_ALIGN_TOP;
079: }
080: }
081:
082: horizontalAlignment = HORIZONTAL_ALIGN_LEFT;
083: switch (text.getHorizontalAlignment()) {
084: case JRAlignment.HORIZONTAL_ALIGN_RIGHT: {
085: horizontalAlignment = HORIZONTAL_ALIGN_RIGHT;
086: break;
087: }
088: case JRAlignment.HORIZONTAL_ALIGN_CENTER: {
089: horizontalAlignment = HORIZONTAL_ALIGN_CENTER;
090: break;
091: }
092: case JRAlignment.HORIZONTAL_ALIGN_JUSTIFIED: {
093: horizontalAlignment = HORIZONTAL_ALIGN_JUSTIFY;
094: break;
095: }
096: case JRAlignment.HORIZONTAL_ALIGN_LEFT:
097: default: {
098: horizontalAlignment = HORIZONTAL_ALIGN_LEFT;
099: }
100: }
101:
102: runDirection = null;
103: if (text.getRunDirection() == JRPrintText.RUN_DIRECTION_RTL) {
104: runDirection = "rl";
105: }
106: }
107:
108: /**
109: *
110: */
111: public String getId() {
112: return verticalAlignment + "|" + horizontalAlignment + "|"
113: + runDirection;
114: }
115:
116: /**
117: *
118: */
119: public void write(String paragraphStyleName) throws IOException {
120: styleWriter.write("<style:style style:name=\""
121: + paragraphStyleName + "\"");
122: styleWriter.write(" style:family=\"paragraph\">\n");
123: styleWriter.write("<style:paragraph-properties");
124: // styleWriter.write(" fo:line-height=\"" + pLineHeight + "\"");
125: // styleWriter.write(" style:line-spacing=\"" + pLineSpacing + "\"");
126: styleWriter.write(" fo:text-align=\"" + horizontalAlignment
127: + "\"");
128: // styleWriter.write(" fo:keep-together=\"" + pKeepTogether + "\"");
129: // styleWriter.write(" fo:margin-left=\"" + pMarginLeft + "\"");
130: // styleWriter.write(" fo:margin-right=\"" + pMarginRight + "\"");
131: // styleWriter.write(" fo:margin-top=\"" + pMarginTop + "\"");
132: // styleWriter.write(" fo:margin-bottom=\"" + pMarginBottom + "\"");
133: // styleWriter.write(" fo:background-color=\"#" + pBackGroundColor + "\"");
134: styleWriter.write(" style:vertical-align=\""
135: + verticalAlignment + "\"");
136: if (runDirection != null) {
137: styleWriter.write(" style:writing-mode=\"" + runDirection
138: + "\"");
139: }
140: styleWriter.write("> \r\n");
141: styleWriter.write("</style:paragraph-properties>\n");
142: styleWriter.write("</style:style>\n");
143: }
144:
145: }
|