Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ResizeToFitText Infinite loop (Read 2462 times)
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
ResizeToFitText Infinite loop
Aug 23rd, 2007 at 12:32pm
Print Post  
Hi,

I tried out the following example and the Flowchart goes into an infinite loop.


private void testResizeToFitText() {
flowChart = new FlowChart();
this.getContentPane().add(flowChart);

Box sizerUp = new Box(this.flowChart);
sizerUp.setFont(new Font("Arial", 0, 1));
String text = "fjfj";
Rectangle2D.Float stringSize =
this.flowChart.measureString(text, sizerUp.getFont());
sizerUp.setText(text);

flowChart.add(sizerUp);

sizerUp.resize(stringSize.width, stringSize.height);
sizerUp.resizeToFitText(FitSize.KeepWidth);
sizerUp.resizeToFitText(FitSize.KeepHeight);
}

I have narrowed down the problem to the font size - 1.

If you change the font size to 10, you will see that the flowchart is drawn properly.

I guess this is a bug, yes?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ResizeToFitText Infinite loop
Reply #1 - Aug 24th, 2007 at 5:36am
Print Post  
Hi,

resizeToFitText(FitSize.KeepWidth/Height) might not work if the box is exactly as big as the string. There is some margin space left inside the box, and the text will never fit if the box width or height must be preserved. Indeed, when that happens, resizeToFitText should return false instead of looping infinitely. For now try starting with a slightly bigger box size with enough space for the margins.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: ResizeToFitText Infinite loop
Reply #2 - Aug 24th, 2007 at 5:39am
Print Post  
Hi,

In that case, can't we have a resizeToFitText method that doesn't take any parameters? So that the box will fit to any text that is passed to it.

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint