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.awt.Color;
031: import java.io.IOException;
032: import java.io.Writer;
033:
034: import net.sf.jasperreports.engine.JRBox;
035: import net.sf.jasperreports.engine.JRGraphicElement;
036: import net.sf.jasperreports.engine.JRPrintElement;
037: import net.sf.jasperreports.engine.util.JRColorUtil;
038:
039: /**
040: * @author Teodor Danciu (teodord@users.sourceforge.net)
041: * @version $Id: BorderStyle.java 1664 2007-03-26 09:48:03Z lucianc $
042: */
043: public abstract class BorderStyle extends Style {
044: /**
045: *
046: */
047: private static final String[] border = new String[] { "top",
048: "left", "bottom", "right" };
049: protected static final int TOP_BORDER = 0;
050: protected static final int LEFT_BORDER = 1;
051: protected static final int BOTTOM_BORDER = 2;
052: protected static final int RIGHT_BORDER = 3;
053:
054: protected JRPrintElement element = null;
055:
056: private String[] borderColor = new String[4];
057: private String[] borderWidth = new String[4];
058: private String[] borderStyle = new String[4];
059: private String[] borderPadding = new String[4];
060:
061: /**
062: *
063: */
064: public BorderStyle(Writer styleWriter, JRPrintElement element) {
065: super (styleWriter);
066:
067: this .element = element;
068: }
069:
070: /**
071: *
072: */
073: public void setBox(JRBox box) throws IOException {
074: if (box != null) {
075: appendBorder(box.getTopBorder(),
076: box.getTopBorderColor() == null ? element
077: .getForecolor() : box.getTopBorderColor(),
078: box.getTopPadding(), TOP_BORDER);
079: appendBorder(box.getLeftBorder(),
080: box.getLeftBorderColor() == null ? element
081: .getForecolor() : box.getLeftBorderColor(),
082: box.getLeftPadding(), LEFT_BORDER);
083: appendBorder(box.getBottomBorder(), box
084: .getBottomBorderColor() == null ? element
085: .getForecolor() : box.getBottomBorderColor(), box
086: .getBottomPadding(), BOTTOM_BORDER);
087: appendBorder(box.getRightBorder(), box
088: .getRightBorderColor() == null ? element
089: .getForecolor() : box.getRightBorderColor(), box
090: .getRightPadding(), RIGHT_BORDER);
091: }
092: }
093:
094: /**
095: *
096: */
097: public String getId() {
098: return borderWidth[TOP_BORDER] + "|" + borderColor[TOP_BORDER]
099: + "|" + borderStyle[TOP_BORDER] + "|"
100: + borderPadding[TOP_BORDER] + "|"
101: + borderWidth[LEFT_BORDER] + "|"
102: + borderColor[LEFT_BORDER] + "|"
103: + borderStyle[LEFT_BORDER] + "|"
104: + borderPadding[LEFT_BORDER] + "|"
105: + borderWidth[BOTTOM_BORDER] + "|"
106: + borderColor[BOTTOM_BORDER] + "|"
107: + borderStyle[BOTTOM_BORDER] + "|"
108: + borderPadding[BOTTOM_BORDER] + "|"
109: + borderWidth[RIGHT_BORDER] + "|"
110: + borderColor[RIGHT_BORDER] + "|"
111: + borderStyle[RIGHT_BORDER] + "|"
112: + borderPadding[RIGHT_BORDER];
113: }
114:
115: /**
116: *
117: */
118: protected void writeBorder(int side) throws IOException {
119: if (borderWidth[side] != null) {
120: styleWriter.write(" fo:border-");
121: styleWriter.write(border[side]);
122: styleWriter.write("=\"");
123: styleWriter.write(borderWidth[side]);
124: styleWriter.write("in ");
125: styleWriter.write(borderStyle[side]);
126: styleWriter.write(" #");
127: styleWriter.write(borderColor[side]);
128: styleWriter.write("\"");
129: }
130:
131: if (borderPadding[side] != null) {
132: styleWriter.write(" fo:padding-");
133: styleWriter.write(border[side]);
134: styleWriter.write("=\"");
135: styleWriter.write(borderPadding[side]);
136: styleWriter.write("\"");
137: }
138: }
139:
140: /**
141: *
142: */
143: private void appendBorder(byte pen, Color color, int padding,
144: int side) throws IOException {
145: String style = null;
146: double width = 0;
147:
148: switch (pen) {
149: case JRGraphicElement.PEN_DOTTED: {
150: style = "dashed";
151: width = 1;
152: break;
153: }
154: case JRGraphicElement.PEN_4_POINT: {
155: style = "solid";
156: width = 4;
157: break;
158: }
159: case JRGraphicElement.PEN_2_POINT: {
160: style = "solid";
161: width = 2;
162: break;
163: }
164: case JRGraphicElement.PEN_THIN: {
165: style = "solid";
166: width = 0.5;
167: break;
168: }
169: case JRGraphicElement.PEN_NONE: {
170: style = "none";
171: break;
172: }
173: case JRGraphicElement.PEN_1_POINT:
174: default: {
175: style = "solid";
176: width = 1;
177: break;
178: }
179: }
180:
181: borderStyle[side] = style;
182: borderWidth[side] = String.valueOf(Utility
183: .translatePixelsToInchesWithNoRoundOff(width));
184: borderColor[side] = JRColorUtil.getColorHexa(color);
185: borderPadding[side] = String.valueOf(Utility
186: .translatePixelsToInchesWithNoRoundOff(padding));
187: }
188:
189: }
|