Switch Browser to "sleep mode" (disabled) and switch back - java

I am trying to embed a website as a user interface into a game I'm making using JxBrowser. The problem is, keeping the browser running in the background causes the game's FPS drops from 120 to 20.
Since I need to render the BufferedImage from the browser, I don't think I can switch to HeavyWeight mode for that GPU-acceleration (Please correct me if I can).
The plan is, the browser is only active under certain circumstances (e.g. player is looking at the interface). I wonder if there's any way that I can disable the browser, and resume to previous state when needed?
P.S. I do notice the browser.dispose() method, but that won't resume the browser to the previous state before disabled.

JxBrowser doesn't provide any API to "disable" the browser.
JxBrowser uses CPU to perform the off-screen rendering in the lightweight mode. Every time something changes on the loaded document(e.g. DOM updates, etc.) JxBrowser re-renders the web page content in memory.
Probably, this is the root-cause of the FPS decreasing.
I suggest that you find the way to display more statical content in the user interface.
Also, please take a look at the following article, maybe an accelerated rendering helps reduce this issue:
https://jxbrowser.support.teamdev.com/support/solutions/articles/9000104965-accelerated-lightweight-rendering

Related

How to make sure the user does not able to do any other thing once my window is shown in linux/mac [duplicate]

How can I disable OS-level keyboard shortcuts (e.g. Alt-Tab, Ctrl-Alt-Left/Right, etc.) on a [Ubuntu] Linux machine? I'm developing a full-screen Java Swing app and don't want the user to be able to task switch away from the program arbitrarily. It's not enough to toggle the "always on top" flag; users mustn't be allowed to switch workspaces, migrate focus or any other such things. The machine must function normally before and after the application is executed. Google says that this will require JNI or JNA but I'm looking for a bit more hand-holding.
There's no point in trying to do this in your application because any of these changes are going to need to be handled by X11 and/or the window manager since those are what respond to the commands. Assuming that you have control of the platform, choose a window manager which supports a kiosk mode. Then use the window manager's settings to start your application and enter kiosk mode.
Options for window managers which can do this include KDE or twm-kiosk.
(And if you don't have control of the platform, you're not likely to be able to have your application intercept things like ctrl-alt-backspace anyway.)
Edit:
In response to a scaled-down version of the question in which he's willing to let things like ctl-alt-backspace go and just wants most of the keys including alt-tab or other similar application switching key combinations, the following should work:
You should be able to do this using XLib's XGrabKeyboard method through JNI. This Java/XLib JNI keypress capture tutorial should be a good starting point. However, it uses XGrabKey which just passively listens for keys and does not prevent other applications from receiving them. You'll instead want to use XGrabKeyboard which actively snags all of the normal keyboard events (which, if the premise of this StackOverflow question is correct, includes the task switching keys).
Note that as a side-effect, key capture in Swing will also probably stop working because your Swing windows are going to be separate from the window you create in C. As such, you will probably have to use your JNI interface to get key presses to your program when needed. (Although I would definitely advise testing it first before writing the code.) You might be able to avoid this if you can get the window using Java AWT Native Interface to get the window ID. (Note that Swing is built on top of AWT, so this will work for Swing.) However, I'm not sure how to do this. It looks like you might be able to navigate the window tree by getting the root window from the Display and going from there to find your Window, but it's all kind of weird. It would be nice if the AWT NI just told you the window ID, but it doesn't look like it does that.
As this warning Reminder: XGrabKeyboard is not a security interface notes, this doesn't make it impossible for other programs to see the keys, but it seems likely that window managers will not be using XQueryKeyMap so it is likely to prevent task switching.

How to enable interact on UI while method is still running in GWT

I have a logic on client side which will take around 10 seconds or more time to evaluate, but in the moment of waiting the screen it will change to a new screen where i wish the screen is enable for user to interact while waiting.
Now the problem is although the screen is changed, but it is unable to interact on it unless the method is completed.
I try to search on internet, but i realise GWT is not support synchronized. What is the alternative way to achieve it? Thanks
GWT creates JavaScript - you can do everything with GWT that you can do with JavaScript. JavaScript does not allow multithreading - you will have to use Web Workers.

Is capturing screen image and displaying it on an application every second effective?

