Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Getting width of text(How to get the width of text so the graphical element can be adjusted to show all text?)
Getting width of text [message #1066432] Tue, 02 July 2013 15:56 Go to next message
Albert Hofkamp is currently offline Albert HofkampFriend
Messages: 41
Registered: August 2009
Member
First of all, I really like your tutorial, the pattern to build features becomes very clear with it.
The main things still causing a lot of confusion for me are the "PictogramElement", "ContainerShape", "Shape", and in particular the "GraphicsAlgorithm" concepts and how they relate.
To me, an algorithm is a function to calculate something (ie the usual computer science notion), while "Text" or "Rectangle" feels like an object rather than a function to compute something.


On to my question.

In the tutorial, the add feature does

int width = 100;
...
Text text = gaService.createText(shape, addedClass.getName());
...
gaService.setLocationAndSize(text, 0, 0, width, 20);
to set the width of the displayed text. For longer text however, a fixed length is not working, I want the graphical elements to adjust to the width needed by the text to get it fully displayed instead.

I have been trying to get the width of the text from the system.
IDimension dim = gls.calculateSize(text);
would seem the obvious solution, but I either get (0,0) (before setting width/height) or my previously set width/height, instead the minimally required width of the text to get it fully displayed.

Querying before or after first rendering does not seem to make any difference, so I have run out of ideas how to do this.

In other words, how do I retrieve the natural width of a text so I can use that to decide the size of my graphical elements?
Re: Getting width of text [message #1066804 is a reply to message #1066432] Thu, 04 July 2013 13:18 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Albert,

the name algorithm might indeed a bit confusing. It comes from the fact that
its intention is to define the way how a shape will be rendered, so it
somehow calculates the rendering.

To your question: IGefService.calculateTextSize() might be the think you are
looking for.

Michael
Re: Getting width of text [message #1067032 is a reply to message #1066804] Fri, 05 July 2013 14:02 Go to previous messageGo to next message
Albert Hofkamp is currently offline Albert HofkampFriend
Messages: 41
Registered: August 2009
Member
Rendering the shape is no doubt an important function of the object, but as Graphiti user, I would consider that not so relevant, in the sense that I expect such functionality to "just work" (so I can worry about higher level puzzles). I see it more as ShapeData or ShapeType (perhaps ShapeKind if "Type" is too ambiguous).
(Making it part of the "Shape" hierarchy would be *really* nice, but that may be a bridge too far, I don't know the structure well enough to judge feasibility of that step.)


IGefService doesn't seem to be public, but
IUiLayoutService uil = GraphitiUi.getUiLayoutService();
dim = uil.calculateTextSize(text.getValue(), text.getFont());
did the trick, thanks for the pointer.
Re: Getting width of text [message #1071993 is a reply to message #1067032] Sun, 21 July 2013 20:33 Go to previous messageGo to next message
Zhongwen Jiang is currently offline Zhongwen JiangFriend
Messages: 3
Registered: June 2013
Junior Member
Hey Albert,

why i get NULL after i called the method "calculateTextSize()"? Any hint will be appreciated Smile

Zhongwen
Re: Getting width of text [message #1131262 is a reply to message #1071993] Thu, 10 October 2013 11:04 Go to previous message
Antoine Lorence is currently offline Antoine LorenceFriend
Messages: 3
Registered: September 2013
Junior Member
Zhongwen Jiang wrote on Sun, 21 July 2013 16:33
why i get NULL after i called the method "calculateTextSize()"? Any hint will be appreciated Smile


Because text.getFont() return NULL if you didn't set explicitely a font to your text. If you set a style containing a font, you can use text.getStyle().getFont(). If you didn't, I don't know how to get the default font applied to a text.

Somebody knows ?
Previous Topic:How UNDO works in graphiti?
Next Topic:Update diagram after business object has been deleted
Goto Forum:
  


Current Time: Fri Mar 29 05:59:18 GMT 2024

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

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

Back to the top