Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Sizing Multi-line text
Sizing Multi-line text [message #747830] Mon, 24 October 2011 10:02 Go to next message
Adrian Mouat is currently offline Adrian MouatFriend
Messages: 16
Registered: September 2011
Junior Member
One of my diagram elements takes a multi-line text input. I would like to resize the containing box to the appropriate size for the number of lines.

I thought text.getHeight() might have given the height of the of the text, but it seems to stay the same regardless of the text value.

Do I have to parse the value of the text to count the number of lines to do my resizing or is there a better way? Is there a programmatic way to get the line height?
Re: Sizing Multi-line text [message #747868 is a reply to message #747830] Mon, 24 October 2011 10:28 Go to previous messageGo to next message
Christian B is currently offline Christian BFriend
Messages: 68
Registered: August 2011
Member
you might try GraphitiUi.getUiLayoutService().calculateTextSize(). Didn't test it, but could help Wink
Re: Sizing Multi-line text [message #747921 is a reply to message #747868] Mon, 24 October 2011 11:07 Go to previous messageGo to next message
Adrian Mouat is currently offline Adrian MouatFriend
Messages: 16
Registered: September 2011
Junior Member
Unfortunately, GraphitiUi.getUiLayoutService().calculateTextSize() seems to be broken. Height isn't affected by newlines, but width is!

Thanks for the pointer though.
Re: Sizing Multi-line text [message #747968 is a reply to message #747921] Mon, 24 October 2011 11:50 Go to previous messageGo to next message
Adrian Mouat is currently offline Adrian MouatFriend
Messages: 16
Registered: September 2011
Junior Member
It seems you can get (more or less) the correct height by:

IDimension dim = GraphitiUi.getUiLayoutService(
).calculateTextSize(
val, text.getFont());

int height = 2 + (dim.getHeight() * val.split("\n").length));

(I guess using "\n" is platform dependent and you should grab the correct value from properties though). The 2 at the start probably just represents the margin; I found the text was very slightly clipped if I didn't use it.

I'm not sure how to find the correct value for width Sad


Re: Sizing Multi-line text [message #747973 is a reply to message #747968] Mon, 24 October 2011 11:54 Go to previous messageGo to next message
Christian B is currently offline Christian BFriend
Messages: 68
Registered: August 2011
Member
As a workaround you could measure the width with calculateTextSize() of all splitted (with \n) text parts and then take the max of it.
Re: Sizing Multi-line text [message #748032 is a reply to message #747973] Mon, 24 October 2011 12:45 Go to previous message
Adrian Mouat is currently offline Adrian MouatFriend
Messages: 16
Registered: September 2011
Junior Member
Yeah, I was just thinking that. Not very nice though.
Previous Topic:Incorrect behaviour from using "EcoreUtil.equals" instead "==" in Graphiti
Next Topic:ResizeFeature
Goto Forum:
  


Current Time: Thu Apr 25 16:57:54 GMT 2024

Powered by FUDForum. Page generated in 0.03194 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top