Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Insert image as shape
Insert image as shape [message #1006590] Fri, 01 February 2013 03:27 Go to next message
Emerson Simbolon is currently offline Emerson SimbolonFriend
Messages: 12
Registered: April 2012
Junior Member
Hi all, I wonder whether Graphiti supports custom image as shape or not. I want to create components arrangement. Each component already has its own image defined. So, what I need is to arrange those image in Graphiti editor.

Thanks in advance.

Emerson
Re: Insert image as shape [message #1006687 is a reply to message #1006590] Fri, 01 February 2013 12:38 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Emerson,

there's a graphics algorithm image available, so instead of e.g. a rectangle
with text you could use that.

Michael
Re: Insert image as shape [message #1008626 is a reply to message #1006687] Wed, 13 February 2013 11:00 Go to previous messageGo to next message
Emerson Simbolon is currently offline Emerson SimbolonFriend
Messages: 12
Registered: April 2012
Junior Member
Hi Wenz,

I don't understand how to use your instruction. I looked down the the gaService instance of Graphiti. I create an Image instance using "createImage(containershape,stringid)". I lost it when I didn't found any function related to how to set the picture url. Can you point me a code snippet to insert an image?

Thanks and regards.
Emerson
Re: Insert image as shape [message #1009724 is a reply to message #1008626] Fri, 15 February 2013 15:37 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Emerson,

images have an ID that is used from within a diagram and defined within the
image provider. The tutorial page
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.graphiti.doc%2Fresources%2Fdocu%2Fgfw%2Fimages.htm&cp=27_1_6
should give you an idea how to handle them.

Michael
Re: Insert image as shape [message #1009976 is a reply to message #1009724] Sat, 16 February 2013 06:00 Go to previous messageGo to next message
Emerson Simbolon is currently offline Emerson SimbolonFriend
Messages: 12
Registered: April 2012
Junior Member
index.php/fa/13447/0/
What I want to achieve is described by picture above. I try to add image instance like this:
Image image = gaService.createImage(containerShape, GraphBTImageProvider.IMG_EREFERENCE);


But nothing happens, even the green box was not drawn. However, I tried to apply the registered image id (GraphBTImageProvider.IMG_EREFERENCE) to a ContextButton and it appeared. I think, the tutorial is not what I looking for (but still essential), or maybe I am mistaken something in using the registered image to a pictogram element.

[Updated on: Sat, 16 February 2013 06:04]

Report message to a moderator

Re: Insert image as shape [message #1011979 is a reply to message #1009976] Wed, 20 February 2013 16:11 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Emerson,

Sorry for the late reply, this somehow dropped in the depths of the forum...

Are the sizes set correctly for the image? Default is 0, so nothing
appears. Also you may need to set stretch/proportional flags on the image
depending on the size.

Michael
Re: Insert image as shape [message #1012018 is a reply to message #1011979] Wed, 20 February 2013 17:54 Go to previous messageGo to next message
Emerson Simbolon is currently offline Emerson SimbolonFriend
Messages: 12
Registered: April 2012
Junior Member
Thanks Michael, now it works Smile

However, to make sure I will use the feature, I want to ask, can I add/register the picture at run time. E.g, user just added a picture through a form, then, he opens the Graphiti editor. At that time, the picture shows up in the palette, ready to be included in the canvas. If this is not possible, maybe I will code the feature myself. But, if it is possible, I'll worship Graphiti for make me save my precious hours.

Thanks as always.
Emerson
Re: Insert image as shape [message #1012910 is a reply to message #1012018] Fri, 22 February 2013 12:50 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Emerson,

basically, the image provider manages a hash map containing ids and paths
for your images. You should be able to call addImageFilePath also after the
user added the picture. What you would need to care about yourself would be
removal of images in case you want to support that as well.

Michael
Re: Insert image as shape [message #1063192 is a reply to message #1012910] Wed, 12 June 2013 15:14 Go to previous messageGo to next message
Andrej K is currently offline Andrej KFriend
Messages: 26
Registered: March 2013
Location: germany
Junior Member
I have additional question about images
in my resize feature I'm resizing my Images to the correct size
and i want to put resized image into the shape, how i can do this? If i try with this code i get nothing/no image
(through debug mode, i can see that all images are correct "mapped" into the hashmap")
for (Shape shapeInside : cs.getChildren()) {//find/manipulate alls hapes(text,image,rectangle...)
     if(shapeInside.getGraphicsAlgorithm() instanceof Image){//find my Image
      int iconSide=...;//compute new Image Size
      conv.rasterizeImage("name", ""+this.elementToResize, iconSide,iconSide ); //convert new Image
      imgName= "name"+"_"+this.elementToResize+".png";
      iwas=new ImageProvider();
          	  					
      Image entityIcon;
      IGaService gaService = Graphiti.getGaService();
          	  					
      int id = iwas.getImageId(imgName); //output is an index for the given imgName
      Image imgIcon = gaService.createImage(shapeInside,ImageProvider.resizedIcons[id]);
          	  					
      imgIcon.setWidth(iconSide);
      imgIcon.setHeight(iconSide);
      imgIcon.setProportional(true);
      imgIcon.setX(20);
      imgIcon.setY(20);
          	  						
      gaService.setLocationAndSize(imgIcon, 0, 0, iconSide, iconSide);
}
...
}

if i change the id to for example to 0 or 4(and this image exists/ was resized at the last start) in the line:
Image imgIcon = gaService.createImage(shapeInside,ImageProvider.resizedIcons[id]);

so the Image is displayed correct

what I'm doing wrong? or how can i do this another way?
Re: Insert image as shape [message #1064078 is a reply to message #1063192] Mon, 17 June 2013 13:56 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Andrej,

in the resize feature you would typically only adapt the size of already
existing images in the diagram (the images should have already been added in
an add feature).
So in the add feature you would code something like this (gac is the
container shape for the image):
Image image = gaService.createImage(gac, SketchImageProvider.IMG_GRAPHITI);
image.setStretchH(true);
image.setStretchV(true);
image.setProportional(true);

while in the resize feature a simply gaService.setLocationAndSize(image,
.....) should be enough.

Michael
Previous Topic:Anchors
Next Topic:GetRemove function
Goto Forum:
  


Current Time: Fri Mar 29 10:20:55 GMT 2024

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

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

Back to the top