Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic node remains in odd state after resizetofitText (Read 2085 times)
hans
Junior Member
**
Offline


I Love MindFusion!

Posts: 81
Location: Netherlands
Joined: Mar 17th, 2012
node remains in odd state after resizetofitText
Jun 21st, 2012 at 1:20pm
Print Post  
When I change the Textsize of a selected shapenode and then resizeToFitText(scriptHelper1.getConstant("FitSize", "KeepRatio")), sometimes the node remains in an odd state:
The node is selected (the handles are visible), but the node is not resizable and not movable. The text is invisible.
But when I unselect the node, the text is visible and the node fits the text.
When i select the node again, the text becomes invisible, the node unmovable and not resizable. (though the mousepointer changes to move or resize)

This does happen sometimes. If it happens, it is when I choose a smaller fontsize.
When I go back to the original font, this add state remains, but I can see the original font when I deselect the node.

this is my code:
var _font = node.getFont();
var _style = _font.getStyle();
var _size = _font.getSize();
var nw_font = _font.deriveFont(_style, myNewSize);
node.SetFont(nw_font);
var succes = node.resizeToFitText(scriptHelper1.getConstant("FitSize", "KeepHeight"));

I tried KeepRatio, but that makes no different.

Also noticed: when this happens, the node becomes slowly smaller, as if animated.

Is this an bug or am i using fontssize in a wrong way ?

In my attachment some illustrations from this behavior.

Hope someone can help.
  

odd_behavior_resizeToFittext.docx (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: node remains in odd state after resizetofitText
Reply #1 - Jun 21st, 2012 at 6:42pm
Print Post  
This might be caused by a multi-threading problem if this code does not run in the applet's UI thread (i.e. outside of diagram's event handler). If you are running the script in response to a browser's event, it might be running in parallel with the Java drawing code, and say access the text layout data structure while the resizeToFit code modifies it. Since the control is not thread-safe, this might cause exceptions and leave the text layout structure in undefined state.

To avoid this, you could try suspending repaint operations by calling the suspendRepaint method of DiagramView before calling resizeToFitText, or use the applet's runInAppletThread method to run the script in the Java UI thread.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
hans
Junior Member
**
Offline


I Love MindFusion!

Posts: 81
Location: Netherlands
Joined: Mar 17th, 2012
Re: node remains in odd state after resizetofitText
Reply #2 - Jun 22nd, 2012 at 9:07am
Print Post  
suspendRepaint solved the problem.
I love this forum.
Thanks Stoyan, great help.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint