@Override public JRPrintElement convert(ReportConverter reportConverter, JRElement element) { JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider()); JRChart chart = (JRChart)element; copyElement(reportConverter, chart, printImage); printImage.copyBox(chart.getLineBox()); printImage.setAnchorName(JRExpressionUtil.getExpressionText(chart.getAnchorNameExpression())); printImage.setBookmarkLevel(chart.getBookmarkLevel()); printImage.setLinkType(chart.getLinkType()); printImage.setOnErrorType(OnErrorTypeEnum.ICON); printImage.setRenderer(getRenderer(reportConverter, chart)); printImage.setScaleImage(ScaleImageEnum.CLIP); return printImage; }
/** * */ public JRPrintElement convert(ReportConverter reportConverter, JRElement element) { JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider()); JRChart chart = (JRChart) element; copyElement(reportConverter, chart, printImage); printImage.copyBox(chart.getLineBox()); printImage.setAnchorName(JRExpressionUtil.getExpressionText(chart.getAnchorNameExpression())); printImage.setBookmarkLevel(chart.getBookmarkLevel()); printImage.setLinkType(chart.getLinkType()); printImage.setOnErrorType(OnErrorTypeEnum.ICON); printImage.setRenderable(getRenderer(reportConverter, chart)); printImage.setScaleImage(ScaleImageEnum.CLIP); return printImage; }
/** * */ public JRPrintElement convert(final ReportConverter reportConverter, final JRElement element) { JRImage image = (JRImage) element; JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider()); Renderable cacheRenderer = getRenderable(reportConverter, element, image, printImage); copyGraphicElement(reportConverter, image, printImage); printImage.copyBox(image.getLineBox()); printImage.setAnchorName(JRExpressionUtil.getExpressionText(image.getAnchorNameExpression())); printImage.setBookmarkLevel(image.getBookmarkLevel()); printImage.setHorizontalAlignment(image.getOwnHorizontalAlignmentValue()); printImage.setLazy(image.isLazy()); printImage.setLinkType(image.getLinkType()); printImage.setOnErrorType(OnErrorTypeEnum.ICON); printImage.setVerticalAlignment(image.getOwnVerticalAlignmentValue()); if (cacheRenderer == null) cacheRenderer = getRenderableNoImage(reportConverter.getJasperReportsContext(), image, printImage); printImage.setRenderable(cacheRenderer); printImage.setScaleImage(image.getOwnScaleImageValue()); return printImage; }
/** * */ public JRPrintElement convert(final ReportConverter reportConverter, final JRComponentElement element) { MapComponent map = (MapComponent) element.getComponent(); JRBasePrintImage printImage = new JRBasePrintImage(element.getDefaultStyleProvider()); Renderable cacheRenderer = getRenderable(reportConverter, element, map, printImage); printImage.setUUID(element.getUUID()); printImage.setX(element.getX()); printImage.setY(element.getY()); printImage.setWidth(element.getWidth()); printImage.setHeight(element.getHeight()); printImage.setStyle(element.getStyle()); printImage.setMode(element.getModeValue()); printImage.setBackcolor(element.getBackcolor()); printImage.setForecolor(element.getForecolor()); printImage.setLazy(false); // FIXMEMAP there are no scale image, alignment and onError attributes // defined for the map element printImage.setScaleImage(ScaleImageEnum.CLIP); printImage.setHorizontalAlignment(HorizontalAlignEnum.LEFT); printImage.setVerticalAlignment(VerticalAlignEnum.TOP); printImage.setRenderable(cacheRenderer); return printImage; }
/** * Return the content for an MImage element * * @param reportConverter the report converter * @param element a not null MImage element * @return An image pointed by the expression of the element if it can be found, the * standard not found image otherwise. it is never null */ public JRPrintElement convertImage(ReportConverter reportConverter, MGraphicElement element){ JRImage image = (JRImage) element.getValue(); JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider()); Renderable cacheRenderer = getRenderable(reportConverter, image, element); copyGraphicElement(reportConverter, image, printImage); printImage.copyBox(image.getLineBox()); printImage.setAnchorName(JRExpressionUtil.getExpressionText(image.getAnchorNameExpression())); printImage.setBookmarkLevel(image.getBookmarkLevel()); printImage.setHorizontalAlignment(image.getOwnHorizontalAlignmentValue()); printImage.setLazy(image.isLazy()); printImage.setLinkType(image.getLinkType()); printImage.setOnErrorType(OnErrorTypeEnum.ICON); printImage.setVerticalAlignment(image.getOwnVerticalAlignmentValue()); //If it is null load the no image found element if (cacheRenderer == null) cacheRenderer = getRenderableNoImage(reportConverter.getJasperReportsContext(), image, printImage); printImage.setRenderable(cacheRenderer); printImage.setScaleImage(image.getOwnScaleImageValue()); return printImage; }
@Override public JRPrintImage createImageFromElement(JRGenericPrintElement element) throws JRException { String htmlContent = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_HTML_CONTENT); String scaleType = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_SCALE_TYPE); String horizontalAlignment = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_HORIZONTAL_ALIGN); String verticalAlignment = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_VERTICAL_ALIGN); Boolean hasOverflowed = (Boolean) element.getParameterValue(HtmlPrintElement.BUILTIN_PARAMETER_HAS_OVERFLOWED); Boolean clipOnOverflow = (Boolean) element.getParameterValue(HtmlPrintElement.PARAMETER_CLIP_ON_OVERFLOW); JRBasePrintImage printImage = new JRBasePrintImage(element.getDefaultStyleProvider()); printImage.setStyle(element.getStyle()); printImage.setMode(element.getModeValue()); printImage.setBackcolor(element.getBackcolor()); printImage.setForecolor(element.getForecolor()); printImage.setX(element.getX()); printImage.setY(element.getY()); printImage.setWidth(element.getWidth()); printImage.setScaleImage(ScaleImageEnum.getByName(scaleType)); printImage.setHorizontalImageAlign(HorizontalImageAlignEnum.getByName(horizontalAlignment)); printImage.setVerticalImageAlign(VerticalImageAlignEnum.getByName(verticalAlignment)); FlyingSaucerXhtmlToImageRenderer renderer = new FlyingSaucerXhtmlToImageRenderer(getHtmlDocument(htmlContent), element.getWidth(), element.getHeight()); if (printImage.getScaleImageValue() == ScaleImageEnum.REAL_HEIGHT || printImage.getScaleImageValue() == ScaleImageEnum.REAL_SIZE) { boolean canClip = hasOverflowed != null ? hasOverflowed : false; if (canClip) { printImage.setHeight(element.getHeight()); if (clipOnOverflow) { printImage.setScaleImage(ScaleImageEnum.CLIP); } } else { printImage.setHeight(renderer.getComputedSize().height); } } else { printImage.setHeight(element.getHeight()); } printImage.setRenderer(renderer); return printImage; }
@Override public JRPrintImage createImageFromComponentElement(JRComponentElement componentElement) throws JRException { HtmlComponent html = (HtmlComponent) componentElement.getComponent(); String htmlContent = ""; if (html.getHtmlContentExpression() != null) { htmlContent = JRExpressionUtil.getExpressionText(html.getHtmlContentExpression()); } JRBasePrintImage printImage = new JRBasePrintImage(componentElement.getDefaultStyleProvider()); printImage.setStyle(componentElement.getStyle()); printImage.setMode(componentElement.getModeValue()); printImage.setBackcolor(componentElement.getBackcolor()); printImage.setForecolor(componentElement.getForecolor()); printImage.setX(componentElement.getX()); printImage.setY(componentElement.getY()); printImage.setWidth(componentElement.getWidth()); printImage.setHeight(componentElement.getHeight()); printImage.setScaleImage(html.getScaleType()); printImage.setHorizontalImageAlign(html.getHorizontalImageAlign()); printImage.setVerticalImageAlign(html.getVerticalImageAlign()); FlyingSaucerXhtmlToImageRenderer renderer = new FlyingSaucerXhtmlToImageRenderer(getHtmlDocument(htmlContent), componentElement.getWidth(), componentElement.getHeight()); printImage.setRenderer(renderer); return printImage; }
@Override public JRPrintImage createImageFromElement(JRGenericPrintElement element) { String htmlContent = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_HTML_CONTENT); String scaleType = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_SCALE_TYPE); String horizontalAlignment = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_HORIZONTAL_ALIGN); String verticalAlignment = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_VERTICAL_ALIGN); JEditorPane editorPane = new JEditorPane(); editorPane.setEditorKitForContentType("text/html", new SynchronousImageLoaderKit()); editorPane.setContentType("text/html"); editorPane.setText(htmlContent); editorPane.setBorder(null); editorPane.setSize(editorPane.getPreferredSize()); JRBasePrintImage printImage = new JRBasePrintImage(element.getDefaultStyleProvider()); printImage.setX(element.getX()); printImage.setY(element.getY()); printImage.setWidth(element.getWidth()); printImage.setHeight(element.getHeight()); printImage.setScaleImage(ScaleImageEnum.getByName(scaleType)); printImage.setHorizontalImageAlign(HorizontalImageAlignEnum.getByName(horizontalAlignment)); printImage.setVerticalImageAlign(VerticalImageAlignEnum.getByName(verticalAlignment)); printImage.setStyle(element.getStyle()); printImage.setMode(element.getModeValue()); printImage.setBackcolor(element.getBackcolor()); printImage.setForecolor(element.getForecolor()); printImage.setRenderer(new AwtComponentRendererImpl(editorPane)); return printImage; }
@Override public JRPrintImage createImageFromComponentElement(JRComponentElement componentElement) throws JRException { HtmlComponent html = (HtmlComponent) componentElement.getComponent(); JEditorPane editorPane = new JEditorPane(); editorPane.setEditorKitForContentType("text/html", new SynchronousImageLoaderKit()); editorPane.setContentType("text/html"); String htmlContent = ""; if (html.getHtmlContentExpression() != null) { htmlContent = JRExpressionUtil.getExpressionText(html.getHtmlContentExpression()); } editorPane.setText(htmlContent); editorPane.setBorder(null); editorPane.setSize(editorPane.getPreferredSize()); JRBasePrintImage printImage = new JRBasePrintImage(componentElement.getDefaultStyleProvider()); printImage.setX(componentElement.getX()); printImage.setY(componentElement.getY()); printImage.setWidth(componentElement.getWidth()); printImage.setHeight(componentElement.getHeight()); printImage.setScaleImage(html.getScaleType()); printImage.setHorizontalImageAlign(html.getHorizontalImageAlign()); printImage.setVerticalImageAlign(html.getVerticalImageAlign()); printImage.setStyle(componentElement.getStyle()); printImage.setMode(componentElement.getModeValue()); printImage.setBackcolor(componentElement.getBackcolor()); printImage.setForecolor(componentElement.getForecolor()); printImage.setRenderer(new AwtComponentRendererImpl(editorPane)); return printImage; }
@Override public JRPrintElement convert(ReportConverter reportConverter, JRElement element) { JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider()); JRImage image = (JRImage)element; copyGraphicElement(reportConverter, image, printImage); printImage.copyBox(image.getLineBox()); printImage.setAnchorName(JRExpressionUtil.getExpressionText(image.getAnchorNameExpression())); printImage.setBookmarkLevel(image.getBookmarkLevel()); printImage.setHorizontalImageAlign(image.getOwnHorizontalImageAlign()); printImage.setLinkType(image.getLinkType()); printImage.setOnErrorType(OnErrorTypeEnum.ICON); printImage.setVerticalImageAlign(image.getOwnVerticalImageAlign()); printImage.setRenderer( ResourceRenderer.getInstance( JRExpressionUtil.getSimpleExpressionText(image.getExpression()), image.isLazy() ) ); printImage.setScaleImage(image.getOwnScaleImageValue()); return printImage; }
@Override public JRPrintElement convert(ReportConverter reportConverter, JRElement element) { JRBasePrintImage printImage = new JRBasePrintImage( reportConverter.getDefaultStyleProvider()); copyElement(reportConverter, element, printImage); printImage.getLineBox().setPadding(3); printImage.setScaleImage(ScaleImageEnum.CLIP); printImage.setRenderer(ResourceRenderer.getInstance(iconLocation, false)); return printImage; }
@Override public JRPrintElement convert(ReportConverter reportConverter, JRComponentElement element) { JRBasePrintImage printImage = new JRBasePrintImage( reportConverter.getDefaultStyleProvider()); reportConverter.copyBaseAttributes(element, printImage); printImage.setScaleImage(ScaleImageEnum.RETAIN_SHAPE); Renderable barcodeImage = evaluateBarcode(reportConverter, element); printImage.setRenderer(barcodeImage); return printImage; }
protected Renderable getRenderable(final ReportConverter reportConverter, final JRElement element, final JRImage image, final JRBasePrintImage printImage) { Renderable cacheRenderer = null; try { cacheRenderer = cache.get(element); if (image.getExpression() != null) { String expr = image.getExpression().getText(); KeyValue<String, Long> last = running.get(element); Renderable r = null; if (cacheRenderer == null) { cacheRenderer = getRenderableNoImage(reportConverter.getJasperReportsContext(), image, printImage); cache.put(element, cacheRenderer); if (last == null) r = doFindImage(reportConverter, element, image, printImage, expr, cacheRenderer); } if (last != null && (!last.key.equals(expr) || (last.value != null && System.currentTimeMillis() - last.value.longValue() > 2000))) { r = doFindImage(reportConverter, element, image, printImage, expr, cacheRenderer); } if (last == null) r = doFindImage(reportConverter, element, image, printImage, expr, cacheRenderer); if (r != null) cacheRenderer = r; } else { running.remove(element); cacheRenderer = getRenderableNoImage(reportConverter.getJasperReportsContext(), image, printImage); cache.put(element, cacheRenderer); } } catch (Throwable e) { return getRenderableNoImage(reportConverter.getJasperReportsContext(), image, printImage); } return cacheRenderer; }
public static JRPrintImage getImage( JasperReportsContext jasperReportsContext, JRGenericPrintElement element) throws JRException, IOException { JRBasePrintImage printImage = new JRBasePrintImage( element.getDefaultStyleProvider()); printImage.setUUID(element.getUUID()); printImage.setX(element.getX()); printImage.setY(element.getY()); printImage.setWidth(element.getWidth()); printImage.setHeight(element.getHeight()); printImage.setStyle(element.getStyle()); printImage.setMode(element.getModeValue()); printImage.setBackcolor(element.getBackcolor()); printImage.setForecolor(element.getForecolor()); printImage.setLazy(false); printImage.setScaleImage(ScaleImageEnum.CLIP); printImage.setHorizontalAlignment(HorizontalAlignEnum.LEFT); printImage.setVerticalAlignment(VerticalAlignEnum.TOP); Renderable cacheRenderer = (Renderable) element .getParameterValue(WmsMapPrintElement.PARAMETER_CACHE_RENDERER); if (cacheRenderer == null) { cacheRenderer = getImageRenderable(jasperReportsContext, element); element.setParameterValue(WmsMapPrintElement.PARAMETER_CACHE_RENDERER, cacheRenderer); } printImage.setRenderable(cacheRenderer); return printImage; }
@Override public Object createObject(Attributes atts) { JasperPrint jasperPrint = (JasperPrint)digester.peek(digester.getCount() - 2); JRBasePrintImage image = new JRBasePrintImage(jasperPrint.getDefaultStyleProvider()); // get image attributes ScaleImageEnum scaleImage = ScaleImageEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_scaleImage)); if (scaleImage != null) { image.setScaleImage(scaleImage); } HorizontalImageAlignEnum horizontalImageAlign = HorizontalImageAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_hAlign)); if (horizontalImageAlign != null) { image.setHorizontalImageAlign(horizontalImageAlign); } VerticalImageAlignEnum verticalImageAlign = VerticalImageAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_vAlign)); if (verticalImageAlign != null) { image.setVerticalImageAlign(verticalImageAlign); } OnErrorTypeEnum onErrorType = OnErrorTypeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_onErrorType)); if (onErrorType != null) { image.setOnErrorType(onErrorType); } image.setLinkType(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType)); image.setLinkTarget(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget)); image.setAnchorName(atts.getValue(JRXmlConstants.ATTRIBUTE_anchorName)); image.setHyperlinkReference(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkReference)); image.setHyperlinkAnchor(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkAnchor)); String hyperlinkPage = atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkPage); if (hyperlinkPage != null) { image.setHyperlinkPage(Integer.valueOf(hyperlinkPage)); } image.setHyperlinkTooltip(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTooltip)); String bookmarkLevelAttr = atts.getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel); if (bookmarkLevelAttr != null) { image.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr)); } String isLazy = atts.getValue(JRXmlConstants.ATTRIBUTE_isLazy); if (isLazy != null && isLazy.length() > 0) { //we use a resource renderer just to pass the value of isLazy flag to image source factory image.setRenderer(ResourceRenderer.getInstance("", Boolean.valueOf(isLazy).booleanValue())); } return image; }
@Override public JRPrintElement convert(ReportConverter reportConverter, JRComponentElement element) { SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent(); if (chartComponent == null) { return null; } JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider()); ChartSettings chartSettings = chartComponent.getChartSettings(); reportConverter.copyBaseAttributes(element, printImage); //TODO: spiderchart box // printImage.copyBox(element.getLineBox()); printImage.setAnchorName(JRExpressionUtil.getExpressionText(chartSettings.getAnchorNameExpression())); printImage.setBookmarkLevel(chartSettings.getBookmarkLevel()); printImage.setLinkType(chartSettings.getLinkType()); printImage.setOnErrorType(OnErrorTypeEnum.ICON); printImage.setScaleImage(ScaleImageEnum.CLIP); SpiderChartSharedBean spiderchartBean = new SpiderChartSharedBean( chartSettings.getRenderType(), SpiderChartRendererEvaluator.SAMPLE_MAXVALUE, JRExpressionUtil.getExpressionText(chartSettings.getTitleExpression()), JRExpressionUtil.getExpressionText(chartSettings.getSubtitleExpression()), null, null ); printImage.setRenderer( SpiderChartRendererEvaluator.evaluateRenderable( reportConverter.getJasperReportsContext(), element, spiderchartBean, null, JRPropertiesUtil.getInstance(reportConverter.getJasperReportsContext()).getProperty(reportConverter.getReport(), JRChart.PROPERTY_CHART_RENDER_TYPE), SpiderChartRendererEvaluator.SAMPLE_DATASET) ); return printImage; }
@Override public JRPrintElement convert(ReportConverter reportConverter, JRComponentElement element) { BarbecueComponent component = (BarbecueComponent) element.getComponent(); if (component == null || component.getType() == null) { return null; } try { JRBasePrintImage image = new JRBasePrintImage( reportConverter.getDefaultStyleProvider()); reportConverter.copyBaseAttributes(element, image); image.setScaleImage(ScaleImageEnum.RETAIN_SHAPE); String code = null; if (component.getCodeExpression() != null) { code = JRExpressionUtil.getSimpleExpressionText( component.getCodeExpression()); } if (code == null) { //TODO custom default code code = DEFAULT_PREVIEW_CODE; } String applicationIdentifier = null; if (component.getApplicationIdentifierExpression() != null) { applicationIdentifier = JRExpressionUtil.getSimpleExpressionText( component.getApplicationIdentifierExpression()); } //TODO custom default app id BarcodeInfo barcodeInfo = new BarcodeInfo(); barcodeInfo.setType(component.getType()); barcodeInfo.setCode(code); barcodeInfo.setApplicationIdentifier(applicationIdentifier); barcodeInfo.setDrawText(component.isDrawText()); barcodeInfo.setRequiresChecksum(component.isChecksumRequired()); barcodeInfo.setBarWidth(component.getBarWidth()); barcodeInfo.setBarHeight(component.getBarHeight()); Barcode barcode = BarcodeProviders.createBarcode(barcodeInfo); BarbecueRendererImpl renderer = new BarbecueRendererImpl(barcode); renderer.setRotation(BarbecueStyleResolver.getRotationValue(element)); image.setRenderer(renderer); return image; } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Error while previewing barcode", e); } return null; } }
protected Renderable getRenderable(final ReportConverter reportConverter, final JRComponentElement element, MapComponent map, final JRBasePrintImage printImage) { Renderable cacheRenderer = null; try { cacheRenderer = cache.get(element); String expr = "" + element.getWidth() + element.getHeight(); if (map.getLongitudeExpression() != null) expr += map.getLongitudeExpression().getText(); if (map.getLatitudeExpression() != null) expr += map.getLatitudeExpression().getText(); if (map.getLanguageExpression() != null) expr += map.getLanguageExpression().getText(); if (map.getZoomExpression() != null) expr += map.getZoomExpression().getText(); if (map.getMapType() != null) expr += map.getMapType().getName(); if (map.getMapScale() != null) expr += map.getMapScale().getName(); if (!expr.isEmpty()) { KeyValue<String, Long> last = running.get(element); Renderable r = null; if (cacheRenderer == null) { cacheRenderer = getRenderableNoImage(reportConverter.getJasperReportsContext(), map, printImage); cache.put(element, cacheRenderer); if (last == null) r = doFindImage(reportConverter, element, map, expr, cacheRenderer); } if (last != null && (!last.key.equals(expr))) r = doFindImage(reportConverter, element, map, expr, cacheRenderer); if (last == null) r = doFindImage(reportConverter, element, map, expr, cacheRenderer); if (r != null) cacheRenderer = r; } else { running.remove(element); cacheRenderer = getRenderableNoImage(reportConverter.getJasperReportsContext(), map, printImage); cache.put(element, cacheRenderer); } } catch (Throwable e) { return getRenderableNoImage(reportConverter.getJasperReportsContext(), map, printImage); } return cacheRenderer; }