Package gr.zeus.ui
Class SingleAppInstance
java.lang.Object
gr.zeus.ui.SingleAppInstance
This helper component provides a simple solution to the multiple applications
instances problem. Just invoke
onInit()
at your application's
startup and onExit()
at your application's shutdown and that's
all there is to it. SingleAppInstance
creates and locks a file
within the startup directory so if anyone is to execute your application
again the second onInit()
call fails with a message.
The onExit()
method unlocks and deletes the file.
If m_reportPopup
is true, a popup window is displayed for the
user to take action, else the user is informed via stderr
.
If you wish to change the look and feel of the popup window invoke
SingleAppInstance
after setting the look and feel inside your
application. If you wish to translate the messages for this component create
a new property file for your locale and place it inside
/gr/zeus/
where the default
"singleappinstance.properties" resides.
- Since:
- 1.05
- Author:
- Gregory Kotsaftis
-
Method Summary
Modifier and TypeMethodDescriptionstatic SingleAppInstance
This method returns the single instance of this class.static SingleAppInstance
getInstance
(String filename) This method returns the single instance of this class.boolean
Gets whether to report via a popup or viastderr
.void
onExit()
Release the file lock and delete the file.void
onInit()
Creates a file and obtains a lock.void
setReportPopup
(boolean f) Sets whether to report via a popup or viastderr
.
-
Method Details
-
getInstance
This method returns the single instance of this class.- Returns:
- The single instance of this class.
-
getInstance
This method returns the single instance of this class. Uses the filename parameter instead of default filename.- Parameters:
filename
- The filename to create and lock, should be unique and within current folder.- Returns:
- The single instance of this class.
-
onInit
public void onInit()Creates a file and obtains a lock. If the file exists or there is any error creating it this method invokesSystem.exit()
. Should be invoked ONCE insidemain()
in your application. -
onExit
public void onExit()Release the file lock and delete the file. Should be invoked ONCE just before callingSystem.exit()
on your application. -
getReportPopup
public boolean getReportPopup()Gets whether to report via a popup or viastderr
.- Returns:
- If
true
, a popup window is displayed, else the user is informed viastderr
.
-
setReportPopup
public void setReportPopup(boolean f) Sets whether to report via a popup or viastderr
.- Parameters:
f
- Iftrue
, via a popup window, else viastderr
.
-