Displaying Images [message #1310568] |
Wed, 23 April 2014 09:03 |
John Cole Messages: 66 Registered: June 2013 |
Member |
|
|
Hello everyone,
I am trying to display a simple image and unfortunately it doesn't appear.
The affected part of my AddFeature looks like this:
public PictogramElement add(IAddContext context) {
// CODE
ContainerShape container = peCreateService.createContainerShape(context.getTargetContainer(), true);
// CODE
createImage(context, container);
// CODE
}
private void createImage(IAddContext context, ContainerShape container) {
Image image = gaService.createImage(container, DiagramImageProvider.IMG_EREFERENCE);
gaService.setLocationAndSize(image, context.getX(), context.getY(), 500, 500);
}
My ImageProvider looks like this:
public class DiagramImageProvider extends AbstractImageProvider {
// The prefix for all identifiers of this image provider
protected static final String PREFIX = "my.example.diagram.";
// The image identifier for an EReference.
public static final String IMG_EREFERENCE = PREFIX + "exampleimage";
@Override
protected void addAvailableImages() {
String path = (FileSystems.getDefault().getPath("icons", "exampleimage.png")).toString();
// register the path for each image identifier
addImageFilePath(IMG_EREFERENCE, path);
}
}
I think I misunderstand something but the method addAvailableImages() in my ImageProvider is never called and due to this the image is not displayed. It simply looks like this:
What do I have to do, to display the image in my editor?
I appreciate any advice!
-
Attachment: Screen.png
(Size: 9.89KB, Downloaded 479 times)
|
|
|
|
Re: Displaying Images [message #1312437 is a reply to message #1310820] |
Thu, 24 April 2014 09:40 |
John Cole Messages: 66 Registered: June 2013 |
Member |
|
|
Thank you very much once again, Michael! I did not assign it to the diagram type provider. Now it works.
But I've got another question concerning a similar problem.
I want to load images on the fly. Means, that I know which image in my icons folder has to be loaded and I know the path. Currently my ImageProvider looks like this:
public class ImageProvider extends AbstractImageProvider {
// The prefix for all identifiers of this image provider
protected static final String PREFIX = "my.example.diagram.";
public static String image = PREFIX + "circle";
@Override
protected void addAvailableImages() {
String path = (FileSystems.getDefault().getPath("icons", "circle.png")).toString();
// register the path for each image identifier
addImageFilePath(image, path);
}
}
So only the circle.png is supported at the moment. In my AddFeature I've got the following code:
Image image = gaService.createImage(container, ImageProvider.image);
gaService.setLocationAndSize(image, context.getX(), context.getY(), context.getWidth(), context.getHeight());
Now I want to load different images on the fly, when the add() method in my AddFeature is called. How is that possible?
Thank you very much in advance!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07132 seconds