1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.io.IOException ; 31 32 import net.sf.jasperreports.engine.JRAbstractObjectFactory; 33 import net.sf.jasperreports.engine.JRChild; 34 import net.sf.jasperreports.engine.JRException; 35 import net.sf.jasperreports.engine.JRExpressionCollector; 36 import net.sf.jasperreports.engine.JRPrintElement; 37 import net.sf.jasperreports.engine.JRPrintText; 38 import net.sf.jasperreports.engine.JRStaticText; 39 import net.sf.jasperreports.engine.JRStyle; 40 import net.sf.jasperreports.engine.xml.JRXmlWriter; 41 42 43 47 public class JRFillStaticText extends JRFillTextElement implements JRStaticText 48 { 49 50 51 54 protected JRFillStaticText( 55 JRBaseFiller filler, 56 JRStaticText staticText, 57 JRFillObjectFactory factory 58 ) 59 { 60 super(filler, staticText, factory); 61 62 String text = staticText.getText(); 64 if (text == null) 65 { 66 text = ""; 67 } 68 setRawText(text); 69 } 70 71 72 protected JRFillStaticText(JRFillStaticText staticText, JRFillCloneFactory factory) 73 { 74 super(staticText, factory); 75 76 String text = staticText.getText(); 78 if (text == null) 79 { 80 text = ""; 81 } 82 setRawText(text); 83 } 84 85 86 89 public void setText(String text) 90 { 91 } 92 93 94 97 protected JRTemplateText getJRTemplateText() 98 { 99 JRStyle style = getStyle(); 100 JRTemplateText template = (JRTemplateText) getTemplate(style); 101 if (template == null) 102 { 103 template = new JRTemplateText(filler.getJasperPrint().getDefaultStyleProvider(), this); 104 registerTemplate(style, template); 105 } 106 return template; 107 } 108 109 110 113 protected void evaluate( 114 byte evaluation 115 ) throws JRException 116 { 117 reset(); 118 119 evaluatePrintWhenExpression(evaluation); 120 121 setTextStart(0); 122 setTextEnd(0); 123 124 setValueRepeating(true); 125 } 126 127 128 131 protected boolean prepare( 132 int availableStretchHeight, 133 boolean isOverflow 134 ) throws JRException 135 { 136 boolean willOverflow = false; 137 138 super.prepare(availableStretchHeight, isOverflow); 139 140 if (!isToPrint()) 141 { 142 return willOverflow; 143 } 144 145 boolean isToPrint = true; 146 boolean isReprinted = false; 147 148 if (isOverflow && isAlreadyPrinted() && !isPrintWhenDetailOverflows()) 149 { 150 isToPrint = false; 151 } 152 153 if ( 154 isToPrint && 155 isPrintWhenExpressionNull() && 156 !isPrintRepeatedValues() 157 ) 158 { 159 if ( 160 ( !isPrintInFirstWholeBand() || !getBand().isFirstWholeOnPageColumn()) && 161 ( getPrintWhenGroupChanges() == null || !getBand().isNewGroup(getPrintWhenGroupChanges()) ) && 162 ( !isOverflow || !isPrintWhenDetailOverflows() ) 163 ) 164 { 165 isToPrint = false; 166 } 167 } 168 169 if ( 170 isToPrint && 171 availableStretchHeight < getRelativeY() - getY() - getBandBottomY() 172 ) 173 { 174 isToPrint = false; 175 willOverflow = true; 176 } 177 178 if ( 179 isToPrint && 180 isOverflow && 181 (isPrintWhenDetailOverflows() && (isAlreadyPrinted() || (!isAlreadyPrinted() && !isPrintRepeatedValues()))) 183 ) 184 { 185 isReprinted = true; 186 } 187 188 setTextStart(0); 189 setTextEnd(0); 190 191 if (isToPrint) 192 { 193 chopTextElement(0); 194 } 195 196 setToPrint(isToPrint); 197 setReprinted(isReprinted); 198 199 return willOverflow; 200 } 201 202 203 206 protected JRPrintElement fill() 207 { 208 JRPrintText text = null; 209 210 text = new JRTemplatePrintText(getJRTemplateText()); 211 text.setX(getX()); 212 text.setY(getRelativeY()); 213 text.setWidth(getWidth()); 214 if (getRotation() == ROTATION_NONE) 215 { 216 text.setHeight(getStretchHeight()); 217 } 218 else 219 { 220 text.setHeight(getHeight()); 221 } 222 text.setRunDirection(getRunDirection()); 223 text.setLineSpacingFactor(getLineSpacingFactor()); 224 text.setLeadingOffset(getLeadingOffset()); 225 text.setTextHeight(getTextHeight()); 226 227 text.setText(textChopper.chop(this, getTextStart(), getTextEnd())); 229 230 return text; 231 } 232 233 234 237 public JRChild getCopy(JRAbstractObjectFactory factory) 238 { 239 return factory.getStaticText(this); 240 } 241 242 245 public void collectExpressions(JRExpressionCollector collector) 246 { 247 collector.collect(this); 248 } 249 250 253 public void writeXml(JRXmlWriter xmlWriter) throws IOException 254 { 255 xmlWriter.writeStaticText(this); 256 } 257 258 259 protected void resolveElement (JRPrintElement element, byte evaluation) 260 { 261 } 263 264 265 public JRCloneable createClone(JRFillCloneFactory factory) 266 { 267 return new JRFillStaticText(this, factory); 268 } 269 270 } 271 | Popular Tags |