Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » Capturing Images
Capturing Images [message #92984] Mon, 06 June 2005 07:10 Go to next message
Eclipse UserFriend
Originally posted by: rabius.yahoo.de

Hello!
I would like to display an image of an awt component as ImageFigure. I use
the following method to create an image of the existing awt component:

Image compImage = component.createImage(width, height);

Now I would like to display this image as ImageFigure in my GEF editor.
But how can I convert the java.awt.Image into a swt.Image.

TIA, Mario
Re: Capturing Images [message #93013 is a reply to message #92984] Mon, 06 June 2005 09:55 Go to previous messageGo to next message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Mario,


> I would like to display an image of an awt component as ImageFigure. I
> use the following method to create an image of the existing awt component:
>
> Image compImage = component.createImage(width, height);
>
> Now I would like to display this image as ImageFigure in my GEF editor.
> But how can I convert the java.awt.Image into a swt.Image.

http://dev.eclipse.org/newslists/news.eclipse.platform.swt/m sg10712.html

Yannick Saillet also wrote a good article on developerworks at:
http://www-128.ibm.com/developerworks/java/library/j-2dswt/i ndex.html

Both us the same technique that the visual editor does, which is to walk
the pixel bytes do the conversion, taking into account things like the
palette type, the color depth, transparency, etc... If you want to see
the VE class that does this it is
org.eclipse.ve.internal.jfc.core.ImageDataCollector.

Out of curiosity however, if you are doing some kind of AWT image
capture and displaying it in GEF that sort of sounds like you are
building a GUI builder. If so, cool. What is your end game though, and
is there any possibility that you could share more about your project as
it is possible that the VE might be able to help as a framework. The
Visual Editor is both an end-user GUI builder and also a framework, and
the framework has been successfully extended by a number of people for
various things such as XML persistence or lightweight Swing J2EE
widgets, as well as for AWT/Swing and SWT. We're always interested to
see what kind of things people are trying to build using Eclipse that
are GUIbuilder ish so that we can document and shape the VE framework to
help in their endeavours.

Best regards,

Joe Winchester
Re: Capturing Images [message #93071 is a reply to message #93013] Mon, 06 June 2005 20:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rabius.yahoo.de

Dear Joe,
Thanks for the answer and the helpful links. I succeeded in converting the
captured awt images.
Concerning your curiosity, my project is really some kind of GUI builder.
I considered using the visual editor framework, but I didn't actually find
out how to use it. It coudn't find much documentation and I was not sure
if it is clever to use the API specified in internal packages. Moreover,
my graphical editor displayes Swing components, but it does not generate
Java code, but an own scripting language which describes the Swing
components and the layout on a meta level. To build the GUI, the generated
script is sent to an external layout engine which sends back a Swing frame
that is displayed in the GEF editor. As model I use an own EMF model and I
didn't see how to use the VE framework since it seems to be dependent on
the Java model. Would it be possible to extend the VE framework using an
own model?
By the way, I wonder why VE uses additional Java virtual machines for the
capturing of live images. Wouldn't it be possible to do this in the same
vm? It seems rather complicated to me and for my editor I do the layouting
and the capturing of images in the same vm.
Regards, Mario


Joe Winchester wrote:

> Hi Mario,


>> I would like to display an image of an awt component as ImageFigure. I
>> use the following method to create an image of the existing awt component:
>>
>> Image compImage = component.createImage(width, height);
>>
>> Now I would like to display this image as ImageFigure in my GEF editor.
>> But how can I convert the java.awt.Image into a swt.Image.

> http://dev.eclipse.org/newslists/news.eclipse.platform.swt/m sg10712.html

> Yannick Saillet also wrote a good article on developerworks at:
> http://www-128.ibm.com/developerworks/java/library/j-2dswt/i ndex.html

> Both us the same technique that the visual editor does, which is to walk
> the pixel bytes do the conversion, taking into account things like the
> palette type, the color depth, transparency, etc... If you want to see
> the VE class that does this it is
> org.eclipse.ve.internal.jfc.core.ImageDataCollector.

> Out of curiosity however, if you are doing some kind of AWT image
> capture and displaying it in GEF that sort of sounds like you are
> building a GUI builder. If so, cool. What is your end game though, and
> is there any possibility that you could share more about your project as
> it is possible that the VE might be able to help as a framework. The
> Visual Editor is both an end-user GUI builder and also a framework, and
> the framework has been successfully extended by a number of people for
> various things such as XML persistence or lightweight Swing J2EE
> widgets, as well as for AWT/Swing and SWT. We're always interested to
> see what kind of things people are trying to build using Eclipse that
> are GUIbuilder ish so that we can document and shape the VE framework to
> help in their endeavours.

> Best regards,

> Joe Winchester
Re: Capturing Images [message #93100 is a reply to message #93071] Mon, 06 June 2005 21:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

The reason we do this is because we need to:

1) Run on different vm's than the one that the IDE is running on.
2) We are running user code. We don't want to cause the IDE to crash
because some user code happened to do something bad.
3) We are constantly changing and recompilling classes, this makes it
very difficult to work with the IDE vm because it would load the classes
and keep them loaded. We would have to some complicated class loader
stuff to get around this.

--
Thanks,
Rich Kulp
Re: Capturing Images [message #93129 is a reply to message #93071] Tue, 07 June 2005 09:01 Go to previous messageGo to next message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Mario,

> my project is really some kind of GUI builder. I considered using the
> visual editor framework, but I didn't actually find out how to use it.
> It coudn't find much documentation and I was not sure if it is clever to
> use the API specified in internal packages.

I wouldn't worry that much about using the internal packages. The VE
itself uses them for its AWT/Swing/SWT implementations as do other
people extending the VE so there is strength in numbers. We do intend
to move them from the internal to the fully public API but there is
protocol required to do this that we just haven't done yet. Any changes
that occur during the transition will be because we iron out problems
and will be improvements and should be easy to accomodate.

> Moreover, my graphical
> editor displayes Swing components, but it does not generate Java code,
> but an own scripting language which describes the Swing components and
> the layout on a meta level. To build the GUI, the generated script is
> sent to an external layout engine which sends back a Swing frame that is
> displayed in the GEF editor. As model I use an own EMF model and I
> didn't see how to use the VE framework since it seems to be dependent on
> the Java model. Would it be possible to extend the VE framework using an
> own model?

The VE model is an EMF model in the .jem packages whose meta layer is a
model of a Java class and instances. This model gives you a lot, mainly
because all of the entries in the project's build path are available in
the model whether they are in dependent projects, .jar files, exist as
binaries only, have BeanInfo extensions, etc... The VE also has
adapters for the model that handle things like the target VM that can
crank up the live beans for you, so if you set a property on the
property sheet or drop from the palette and GEF updates the model then
the live bean is updated automagically for you. In addition there is a
code generation set of adapters and parsers that work with .java source
but for your app these wouldn't be required, and there are other VE
extension projects that work without them just leveraging the VE's EMF
model.

Given the fact that the VE provides viewers that work with its model;
the property sheet, the GEF graphical viewer, the tree viewer, etc...
the technique used so far with other models is to have them generate the
VE model on open and save to their model on close. If you didn't do
this you would have to re-invent the entire property sheet and live VM
and the devil is in the detail - for example the whole Swing
invalidate/validate tree when things are changed and how you handle
tabbed folders, split panes, toolbars, content panes, layout managers
with all of the various feedback etc... will take a fair while.

Does the route of having your model round trip into the VE model on open
and save sound like it would work for you ?

> By the way, I wonder why VE uses additional Java virtual machines for
> the capturing of live images. Wouldn't it be possible to do this in the
> same vm? It seems rather complicated to me and for my editor I do the
> layouting and the capturing of images in the same vm.

It is kinda complicated however it's one of the strengths of the VE.
There is an option to have the VE actually use the IDE as its VM that
can be enabled although you will need to ask for help on the VE
newsgroup for this as it comes with a health warning that Rich
articulates. The target VM means that the -classpath of the VM is NOT
the Eclipse IDE one but the build path of the Java project. The way to
think of this is what happens when you do a Run As>Java Application - a
separate JVM is started for you with the necessary .jar files for you
code. The VE has to create a preview of your GUI using the Java files
in the project's build path so it starts its own VM. The complication
is hidden from you however and we have done considerable work in our
last and next release (M1.1 and M1.2) to improve performance across the
socket layer between our VMs.

VisualAge for Java used to run its widgets in the same VM and while this
has attractions of being easier to write it is sort of a fool's gold.
Ultimately people want to replace the JRE level to be one other than the
one the IDE supports and work with jars and projects that are not in the
IDE's -classpath and to do so either requires class loader magic (which
introduces its own set of problems and becomes complicated) or else a
proper architected sandbox environment which is what the VE uses.

Best regards,

Joe Winchester
Re: Capturing Images [message #93144 is a reply to message #93129] Tue, 07 June 2005 16:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

>
>> Moreover, my graphical editor displayes Swing components, but it does
>> not generate Java code, but an own scripting language which describes
>> the Swing components and the layout on a meta level. To build the GUI,
>> the generated script is sent to an external layout engine which sends
>> back a Swing frame that is displayed in the GEF editor. As model I use
>> an own EMF model and I didn't see how to use the VE framework since it
>> seems to be dependent on the Java model. Would it be possible to
>> extend the VE framework using an own model?
>
>

As Joe mentioned the devil is in the details, but if you are not a java
project, nor are you generating java code, nor are you trying to compose
together java components, but you are using Swing simply as a rendering
mechanism, then there is something we have that can help.

It is called the jfc.ComponentManager. It has been extensively changed
and enhanced in the latest VE 1.1 drivers. It doesn't require the Jave
EMF model, nor does it even require a remote vm. It does require what we
call a proxy registry (which is what we use, but we have a version that
runs a remote vm, or one that runs within the IDE). If you have a
predefined set of visuals and you will not be running any user code to
do the Swing rendering, just your layout engine which you have complete
control of, then you can use the IDE registry. You won't be changing
class and you won't be needing a different JVM than the IDE's.

The ComponentManager handles Swing/AWT components. It listens for
changes (move/size), does validate() for you, and returns a new image
whenever the validation was done.

It is in the JFC plugin, but it doesn't require any of the other Java
EMF jfc stuff, like the proxy adapters.
--
Thanks,
Rich Kulp
Re: Capturing Images [message #93158 is a reply to message #93144] Tue, 07 June 2005 17:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

The best way would be if on bringing up your editor, you convert it into
an EMF model. It doesn't need to be Java EMF, just an EMF model. That
way you can have adapters on the EMF objects that listen for feature
changes, and when these changes occur, they can contact your display
engine to have it update the Swing visual, and then tell the
ComponentManager that it has been updated and needs validation. Then
using the new ModelChangeController and transaction grouping it will
then give you the new image at the end.

Then when you save you would convert the EMF model back into your saved
representation.


I wish we had an example of doing this. It is a powerful concept but we
haven't had time to do this.

--
Thanks,
Rich Kulp
Re: Capturing Images [message #93173 is a reply to message #93158] Thu, 09 June 2005 17:14 Go to previous message
Eclipse UserFriend
Originally posted by: rabuis.yahoo.de

Dear Joe, dear Rich,
Thank you very much for the detailed answers. I understand now why VE uses
several VMs.
For my editor I'll try to use my own EMF model together with the VEs
ComponentManager as Rich sugested. I hope to get it working without an
example.
-- Mario
Re: Capturing Images [message #607889 is a reply to message #92984] Mon, 06 June 2005 09:55 Go to previous message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Mario,


> I would like to display an image of an awt component as ImageFigure. I
> use the following method to create an image of the existing awt component:
>
> Image compImage = component.createImage(width, height);
>
> Now I would like to display this image as ImageFigure in my GEF editor.
> But how can I convert the java.awt.Image into a swt.Image.

http://dev.eclipse.org/newslists/news.eclipse.platform.swt/m sg10712.html

Yannick Saillet also wrote a good article on developerworks at:
http://www-128.ibm.com/developerworks/java/library/j-2dswt/i ndex.html

Both us the same technique that the visual editor does, which is to walk
the pixel bytes do the conversion, taking into account things like the
palette type, the color depth, transparency, etc... If you want to see
the VE class that does this it is
org.eclipse.ve.internal.jfc.core.ImageDataCollector.

Out of curiosity however, if you are doing some kind of AWT image
capture and displaying it in GEF that sort of sounds like you are
building a GUI builder. If so, cool. What is your end game though, and
is there any possibility that you could share more about your project as
it is possible that the VE might be able to help as a framework. The
Visual Editor is both an end-user GUI builder and also a framework, and
the framework has been successfully extended by a number of people for
various things such as XML persistence or lightweight Swing J2EE
widgets, as well as for AWT/Swing and SWT. We're always interested to
see what kind of things people are trying to build using Eclipse that
are GUIbuilder ish so that we can document and shape the VE framework to
help in their endeavours.

Best regards,

Joe Winchester
Re: Capturing Images [message #607893 is a reply to message #93013] Mon, 06 June 2005 20:30 Go to previous message
Eclipse UserFriend
Originally posted by: rabius.yahoo.de

Dear Joe,
Thanks for the answer and the helpful links. I succeeded in converting the
captured awt images.
Concerning your curiosity, my project is really some kind of GUI builder.
I considered using the visual editor framework, but I didn't actually find
out how to use it. It coudn't find much documentation and I was not sure
if it is clever to use the API specified in internal packages. Moreover,
my graphical editor displayes Swing components, but it does not generate
Java code, but an own scripting language which describes the Swing
components and the layout on a meta level. To build the GUI, the generated
script is sent to an external layout engine which sends back a Swing frame
that is displayed in the GEF editor. As model I use an own EMF model and I
didn't see how to use the VE framework since it seems to be dependent on
the Java model. Would it be possible to extend the VE framework using an
own model?
By the way, I wonder why VE uses additional Java virtual machines for the
capturing of live images. Wouldn't it be possible to do this in the same
vm? It seems rather complicated to me and for my editor I do the layouting
and the capturing of images in the same vm.
Regards, Mario


Joe Winchester wrote:

> Hi Mario,


>> I would like to display an image of an awt component as ImageFigure. I
>> use the following method to create an image of the existing awt component:
>>
>> Image compImage = component.createImage(width, height);
>>
>> Now I would like to display this image as ImageFigure in my GEF editor.
>> But how can I convert the java.awt.Image into a swt.Image.

> http://dev.eclipse.org/newslists/news.eclipse.platform.swt/m sg10712.html

> Yannick Saillet also wrote a good article on developerworks at:
> http://www-128.ibm.com/developerworks/java/library/j-2dswt/i ndex.html

> Both us the same technique that the visual editor does, which is to walk
> the pixel bytes do the conversion, taking into account things like the
> palette type, the color depth, transparency, etc... If you want to see
> the VE class that does this it is
> org.eclipse.ve.internal.jfc.core.ImageDataCollector.

> Out of curiosity however, if you are doing some kind of AWT image
> capture and displaying it in GEF that sort of sounds like you are
> building a GUI builder. If so, cool. What is your end game though, and
> is there any possibility that you could share more about your project as
> it is possible that the VE might be able to help as a framework. The
> Visual Editor is both an end-user GUI builder and also a framework, and
> the framework has been successfully extended by a number of people for
> various things such as XML persistence or lightweight Swing J2EE
> widgets, as well as for AWT/Swing and SWT. We're always interested to
> see what kind of things people are trying to build using Eclipse that
> are GUIbuilder ish so that we can document and shape the VE framework to
> help in their endeavours.

> Best regards,

> Joe Winchester
Re: Capturing Images [message #607895 is a reply to message #93071] Mon, 06 June 2005 21:03 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

The reason we do this is because we need to:

1) Run on different vm's than the one that the IDE is running on.
2) We are running user code. We don't want to cause the IDE to crash
because some user code happened to do something bad.
3) We are constantly changing and recompilling classes, this makes it
very difficult to work with the IDE vm because it would load the classes
and keep them loaded. We would have to some complicated class loader
stuff to get around this.

--
Thanks,
Rich Kulp
Re: Capturing Images [message #607897 is a reply to message #93071] Tue, 07 June 2005 09:01 Go to previous message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Mario,

> my project is really some kind of GUI builder. I considered using the
> visual editor framework, but I didn't actually find out how to use it.
> It coudn't find much documentation and I was not sure if it is clever to
> use the API specified in internal packages.

I wouldn't worry that much about using the internal packages. The VE
itself uses them for its AWT/Swing/SWT implementations as do other
people extending the VE so there is strength in numbers. We do intend
to move them from the internal to the fully public API but there is
protocol required to do this that we just haven't done yet. Any changes
that occur during the transition will be because we iron out problems
and will be improvements and should be easy to accomodate.

> Moreover, my graphical
> editor displayes Swing components, but it does not generate Java code,
> but an own scripting language which describes the Swing components and
> the layout on a meta level. To build the GUI, the generated script is
> sent to an external layout engine which sends back a Swing frame that is
> displayed in the GEF editor. As model I use an own EMF model and I
> didn't see how to use the VE framework since it seems to be dependent on
> the Java model. Would it be possible to extend the VE framework using an
> own model?

The VE model is an EMF model in the .jem packages whose meta layer is a
model of a Java class and instances. This model gives you a lot, mainly
because all of the entries in the project's build path are available in
the model whether they are in dependent projects, .jar files, exist as
binaries only, have BeanInfo extensions, etc... The VE also has
adapters for the model that handle things like the target VM that can
crank up the live beans for you, so if you set a property on the
property sheet or drop from the palette and GEF updates the model then
the live bean is updated automagically for you. In addition there is a
code generation set of adapters and parsers that work with .java source
but for your app these wouldn't be required, and there are other VE
extension projects that work without them just leveraging the VE's EMF
model.

Given the fact that the VE provides viewers that work with its model;
the property sheet, the GEF graphical viewer, the tree viewer, etc...
the technique used so far with other models is to have them generate the
VE model on open and save to their model on close. If you didn't do
this you would have to re-invent the entire property sheet and live VM
and the devil is in the detail - for example the whole Swing
invalidate/validate tree when things are changed and how you handle
tabbed folders, split panes, toolbars, content panes, layout managers
with all of the various feedback etc... will take a fair while.

Does the route of having your model round trip into the VE model on open
and save sound like it would work for you ?

> By the way, I wonder why VE uses additional Java virtual machines for
> the capturing of live images. Wouldn't it be possible to do this in the
> same vm? It seems rather complicated to me and for my editor I do the
> layouting and the capturing of images in the same vm.

It is kinda complicated however it's one of the strengths of the VE.
There is an option to have the VE actually use the IDE as its VM that
can be enabled although you will need to ask for help on the VE
newsgroup for this as it comes with a health warning that Rich
articulates. The target VM means that the -classpath of the VM is NOT
the Eclipse IDE one but the build path of the Java project. The way to
think of this is what happens when you do a Run As>Java Application - a
separate JVM is started for you with the necessary .jar files for you
code. The VE has to create a preview of your GUI using the Java files
in the project's build path so it starts its own VM. The complication
is hidden from you however and we have done considerable work in our
last and next release (M1.1 and M1.2) to improve performance across the
socket layer between our VMs.

VisualAge for Java used to run its widgets in the same VM and while this
has attractions of being easier to write it is sort of a fool's gold.
Ultimately people want to replace the JRE level to be one other than the
one the IDE supports and work with jars and projects that are not in the
IDE's -classpath and to do so either requires class loader magic (which
introduces its own set of problems and becomes complicated) or else a
proper architected sandbox environment which is what the VE uses.

Best regards,

Joe Winchester
Re: Capturing Images [message #607898 is a reply to message #93129] Tue, 07 June 2005 16:43 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

>
>> Moreover, my graphical editor displayes Swing components, but it does
>> not generate Java code, but an own scripting language which describes
>> the Swing components and the layout on a meta level. To build the GUI,
>> the generated script is sent to an external layout engine which sends
>> back a Swing frame that is displayed in the GEF editor. As model I use
>> an own EMF model and I didn't see how to use the VE framework since it
>> seems to be dependent on the Java model. Would it be possible to
>> extend the VE framework using an own model?
>
>

As Joe mentioned the devil is in the details, but if you are not a java
project, nor are you generating java code, nor are you trying to compose
together java components, but you are using Swing simply as a rendering
mechanism, then there is something we have that can help.

It is called the jfc.ComponentManager. It has been extensively changed
and enhanced in the latest VE 1.1 drivers. It doesn't require the Jave
EMF model, nor does it even require a remote vm. It does require what we
call a proxy registry (which is what we use, but we have a version that
runs a remote vm, or one that runs within the IDE). If you have a
predefined set of visuals and you will not be running any user code to
do the Swing rendering, just your layout engine which you have complete
control of, then you can use the IDE registry. You won't be changing
class and you won't be needing a different JVM than the IDE's.

The ComponentManager handles Swing/AWT components. It listens for
changes (move/size), does validate() for you, and returns a new image
whenever the validation was done.

It is in the JFC plugin, but it doesn't require any of the other Java
EMF jfc stuff, like the proxy adapters.
--
Thanks,
Rich Kulp
Re: Capturing Images [message #607899 is a reply to message #93144] Tue, 07 June 2005 17:04 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

The best way would be if on bringing up your editor, you convert it into
an EMF model. It doesn't need to be Java EMF, just an EMF model. That
way you can have adapters on the EMF objects that listen for feature
changes, and when these changes occur, they can contact your display
engine to have it update the Swing visual, and then tell the
ComponentManager that it has been updated and needs validation. Then
using the new ModelChangeController and transaction grouping it will
then give you the new image at the end.

Then when you save you would convert the EMF model back into your saved
representation.


I wish we had an example of doing this. It is a powerful concept but we
haven't had time to do this.

--
Thanks,
Rich Kulp
Re: Capturing Images [message #607900 is a reply to message #93158] Thu, 09 June 2005 17:14 Go to previous message
Eclipse UserFriend
Originally posted by: rabuis.yahoo.de

Dear Joe, dear Rich,
Thank you very much for the detailed answers. I understand now why VE uses
several VMs.
For my editor I'll try to use my own EMF model together with the VEs
ComponentManager as Rich sugested. I hope to get it working without an
example.
-- Mario
Previous Topic:Painting an SWT Table
Next Topic:Candidate build available for VE 1.1M2
Goto Forum:
  


Current Time: Thu Mar 28 10:01:09 GMT 2024

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

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

Back to the top