I'm new to programming but I really wish to improve, right now learning Java. Basically there is this game, online strategy it's pretty basic with most of the images are static and very few of them change. I wish to change how I view the game from my end and add some functionality to it as well.
For example the website displays an orange rectangle, I wish to display a red rectangle by drawing over it. Or drawing a button when, if clicked, re-directs me to another part of the game. Originally I am using Selenium Chrome WebDriver to navigate the website but it seems you can't paint or display your own images over it. So I was wondering if I should use Selenium headless in the background performing tasks while I just make a Java Application. Make the WebDriver capture the image every second and display it on the Java Application every second, and than edit that image to my liking? Would this be effective way to do it or is there better options?
It is not clear what you are actually trying to achieve here. And whether your approach is likely to be "effective" depends what you are trying to achieve!
However, I can see some issues:
I don't know if it is technically possible to get the Selenium WebDriver to do that ...
Capturing images at a high rate could be problematic from a performance perspective.
Once you have captured the images:
Modifying the images by hand would be tedious and labour intensive. (And probably not what you want to do.)
Modifying static images programatically would be possible, but fiddly to implement and incredibly fragile. The slightest change to the game's screen rendering could result in your "tweaks" writing to the wrong place on the image.
Making changes to the dynamic part of images would be next to impossible ... except in the destructive sense.
You can't affect game play by this approach. Nothing you do to the images will impact on the browser and hence on the server. You can't add functionality this way.
In short, this is a poor idea, and unlikely to achieve anything worthwhile.
Can I think of any good options? No I can't.
The best I can think of would be to:
reverse engineer the HTML / Javascript uploaded to your browser,
figure out what you want to change in that content, and
place an HTTP proxy between your web browser and the server that injects the relevant changes into the content.
However:
It will be a lot of tricky and tedious work to implement.
It will be fragile; i.e. changes to the game / game server are liable to break your "hacks".
It could be a violation of the game owner's copyright and/or the license that grants you the right to use the game. This could result in your game accounts being cancelled, along with the accounts of anyone else who uses your "hacks".
My advice? Just play the game!

Screensharing via Java Applet

