PDA

View Full Version : ItemBand limitation?



Anonymous
08-01-2002, 01:15 AM
JFreeReport is a powerful and well designed library. I'm impressed!

One limitation is getting in the way - it appears every row printed with an ItemBand has to have the same height. Is this correct?

All the posts about multiline fields have been answered with the same response about element height being at least twice the font height. The whole point of multiline fields is that one doesn't know the length of the string in advance, and so, unless the field has the capability of shrinking vertically when the text is short, the multiline capability is useless.

Finally, in no case should the next field be overwritten. A single line field should also truncate the text.

Best,
Shivchow.

Anonymous
08-01-2002, 07:18 AM
Hi,

sadly , JFreeReport has no dynamic element- or band-dimensions yet. In the current state all elements have a fixed position and dimension. JFreeReport will get some Java-Stylish Layout-Management as soon as posible.

You are right, single line fields should truncate text too, the whole wordwrapping needs some redesign. The current implementation is a quick and dirty implementation to enable some sort of text-area. Having only single-line textelements would have been even more worse, so don't take the current stuff not too serious at all :)
But a replacement is on the way, as the current implementation has problems with words which are greater than the elements width.

The single line implementation does no truncating at all as the old implementation had this behaviour. The next implementation will skip this compatiility "feature" ...

Having a more intelligent approach of placing elements is on the list for a long time, arrrg .. so much to do :)

Have more fun,
said Thomas

Anonymous
08-01-2002, 11:16 AM
Hey taqua,

Thanks for the quick response. One more question and my two cents worth:

From my scan through the source, it seems to me that if one extended TextElement so that, in the draw method, it simply stretched the band height if necessary, that would suffice. Or am I missing something?

shivchow.

Anonymous
08-01-2002, 01:27 PM
Some small modifications to the code gave me the results I wanted.(again, good design!) I'm posting the changes in case they're useful to anyone.

In ReportProcessor, redefine the draw method:

protected void draw (Band band, float y)
{
float dheight = 0;
if (isDraw())
{
try
{
dheight = band.draw (target, cursor.getPageLeft (), y);
}
catch (OutputTargetException e)
{
Log.error ("Unable to draw band", e);
}
}
//cursor.advance (y - cursor.getY() + band.getHeight ());
if (dheight < band.getHeight()) dheight = band.getHeight();

cursor.advance (y - cursor.getY() + dheight);
}

In Band, redefine the draw method:

public float draw (OutputTarget target, float x, float y) throws OutputTargetException
{
if (target == null) throw new NullPointerException ();
float maxheight = 0;

Rectangle2D bounds = new Rectangle2D.Float ();
bounds.setRect (x, y, target.getUsableWidth (), getHeight ());
target.setClippingArea (bounds);

target.setPaint (getDefaultPaint ());
Iterator iterator = allElements.iterator ();
while (iterator.hasNext ())
{
Element e = (Element) iterator.next ();
if (e.isVisible ())
{
target.getCursor ().setElementBounds (translateBounds (target, e.getBounds ()));
try
{
Object state = target.saveState ();
e.draw (target, this);
target.restoreState (state);
}
catch (OutputTargetException ex)
{
Log.error ("Failed to draw band", ex);
}
double eh = target.getCursor().getDrawBounds().getY() +
target.getCursor().getDrawBounds().getHeight();
if (eh > maxheight) maxheight = (float) eh;
}
}
return maxheight;
}

In AbstractOutputTarget, in the method drawMultiLineText
replace

Rectangle2D bounds = getCursor ().getDrawBounds ();
float fontheight = getFontHeight ();
int maxLinesToDisplay = (int) (bounds.getHeight () / fontheight);
Vector lines = null;
if (maxLinesToDisplay <= 1)
{
lines = new Vector ();
lines.add (clearWhitespaces(mytext));
}
else
{
lines = breakLines (mytext, (float) bounds.getWidth (), maxLinesToDisplay);
}


with

Rectangle2D bounds = getCursor ().getDrawBounds ();
float fontheight = getFontHeight ();
int maxLinesToDisplay = 10; // want max 10 lines
Vector lines = breakLines (mytext, (float) bounds.getWidth (), maxLinesToDisplay);
float newheight = lines.size() * (fontheight+1);
float oldheight = (float) bounds.getHeight();
if (newheight > oldheight) {
bounds.setRect(bounds.getX(), bounds.getY(), bounds.getWidth(), newheight);
getCursor().setElementBounds(bounds);
}

Enjoy,
shivchow.

