Detect java applet modal dialog in webbrowser control - java

We are hosting web applications in a .Net webbrowser control embedded in a winform.
When a java applet in a web application displays a modal dialog, only the applet area within the webapplication is deactivated. (The requirement is firefox-style modality).
Is there a way to detect that the applet in the webbrowser control displays a modal dialog? (alternatively, get a window handle, when a java applet dialog is opening?)

Use some JavaScript to directly call the Java method Window.getWindows() for an array of existing Window objects. (J)Frame objects and (J)Dialog objects all extend Window.
Note that, AFAIR, each applet gets a Frame to contain it. Because there will be more 'windows' on screen than just dialogs, you'll need to check the types.
Do that at an appropriate interval repeatedly from JS, and it should be possible to detect any dialogs produced by Java applets.
Alternately it might be easier to extend the applet and add some extra methods to make those same checks outlined above, then call a JavaScript to notify that there are dialogs opened.

Use sun.plugin2.main.client.ModalityHelper.installModalityListener(). This will signal modalityPopped and modalityPushed.
http://www.javasourcecode.org/html/open-source/jdk/jdk-6u23/sun/plugin2/main/client/ModalityHelper.html#installModalityListener%28sun.plugin2.main.client.ModalityInterface%29
Requires Java 6 and may only work on some specific platforms (scope yet unknown).

Related

Applet lifecycle when out of focus

Does a Java Applet always execute its code even when it losts focus? I've to put this applet in a web page.
I'm tryng to understand this cause i've to develop an applet that listen to some hardware components through JavaPos. I have a callback method defined inside the applet and i'm not sure if it works even when users click on other page component.
Thanks
Does a Java Applet always execute its code even when it losts focus?
Yes, unless of course the applet code intentionally stops execution on loss of focus.

Handling events in multiple windows of the same applet

What is the best way to handle events (enable or disable button) or share parameters across different windows that are opened of the same applet ?
I am not referring to the browser window, instead (run as applet) window in the local IDE.
Which can be the best method to handle this scenario and let the other window know that the event has occurred already and proceed to the next step ? Here, there are no multiple applets. Just one applet, one code base, but multiple instances created.
Java uses a model, view, controller system. The model would be the variables under the hood, the view would be the applet, and the controller would be the buttons and other interactions. Many of the Swing components take a variable(model) in the constructor and automatically update with that. If you want to alert a specific function that a variable has been changed by any button, use property change listeners.
http://docs.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html

Can JavaFX call and embedd OCX Components

is JavaFX capable of loading and embedding OCX Controls? I would like to use the Internet explorer in my Application, because the WebKit browser lacks support for ActiveX. And since I have to rely on third party ActiveX Controls (I know they are evil), I am bound to the IE.
This question is not purely related to "Can I use OCX in Java" because I would like to have some kind of component for JavaFX I would like to use.
Or do I have to rely on libraries posted here:
Use a .OCX Control in Java
Thanks in advance,
Sven
You have to rely on the libraries posted in the link you supplied in your question.
Or you need to write your own JNI interface.
If you do access OCX components, you may need to place them in their own window rather than sharing a window created by a JavaFX stage as you may run into issues with the JavaFX renderer conflicting writes on the window portions in which the OCX components are displayed - you would have to try it and see what happens to confirm.
The easier way to do this may be to request that users of your application set their default browser to IE, and then call the JavaFX hostservices.showDocument(uri) api to launch an IE page which embeds the OCX components you need.
Another alternative is to:
Embed your JavaFX application as an applet in a web page.
Also embed your activex controls in the web page.
On display of the web page, check the browser and, if it isn't IE, tell they user that the must be using Internet Explorer.
Have the user accept any miscellaneous security warnings the Browser displays.
Have the user (or perhaps JavaScript) resize the browser window to fullscreen (see IE9 Full Screen Mode or Full Screen Browsers with JavaScript).
Communicate between your active X controls and java app using javascript invoked via calls from the javafx/javascript bridge and control your active X controls via VBScript embedded in the page.
It would probably work, but it is such an ugly Frankenstein solution . . .
If you can convert your media to a format which JavaFX supports and just play it back direct through JavaFX, that would be much preferable, or it may also turn out that due to a deep ActiveX integration requirement that JavaFX is not the best solution to your problem and you could be better off with something like Silverlight.

Block all other input to an application and control it from a wrapper in Java

I have a windows application which has a complex GUI that I would like to hide from users. In order to do this, I would like to create a wrapper with an extremely simple interface that overlays this application and automates a number of actions when a user clicks a single button on the wrapper. (I hope "wrapper" is the proper term.) Is it possible to use Java to block input to the underlying application so that users cannot inadvertently mess up the automation? How would I go about this? Also, how can I automate key presses and clicks to the application without hijacking the mouse? Is this possible in Java?
I have looked at java.awt.Robot, but it appears to hijack the mouse.
I have also looked at AutoIT, but it too hijacks the mouse and does not integrate with Java.
Neither of these options seem powerful enough for what I need, but I do not know how else to proceed.
I recommend that automation via the GUI only as the last resort if you really have no other alternative.
If there is an API that your application exposes, I would try to use that. For example, if the GUI is implemented in one DLL and the logic in another, then you can use JNA to load your application logic DLL and invoke the application functions directly from java. Even better would be if your application exposes a COM/OLE interface - there are plenty of Java<>COM briges, that will alow you to call this interface directly, e.g. Jacob.
If you really have no choice but to automate via the GUI, then here's how to go about doing that:
Use JNA to access the windows shell API. You can then use ShellExecute to launch your wrapped application. Specifically, passing SW_HIDE as the window mode should help ensure that the application does not appear.
Use JNA to access the windows API FindWindow to find your application window. You can also make it invisible using the ShowWindow API, just in case step 1 did not work (not all applications are written to use the nCmdShow parameter.)
You can now post messages to the application window using PostMessage. You can send keystrokes and mouse events using windows messages. E.g. See WM_KEYUP, WM_LBUTTONDOWN.
Because the wrapped application window is made invisible, you don't need to "block" that application, The user simply cannot access it's GUI. But you can still programmatically send input to it.

Display another modal dialog box on top of other modal dialog boxes in Java

I have a rather strange question:
I have a Java application which uses "applications" (plugins) run in different threads.
Most of these plugins will be written by other people and I will have no control over the code. The application requires a permanent connection to the Internet as information is constantly transferred between the server and app. What I want to do is have a thread which runs in the backround checking to see if there is a Internet connection. If the connection drops I want the ENTIRE application (and all its threads) to pause, display a message and when reconnected resume. I want this dialog box to be displayed above all other dialog boxes (modal or not). I'm thinking of something like the Windows Vista User Account Control Alerts.
How can I do this?
To solve this at all reasonably, you need to use Java 6, as previous versions simply don't give you the granularity of modality you need.
Here are the modality options.
For this to work effectively, you would have to have each plugin honor a contract to not use Toolkit modality (the default behavior is that a modal dialog box locks everything up, to keep backwards compatibility). Application modality would seem to be a great fit for you, but I don't see that you can implement this in Java. This seems to be up to the JVM vendor, as far as I could find.

Categories

Resources