views:

444

answers:

1

I want to highlight some parts of the reports i'm generating for display.
I don't want to change the report definition. I want to highlight the output at runtime.

But the JRViewer i'm using doesn't really have much of an API.
And manipulating the JasperPrint object with setForecolor/setBackcolor before displaying it, didn't seem to change the output.

Any ideas? Or do i have to overload/reimplement the viewer? Wouldn't be much of a problem since it's open source, but i'd like to prevent reinventing the wheel.

A: 

Looks like i have to answer my questions myself... again.

I overloaded the JRViewer class (actually copied the code of JRViewer because none of the interesting panels were accessible) and added some highlighting methods to do the following:

Template based JasperPrint data uses - like the name suggests - templates. Meaning the text objects don't have a style of their own, they use their template's style.
That is the reason why setForecolor didn't do anything - the JRTemplatePrintElement implementation is plain empty.

But if i would set the highlight on the text template i would end up with a full column of highlighted texts, since they share the template instance.
Instead i create a new template as a copy of the original with highlighting and use that in the highlighted print elements. Btw, those jasper elements could really use a clone() method.
Feels like a hack, but i don't see a better way.

UPDATE:
However this has a nasty sideeffect for file based (virtualized) reports. These apparently save any changes you make to the elements while you walk the pages. If however the viewer in the meantime causes the virtualizer to discard the elements you reference (for example by flipping pages), your further changes won't be saved...

So that made me reconsider and now i'm just drawing my highlighting on top of the Graphics object painted by Jasper's PageRenderer.
Much simpler and cleaner. Only highlighting the background won't work this way.

Stroboskop

related questions