Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Getting Text from graphic element
Getting Text from graphic element [message #1385735] Tue, 10 June 2014 19:15 Go to next message
Filipe Ramos is currently offline Filipe Ramos
Messages: 18
Registered: December 2013
Junior Member
Hi,

In my addFeature class, I create a Text in the following way:

Shape typeTextShape = peCreateService.createShape(containerShape, false);
Text typeText = gaService.createText(typeTextShape, "Some text!");

gaService.setLocationAndSize(typeText, 10, 10, 150, 50);

link(typeTextShape, addedElement);


Then, on my update feature I want to read that text. How can I do that? I tried:

for (Shape shape : containerShape.getChildren())
	if (shape instanceof Text)
		System.out.println("Text: " + ((Text) shape).getValue());


but it never finds a shape that is instance of Text...



Thanks in advance!
Re: Getting Text from graphic element [message #1385827 is a reply to message #1385735] Wed, 11 June 2014 12:34 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1595
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Filipe,

not sure...

Have you debugged that? Basic ideas could be:
- the container shaped are different instances
- you check for the wrong Text (wrong import?)

Michael
Re: Getting Text from graphic element [message #1385828 is a reply to message #1385827] Wed, 11 June 2014 12:38 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1595
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Sorry, forget my previous answer...

I just noticed that you check the children of the container if they are
instance of text. That will not work because there you are in the hierarchy
model of Graphiti and you get either shapes or container shapes mostly.

You will need to check if the graphics algorithm of the shape is instance of
Text:
if (shape.getGraphicsAlgorithm() instanceof Text)

Michael
Re: Getting Text from graphic element [message #1385938 is a reply to message #1385828] Thu, 12 June 2014 11:21 Go to previous message
Filipe Ramos is currently offline Filipe Ramos
Messages: 18
Registered: December 2013
Junior Member
That worked, thanks. Smile
Previous Topic:Draw Matrix in Graphiti
Next Topic:Complicated Shapes & Member Access
Goto Forum:
  


Current Time: Thu Sep 18 15:51:28 GMT 2014

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

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