Meaningless Drivel is fun!*
The moose likes JavaFX and the fly likes VirtualMachine.attach and LoadAgent under JavaFX? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JavaFX
Bookmark "VirtualMachine.attach and LoadAgent under JavaFX?" Watch "VirtualMachine.attach and LoadAgent under JavaFX?" New topic
Author

VirtualMachine.attach and LoadAgent under JavaFX?

Michel Legris
Greenhorn

Joined: Feb 21, 2012
Posts: 19
We are working on a kind of spy++ for java FX application (snoop for javafx)

- Is there a way to "inject" my own code inside the java fx application?
- Is there any equivalent to VirtualMachine.attach and LoadAgent for JavaFX ?
- Is there any open source automated testing tool compatible with JavaFX ?

Thanks!

Michel
Michel Legris
Greenhorn

Joined: Feb 21, 2012
Posts: 19
I can Load my agent class into a JavaFX Process. (There was a problem with my manifest and the library must be build for javafx ...my bad)

BUT :
- How do I access to the stage top level object from my JavaFX agent library? Is there a method to get a reference to the stage or the top level UI parent node ??
Is there any javafx equivalent to WPF VisualTreeHelper.GetRoot() ?? How can I get access to an instance of the top level UI node of a javafx application

thanks,

Michel
Michel Legris
Greenhorn

Joined: Feb 21, 2012
Posts: 19
I'm still trying to figure out how to use my agent in a javafx context in order to get a reference to the UI....

I just need to get access to the root top level UI element of the application...Nobody can help on this?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

One way is to pass the Stage obtained in the start method. Or another way is to create a static variable in the class which contains your start() method. So in the start() method you can initialize this field with the stage you get. So to access the Stage in different classes would be possible.


Mohamed Sanaulla | My Blog
Michel Legris
Greenhorn

Joined: Feb 21, 2012
Posts: 19
There is no start method in an Agent class...

There is no way to create or use a static variable or modify the application since it's NOT my own application (the one with the start() method) and it's only at run-time (no code can be modified in the application)

I'm using an agent because "injecting" some code in the application process...The problem is that in a JavaFX context you CANT talk with the UI at all because you dont have an access to the stage object
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

There is no start method in an Agent class...


I meant to say: start method of the JavaFX application.

I'm using an agent because "injecting" some code in the application process...The problem is that in a JavaFX context you CANT talk with the UI at all because you dont have an access to the stage object


You can capture the Stage object in the JavaFX application itself right? That's what I meant by saying keeping a class level variable in the JavaFX class and then initialise with the required Stage object. You get an access to the Stage object in the start() method of your JavaFX application. Something like:



I understand that you want the Agent to interact with the JavaFX application and for that you need an access to the Stage object to directly manipulate the data/ui of the JavaFX application. Correct me if my understanding is wrong.

Now if you want to monitor the system performance information, assuming the agent which captures the data is a separate process than the application which would display the data- Is that what you are trying to achieve? Or is it that you want to monitor some Java process?
Michel Legris
Greenhorn

Joined: Feb 21, 2012
Posts: 19
Yes I DONT have any acces to the javaFX application

I'm using an agent to inject my code into the JavaFX application (not my application, code cannot be modified so start method is unavailable)

It's not for performance monitoring, Im working on a kind of spy++/snoop for java so i need to get the UI structure, component size and position to "highlight" them from another process (My agent) I also need to get component properties

For doing all this I need a top level object to parse the entire UI structure and get what I want...

The javafx applications cannot be modified since they are not my own application (any javafx application)
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Ah I see, I got this now. You are trying to analyse the UI structure of any JavaFX application and for that you need to access the root Stage. Even I am not aware of how this can be done in JavaFX or Swing for that matter.
Michel Legris
Greenhorn

Joined: Feb 21, 2012
Posts: 19
Exactly!!

for swing/AWT i'm simply using an agent with window.GetWindows(), then loop though child components.

In JavaFX there is no way to access the root stage (from my agent or external class)
Michel Legris
Greenhorn

Joined: Feb 21, 2012
Posts: 19
Is it possible to use a classTransformer in my agent and somehow get access to the Stage object? It it possible to "hook" the start method with ASM bytecode manupulation in order to get the top level UI element? Is this make any sense?

Thanks...
Michel Legris
Greenhorn

Joined: Feb 21, 2012
Posts: 19
It work!!! thanks for trying to help
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Michel Legris wrote:It work!!! thanks for trying to help

How did you fix it? This would be helpful for people reading this thread sometime in future.
Michel Legris
Greenhorn

Joined: Feb 21, 2012
Posts: 19
The same method used by the jemmy project from http://java.net/projects/jemmy

Just check how they manage to get access to the top level ROOT element in their AgentMain() implementation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: VirtualMachine.attach and LoadAgent under JavaFX?