Java 类net.sf.jasperreports.engine.Renderable 实例源码

项目:PDFReporter-Studio    文件:ImageConverter.java   
/**
 *
 */
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;
}
项目:PDFReporter-Studio    文件:ImageConverter.java   
/**
 * 
 */
private Renderable getRenderable(JasperReportsContext jasperReportsContext, JRImage imageElement,
        JRPrintImage printImage, KeyValue<JasperReportsContext, String> key) {
    // long ctime = System.currentTimeMillis();
    Renderable r = null;
    String location = ExpressionUtil.eval(imageElement.getExpression(),
            (JasperReportsConfiguration) jasperReportsContext);
    // JRExpressionUtil.getSimpleExpressionText(imageElement.getExpression());
    // long etime = System.currentTimeMillis();
    if (location != null) {
        try {
            r = RenderableUtil.getInstance(jasperReportsContext).getRenderable(location, OnErrorTypeEnum.ERROR, false);
            imgCache.put(key, r);
        } catch (JRException e) {
            if (log.isDebugEnabled())
                log.debug("Creating location renderer for converted image failed.", e);
        }
    }
    if (r == null)
        r = getRenderableNoImage(jasperReportsContext, imageElement, printImage);
    // long ftime = System.currentTimeMillis();
    // System.out.println("GetRenderable: " + (ftime - ctime) + " : " + (ftime - etime) + " " + location);
    return r;
}
项目:PDFReporter-Studio    文件:MapDesignConverter.java   
/**
 *
 */
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;
}
项目:PDFReporter-Studio    文件:LazyImageConverter.java   
/**
 * 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;
}
项目:PDFReporter-Studio    文件:LazyImageConverter.java   
/**
 * Extract the requested image from the cache if it is available. If it is available is returned (even if it is 
 * expired). If it is expired is returned but a refresh job is started. Otherwise, if it is unavailable is returned
 * null but a refresh job to try to get the image is started
 * 
 * @param reportConverter the report converter
 * @param image the image element
 * @param modelElement the model that encapsulate the image
 * @return the image to display if it is cached (expired or not), null otherwise
 */
