WM_PAINT, Java and capturing hidden windows - java

First a disclaimer, I'm a Java programmer and have almost no idea about the Windows API. So please bear with me.
My goal is to use Java to capture a hidden window. My target platform is Windows. I do understand that the Robot class is used for capuring the visible part of the screen. After some browsing, I came across these three links, which seem to be relevant:
http://www.support.teamdev.com/thread/1930
http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.ui/2006-02/msg00204.html
http://www.fengyuan.com/article/wmprint.html
JxCapture is as bloodily expensive as Feng Yuan article is complicated. My question is this, if the gurus in this forum can help me find a reasonable solution. The approach suggested in JxCapture does not seem to be overly complex. Any hints? A visual basic script or some C# code that does this would be a good starting point.
I was of the belief that when the window is hidden, if I send a keypress event or a mouse press event to it, it would force it to redraw itself and hence allow itself to be captured even by java.awt.Robot. That was an illusion and it doesn't work.
On the other hand, the message in the JxCapture thread is from the year 2006; could it be that Sun has included such a feature since then and I'm just not aware of it?

Related

Java AWT Window management, user input, and focus?

I'm trying to hunt down the source of a bug that relates to window management, and possibly awt specifically. However, I have little to no familiarity with window management in general, or awt, so I'm even sure what I searching for. I'm hoping for some general guidance on terminology or otherwise that might help guide me in the correct direction.
In the program I am working on, the user can open windows that can be interacted with (i.e. they have text input boxes, drop down menus, etc) and windows that cannot be interacted with (i.e. they just display dialog). When the user opens a "non-interactive" window, the user can still use the underlying program. However, when an "interactive" window is opened, the user is blocked from using the underlying program until the window is closed. Additionally, "interactive" windows seem to stack themselves on top of "non-interactive" windows. That is to say, if I open a "non-interactive" window and then open an "interactive" window after, the "interactive" window will place itself on top of the "non-interactive" window and won't allow the user to use any of the title bar widgets. In this program, this behavior is not always desirable.
I assumed that this would have something to do with focusing, but I read through this document without much luck (this could be that I just don't know what I'm looking for). Particularly, I noticed the mention of "VetoableChangeLister" which doesn't seem to appear anywhere in the code I'm working with, as well as the method "requestFocusInWindow", which does appear in the code I'm working with but not in any way that I could see that relates to my above problem description.
Would the above problem be related to window focusing? Or am I barking up the wrong tree here? If nothing else, even some basic terminology so I can at least Google search intelligently.
The question I was asking relates to the "modality" of windows and was answered in the comments. The link provided explaining modality is https://docs.oracle.com/javase/tutorial/uiswing/misc/modality.html

Can CheerpJ extend Java mouseDragged actions outside an applet frame?

In this page the CheerpJ conversion of the applet in this page (with identical byte-code) does not seem to recognize mouse dragging past the applet frame boundary. It would be nice if that were possible.
Is this just a problem with my client-side setup (Linux Debian 9.2), or do others see the same behvior?
What is very strange, is that the original behavior is converted correctly on the not-supported-by-CheerpJ iphone browsers (I have checked safari and firefox there). Could investigation of this fact help CheerpJ developers understand how to make the MouseMotionListener interface recognize mouse dragging anywhere on the screen, not just within the applet frame?
Maybe this is impossible, but I thought it was worth asking.
Edit: Changed title to be less negative about CheerpJ (which overall I find almost too cool to be true!) and more reflective of actual the question.
The mouseDragged method is correctly implemented to the best of our understanding. The Java event is derived from the mousemove JavaScript event which is not delivered when the mouse is outside of the applet surface. With the legacy plugin applets are displayed on native windows which have different behavior.
It could be possible that using different JavaScript events, like mousedrag would make CheerpJ behavior more similar to native, but reworking this without causing regressions would require significant work and it is not currently a priority for us. Especially considering that our customers normally have full screen Swing applets which cannot exhibit the problem
On mobile devices the touchmove event is used, which is probably what causes the difference you see.
If you want to report a bug you can do it here: https://github.com/leaningtech/cheerpj-meta/issues