I am looking for an addition for our "livestream and podcast" solution, which uses a camera to film speeches in our house.
It has been requested to view the slides of our speakers directly as a image in the webbrowser instead of the video stream. We don't want/can not install software on the speakers laptop, so I thought about a Java applet, which the speaker can just run via a webbrowser.
So what I need is technically this:
[speakers laptop] -> [Screencapture every N seconds via applet on a webpage] -> [Displaying the screen of the speaker on a different webpage for the external viewers]
I know there are Java applications which do record the screen, but save the file output locally. I need something that does the same, but sends the image to the server. On the server side I thought about a websocket.js accepting and displaying the image (other suggestions are welcome).
It would be great if somebody could help me out here. Btw, I never programmed in Java, so telling me which frameworks I need won't really help me.
Thanks!!
I was recently asked to evaluate possibilities for live screen-cast via applet. Most video APIs do not support codecs that have high enough compression (e.g. JMF). Some APIs can do advanced formats (JFFMPEG, Xuggle) but also use natives. While natives are normally no problem for an app. launched (free floating) using Java Web Start or a Plug-In 2 applet, the makers of Xuggle identify 'the order of loading natives' as a problem (e.g. won't work) for both JWS and applets.
It is a pity that more than a decade into its development, Java has no reasonable API for video capture/processing that can be deployed for a wide use (applet/JWS based - for the 'general public') GUI.
Perhaps you can find a solution using Flash.
Update 1
In fact, I do not need the screen to be recorded as a video.
In fact, you mentioned much of that in your initial question, but I focused on just a few keywords before drafting a reply. My bad. :P
OK.
Getting an image is relatively easy. An applet would need to be trusted in order to get a screenshot, but once trusted, it is just a few lines of code to get the image.
Encoding the image to JPEG of particular quality/compression setting (in memory) is also doable.
Sending the image to the server would depend on the size in bytes and connection speed, but one image with a high compression, every 10 seconds, should be doable. The server would need to implement functionality to accept the image.
As far as displaying the image on the client, it seems you already have some ideas based around JS. If you can make that work that would be optimal, since it can then be viewed in browsers with no Java.
I would still recommend you deploy the app. to the 'speaker' using Java Web Start, rather than embed an applet. A JWS app. will give you less deployment & maintenance troubles, and the JWS launch is ..nicer. Further, a free floating frame launched using JWS can minimize itself (or in later JREs, become transparent), during the action of taking a screen image - thereby capturing everything on the screen except itself.
Update 2
I actually found this code here.
That is ..horrible. Not the code, the site. When I visited it I got a message saying a pop-up had been suppressed (fair enough). Then there was the irritating 'vibrating dialog' hovering in the middle of the page (and following the scroll). You click the little x to see - another tab opened with yet another floating dialog, saying some other rubbish about how "You've won.." - with sound loud enough to drown out my high volume trance/dance playlist.
Then after closing that the hell out of my FF, I go back to the original page, close the damn 'dialog', scroll down & see.. a red background to the code (shudder). That is as far as I could manage. I closed the page with the code.
Try this code instead, for a single screen-shot.
Would it be possible to use this on the client side..
Yes.
.. and receive it with javascript on the server side?
Not really. Unless you mean an IIS based server running Microsoft's JScript. JavaScript is a client side technology.
For security reasons, servers need to protect themselves. E.G. From:
Someone creating a slavebot that uploads all the 1000s of docs on the slave machine's to the site - to make it crash.
People high-jacking your server for storing and serving bestiality porn (or worse).
Because of things like that (bad people have lots of imagination), while servers can easily accept uploads, they are generally not configured by default to allow them.
.. (I don't want Java on my server ;-)
It can be done using PHP, ASP, CGI etc. It does not need Java specifically, but it does need some active involvement from the server, if only to check the size of what is being uploaded and abort if it gets too large!
..Will take a look at the link you posted, but as I said, I can't program in Java, though I can understand some of it. Thanks!
It sounds like you'll need some help getting the server-side of it ready, as well. It is trivial for someone that knows how (not me), but a potential security nightmare for the inexperienced.
Update 3
where do I add the function to send the picture?
Sorry. I've not tried to implement that - you'd want to want to encode it to JPEG before sending, to reduce the size. See this code for how to provide an adjustable compression/quality where the user can see the effect.
There are various ways to get an image to a server. E.G. sockets, HTTP, FTP.. AFAIU it would depend on how the server is accepting it. I am unfamiliar with the specific term 'websocket' or the node.js script. Can you link to what you mean?
..the old code added to pastebin, so it's readable
Smart thinking. I notice it uses sockets, it was in the back of my mind that sockets would be best for this, since they have low overhead and short wait times.

Checking if a browser has support for blind or partially-sighted people?

How do I check (using Java or JavaScript) if a browser has support for blind or partially-sighted people?
If you are looking to determine whether an assistive technology (like JAWS or Window-Eyes) are installed, no, you cannot with Javascript. These technologies use OS-level APIs, and current browsers don't do anything that would cause their presence to be detectable. There is a flash-based hack that can detect newer versions of screen readers see http://webaim.org/techniques/flash/techniques
Perhaps you want to provide a different Flash interface or options if a user is using a screen reader. For instance, you may want to provide additional buttons or turn on self-voicing features when the person watching your movie is using a screen reader. You can detect screen readers using ActionScript. The Accessibility.isActive() function will return "true" if a screen reader that is capable of accessing Flash content is detected (currently only up-to-date versions of Window-Eyes, JAWS, and IBM Home Page Reader). For instance, you might add:
if (Accessibility.isActive()) {
_root.selfVoicing.play();
}
Important
Because there is a slight delay between when your movie begins and when the screen reader is detected, Accessibility.isActive() may incorrectly return false during the first few moments that your movie is playing. The Flash movie must also have focus in order for this to work. This can be solved by associating the ActionScript with a button within the Flash movie.
Finally, this method of detecting a screen reader, will not detect all screen readers. It will only detect the most recent versions of screen readers that support MSAA and have the Flash 6+ player installed.
This method is the only way of automatically detecting screen readers on the web. If you want to provide alternative content for screen reader users, you could use a Flash movie to detect the presence of a screen reader and redirect appropriately. However, this also assumes that the user has the Flash player installed (which most users do). If the user does not have Flash, then the detection will not work and the user might be presented with additional accessibility issues. Care must also be taken in providing alternative content for screen reader users. The alternative content must be kept up-to-date and provide the same information and functionality as the non-screen reader content. Here is the code to redirect based on screen reader presence:
if (Accessibility.isActive()) {
getURL(screenreaderpage.htm);
} else {
getURL(normalpage.htm);
}
The short answer is there's no bulletproof way to do this. While the flash solution may work in some situations it isn't a good solution. I'm a totally blind programmer and since flash is generally so completely inaccessible I don't have it enabled by default in my browser. iPhones are used by a lot of blind individuals and for obvious reasons the flash solution won't work on them either. Even if the browser does support assistive technology that does not mean your site will be accessible. If your entire site is JavaScript or WebGL that draws pictures onto a canvas it doesn’t matter how good the screen reader supporter in a browser is, there’s no way to provide information on dynamically created graphics unless the author provides textual descriptions of what is drawn to the screen. Ideally you would want to code your site in such a way that it can be used by both blind and sited individuals with no changes. If that doesn't work you could always put an invisible link to an alternative version of your site or other invisible content specific to screen readers that won't be displayed to sited users. For a discussion of creating content that is only visible to screen reader users see this link For a general intro to web accessibility see http://webaim.org/intro/

Categories

Resources