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.JRElement;
034: import net.sf.jasperreports.engine.JRGraphicElement;
035: import net.sf.jasperreports.engine.JRPrintGraphicElement;
036: import net.sf.jasperreports.engine.util.JRColorUtil;
037:
038: /**
039: * @author Teodor Danciu (teodord@users.sourceforge.net)
040: * @version $Id: GraphicStyle.java 1664 2007-03-26 09:48:03Z lucianc $
041: */
042: public class GraphicStyle extends Style {
043: /**
044: *
045: */
046: private String backcolor = null;
047: private String forecolor = null;
048: private String style = null;
049: private String width = null;
050:
051: /**
052: *
053: */
054: public GraphicStyle(Writer styleWriter,
055: JRPrintGraphicElement element) {
056: super (styleWriter);
057:
058: if (element.getMode() == JRElement.MODE_OPAQUE) {
059: //fill = "solid";
060: backcolor = JRColorUtil
061: .getColorHexa(element.getBackcolor());
062: } else {
063: //fill = "none";
064: }
065:
066: forecolor = JRColorUtil.getColorHexa(element.getForecolor());
067:
068: double doubleWidth = 0;
069:
070: switch (element.getPen()) {
071: case JRGraphicElement.PEN_DOTTED: {
072: style = "dash";
073: doubleWidth = 1;
074: break;
075: }
076: case JRGraphicElement.PEN_4_POINT: {
077: style = "solid";
078: doubleWidth = 4;
079: break;
080: }
081: case JRGraphicElement.PEN_2_POINT: {
082: style = "solid";
083: doubleWidth = 2;
084: break;
085: }
086: case JRGraphicElement.PEN_THIN: {
087: style = "solid";
088: doubleWidth = 0.5f;
089: break;
090: }
091: case JRGraphicElement.PEN_NONE: {
092: style = "none";
093: break;
094: }
095: case JRGraphicElement.PEN_1_POINT:
096: default: {
097: style = "solid";
098: doubleWidth = 1;
099: break;
100: }
101: }
102:
103: width = String.valueOf(Utility
104: .translatePixelsToInchesWithNoRoundOff(doubleWidth));
105: }
106:
107: /**
108: *
109: */
110: public String getId() {
111: //return fill + "|" + backcolor
112: StringBuffer id = new StringBuffer();
113: id.append(backcolor);
114: id.append("|");
115: id.append(forecolor);
116: id.append("|");
117: id.append(style);
118: id.append("|");
119: id.append(width);
120: return id.toString();
121: }
122:
123: /**
124: *
125: */
126: public void write(String lineStyleName) throws IOException {
127: styleWriter.write(" <style:style style:name=\"" + lineStyleName
128: + "\"");
129: styleWriter.write(" style:family=\"graphic\">\n");
130: styleWriter.write(" <style:graphic-properties");
131: styleWriter.write(" draw:fill-color=\"#" + backcolor + "\"");
132: styleWriter.write(" svg:stroke-color=\"#" + forecolor + "\"");
133: styleWriter.write(" draw:stroke=\"" + style + "\"");
134: styleWriter.write(" draw:stroke-dash=\"Dashed\"");
135: styleWriter.write(" svg:stroke-width=\"" + width + "in\"");
136: styleWriter.write("/>\n");
137: styleWriter.write("</style:style>\n");
138: }
139:
140: }
|