private Renderable getRenderable(ReportConverter reportConverter, JRImage image, MGraphicElement modelElement) {
    JasperReportsContext jrContext = reportConverter.getJasperReportsContext();
    JRExpression expr = image.getExpression();
    KeyValue<JasperReportsContext, String> key = new KeyValue<JasperReportsContext, String>(jrContext, expr != null ? expr.getText() : "");
    TimedCache imageInfo = imgCache.get(key);

    //Check if the image was cached
    if (imageInfo == null){
        imageInfo = new TimedCache();
        imgCache.put(key, imageInfo);
    }

    //If the image is expired (it is also expired when is empty, the refresh thread is started)
    if (imageInfo.isExpired()) refreshImageInfo(imageInfo, modelElement, expr, jrContext, key);

    return imageInfo.getImage();

}
项目:PDFReporter-Studio    文件:ViewerCanvas.java   
private void initHypelinks() {
    links.clear();
    if (page == null)
        return;
    List<JRPrintElement> elements = page.getElements();
    if (elements == null)
        return;

    for (JRPrintElement element : elements) {
        if (element instanceof JRPrintImage) {
            Renderable r = ((JRPrintImage) element).getRenderable();
            if (r instanceof ImageMapRenderable) {
                try {
                    List<JRPrintImageAreaHyperlink> hyperlinks = ((ImageMapRenderable) r).getImageAreaHyperlinks(new java.awt.Rectangle(0, 0, element.getWidth(), element.getHeight()));
                    if (hyperlinks != null)
                        links.add(new ImageAreaHyperlink(element.getX(), element.getY(), hyperlinks));
                } catch (JRException e) {
                    throw new RuntimeException(e);
                }
            }
        } else if (element instanceof JRPrintHyperlink && !((JRPrintHyperlink) element).getHyperlinkTypeValue().equals(HyperlinkTypeEnum.NONE))
            links.add(new PrintHyperlink(0, 0, element));
    }
}
项目:jasperreports-wms-component    文件:WmsMapElementImageProvider.java   
public static Renderable getImageRenderable(
    JasperReportsContext jasperReportsContext, String elementName,
    WmsRequestBuilder requestBuilder)
    throws MalformedURLException,
    IOException, JRException {

  URL mapUrl = requestBuilder.toMapUrl();
  HttpURLConnection httpConnection = (HttpURLConnection) mapUrl
      .openConnection();

  // Handle XML response
  validateServerResponse(elementName, mapUrl, httpConnection);

  JasperReportsContext context = jasperReportsContext;
  if (context == null) {
    context = DefaultJasperReportsContext.getInstance();
  }
  Renderable cacheRenderer = RenderableUtil.getInstance(context)
      .getRenderable(
          httpConnection.getInputStream(),
          OnErrorTypeEnum.ERROR);
  // cacheRenderer.getImageData(jasperReportsContext);
  return cacheRenderer;
}
项目:PDFReporter-Studio    文件:ImageConverter.java   
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;
}
项目:PDFReporter-Studio    文件:ImageConverter.java   
private Renderable getRenderableNoImage(JasperReportsContext jasperReportsContext, JRImage imageElement,
        JRPrintImage printImage) {
    try {
        printImage.setScaleImage(ScaleImageEnum.CLIP);
        if (noImage == null)
            noImage = RenderableUtil.getInstance(jasperReportsContext).getRenderable(JRImageLoader.NO_IMAGE_RESOURCE,
                    imageElement.getOnErrorTypeValue(), false);
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug("Creating icon renderer for converted image failed.", e);
    }
    return noImage;
}
项目:PDFReporter-Studio    文件:MapDesignConverter.java   
private Renderable getRenderableNoImage(JasperReportsContext jasperReportsContext, MapComponent map,
        JRPrintImage printImage) {
    try {
        printImage.setScaleImage(ScaleImageEnum.CLIP);
        if (noImage == null)
            noImage = RenderableUtil.getInstance(jasperReportsContext).getRenderable(JRImageLoader.NO_IMAGE_RESOURCE,
                    map.getOnErrorType(), false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return noImage;
}
项目:PDFReporter-Studio    文件:LazyImageConverter.java   
/**
 * Start the thread to refresh a specific image. when the thread has cached a new image then the model and the editor 
 * are notified to ask a refresh
 * 
 * @param info The timed container of the image requested (where it will be placed)
 * @param modelElement the model of the element where the image will be placed
 * @param expr the expression to get the image
 * @param jrContext the context to get the image
 * @param key the key of the image in the cache map.
 */
private void refreshImageInfo(final TimedCache info,  final MGraphicElement modelElement, final JRExpression expr, final JasperReportsContext jrContext, final KeyValue<JasperReportsContext, String> key){
    if (!pendingRequests.contains(modelElement)){
        pendingRequests.add(modelElement);
        Job job = new Job("load image") {
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    String location = evaluatedExpression((JasperReportsConfiguration) jrContext, modelElement, expr); 
                    if (location != null){
                        Renderable r = RenderableUtil.getInstance(jrContext).getRenderable(location, OnErrorTypeEnum.ERROR, false);
                        info.update(r);
                        if (modelElement != null) {
                            modelElement.setChangedProperty(true);
                        }   

                        //The editor refresh must be executed inside the graphic threads
                        Display.getDefault().asyncExec(new Runnable() {
                            @Override
                            public void run() {
                                PropertyChangeEvent event = new PropertyChangeEvent(modelElement.getValue(), JRDesignImage.PROPERTY_EXPRESSION, null,  expr);
                                modelElement.setChangedProperty(true);
                                AMultiEditor.refreshElement(jrContext, event);
                            }
                        });
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                pendingRequests.remove(modelElement);
                return Status.OK_STATUS;
            }
        };
        job.setSystem(true);
        job.setPriority(Job.SHORT);
        job.schedule();
    }
}
项目:PDFReporter-Studio    文件:LazyImageConverter.java   
/**
 * Return the standard printable element when the image is not found
 * 
 * @param jasperReportsContext the context
 * @param imageElement the actual element
 * @param printImage the print image
 * @return return the not printable element
 */
private Renderable getRenderableNoImage(JasperReportsContext jasperReportsContext, JRImage imageElement,
        JRPrintImage printImage) {
    try {
        printImage.setScaleImage(ScaleImageEnum.CLIP);
        if (noImage == null)
            noImage = RenderableUtil.getInstance(jasperReportsContext).getRenderable(JRImageLoader.NO_IMAGE_RESOURCE,
                    imageElement.getOnErrorTypeValue(), false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return noImage;
}
项目:dynamicreports-jasper    文件:ComponentTransform.java   
@Override
public Renderable evaluate(List<?> values, ReportParameters reportParameters) {
    Boolean value = (Boolean) values.get(0);
    if (emptyWhenNullValue && value == null) {
        return null;
    }
    if (value != null && value) {
        return imageTrue;
    } else {
        return imageFalse;
    }
}
项目:jasperreports-wms-component    文件:WmsMapElementImageProvider.java   
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;
}
项目:jasperreports-wms-component    文件:WmsMapElementImageProvider.java   
public static Renderable getImageRenderable(
    JasperReportsContext jasperReportsContext, JRGenericPrintElement element)
    throws MalformedURLException, IOException, JRException {
  WmsRequestBuilder requestBuilder = mapRequestBuilder(element);
  return getImageRenderable(jasperReportsContext, element.getKey(),
      requestBuilder);
}
项目:PDFReporter-Studio    文件:MapDesignConverter.java   
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;
}
项目:PDFReporter-Studio    文件:LazyImageConverter.java   
@SuppressWarnings("unused")
public TimedCache(Renderable image){
    this.image = image;
}
项目:dynamicreports-jasper    文件:CustomChartReport.java   
@Override
public Renderable evaluate(ReportParameters reportParameters) {
    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Box and Whisker chart", "Category", "Value", dataset, true);
    return new DrawChartRenderer(chart, null);
}
项目:PDFReporter-Studio    文件:LazyImageConverter.java   
/**
 * Update the current item and the time when it was added
 * 
 * @param image the new item
 */
public void update(Renderable image){
    this.image = image;
    newtime = System.currentTimeMillis();
}
项目:PDFReporter-Studio    文件:LazyImageConverter.java   
/**
 * Return the current item
 * 
 * @return the current item, could be null
 */
public Renderable getImage(){
    return image;
}