Home » Modeling » GMF (Graphical Modeling Framework) » Loading images into diagram editor
Loading images into diagram editor [message #188172] |
Wed, 21 May 2008 08:13  |
Eclipse User |
|
|
|
Hello everyone.
Is it possible to load images as shapes in a diagram editor? The images
would come from the file system and be selected by the user at shape
addition time.
How would this be reflected into the XML file for the diagram?
What formats would be acceptable?
Any examples out there that I could be pointed to?
TIA,
B.
--
Barbara Rosi-Schwartz
Etish Limited [http://www.etish.org]
Blog: http://www.brs4etish.blogspot.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^...^
/ o,o \ The proud parents of Useme
|) ::: (| The Open Requirements Management Tool
====w=w==== [https://useme.dev.java.net]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
Re: Loading images into diagram editor [message #188338 is a reply to message #188172] |
Wed, 21 May 2008 15:17   |
Eclipse User |
|
|
|
Hi Barbara,
I had a use-case for a similar feature as far as I understand, you desire.
Comments and snippets inline below.
Barbara Rosi-Schwartz schrieb:
> Hello everyone.
>
> Is it possible to load images as shapes in a diagram editor? The images
> would come from the file system and be selected by the user at shape
> addition time.
I created an Image-class with an attribute "imagePath" in my ecore-model.
I define a simple rectangle-figure (with no bounds) in the
..gmfgraph-model and add a label mapping in the gmfmap-model. (not a
feature label mapping, linked to the image-attribute)
1.The first thing to do is set a new property-descriptors for the
attribute in the generated code. This will allow you to choose an image
via a FileChooserDialog.
create a cell editor:
##
public class ImageCustomizableDialogCellEditor extends DialogCellEditor {
public ImageCustomizableDialogCellEditor(Composite parent) {
super(parent);
}
protected Object openDialogBox(Control cellEditorWindow) {
FileDialog dialog = new FileDialog(cellEditorWindow.getShell(),
SWT.OPEN);
dialog.open();
if (dialog.getFileName() != null && !dialog.getFileName().equals(""))
return dialog.getFilterPath() + "\\" + dialog.getFileName();
return getValue();
}
}
##
and a propertydecriptor:
##
public class ImageCustomizablePropertyDescriptor extends
EMFCompositeSourcePropertyDescriptor {
public ImageCustomizablePropertyDescriptor(Object object,
IItemPropertyDescriptor itemPropertyDescriptor, String category) {
super(object, itemPropertyDescriptor, category);
}
protected CellEditor doCreateEditor(Composite composite) {
/*
* The features for your element will be fed in one at a time Here you
* will override just the one(s) you want
*/
// System.out.println();
if (((EAttribute) getFeature()).getName().equals("image")) {
return new ImageCustomizableDialogCellEditor(composite);
}
return super.doCreateEditor(composite);
}
}
##
in the generated PropertySection modify the #getPropertySource-method:
##
public IPropertySource getPropertySource(Object object) {
if (object instanceof IPropertySource) {
return (IPropertySource) object;
}
AdapterFactory af = getAdapterFactory(object);
if (af != null) {
IItemPropertySource ips = (IItemPropertySource) af.adapt(object,
IItemPropertySource.class);
if (ips != null) {
//check for specific EObjects and assign custom IPropertyDescriptor
if (object instanceof <YOURCLASS>) {
return new EMFCompositePropertySource(object, ips, null) {
protected IPropertyDescriptor newPropertyDescriptor(
IItemPropertyDescriptor itemPropertyDescriptor) {
return new ImageCustomizablePropertyDescriptor(
object, itemPropertyDescriptor, null);
}
};
}
....
##
and you have the file-dialog to select the image-file.
2. Change the generated EditParts to show your image, set in the attribute.
In your generated EditPart for the Image-thingy, add the method
##
/**
* @generated NOT
*/
protected final void handleNotificationEvent(final Notification
notification) {
if (notification.getEventType() == Notification.SET &&
notification.getFeature() instanceof EAttribute){
EAttribute attr = (EAttribute) Notification.getFeature();
if (attr.getName().equals("image")) {
String elementName = notification.getNewStringValue();
Image image;
if (elementName != null && !elementName.equals("")
&& new File(elementName).exists()) {
try {
File file = new File(elementName);
URL url = file.toURI().toURL();
image = ImageDescriptor.createFromURL(url)
.createImage();
} catch (MalformedURLException e) {
e.printStackTrace();
image = ImageLoader
.getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
}
} else {
image = ImageLoader
.getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
}
//add the image to the label
((ImageCustomizableEditPart) source).getPrimaryShape()
.getFigureImageCustomizableImageIconLabel()
.setIcon(image);
super.handleNotificationEvent(notification);
}
##
modify the method getLabelIcon in the corresponding WrappingLabel of the
ImageEditPart to set an image right upon creation. The Notification will
only change it during runtime. But you want to show the image when the
diagram is initially loaded.
/**
* @generated NOT
*/
protected Image getLabelIcon() {
EObject parserElement = getParserElement();
if (parserElement == null) {
return null;
}
Eobject eObject = (EObject)parserElement;
String imagePath;
URL url = null;
if (eObject instanceof ImageCustomizable) {
imagePath = ((ImageCustomizable) eObject).getImage();
if (imagePath == null || imagePath.equals(""))
return ImageLoader
.getImageFromPath(ImageLoader.IMG_DEFAULT_IMG_CUSTOM);
if (!(new File(imagePath).exists()))
return ImageLoader
.getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
try {
url = new File(imagePath).toURI().toURL();
return ImageDescriptor.createFromURL(url).createImage();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
}
##
DONE
Excuse my copying, there could be some code, that references some
error-handling, I wrote in other classes. I hope the intention is clear.
> How would this be reflected into the XML file for the diagram?
Well, the solution I choose, only reflects the imagePath (which is a
String) as an attribute in the model-file.
>
> What formats would be acceptable?
Using a WrappingLabel, I succesfully use png, gif, jpg.
You could also use a ScalableImageFigure instead of a WrappingLabel in
order to use svg for example.
>
> Any examples out there that I could be pointed to?
See above.
HTH. If you need further explanation, don't hesitate to ask.
Regards Thomas
>
> TIA,
> B.
|
|
|
Re: Loading images into diagram editor [message #188641 is a reply to message #188338] |
Thu, 22 May 2008 06:26   |
Eclipse User |
|
|
|
Thomas, you are a star!
Fantastic example and explanation, thank you greatly. I definitely owe
you a few Pilsners... :-)
I will get onto it today and ask for your help if I come across any problem.
Tschuess,
B.
On 2008-05-21 20:17:29 +0100, Thomas Beyer
<thomas.beyer@atlas-elektronik.com> said:
> Hi Barbara,
>
> I had a use-case for a similar feature as far as I understand, you desire.
> Comments and snippets inline below.
>
> Barbara Rosi-Schwartz schrieb:
>> Hello everyone.
>>
>> Is it possible to load images as shapes in a diagram editor? The images
>> would come from the file system and be selected by the user at shape
>> addition time.
>
> I created an Image-class with an attribute "imagePath" in my ecore-model.
> I define a simple rectangle-figure (with no bounds) in the
> .gmfgraph-model and add a label mapping in the gmfmap-model. (not a
> feature label mapping, linked to the image-attribute)
>
> 1.The first thing to do is set a new property-descriptors for the
> attribute in the generated code. This will allow you to choose an image
> via a FileChooserDialog.
>
> create a cell editor:
>
> ##
> public class ImageCustomizableDialogCellEditor extends DialogCellEditor {
>
> public ImageCustomizableDialogCellEditor(Composite parent) {
> super(parent);
> }
>
> protected Object openDialogBox(Control cellEditorWindow) {
> FileDialog dialog = new FileDialog(cellEditorWindow.getShell(),
> SWT.OPEN);
> dialog.open();
> if (dialog.getFileName() != null && !dialog.getFileName().equals(""))
> return dialog.getFilterPath() + "\\" + dialog.getFileName();
> return getValue();
> }
>
> }
> ##
>
> and a propertydecriptor:
>
> ##
> public class ImageCustomizablePropertyDescriptor extends
> EMFCompositeSourcePropertyDescriptor {
> public ImageCustomizablePropertyDescriptor(Object object,
> IItemPropertyDescriptor itemPropertyDescriptor, String category) {
> super(object, itemPropertyDescriptor, category);
> }
>
> protected CellEditor doCreateEditor(Composite composite) {
> /*
> * The features for your element will be fed in one at a time Here you
> * will override just the one(s) you want
> */
> // System.out.println();
> if (((EAttribute) getFeature()).getName().equals("image")) {
> return new ImageCustomizableDialogCellEditor(composite);
> }
> return super.doCreateEditor(composite);
> }
> }
> ##
>
> in the generated PropertySection modify the #getPropertySource-method:
>
> ##
> public IPropertySource getPropertySource(Object object) {
> if (object instanceof IPropertySource) {
> return (IPropertySource) object;
> }
> AdapterFactory af = getAdapterFactory(object);
> if (af != null) {
> IItemPropertySource ips = (IItemPropertySource) af.adapt(object,
> IItemPropertySource.class);
> if (ips != null) {
> //check for specific EObjects and assign custom IPropertyDescriptor
> if (object instanceof <YOURCLASS>) {
> return new EMFCompositePropertySource(object, ips, null) {
> protected IPropertyDescriptor newPropertyDescriptor(
> IItemPropertyDescriptor itemPropertyDescriptor) {
> return new ImageCustomizablePropertyDescriptor(
> object, itemPropertyDescriptor, null);
> }
> };
> }
> ...
>
> ##
>
> and you have the file-dialog to select the image-file.
>
> 2. Change the generated EditParts to show your image, set in the attribute.
>
> In your generated EditPart for the Image-thingy, add the method
> ##
> /**
> * @generated NOT
> */
> protected final void handleNotificationEvent(final Notification
> notification) {
>
> if (notification.getEventType() == Notification.SET &&
> notification.getFeature() instanceof EAttribute){
> EAttribute attr = (EAttribute) Notification.getFeature();
> if (attr.getName().equals("image")) {
> String elementName = notification.getNewStringValue();
> Image image;
> if (elementName != null && !elementName.equals("")
> && new File(elementName).exists()) {
> try {
> File file = new File(elementName);
> URL url = file.toURI().toURL();
> image = ImageDescriptor.createFromURL(url)
> .createImage();
>
> } catch (MalformedURLException e) {
> e.printStackTrace();
> image = ImageLoader
> .getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
> }
> } else {
> image = ImageLoader
> .getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
> }
>
> //add the image to the label
> ((ImageCustomizableEditPart) source).getPrimaryShape()
> .getFigureImageCustomizableImageIconLabel()
> .setIcon(image);
>
> super.handleNotificationEvent(notification);
> }
> ##
>
> modify the method getLabelIcon in the corresponding WrappingLabel of
> the ImageEditPart to set an image right upon creation. The Notification
> will only change it during runtime. But you want to show the image when
> the diagram is initially loaded.
>
> /**
> * @generated NOT
> */
> protected Image getLabelIcon() {
> EObject parserElement = getParserElement();
> if (parserElement == null) {
> return null;
> }
> Eobject eObject = (EObject)parserElement;
> String imagePath;
> URL url = null;
> if (eObject instanceof ImageCustomizable) {
> imagePath = ((ImageCustomizable) eObject).getImage();
> if (imagePath == null || imagePath.equals(""))
> return ImageLoader
> .getImageFromPath(ImageLoader.IMG_DEFAULT_IMG_CUSTOM);
> if (!(new File(imagePath).exists()))
> return ImageLoader
> .getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
>
> try {
> url = new File(imagePath).toURI().toURL();
> return ImageDescriptor.createFromURL(url).createImage();
> } catch (MalformedURLException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> return null;
> }
> }
>
> }
> ##
>
> DONE
> Excuse my copying, there could be some code, that references some
> error-handling, I wrote in other classes. I hope the intention is clear.
>
>> How would this be reflected into the XML file for the diagram?
>
> Well, the solution I choose, only reflects the imagePath (which is a
> String) as an attribute in the model-file.
>
>>
>> What formats would be acceptable?
>
> Using a WrappingLabel, I succesfully use png, gif, jpg.
> You could also use a ScalableImageFigure instead of a WrappingLabel in
> order to use svg for example.
>
>>
>> Any examples out there that I could be pointed to?
>
> See above.
>
>
> HTH. If you need further explanation, don't hesitate to ask.
>
>
> Regards Thomas
>
>>
>> TIA,
>> B.
--
Barbara Rosi-Schwartz
Etish Limited [http://www.etish.org]
Blog: http://www.brs4etish.blogspot.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^...^
/ o,o \ The proud parents of Useme
|) ::: (| The Open Requirements Management Tool
====w=w==== [https://useme.dev.java.net]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
Re: Loading images into diagram editor [message #188795 is a reply to message #188338] |
Thu, 22 May 2008 09:51   |
Eclipse User |
|
|
|
The image formats supported are anything that SWT supports so PNG, JPG,
GIF, BMP, and Windows ICO formats.
Matt
Thomas Beyer wrote:
> Hi Barbara,
>
> I had a use-case for a similar feature as far as I understand, you desire.
> Comments and snippets inline below.
>
> Barbara Rosi-Schwartz schrieb:
>> Hello everyone.
>>
>> Is it possible to load images as shapes in a diagram editor? The
>> images would come from the file system and be selected by the user at
>> shape addition time.
>
> I created an Image-class with an attribute "imagePath" in my ecore-model.
> I define a simple rectangle-figure (with no bounds) in the
> .gmfgraph-model and add a label mapping in the gmfmap-model. (not a
> feature label mapping, linked to the image-attribute)
>
> 1.The first thing to do is set a new property-descriptors for the
> attribute in the generated code. This will allow you to choose an image
> via a FileChooserDialog.
>
> create a cell editor:
>
> ##
> public class ImageCustomizableDialogCellEditor extends DialogCellEditor {
>
> public ImageCustomizableDialogCellEditor(Composite parent) {
> super(parent);
> }
>
> protected Object openDialogBox(Control cellEditorWindow) {
> FileDialog dialog = new FileDialog(cellEditorWindow.getShell(),
> SWT.OPEN);
> dialog.open();
> if (dialog.getFileName() != null &&
> !dialog.getFileName().equals(""))
> return dialog.getFilterPath() + "\\" + dialog.getFileName();
> return getValue();
> }
>
> }
> ##
>
> and a propertydecriptor:
>
> ##
> public class ImageCustomizablePropertyDescriptor extends
> EMFCompositeSourcePropertyDescriptor {
> public ImageCustomizablePropertyDescriptor(Object object,
> IItemPropertyDescriptor itemPropertyDescriptor, String
> category) {
> super(object, itemPropertyDescriptor, category);
> }
>
> protected CellEditor doCreateEditor(Composite composite) {
> /*
> * The features for your element will be fed in one at a time
> Here you
> * will override just the one(s) you want
> */
> // System.out.println();
> if (((EAttribute) getFeature()).getName().equals("image")) {
> return new ImageCustomizableDialogCellEditor(composite);
> }
> return super.doCreateEditor(composite);
> }
> }
> ##
>
> in the generated PropertySection modify the #getPropertySource-method:
>
> ##
> public IPropertySource getPropertySource(Object object) {
> if (object instanceof IPropertySource) {
> return (IPropertySource) object;
> }
> AdapterFactory af = getAdapterFactory(object);
> if (af != null) {
> IItemPropertySource ips = (IItemPropertySource)
> af.adapt(object,
> IItemPropertySource.class);
> if (ips != null) {
> //check for specific EObjects and assign custom
> IPropertyDescriptor
> if (object instanceof <YOURCLASS>) {
> return new EMFCompositePropertySource(object, ips,
> null) {
> protected IPropertyDescriptor
> newPropertyDescriptor(
> IItemPropertyDescriptor
> itemPropertyDescriptor) {
> return new ImageCustomizablePropertyDescriptor(
> object, itemPropertyDescriptor, null);
> }
> };
> }
> ...
>
> ##
>
> and you have the file-dialog to select the image-file.
>
> 2. Change the generated EditParts to show your image, set in the attribute.
>
> In your generated EditPart for the Image-thingy, add the method
> ##
> /**
> * @generated NOT
> */
> protected final void handleNotificationEvent(final Notification
> notification) {
>
> if (notification.getEventType() == Notification.SET &&
> notification.getFeature() instanceof EAttribute){
> EAttribute attr = (EAttribute) Notification.getFeature();
> if (attr.getName().equals("image")) {
> String elementName = notification.getNewStringValue();
> Image image;
> if (elementName != null && !elementName.equals("")
> && new File(elementName).exists()) {
> try {
> File file = new File(elementName);
> URL url = file.toURI().toURL();
> image = ImageDescriptor.createFromURL(url)
> .createImage();
>
> } catch (MalformedURLException e) {
> e.printStackTrace();
> image = ImageLoader
>
> .getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
> }
> } else {
> image = ImageLoader
>
> .getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
> }
>
> //add the image to the label
> ((ImageCustomizableEditPart) source).getPrimaryShape()
> .getFigureImageCustomizableImageIconLabel()
> .setIcon(image);
>
> super.handleNotificationEvent(notification);
> }
> ##
>
> modify the method getLabelIcon in the corresponding WrappingLabel of the
> ImageEditPart to set an image right upon creation. The Notification will
> only change it during runtime. But you want to show the image when the
> diagram is initially loaded.
>
> /**
> * @generated NOT
> */
> protected Image getLabelIcon() {
> EObject parserElement = getParserElement();
> if (parserElement == null) {
> return null;
> }
> Eobject eObject = (EObject)parserElement;
> String imagePath;
> URL url = null;
> if (eObject instanceof ImageCustomizable) {
> imagePath = ((ImageCustomizable) eObject).getImage();
> if (imagePath == null || imagePath.equals(""))
> return ImageLoader
>
> .getImageFromPath(ImageLoader.IMG_DEFAULT_IMG_CUSTOM);
> if (!(new File(imagePath).exists()))
> return ImageLoader
>
> .getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
>
> try {
> url = new File(imagePath).toURI().toURL();
> return ImageDescriptor.createFromURL(url).createImage();
> } catch (MalformedURLException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> return null;
> }
> }
>
> }
> ##
>
> DONE
> Excuse my copying, there could be some code, that references some
> error-handling, I wrote in other classes. I hope the intention is clear.
>
>> How would this be reflected into the XML file for the diagram?
>
> Well, the solution I choose, only reflects the imagePath (which is a
> String) as an attribute in the model-file.
>
>>
>> What formats would be acceptable?
>
> Using a WrappingLabel, I succesfully use png, gif, jpg.
> You could also use a ScalableImageFigure instead of a WrappingLabel in
> order to use svg for example.
>
>>
>> Any examples out there that I could be pointed to?
>
> See above.
>
>
> HTH. If you need further explanation, don't hesitate to ask.
>
>
> Regards Thomas
>
>>
>> TIA,
>> B.
|
|
| | |
Re: Loading images into diagram editor [message #189169 is a reply to message #188338] |
Fri, 23 May 2008 10:43   |
Eclipse User |
|
|
|
On 2008-05-21 20:17:29 +0100, Thomas Beyer
<thomas.beyer@atlas-elektronik.com> said:
> Hi Barbara,
>
> I had a use-case for a similar feature as far as I understand, you desire.
> Comments and snippets inline below.
>
> Barbara Rosi-Schwartz schrieb:
>> Hello everyone.
>>
>> Is it possible to load images as shapes in a diagram editor? The images
>> would come from the file system and be selected by the user at shape
>> addition time.
>
> I created an Image-class with an attribute "imagePath" in my ecore-model.
> I define a simple rectangle-figure (with no bounds) in the
> .gmfgraph-model and add a label mapping in the gmfmap-model. (not a
> feature label mapping, linked to the image-attribute)
>
> 1.The first thing to do is set a new property-descriptors for the
> attribute in the generated code. This will allow you to choose an image
> via a FileChooserDialog.
>
> create a cell editor:
>
> ##
> public class ImageCustomizableDialogCellEditor extends DialogCellEditor {
>
> public ImageCustomizableDialogCellEditor(Composite parent) {
> super(parent);
> }
>
> protected Object openDialogBox(Control cellEditorWindow) {
> FileDialog dialog = new FileDialog(cellEditorWindow.getShell(),
> SWT.OPEN);
> dialog.open();
> if (dialog.getFileName() != null && !dialog.getFileName().equals(""))
> return dialog.getFilterPath() + "\\" + dialog.getFileName();
> return getValue();
> }
>
> }
> ##
>
> and a propertydecriptor:
>
> ##
> public class ImageCustomizablePropertyDescriptor extends
> EMFCompositeSourcePropertyDescriptor {
> public ImageCustomizablePropertyDescriptor(Object object,
> IItemPropertyDescriptor itemPropertyDescriptor, String category) {
> super(object, itemPropertyDescriptor, category);
> }
>
> protected CellEditor doCreateEditor(Composite composite) {
> /*
> * The features for your element will be fed in one at a time Here you
> * will override just the one(s) you want
> */
> // System.out.println();
> if (((EAttribute) getFeature()).getName().equals("image")) {
> return new ImageCustomizableDialogCellEditor(composite);
> }
> return super.doCreateEditor(composite);
> }
> }
> ##
>
> in the generated PropertySection modify the #getPropertySource-method:
>
> ##
> public IPropertySource getPropertySource(Object object) {
> if (object instanceof IPropertySource) {
> return (IPropertySource) object;
> }
> AdapterFactory af = getAdapterFactory(object);
> if (af != null) {
> IItemPropertySource ips = (IItemPropertySource) af.adapt(object,
> IItemPropertySource.class);
> if (ips != null) {
> //check for specific EObjects and assign custom IPropertyDescriptor
> if (object instanceof <YOURCLASS>) {
> return new EMFCompositePropertySource(object, ips, null) {
> protected IPropertyDescriptor newPropertyDescriptor(
> IItemPropertyDescriptor itemPropertyDescriptor) {
> return new ImageCustomizablePropertyDescriptor(
> object, itemPropertyDescriptor, null);
> }
> };
> }
> ...
>
> ##
>
> and you have the file-dialog to select the image-file.
>
> 2. Change the generated EditParts to show your image, set in the attribute.
>
> In your generated EditPart for the Image-thingy, add the method
> ##
> /**
> * @generated NOT
> */
> protected final void handleNotificationEvent(final Notification
> notification) {
>
> if (notification.getEventType() == Notification.SET &&
> notification.getFeature() instanceof EAttribute){
> EAttribute attr = (EAttribute) Notification.getFeature();
> if (attr.getName().equals("image")) {
> String elementName = notification.getNewStringValue();
> Image image;
> if (elementName != null && !elementName.equals("")
> && new File(elementName).exists()) {
> try {
> File file = new File(elementName);
> URL url = file.toURI().toURL();
> image = ImageDescriptor.createFromURL(url)
> .createImage();
>
> } catch (MalformedURLException e) {
> e.printStackTrace();
> image = ImageLoader
> .getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
> }
> } else {
> image = ImageLoader
> .getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
> }
>
> //add the image to the label
> ((ImageCustomizableEditPart) source).getPrimaryShape()
> .getFigureImageCustomizableImageIconLabel()
> .setIcon(image);
>
> super.handleNotificationEvent(notification);
> }
> ##
>
> modify the method getLabelIcon in the corresponding WrappingLabel of
> the ImageEditPart to set an image right upon creation. The Notification
> will only change it during runtime. But you want to show the image when
> the diagram is initially loaded.
>
> /**
> * @generated NOT
> */
> protected Image getLabelIcon() {
> EObject parserElement = getParserElement();
> if (parserElement == null) {
> return null;
> }
> Eobject eObject = (EObject)parserElement;
> String imagePath;
> URL url = null;
> if (eObject instanceof ImageCustomizable) {
> imagePath = ((ImageCustomizable) eObject).getImage();
> if (imagePath == null || imagePath.equals(""))
> return ImageLoader
> .getImageFromPath(ImageLoader.IMG_DEFAULT_IMG_CUSTOM);
> if (!(new File(imagePath).exists()))
> return ImageLoader
> .getImageFromPath(ImageLoader.IMG_ERROR_IMG_CUSTOM);
>
> try {
> url = new File(imagePath).toURI().toURL();
> return ImageDescriptor.createFromURL(url).createImage();
> } catch (MalformedURLException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> return null;
> }
> }
>
> }
> ##
>
> DONE
> Excuse my copying, there could be some code, that references some
> error-handling, I wrote in other classes. I hope the intention is clear.
>
>> How would this be reflected into the XML file for the diagram?
>
> Well, the solution I choose, only reflects the imagePath (which is a
> String) as an attribute in the model-file.
>
>>
>> What formats would be acceptable?
>
> Using a WrappingLabel, I succesfully use png, gif, jpg.
> You could also use a ScalableImageFigure instead of a WrappingLabel in
> order to use svg for example.
>
>>
>> Any examples out there that I could be pointed to?
>
> See above.
>
>
> HTH. If you need further explanation, don't hesitate to ask.
>
>
> Regards Thomas
>
>>
>> TIA,
>> B.
Thomas,
I do have a quick question after all. What would you do if you were to
support both BMP images and SVG images in the same code?
Thanks,
B.
--
Barbara Rosi-Schwartz
Etish Limited [http://www.etish.org]
Blog: http://www.brs4etish.blogspot.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^...^
/ o,o \ The proud parents of Useme
|) ::: (| The Open Requirements Management Tool
====w=w==== [https://useme.dev.java.net]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
Re: Loading images into diagram editor [message #189238 is a reply to message #189169] |
Fri, 23 May 2008 13:54   |
Eclipse User |
|
|
|
Barbara Rosi-Schwartz schrieb:
[...]
> Thomas,
>
> I do have a quick question after all. What would you do if you were to
> support both BMP images and SVG images in the same code?
>
> Thanks,
> B.
>
Barbara,
I would suggest just to use a ScalableImageFigure instead of the
WrappingLabel in your case.
I use the ScalableImageFigure for some Nodes, and they support svg as
well as the image-types, that the wrappinglabel does.
So you don't need to load different code at runtime, or even switch the
graphicaleditpart.
The code for the imagefigure could look like this:
public class YourFigure extends ScalableImageFigure {
public YourFigure() {
super(yourimage, true,true, true);
}
}
Now you can also add your custom methods to modify the image or use the
ones, the superclass provides.
Simply set a "custom figure" in the gmfgraph-model as a child for your
desired figure an set the entry "qualified class name" to your "YourFigure".
Regenerate, done.
In the resulting GraphicalEditPart you can access the
ScalableImageFigure just as convinient as the WrappingLabel and do
updates on it ;-)
Regards Thomas
|
|
|
Re: Loading images into diagram editor [message #189259 is a reply to message #189238] |
Sat, 24 May 2008 05:24  |
Eclipse User |
|
|
|
On 2008-05-23 18:54:21 +0100, Thomas Beyer
<thomas.beyer@atlas-elektronik.com> said:
> Barbara Rosi-Schwartz schrieb:
> [...]
>> Thomas,
>>
>> I do have a quick question after all. What would you do if you were to
>> support both BMP images and SVG images in the same code?
>>
>> Thanks,
>> B.
>>
>
> Barbara,
>
> I would suggest just to use a ScalableImageFigure instead of the
> WrappingLabel in your case.
> I use the ScalableImageFigure for some Nodes, and they support svg as
> well as the image-types, that the wrappinglabel does.
> So you don't need to load different code at runtime, or even switch the
> graphicaleditpart.
>
> The code for the imagefigure could look like this:
>
>
> public class YourFigure extends ScalableImageFigure {
>
> public YourFigure() {
> super(yourimage, true,true, true);
> }
> }
>
> Now you can also add your custom methods to modify the image or use the
> ones, the superclass provides.
>
> Simply set a "custom figure" in the gmfgraph-model as a child for your
> desired figure an set the entry "qualified class name" to your
> "YourFigure".
> Regenerate, done.
> In the resulting GraphicalEditPart you can access the
> ScalableImageFigure just as convinient as the WrappingLabel and do
> updates on it ;-)
>
>
> Regards Thomas
Thanks Thomas.
My only problem is that I would like for my image node to be resizable
in the case of a scalable (i.e. SVG) image and not resizable in the
case of a BMP image. How do I force the ScalableImageFigure to not
resize? Would a listener be ok?
Thanks and kind regards,
B.
--
Barbara Rosi-Schwartz
Etish Limited [http://www.etish.org]
Blog: http://www.brs4etish.blogspot.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^...^
/ o,o \ The proud parents of Useme
|) ::: (| The Open Requirements Management Tool
====w=w==== [https://useme.dev.java.net]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
Goto Forum:
Current Time: Mon May 12 15:29:53 EDT 2025
Powered by FUDForum. Page generated in 0.03294 seconds
|