Is there a way for a Java GUI application to respond to system shutdown or logoff events, other than to use JNI? (On Windows, the JNI would use WM_QUERYENDSESSION, on Linux
This doesn't answer the question, but addresses part of it.
In a Unix GUI session, I consider the right way to handle the logoff event is to save the document to a temporary file and save the information in the session state. During the session recovery, the program can reload the temporary file and take up where it left off. No need to ask the user about saving or not.
I just wish more software did transparent session save and recovery. Too many programs reopen with empty document windows because the GUI framework used does that much but none of the rest of the work has been done to actually handle any meaningful program state.