Package gr.zeus.ui

Class SingleAppInstance

java.lang.Object
gr.zeus.ui.SingleAppInstance

public final class SingleAppInstance extends Object
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 Details

    • 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(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 invokes System.exit(). Should be invoked ONCE inside main() in your application.
    • onExit

      public void onExit()
      Release the file lock and delete the file. Should be invoked ONCE just before calling System.exit() on your application.
    • getReportPopup

      public boolean getReportPopup()
      Gets whether to report via a popup or via stderr.

      Returns:
      If true, a popup window is displayed, else the user is informed via stderr.
    • setReportPopup

      public void setReportPopup(boolean f)
      Sets whether to report via a popup or via stderr.

      Parameters:
      f - If true, via a popup window, else via stderr.