How can I make it so Eclipse automatically updates my code in a window as I edit it?

How can I make it so Eclipse automatically updates my code in a window as I edit it? I've seen the feature before in youtube videos but I cannot find it. For example : I change a JApplet rectangle width from 20 to 10, I want to see it update immediately.
I've seen Notch do this on development videos (Minecraft), it is awesome but I don't know exactly how he does it.
-- EDIT --
This has been bugging me so I went and googled "how does notch code" and found this on a blog page https://gun.io/blog/what-i-learned-from-watching-notch-code/. It doesn't say exactly how it was done but gives a good hint (HotSwap) and makes it seem like he set it up himself without external software. Here's the most relevant section:
Incredibly Fast Testing
He began by building the engine, and to do this he used the ‘HotSwap’ functionality of the Java JVM 1.4.2, which continuously updates the running code when it detects that a class has changed.
When building the engine, Notch wrote a function which would continuously pan the camera around and clip through the walls and keep the view on top, so he could make changes to the code and see the effects they made in real time. I’m used to testing by writing a function, building it, installing it on the device I’m testing on, and then seeing the result, which can take up to a minute at a time, so it’s easy to see how HotSwapping could save a lot of development time.
--- ORIGINAL POST CONTINUED ---
I get a similar effect by using groovysh though, works smoothly and can use all your java classes as is.
What I'll usually do is write all my code in java, then go and fire up "Groovysh" where it will give you a little window to enter commands (You may have to ensure the classpath works correctly outside of eclipse). I can then "new" any of my classes and call methods on them one line at a time. When you do myFrame.setSize([100,100]) you will see it change immediately.
A good test is to just run groovysh and type something like:
import javax.swing.*
f=new JFrame()
f.setVisible(true)
f.setSize(100,100)
or the groovier version:
f=new JFrame(visible:true, size:[100,100])
and you will see your frame resize on the screen. You can even drag it bigger and then do something like:
println f.getWidth()
to show your new width. It's fun to interact this way but it's more complicated if you want to actually change your class definition and see it pick up the change, I have no idea how Notch did that. I looked into it a little--it's possible he was using something like JRebel
It requires something special since you would have to dynamically reload the classfile into your running system on every save--something that should have serious classloader issues.
By the way there is also a way to get your Java program to throw out a little GroovyConsole which will allow you to inspect and modify all the variables in your running code (but again you can't replace definitions of existing classes).
Also see answer here:
Change a method at runtime via a hot swap mechanism

Swing Works different on different Platform

I have made a Screen Recorder using Java Swing and Xuggler 5.4. I have developed it in Windows 8 64 bit. It's working excellent for Windows. But at client side on Linux's environment , nothing is working. I have searched thoroughly but not getting any solutions. I have checked this thread , but it didn't work for me.
Then I tried to create simple Transparent window in Linux but it's also not working. I was not able to click through the Resizeable Panel. I have used the same JRE version (1.7) for both. Have I miss understood Java's Cross Platform Support as far as Swing is concerned?
Please Give Me Some Advice...
I have always found logging to be the best debugging tool at your disposal! Many a times, java debuggers take you into APIs where you need not go every time. Logging values of your variables, and generic 'I have reached till this point' statements make life a lot easier.
So, I suppose you have ample logging done in your code. That could give you clues on what's happening on your client's system.
Are the right environment variables set? Are they pointing to the correct Java versions you need.
If there are some specific Screen capturing requirements(plugins / modules / API) your code has, are they available on the Linux m/c?
Like #MadProgrammer said, in the end, Java has to talk with the native graphics APIs to render your screen.
I would try to debug it in this way -
Check whether my main screen loads or no(by disabling the screen capture functions for a while).
if not, dig deeper.
Check whether all necessary components for capturing screen(audio and video) are available.
Check whether the code is being run with appropriate permissions to control the h/w devices you may need.

How can I stop using a mouse while programming in my IDE?

I love using an IDE, because I get some great productivity gains. However, I have a couple reasons to stop using a mouse with an IDE:
To code faster - It definitely slows down my coding when my typing is interrupted with all of the constant point and clicking.
To relieve pain - I've never had pain from the keyboard, but I get tendinitis from the mouse.
I've got my cheat sheet for my IDE printed out and now I'm ready.
What's the best way get off the mouse?
Are there any hurdles that I'm going to run into?
Are there any tips for specific IDEs (Visual Studio, Eclipse, etc.) ?
Move it to the wrong side (eg if you are right handed then put it on the left of the keyboard). That way, you can still use it if necessary, but you should find you aren't using it unecessarily.
If changing sides isn't enough to confuse your brain, then moving it to a place where it is accessible but you have to think before reaching for it. As long as you can't reach for the mouse without thinking about it, then you will find that it is easier to use keyboard shortcuts instead. Essentially you want the mouse to be an option but the keyboard to be a better/easier/more convenient one!
As for pitfalls, well you may find that if you have to test any interfaces (web based or dektop) that you need to revert back to using the mouse. Also I find that if I have to work outside of the IDE, then it is just not as efficient to do without the mouse. Often we use WOrd for specifications and documentation, and trying to get away with using that without a mouse, is tricky (in my experience).
Another potential source of annoyance, is when switching between applications (Eclipse, VS, etc), you find that they often use different keyboard shortcuts, and so it can take a while to get back up to speed again, or you have to spend some time reconfiguring the shortcuts to be consistent.
Unplug it.
If your mouse is completely gone then you will be forced to learn how to live without it and therefore will become productive without it.
Anytime you're about to use the mouse, forcibly stop yourself and look up the keyboard shortcut for that operation. Do that a few times per operation and soon your muscle memory will kick in and you won't even have to think about it anymore.
Learn the keyboard short cuts :)
Also some editors are better suited for mouse free operation. I use ViEmu with Visual Studio which has helped me reduce, but not eliminate the need for using the mouse.
Get a trackball.
Your real question is about pain and productivity, the mouse is just a by-product of your circumstances. I would rephrase the question to reflect your real purpose.
Check out the wrist braces. I've heard from people that it makes a huge difference.
For VS, check out Sara Ford's blog.
Bind Macros to Keyboard Shortcuts
Keyboard Shortcuts to navigate task list
Search her blog for plenty of other tips and tricks.
Use the command line whenever you can (Install Powershell)
Switch to vim or emacs for code editing (or use ViEmu if you really need the intellisense)
If you develop web applications and/or spend a lot of time on the web, get the Vimperator or Firemacs extensions
Learn keyboard shortcuts for everything else.
???
Profit!!! (from your increased productivity)
Hide the mouse under a copy of your cheat sheet.
For visual studio I use the ViEmu plugin that allows you to use vi commands in visual studio. It's a bit difficult to get the hang of it but once you're done you'll only be using the mouse on the designer.
Get a webcam and eye-tracking software. Then you can fix bugs just by looking at them. It makes you feel all-powerful.
I've summed up some shortcuts that will get you working faster with Visual Studio in my blog.
I recommend you start at this article, that shows you the shortcuts I'd recommend you should get to know first...
Switch to emacs.
Open the nearest drawer and shove it in and close the drawer. That way, when you really do need it it'll be inconvenient to use it!!!
Also, if you're using multiple IDEs it pays to configure key bindings that are common across them, so that you can switch between them easily.
Change your keys to Emacs setup , Learn the Keyboard Shortcuts. I rarely use the mouse, if ever, in eclipse. i find it alot easier to just use emacs key short cuts.
When I contracted for an investment bank in NYC, there was this guy who didn't use a mouse. He was a java/kdb dev and just used vim. I used to think it was the strangest thing that he didn't have a mouse attached to his computer, but damn.. that guy was productive. Probably the most productive guy I've ever worked with.
So yea, if you really want to go that route you could try using vim, or something similar. You'll lose the features you're used to in your IDE, but it worked for him...
Become a better typer. As a slow
typer, I find myself going to the
mouse so I dont have to type. If I
were more efficient at typing, I would
be less inclined to use the mouse.
If you are using a laptop and a
mouse, remove the mouse and leave the
trackpad as your only option. That
will be so painful that you will be
forced to learn more keyboard
shortcuts.
Some very good answers above.
I spent a while injured with RSI and mousing was an issue. I already used shortcuts a LOT.
But coding using strictly the keyboard was definitely slower, especially when it comes to navigating around the code.
As I was using vi at the time, I would primarily move around the screen by doing searches for text at the location I wanted to go to; this is very fast, assuming you pick unambiguous text. Leaving line-numbers on and then going to the line number is another way to rapidly navigating. Judicious use of code folding (available in many IDEs) helps, too.
Finally, consider an alternate pointing device. A trackpad sucks for games but can be more accessible for coding, especially if you put it in easy reach of the keys (e.g., if you use a split keyboard, between the two hands). Try switching between two or more styles of device, to avoid injury because of one specific device. And don't ignore wrist pain! Treat it before it gets worse and you end up non-productive for a year or something.
Configure your IDE to use VI or EMACS keyboard controls (and learn them.) Both options allow you do do most tasks without moving your hands of the home row. You'll see your productivity drop during the learning curve but jump way up after as you save a lot of time by not moving your hand of the keyboard to use the mouse.
As a side note, learning to use a terminal based editor is a good skill to have in case you ever need to remotely administer a *nix machine. It will save your bacon some day.
MouseFeeds plugin will help you in eclipse:
http://www.mousefeed.com/installation
All these coders and no one suggested to write some code to hide the pointer when the IDE's window is active??
Great question... A co-worker suggested Launchy to me as a way to reduce mouse-use/be more productive. It searches your Start Menu (or non-windows equivalent) for apps, docs, shortcuts, etc. Type alt+spacebar to bring up its prompt where you type what you want to launch. Here are a few examples - what you type depends on other things in your Start Menu.
ch for Chrome, f for Firefox
ca for Calculator
expl for Windows Explorer
A power-user can fiddle with its settings to get more out of it but even basic users will benefit from it. Hope it helps.
Change your keyboard:
(source: datahand.com)
Hide your mouse - at least one arm's length away - then you can always get it back in an emergency
Move it far enough away that it's inconvenient to use, while your cheat sheet is close enough to easily lookup whenever you are in doubt about how to do something. I would not suggest unplugging it, since it is a useful tool for some operations, such as moving files around. I find drag and drop in some sort of tree like file system view is much easier than the alternatives. The majority of editing operations though, are quickly accomplished via key strokes once you remember them.
I am using IntellijIDEA IDE. There is one very annoying plugin - "Key promoter".
For every mouse-inited action it shows annoying alert with keyboard shortcut which you could use to do the same action.
Well, it took about 2 or 3 weeks for me to stop using mouse at all. It was hard to not turn it off (plugin), but very useful :)
IMHO the best answer is combination of two already given answers:
Print out the keyboard shortcut cheat sheet of your IDE and tape it to the wall next to the screen.
Unplug it. Also this makes a bit harder to procrastinate by switching to SO in the other window...
You may also want to consider doing your coding on a Macbook/Macbook pro. I generally HATE touchpads, but I've had to do some coding on the plane and the new touch-sensitive pads are actually really convenient. For example, you can do things like scrolling with a flick of two singers, and it's a lot more accurate.
It may not be perfect, but it might help with your hands.
I don't think avoiding the mouse completely is practical (you need things like hovers, etc.)
First off, don't try to do everything with a keyboard, start by forcing yourself to use keyboards for the top 3 things that you do all the time. Get the biggest bang for your buck/effort and you will quickly want to use more.
Keep a sheet of paper near by where you write down keyboard short cuts you use. (Alternatively, add this to a company wiki so others can benefit.)
Pay attention to menu items, they frequently have keyboard short cuts.
Find out the keyboard shortcuts that show all other keyboard short cuts.
I use Eclipse all the time, there are several keyboard short cuts that I find invaluable:
CTRL + SPACE - Content Assist
CTRL + 3 - Open any UI Element in eclipse by typing
CTRL + SHIFT + T - Open by type (Uses Capital letters to do word searches and * for wild card, for instance NuPoEx would find NullPointerException)
ALT + SHIFT + R - Rename current selection
ALT + SHIFT + T - Refactor Menu
And CTRL+SHIFT + L gives you a list of all keyboard shortcuts

Categories

Resources