Hi,
First of all let me say great work on the new version, the pie labels are much better the the old ones. My problem now is that the label value is been wrapped because of it's length. Is there a way to control it? I mean I want it to be wrapped, but I want to mark where to break it, is it possible?
Thanks,
Tal
Label word warp
Fixed!
Ok, I've found how to do it...
I've add a function to TextUtitlities.java:
public static TextBlock createTextBlock(String text, Font font, Paint paint,
float maxWidth, int maxLines, TextMeasurer measurer) {
TextBlock result = new TextBlock();
result.addLine(text, font, paint);
return result;
}
Then I've changed TextBox constructors to split the string by | char (but I guess some of you might want to use it as a parameter)
now it looks like :
public TextBox(String text) {
this((TextBlock) null);
if (text != null) {
this.textBlock = new TextBlock();
String[] test = text.split("[|]");
for(int i = 0 ; i < test.length ; i++)
this.textBlock.addLine(test, new Font("SansSerif", Font.PLAIN, 10), Color.black);
}
}
public TextBox(TextBlock block) {
java.util.List lines = block.getLines();
this.textBlock = new TextBlock();
for(int i = 0 ; i < lines.size() ; i++){
String text = ((TextLine)lines.get(i)).toString();
String[] test = text.split("[|]");
for(int j = 0 ; j < test.length ; j++)
if(test[j] != null) this.textBlock.addLine(test[j], new Font("SansSerif", Font.PLAIN, 10), Color.black);
}
this.outlinePaint = Color.black;
this.outlineStroke = new BasicStroke(1.0f);
this.interiorGap = new Spacer(Spacer.ABSOLUTE, 3.0, 1.0, 3.0, 1.0);
this.backgroundPaint = new Color(255, 255, 192);
this.shadowPaint = Color.gray;
this.shadowXOffset = 2.0;
this.shadowYOffset = 2.0;
}
Thats it, now you only need to put the name of the section with the | char where you would like it to break (take notice that you still have limitation on the textbox size).
I've add a function to TextUtitlities.java:
public static TextBlock createTextBlock(String text, Font font, Paint paint,
float maxWidth, int maxLines, TextMeasurer measurer) {
TextBlock result = new TextBlock();
result.addLine(text, font, paint);
return result;
}
Then I've changed TextBox constructors to split the string by | char (but I guess some of you might want to use it as a parameter)
now it looks like :
public TextBox(String text) {
this((TextBlock) null);
if (text != null) {
this.textBlock = new TextBlock();
String[] test = text.split("[|]");
for(int i = 0 ; i < test.length ; i++)
this.textBlock.addLine(test, new Font("SansSerif", Font.PLAIN, 10), Color.black);
}
}
public TextBox(TextBlock block) {
java.util.List lines = block.getLines();
this.textBlock = new TextBlock();
for(int i = 0 ; i < lines.size() ; i++){
String text = ((TextLine)lines.get(i)).toString();
String[] test = text.split("[|]");
for(int j = 0 ; j < test.length ; j++)
if(test[j] != null) this.textBlock.addLine(test[j], new Font("SansSerif", Font.PLAIN, 10), Color.black);
}
this.outlinePaint = Color.black;
this.outlineStroke = new BasicStroke(1.0f);
this.interiorGap = new Spacer(Spacer.ABSOLUTE, 3.0, 1.0, 3.0, 1.0);
this.backgroundPaint = new Color(255, 255, 192);
this.shadowPaint = Color.gray;
this.shadowXOffset = 2.0;
this.shadowYOffset = 2.0;
}
Thats it, now you only need to put the name of the section with the | char where you would like it to break (take notice that you still have limitation on the textbox size).
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I'd like to implement this by modifying the createTextBlock() method in the TextUtilities class and have it recognise '\n' characters.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


with no wrap version
Hi David,
It is good to have \n to control the wrapping.
Also if \n is not provided, please make it no wrap please.
Cause we are developer not designer. You know how wierd they are in insisting certain look and feels.
Cheers,
Richard
It is good to have \n to control the wrapping.
Also if \n is not provided, please make it no wrap please.
Cause we are developer not designer. You know how wierd they are in insisting certain look and feels.
Cheers,
Richard

Hi, i would suggest:
in
org.jfree.text.TextUtilities
instead of
Ok to go?
in
org.jfree.text.TextUtilities
Code: Select all
public static TextBlock createTextBlock(final String text,
final Font font,
final Paint paint,
final float maxWidth,
final int maxLines,
final TextMeasurer measurer) {
final TextBlock result = new TextBlock();
if(text != null && text.indexOf('\n') >= 0)
{
int start = 0;
int index = text.indexOf('\n');
do
{
result.addLine(text.substring(start, index), font, paint);
start = index +1;
index = text.indexOf('\n', start);
}
while(index >= 0);
// add the rest of the text behind the last \n as last line
if(start < text.length())
result.addLine(text.substring(start), font, paint);
}
else
{
final BreakIterator iterator = BreakIterator.getLineInstance();
iterator.setText(text);
int current = 0;
int lines = 0;
final int length = text.length();
while (current < length && lines < maxLines) {
final int next = nextLineBreak(text, current, maxWidth, iterator, measurer);
if (next == BreakIterator.DONE) {
result.addLine(text.substring(current), font, paint);
return result;
}
result.addLine(text.substring(current, next), font, paint);
lines++;
current = next;
}
}
return result;
}
Code: Select all
public static TextBlock createTextBlock(final String text,
final Font font,
final Paint paint,
final float maxWidth,
final int maxLines,
final TextMeasurer measurer) {
final TextBlock result = new TextBlock();
final BreakIterator iterator = BreakIterator.getLineInstance();
iterator.setText(text);
int current = 0;
int lines = 0;
final int length = text.length();
while (current < length && lines < maxLines) {
final int next = nextLineBreak(text, current, maxWidth, iterator, measurer);
if (next == BreakIterator.DONE) {
result.addLine(text.substring(current), font, paint);
return result;
}
result.addLine(text.substring(current, next), font, paint);
lines++;
current = next;
}
return result;
}
Regards,
Andreas Schroeder
Andreas Schroeder