Anonymous
08-08-2002, 10:07 AM
Hi,

Thanks for this solution, great!
I included your patch in the cvs release. To enable the functionality you will have to set the elements "dynamic"-property to true (Element.setDynamic(true)).

This implemetation will cause troubles on page breaks, as the final length of the band is not known. The whole layout thing in JFreeReport will need a redesign soon. I removed the limitation to 10 lines and replaced it with an unlimited setting. If maxLines is less than 1, there is no limitation in the number of printable lines.

Have more fun,
said Thomas

Anonymous
10-14-2002, 10:48 AM
Hi

The new functionality is exactly what I want, does jfreereport-0.7.6.jar include it? I couldn't find Element.setDynamic() method.
How can I implement it?

Thank you all very much.
dong

Anonymous
10-14-2002, 01:24 PM
Hi,

the setDynamic() method is defined in the class TextElement, not Element. But be aware that the PageBreak algorithm is not very happy with this solution ..

Have more fun,
said Thomas

Anonymous
10-14-2002, 05:41 PM
Thank you very much, Thomas.

Another question is if I want to show different ROW with different font/backgroud color dynamically depends on the cell value, is it possible to do that?

Thanks in advance.
Dong

Anonymous
10-15-2002, 10:28 AM
Hi,

yes, by writing a function or expression which will check the constraint (f.i. revenue is negative) and which will do the nessesary changes to the elements of the current row's band.

An example for a function that alters the state of an band can be found in the distribution, the ItemVisibilitySwitchFunction alters the visibility of an band on every other row. A similiar approach would be used to alter an element's font, color or any other property.

Have more fun,
said Thomas

Anonymous
10-22-2002, 02:59 PM
Hi Thomas,

Thanks for the early answer, but I didn't find ItemVisibilitySwitchFunction in jfreereport-0.7.6.jar, is it a new one or I have to write my own?

Another issue is some data in certain columns wrapped even there is no space in the value, other columns data only wrap once and second part of the value is much lower than the first part. The patter is like this


column1 | column2
---------------------------------------------
value1= | value2=:
| data2
|
|
|
|
|
data1,data1,data1,data1,data1
----------------------------------------------



The desired result should be

column1 | column2
--------------------------------------------------
value1=data1, | value2=:data2
data1, |
data1, |
data1, |
---------------------------------------------------

note:vertical line and horizontal line are what I added in order to see clearly.

I used same column width.


Thank u very much.
Dong

Anonymous
10-23-2002, 02:42 PM
Hi,

arrgh, the class name is

com.jrefinery.report.function.ElementVisibilitySwitchFunction ...

To the second issue: In its current version, JFreeReport uses a BreakIterator for performing locale sensitive word breaking.
So I'm not sure that the BreakIterator will break after the colon.
If not, you will have to reformat your value using an expression.

I assume now that you work with the latest cvs version, if not, please upgrade to make the dynamic text feature fully working. (the nessesary update was on Oct-15, so if your version is younger forget everything I said here).

To enable a variable element height for your columns, you will have to add the "dynamic" attribute to your xml-element definitions and set this one to "true". The elements height does now define a minimum height for the elements.

The width of elements cannot be set dynamicly yet, so you have to give your elements a suitable width by yourself. Everything should work fine then.

Have more fun,
said Thomas

Anonymous
10-23-2002, 04:26 PM
Hi,

correction:
The "ElementVisibilitySwitchFunction" is not used for that purpose. This function is intended to hide an element every other row.

What is needed here is the

com.jrefinery.report.function.ItemHideFunction

This one compares the current value of an field and hides the field if the value had not changed since the last row.

Have more fun,
said Thomas

Anonymous
10-23-2002, 04:53 PM
Hi,

Thank you for the reply.
Right now I have jfreereport-0.7.6.jar, as for dynamically set Item height, I used
textElement.setDynamic(true);
that is the problem I mentioned early.

You suggested me to check out latest from CVS, did you mean I need to check out latest TextElement.java, compile and re-jar jfreereport-0.7.6.jar? (I'm going to do it now)

If not, would you tell me more, please?

Thank you very much.
dong

Anonymous
10-23-2002, 06:12 PM
Hi,

why not check out everything? The Dynamic-TextElement changes required the change of many files, finding them all is quite difficult. If you don't have a cvs client installed, you can find a daily snapshot of the sources on

http://www.sherito.org/jfreereport/

These sources will need a compile, a re-jaring and everything is working fine...

Have more fun,
said Thomas