|
|
Re: Target VM [message #90149 is a reply to message #89955] |
Mon, 09 May 2005 04:56 |
No real name Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Hi Joe,
Thanks for the reply.
Ill explain the custom component
1. The custom component has an Image in it, in order to display the
image, some initialization code that must be executed
2. The custom component will be added inside a bigger application which
has the necessary init code to display the Image at runtime
Currently I've put my component into the palette. I've writted the
PropertyEditor for setting & getting the Image which runs the necessary
init code for VE to display the image correctly (design time), but if &
only if i change the Imagepath property in the property sheet. If i
close the VE & reopen back.. the image isnt displayed.
BTW. the ClassLoader.getSystemClassLoader().getResource(".") runs
correctly, i need that for getting the project folder.
The PropertyEditor below for editing the ImagePath property of my
Button. See doRunInit() method.. this two lines of code makes my Button
displayes the image which resides inside "Project Folder"/images/
Can u please tell me about BeanProxyAdapter, will writing it solves this
problem? Is there any reference/tutorial about it?
--
public class ButtonImagePathPropertyEditor extends PropertyEditorSupport {
/**
*
*/
public ButtonImagePathPropertyEditor() {
super();
doRunInit();
}
public void doRunInit() {
// These are the necessary code to make the Image displayed at VE
ImageLocator.setClassPath(ClassLoader.getSystemClassLoader() .getResource( ".").toString());
ImageLocator.setImagePath("images/");
}
public Object getValue() {
doRunInit();
return super.getValue();
}
public String getJavaInitializationString() {
return "\"" + super.getValue() + "\"";
}
}
Thank you,
Memet
Joe Winchester wrote:
> Hi Memet,
>
>> I have a custom awt component, so far i've been succesful importing
>> the bean using the 'Choose Bean' on the palette. & the code is
>> generating fine.
>>
>> What i want to know is how for the Target VM (the design display) to
>> call a spesific method that arent generated at the source when i drop
>> my bean into it.
>
>
> You can't really do this. When the VE is opened it never actually runs
> the class you're creating. Imagine the scenario where you have
> something like
>
> B extends A{
> private Button b1;
> private Text t1;
> }
> ...
> b1 = new Button();
> b1.setColor(Color.red);
> add(b1);
> tx = new Text();
> tx.setText("Cow");
> add(t1);
>
> etc...
>
> When you open A what occurs is that B is instantiated, the source is
> parsed and based on the coding pattern it is recognized that there is a
> button and a text. These are then instantiated using the constructors
> in the code they are written and methods run using reflection to build
> up a prototype instance of A. Therefore what you see isn't A, it is a
> guess of what A would look like were it to be compiled and run.
>
> The reason A isn't just run is for several reasons. First - it might
> not be compiled and might be riddled with compile errors, and the
> purpose of the editor is to allow you to work with a file in development
> mode and you might possibly want to fix up the errors so the threshold
> for opening a "broken" file and also for showing target VM errors is
> something the VE does. The second is that if the target VM did load A
> and you then did something like modify the color or drop a new control
> or delete one it'd be hard to swop this out - you'd almost have to
> recompile on every key stroke and then swop out the old A and it'd just
> not work.
>
> For this reason A doesn't exist, and therefore methods created on A
> can't be called and run. That doesn't mean that you can't run custom
> code on the target VM however - it's just that you will have to find
> another way to execute it but only with A's superclass and its modeled
> controls available. If you pasted into a note a simple example of your
> class and what kind of method you want to run it might help to figure
> out a way to do what you want.
>
>> I also wondering if
>> ClassLoader.getSystemClassLoader().getResource(".") will return me the
>> correct runtime path at design time, or is there any other APIs that
>> need to be called to get that.
>
>
> The target VM is just started with javaw.exe and the -classpath set to
> include the items on the build path of the java project. It doesn't use
> any special class loader (which Eclipse does becuase of how it has to
> manage project class loading) so anything that works with a regular JVM
> will work on the target VM.
>
> What is the path you are looking for and why ? If you're trying to load
> a resource file then the general way is to find a marker class and do a
> getResourceAsStream(..) and load it relative to the marker in your
> -classpath.
>
> Best regards,
>
> Joe Winchester
>
>
>
|
|
|
|
|
|
Re: Target VM [message #90471 is a reply to message #90355] |
Tue, 10 May 2005 14:23 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Do this in your ImageLocator class and you don't need a special proxy
adapter or to put special code in your property editor.
public class ImageLocator {
static {
if (Beans.isDesignTime()) {
ImageLocator.setClassPath(ClassLoader.getSystemClassLoader() .getResource( ".").toString());
ImageLocator.setImagePath("images/");
}
}
--
Thanks,
Rich Kulp
|
|
|
|
|
Re: Target VM [message #607366 is a reply to message #89955] |
Mon, 09 May 2005 04:56 |
No real name Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Hi Joe,
Thanks for the reply.
Ill explain the custom component
1. The custom component has an Image in it, in order to display the
image, some initialization code that must be executed
2. The custom component will be added inside a bigger application which
has the necessary init code to display the Image at runtime
Currently I've put my component into the palette. I've writted the
PropertyEditor for setting & getting the Image which runs the necessary
init code for VE to display the image correctly (design time), but if &
only if i change the Imagepath property in the property sheet. If i
close the VE & reopen back.. the image isnt displayed.
BTW. the ClassLoader.getSystemClassLoader().getResource(".") runs
correctly, i need that for getting the project folder.
The PropertyEditor below for editing the ImagePath property of my
Button. See doRunInit() method.. this two lines of code makes my Button
displayes the image which resides inside "Project Folder"/images/
Can u please tell me about BeanProxyAdapter, will writing it solves this
problem? Is there any reference/tutorial about it?
--
public class ButtonImagePathPropertyEditor extends PropertyEditorSupport {
/**
*
*/
public ButtonImagePathPropertyEditor() {
super();
doRunInit();
}
public void doRunInit() {
// These are the necessary code to make the Image displayed at VE
ImageLocator.setClassPath(ClassLoader.getSystemClassLoader() .getResource( ".").toString());
ImageLocator.setImagePath("images/");
}
public Object getValue() {
doRunInit();
return super.getValue();
}
public String getJavaInitializationString() {
return "\"" + super.getValue() + "\"";
}
}
Thank you,
Memet
Joe Winchester wrote:
> Hi Memet,
>
>> I have a custom awt component, so far i've been succesful importing
>> the bean using the 'Choose Bean' on the palette. & the code is
>> generating fine.
>>
>> What i want to know is how for the Target VM (the design display) to
>> call a spesific method that arent generated at the source when i drop
>> my bean into it.
>
>
> You can't really do this. When the VE is opened it never actually runs
> the class you're creating. Imagine the scenario where you have
> something like
>
> B extends A{
> private Button b1;
> private Text t1;
> }
> ...
> b1 = new Button();
> b1.setColor(Color.red);
> add(b1);
> tx = new Text();
> tx.setText("Cow");
> add(t1);
>
> etc...
>
> When you open A what occurs is that B is instantiated, the source is
> parsed and based on the coding pattern it is recognized that there is a
> button and a text. These are then instantiated using the constructors
> in the code they are written and methods run using reflection to build
> up a prototype instance of A. Therefore what you see isn't A, it is a
> guess of what A would look like were it to be compiled and run.
>
> The reason A isn't just run is for several reasons. First - it might
> not be compiled and might be riddled with compile errors, and the
> purpose of the editor is to allow you to work with a file in development
> mode and you might possibly want to fix up the errors so the threshold
> for opening a "broken" file and also for showing target VM errors is
> something the VE does. The second is that if the target VM did load A
> and you then did something like modify the color or drop a new control
> or delete one it'd be hard to swop this out - you'd almost have to
> recompile on every key stroke and then swop out the old A and it'd just
> not work.
>
> For this reason A doesn't exist, and therefore methods created on A
> can't be called and run. That doesn't mean that you can't run custom
> code on the target VM however - it's just that you will have to find
> another way to execute it but only with A's superclass and its modeled
> controls available. If you pasted into a note a simple example of your
> class and what kind of method you want to run it might help to figure
> out a way to do what you want.
>
>> I also wondering if
>> ClassLoader.getSystemClassLoader().getResource(".") will return me the
>> correct runtime path at design time, or is there any other APIs that
>> need to be called to get that.
>
>
> The target VM is just started with javaw.exe and the -classpath set to
> include the items on the build path of the java project. It doesn't use
> any special class loader (which Eclipse does becuase of how it has to
> manage project class loading) so anything that works with a regular JVM
> will work on the target VM.
>
> What is the path you are looking for and why ? If you're trying to load
> a resource file then the general way is to find a marker class and do a
> getResourceAsStream(..) and load it relative to the marker in your
> -classpath.
>
> Best regards,
>
> Joe Winchester
>
>
>
|
|
|
|
|
|
Re: Target VM [message #607388 is a reply to message #90355] |
Tue, 10 May 2005 14:23 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Do this in your ImageLocator class and you don't need a special proxy
adapter or to put special code in your property editor.
public class ImageLocator {
static {
if (Beans.isDesignTime()) {
ImageLocator.setClassPath(ClassLoader.getSystemClassLoader() .getResource( ".").toString());
ImageLocator.setImagePath("images/");
}
}
--
Thanks,
Rich Kulp
|
|
|
|
Powered by
FUDForum. Page generated in 0.03792 seconds