Class BaseApp

All Implemented Interfaces:
ch.autumo.commons.application.LicensedApplication, ch.autumo.commons.security.SecureApplication, InstallEndListener

public abstract class BaseApp extends Application implements ch.autumo.commons.application.LicensedApplication, InstallEndListener
The Java FX application. In any case you always can use the getters from ConfigurationManager to retrieve any configuration parameter.

Two hooks an application usually overrides:

  • isSplashScreenEnabled() and createSplashScreen() - a splash screen while the application starts (logo, scanner bar, colours, jingle). Without them the application starts without one.
  • isJvmExitOnStop() - the application embeds Swing (the code editor of the framework, or components of its own): the AWT event dispatch thread is not a daemon thread and would keep the JVM alive after the JavaFX runtime is gone.
See Also:
  • SecureApplication
  • LicensedApplication
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
      Logger.
    • baseCfgFile

      protected String baseCfgFile
      The base configuration file ('cfg/base.cfg').
    • baseProps

      protected Properties baseProps
      The base configuration properties.
  • Constructor Details

    • BaseApp

      public BaseApp()
      Because of SecureApplication and when console tools such as the Encoder are used.
    • BaseApp

      public BaseApp(ch.autumo.commons.application.RegistrationVersion regVersion)
      Because of LicensedApplication and when console tools such as the Register are used.
      Parameters:
      regVersion - injected registration version
  • Method Details

    • init

      public void init() throws Exception
      Overrides:
      init in class Application
      Throws:
      Exception
    • start

      public void start(Stage primaryStage)
      Specified by:
      start in class Application
    • handleUncaughtException

      public static void handleUncaughtException(Thread thread, Throwable ex)
      Handle for uncaught exceptions.
      Parameters:
      thread - current therad
      ex - exception
    • isSplashScreenEnabled

      protected boolean isSplashScreenEnabled()
      Whether the application shows a splash screen while it starts.

      The default is false: an application without a splash screen does not get one. An application that wants one overrides this method and gives true; the screen itself comes from createSplashScreen().

      Returns:
      true if the application shows a splash screen
    • createSplashScreen

      protected SplashScreen createSplashScreen()
      Creates the splash screen of the application.

      The default is the standard design with the framework's logo. An application overrides this method and sets its own logo, its colours and - if it wants one - a jingle:

      @Override
      protected SplashScreen createSplashScreen() {
          return new SplashScreen()
                  .setLogo(getClass().getResource("icons/app-256.png"))
                  .setJingle(getClass().getResource("sounds/start.wav"));
      }
      
      Returns:
      the splash screen of the application
    • startup

      protected void startup(Stage primaryStage)
      Called before everything else, overwrite if necessary.
      Parameters:
      primaryStage - primary stage
    • isPortableApp

      protected boolean isPortableApp()

      Portable applications do not log, install or write any other files on the host; only the template configuration is read! Portable applications cannot be licensed either.

      Overwrite for portable applications.

      This is the switch that writes cfg/app.cfg. An installed application has no application configuration in the user's application data directory on its first start, so the framework hands null to preInitialize(Stage, Properties) and runs the installer instead - the steps listed in <app resource path>/cfg/installer-steps.cfg, the last of which calls completed(ProcessException). That writes the application configuration into the user's application data directory (<app data>/<vendor>/<app internal name>/cfg/app.cfg) and calls initialize(Stage, Properties) afterwards.

      From then on that file is the configuration: the general values of the bundled template <app resource path>/cfg/app.cfg plus every user setting - the recent files, language and the values the installer steps collect via setConfigurationParameter(String, String). The template itself is never touched; it is the general configuration the file is created from.

      Returns:
      false: the application is installed, not portable
    • stop

      public void stop() throws Exception
      Overrides:
      stop in class Application
      Throws:
      Exception
    • isJvmExitOnStop

      protected boolean isJvmExitOnStop()
      Whether the JVM ends when the application stops.

      When is this needed? After Platform.exit() the JavaFX runtime is gone - but the JVM can still be held by other threads. The AWT event dispatch thread is one of them: it is not a daemon thread, and it exists as soon as the application uses Swing. That is the case for

      • the code editor of the framework (DefaultCodeEditorView) and with it the JSON formatter pane,
      • any Swing component an application embeds itself - the framework's SwingNode or the application's own.

      On macOS the AWT thread can even block for ever in a native call while a Swing component is removed, so the JVM does not end by itself in that case either. An application that uses Swing should therefore end the JVM itself and return true here. An application without any Swing component needs nothing: after Platform.exit() the JVM ends by itself.

      The default is false: the framework does not end the JVM of an application behind its back - only an application that knows that it embeds Swing does.

      Returns:
      true if the JVM ends with the application
    • storeProps

      public void storeProps()
      Store configuration properties to disk.

      Persists what the running application changed in memory: the parameters set with setConfigurationParameter(String, String) and the recent files. The framework calls this when the application exits; an application can call it earlier when a setting has to survive immediately.

    • completed

      public void completed(ProcessException ex)
      Description copied from interface: InstallEndListener
      Will be called when the installer is finished.
      Specified by:
      completed in interface InstallEndListener
      Parameters:
      ex - an exception if any or null
    • getConfigurationParameter

      public String getConfigurationParameter(String key)
      Get a configuration parameter/value.

      Returns the value of the application configuration; a parameter that was changed at runtime (setConfigurationParameter(String, String)) is returned from memory as long as it has not been stored yet.

      Parameters:
      key - key
      Returns:
      value or null
    • setConfigurationParameter

      public void setConfigurationParameter(String key, String value)
      Set an application configuration parameter in memory.

      The value is the one getConfigurationParameter(String) returns afterwards. Like the recent files it is written to the application configuration ('cfg/app.cfg') with the next storeProps() - the exit of the application stores it, and so does every place that wants a setting to survive immediately - and with the file the installation writes (completed(ProcessException)).

      Nothing is written when the application has no configuration on disk yet, e.g. in portable mode; the value then only lives in the running application.

      Parameters:
      key - parameter key
      value - parameter value
    • getPrimaryStage

      public Stage getPrimaryStage()
      Get primary stage.
      Returns:
      primary stage
    • registerOpenExtension

      public final void registerOpenExtension(String extension)
      Registers a file extension the application allows to be opened from the command line (and, by convention, from a double-click / Open With association). Without any registration the framework never treats a bare command-line argument as a file to open.

      Call this from the application's constructor or init(); a leading dot is optional and the value is matched case-insensitively, e.g. registerOpenExtension("ifcx") or registerOpenExtension(".ifcx").

      Parameters:
      extension - file extension, with or without a leading dot; null, blank or a bare dot is ignored
    • getOpenExtensions

      public final Set<String> getOpenExtensions()
      Get the file extensions the application allows to be opened from the command line, each with a leading dot in lower case.
      Returns:
      an unmodifiable view of the registered extensions, in registration order
    • openTargetFromCommandLine

      public final Path openTargetFromCommandLine(List<String> args)
      Picks the file to open from the raw command line arguments, honouring the extensions the application registered via registerOpenExtension(String).

      Recognises --open <file> (any path) and a bare <file> whose extension was registered. Use this in initialize(Stage, Properties) to honour a double-clicked file.

      Parameters:
      args - raw command line arguments (may be null or empty)
      Returns:
      the file to open, or null when the command line carries none
    • loadConfigurationParamaterFromFile

      public String loadConfigurationParamaterFromFile(String key)
      Load a configuration parameter directly from configuration file.
      Parameters:
      key - key for value
      Returns:
      value if any, otherwise null
    • removeConfig

      public void removeConfig()
      Remove app configuration from disk.
    • licenseAccepted

      public final void licenseAccepted()
      Set license accepted flag.
    • isLicenseAccepted

      public final boolean isLicenseAccepted()
      Get license accepted flag.
      Returns:
      true, if license was accepted by the user during install
    • isInstalled

      public boolean isInstalled()
      Checks if this app has been installed before; Installer has been run.
      Returns:
      true if app is installed
    • loadRecentFiles

      public void loadRecentFiles(Properties p)
      Load recent used files.
      Parameters:
      p - configuration properties
    • clearRecentFiles

      public void clearRecentFiles()
      Clear recent used file list.
    • getRecentFiles

      public List<File> getRecentFiles()
      Get recent used files.
      Returns:
      recent files
    • addRecentFile

      public void addRecentFile(File file)
      Add a recent used file.
      Parameters:
      file - recent file
    • removeRecentFile

      public boolean removeRecentFile(File file)
      Remove a file from recent used file list.
      Parameters:
      file - file to remove
      Returns:
      true if removed, false otherwise
    • getInitConfidParameter

      public String getInitConfidParameter(String id)
      Get initial fallback value for the configuration file by specified configuration ID. This is only used if every other method failed; e.g. missing template configuration.
      Parameters:
      id - configuration ID
      Returns:
      configuration value
    • getBaseConfigTemplateFile

      public abstract String getBaseConfigTemplateFile()
      Get base configuration template file. Overwrite this method if you want your application to be licensed.
      Returns:
      base configuration template file
    • getConfigTemplateFile

      public abstract String getConfigTemplateFile()
      Get configuration template file.
      Returns:
      configuration template file
    • getBaseProperties

      protected final Properties getBaseProperties()
      Get base properties (properties from 'cfg/base.ifc'). Used for optional runtime checks.
      Returns:
      base properties
    • getBasePropertiesFile

      protected final String getBasePropertiesFile()
      Get base properties file ('cfg/base.ifc') for possible modifications; e.g. trial period, etc. Used for optional runtime checks.
      Returns:
      base properties
    • getManufacturer

      protected String getManufacturer()
      Manufacturer of this application. We suggest not using spaces for this information; it is used to group the application's data on the desktop in a directory where all application data of a certain manufacturer is located. Overwrite this and use your own enterprise/company name. Typical locations on systems: - Linux : /home/USER/.APPNAME (no manufacturer name used) - macOS : /Users/USER/Library/Application Support/MANUFACTURER/APPNAME - Windows : C:\Users\USER\AppData\Roaming\MANUFACTURER/APPNAME
      Returns:
      manufacturer name
    • preInitialize

      protected abstract Pane preInitialize(Stage primaryStage, Properties configuration)
      Pre-initialize the FX GUI for the installer. Create the main view here and call UI.setup(...). Run before the installer if any.
      Parameters:
      primaryStage - primary stage
      configuration - loaded configuration properties
      Returns:
      the main view
    • initialize

      protected abstract void initialize(Stage primaryStage, Properties configuration)
      Initialize the FX GUI - preInitialize(Stage, Properties) must have been called before this method! This will show the main view created previously. Run after the installer if any.
      Parameters:
      primaryStage - primary stage
      configuration - loaded configuration properties
    • getBaseResourcePath

      public abstract String getBaseResourcePath()
      Get base resource path for application.
      Returns:
      base resource path for application
    • getInMemoryConfigName

      public abstract String getInMemoryConfigName()
      Get in-memory configuration name.
      Returns:
      in-memory configuration name
    • getAppVersion

      public abstract String getAppVersion()
      Get application version. It is also used for online upgrade checks, if applied.
      Specified by:
      getAppVersion in interface ch.autumo.commons.application.LicensedApplication
      Returns:
      application version
    • getAppTitle

      public abstract String getAppTitle()
      Get application title. Part of the online license check, if applied.
      Specified by:
      getAppTitle in interface ch.autumo.commons.application.LicensedApplication
      Returns:
      application title
    • getInternalAppName

      public abstract String getInternalAppName()
      Get an internal application name; make sure it is one word with small and/or big letters and no space. It is used for internal purposes, e.g. configuration directory.
      Returns:
      application name
    • finish

      public abstract void finish(Stage primaryStage)
      Finish program.
      Parameters:
      primaryStage - primary stage
    • getInternalSecurityKey

      public String getInternalSecurityKey()
      Overwrite if you want to use an own internal security key. It is only used when this application is licensed through autumo's licensing mechanism that involves an autumo license server. Contact autumo for more information.

      The default implementation reads the key from the resource autumo.isk, which is looked up relative to this class. The resource is read lazily on the first call and then kept in memory; it is also found when the library is packaged inside a JAR. The resource must carry a valid key (16 hex bytes) and a date entry, otherwise an IllegalStateException is thrown.

      Specified by:
      getInternalSecurityKey in interface ch.autumo.commons.security.SecureApplication
      See Also:
      • SecureApplication.getInternalSecurityKey()
    • getUniqueSecurityKey

      public final String getUniqueSecurityKey()
      Specified by:
      getUniqueSecurityKey in interface ch.autumo.commons.security.SecureApplication
      See Also:
      • SecureApplication.getUniqueSecurityKey()
    • getPassphrase

      public String getPassphrase()
      The pass phrase the Encoder asks for when a value is decoded on the console: the second half of the internal security key.
      Specified by:
      getPassphrase in interface ch.autumo.commons.security.SecureApplication
      See Also:
      • SecureApplication.getPassphrase()
    • initializeBaseConfig

      public void initializeBaseConfig(String rootFolder) throws Exception
      Specified by:
      initializeBaseConfig in interface ch.autumo.commons.application.LicensedApplication
      Throws:
      Exception
    • getLicensePath

      public final String getLicensePath()
      Specified by:
      getLicensePath in interface ch.autumo.commons.application.LicensedApplication
    • getLicInfoTitle

      public final String getLicInfoTitle()
      Specified by:
      getLicInfoTitle in interface ch.autumo.commons.application.LicensedApplication
    • isAllowed2ReadEnvData

      public final boolean isAllowed2ReadEnvData()
      Specified by:
      isAllowed2ReadEnvData in interface ch.autumo.commons.application.LicensedApplication
    • setAllowed2ReadEnvData

      public final void setAllowed2ReadEnvData(boolean allow)
      Specified by:
      setAllowed2ReadEnvData in interface ch.autumo.commons.application.LicensedApplication
    • getRuntimeType

      public String getRuntimeType()
      Overwrite if there's a specific runtime version; e.g. Trial, Full version.
      Specified by:
      getRuntimeType in interface ch.autumo.commons.application.LicensedApplication
      See Also:
      • LicenseHandler.checkRuntimeLicense(LicensedApplication, java.util.Properties, String)
    • getLicType

      public String getLicType()
      Overwrite if there's a specific license version; e.g. Basic, Professional, Enterprise.
      Specified by:
      getLicType in interface ch.autumo.commons.application.LicensedApplication
    • getInlineChecks

      public ch.autumo.commons.utils.license.InlineChecks getInlineChecks()
      Overwrite if inline-checks are used!
      Specified by:
      getInlineChecks in interface ch.autumo.commons.application.LicensedApplication
    • getApiKey

      public String getApiKey()
      Specified by:
      getApiKey in interface ch.autumo.commons.application.LicensedApplication
    • getPublicKey

      public String getPublicKey()
      Specified by:
      getPublicKey in interface ch.autumo.commons.application.LicensedApplication
    • getLicSrvUrl

      public String getLicSrvUrl()
      Specified by:
      getLicSrvUrl in interface ch.autumo.commons.application.LicensedApplication
    • getProductKey

      public String getProductKey()
      You most likely want to overwrite this method if your application can be registered or is registered and product key is not read and decrypted from 'base.ifc'. Must match the product key configured at the autumo product license server. Part of the online license check, if applied.
      Specified by:
      getProductKey in interface ch.autumo.commons.application.LicensedApplication
    • getRegVersion

      public ch.autumo.commons.application.RegistrationVersion getRegVersion()
      You most likely want to overwrite this method if your application can be registered or is registered. Part of the whole licensing mechanism, if applied.
      Specified by:
      getRegVersion in interface ch.autumo.commons.application.LicensedApplication
    • resolveLanguage

      public static String resolveLanguage(Properties configuration)
      Resolves the language an application starts in.

      In order: the -Dapp.lang system property, the language key of the application configuration (Constants.PROP_KEY_LANGUAGE) and its lang alias, then the language of the desktop (Locale.getDefault(), which the JVM filled from the operating system — e.g. de_CH on a Swiss German desktop).

      The result is not checked here: Helper.setLanguage(String) normalises a region away (de_CH → de) and maps an unsupported or blank value — including a desktop language the application has no PO catalogue for — to English.

      Parameters:
      configuration - application configuration, may be null
      Returns:
      the resolved language code, e.g. de
    • log

      public static void log(String message)
      Log debug message if debug file logger is activated. Use -DfileDebug=true for activating debug file log (Log file is written to user home directory).
      Parameters:
      message - message
    • log

      public static void log(Exception ex)
      Log debug exception if debug file logger is activated. Use -DfileDebug=true for activating debug file log (Log file is written to user home directory).
      Parameters:
      ex - exception
    • getInternalSecurityKeyDate

      public static String getInternalSecurityKeyDate()
      Get the date the internal security key was last changed (ISO-8601), read from the ISK_RESOURCE resource.
      Returns:
      the ISK date