Package gr.zeus.ui
Class SingleAppInstance
- java.lang.Object
-
- gr.zeus.ui.SingleAppInstance
-
public final class SingleAppInstance extends java.lang.Object
This helper component provides a simple solution to the multiple applications instances problem. Just invokeonInit()
at your application's startup andonExit()
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 secondonInit()
call fails with a message. TheonExit()
method unlocks and deletes the file. Ifm_reportPopup
is true, a popup window is displayed for the user to take action, else the user is informed viastderr
. If you wish to change the look and feel of the popup window invokeSingleAppInstance
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SingleAppInstance
getInstance()
This method returns the single instance of this class.static SingleAppInstance
getInstance(java.lang.String filename)
This method returns the single instance of this class.boolean
getReportPopup()
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 Detail
-
getInstance
public static SingleAppInstance getInstance()
This method returns the single instance of this class.- Returns:
- The single instance of this class.
-
getInstance
public static SingleAppInstance getInstance(java.lang.String filename)
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
.
-
-