Class BaseApp
- All Implemented Interfaces:
ch.autumo.commons.application.LicensedApplication, ch.autumo.commons.security.SecureApplication, InstallEndListener
ConfigurationManager
to retrieve any configuration parameter.
Two hooks an application usually overrides:
isSplashScreenEnabled()andcreateSplashScreen()- 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:
-
Nested Class Summary
Nested classes/interfaces inherited from class Application
Application.Parameters -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe base configuration file ('cfg/base.cfg').protected PropertiesThe base configuration properties.protected static final org.slf4j.LoggerLogger.Fields inherited from class Application
STYLESHEET_CASPIAN, STYLESHEET_MODENAFields inherited from interface ch.autumo.commons.application.LicensedApplication
AP_LS_AD_KEY, AP_LS_AK_KEY, BASE_CFG_FILE, BASE_CFG_JAR, CONFIG_DEFAULT_FILE, CONFIG_PATH, FILE_REG_SOURCE, INLINE_CHECKS_KEY, LIC_CHARS, LIC_INFO_FILE, LIC_PATH, LIC_TYPE_KEY, LICENSE_PUBLIC_KEY, PROD_KEY, RT_TYPE_KEYFields inherited from interface ch.autumo.commons.security.SecureApplication
SEC_KEY_SEED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRecentFile(File file) Add a recent used file.voidClear recent used file list.voidWill be called when the installer is finished.protected SplashScreenCreates the splash screen of the application.abstract voidFinish program.abstract StringGet application title.abstract StringGet application version.abstract StringGet base configuration template file.protected final PropertiesGet base properties (properties from 'cfg/base.ifc').protected final StringGet base properties file ('cfg/base.ifc') for possible modifications; e.g.abstract StringGet base resource path for application.abstract StringGet configuration template file.Get a configuration parameter/value.Get initial fallback value for the configuration file by specified configuration ID.ch.autumo.commons.utils.license.InlineChecksOverwrite if inline-checks are used!abstract StringGet in-memory configuration name.abstract StringGet an internal application name; make sure it is one word with small and/or big letters and no space.Overwrite if you want to use an own internal security key.static StringGet the date the internal security key was last changed (ISO-8601), read from theISK_RESOURCEresource.final Stringfinal StringOverwrite if there's a specific license version; e.g.protected StringManufacturer of this application.Get the file extensions the application allows to be opened from the command line, each with a leading dot in lower case.The pass phrase theEncoderasks for when a value is decoded on the console: the second half of the internal security key.Get primary stage.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'.Get recent used files.ch.autumo.commons.application.RegistrationVersionYou most likely want to overwrite this method if your application can be registered or is registered.Overwrite if there's a specific runtime version; e.g.final Stringstatic voidhandleUncaughtException(Thread thread, Throwable ex) Handle for uncaught exceptions.voidinit()protected abstract voidinitialize(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.voidinitializeBaseConfig(String rootFolder) final booleanbooleanChecks if this app has been installed before; Installer has been run.protected booleanWhether the JVM ends when the application stops.final booleanGet license accepted flag.protected booleanPortable 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.protected booleanWhether the application shows a splash screen while it starts.final voidSet license accepted flag.Load a configuration parameter directly from configuration file.voidLoad recent used files.static voidLog debug exception if debug file logger is activated.static voidLog debug message if debug file logger is activated.final PathopenTargetFromCommandLine(List<String> args) Picks the file to open from the raw command line arguments, honouring the extensions the application registered viaregisterOpenExtension(String).protected abstract PanepreInitialize(Stage primaryStage, Properties configuration) Pre-initialize the FX GUI for the installer.final voidregisterOpenExtension(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).voidRemove app configuration from disk.booleanremoveRecentFile(File file) Remove a file from recent used file list.static StringresolveLanguage(Properties configuration) Resolves the language an application starts in.final voidsetAllowed2ReadEnvData(boolean allow) voidsetConfigurationParameter(String key, String value) Set an application configuration parameter in memory.voidprotected voidCalled before everything else, overwrite if necessary.voidstop()voidStore configuration properties to disk.Methods inherited from class Application
getHostServices, getParameters, getUserAgentStylesheet, launch, launch, notifyPreloader, setUserAgentStylesheet
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGLogger. -
baseCfgFile
The base configuration file ('cfg/base.cfg'). -
baseProps
The base configuration properties.
-
-
Constructor Details
-
BaseApp
public BaseApp()Because ofSecureApplicationand when console tools such as theEncoderare used. -
BaseApp
public BaseApp(ch.autumo.commons.application.RegistrationVersion regVersion) Because ofLicensedApplicationand when console tools such as theRegisterare used.- Parameters:
regVersion- injected registration version
-
-
Method Details
-
init
- Overrides:
initin classApplication- Throws:
Exception
-
start
- Specified by:
startin classApplication
-
handleUncaughtException
-
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 givestrue; the screen itself comes fromcreateSplashScreen().- Returns:
trueif the application shows a splash screen
-
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
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 handsnulltopreInitialize(Stage, Properties)and runs the installer instead - the steps listed in<app resource path>/cfg/installer-steps.cfg, the last of which callscompleted(ProcessException). That writes the application configuration into the user's application data directory (<app data>/<vendor>/<app internal name>/cfg/app.cfg) and callsinitialize(Stage, Properties)afterwards.From then on that file is the configuration: the general values of the bundled template
<app resource path>/cfg/app.cfgplus every user setting - the recent files,languageand the values the installer steps collect viasetConfigurationParameter(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
- Overrides:
stopin classApplication- 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
SwingNodeor 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
truehere. An application without any Swing component needs nothing: afterPlatform.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:
trueif the JVM ends with the application
- the code editor of the framework (
-
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
Description copied from interface:InstallEndListenerWill be called when the installer is finished.- Specified by:
completedin interfaceInstallEndListener- Parameters:
ex- an exception if any or null
-
getConfigurationParameter
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
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 nextstoreProps()- 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 keyvalue- parameter value
-
getPrimaryStage
-
registerOpenExtension
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")orregisterOpenExtension(".ifcx").- Parameters:
extension- file extension, with or without a leading dot;null, blank or a bare dot is ignored
-
getOpenExtensions
-
openTargetFromCommandLine
Picks the file to open from the raw command line arguments, honouring the extensions the application registered viaregisterOpenExtension(String).Recognises
--open <file>(any path) and a bare<file>whose extension was registered. Use this ininitialize(Stage, Properties)to honour a double-clicked file.- Parameters:
args- raw command line arguments (may benullor empty)- Returns:
- the file to open, or
nullwhen the command line carries none
-
loadConfigurationParamaterFromFile
-
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
Load recent used files.- Parameters:
p- configuration properties
-
clearRecentFiles
public void clearRecentFiles()Clear recent used file list. -
getRecentFiles
-
addRecentFile
-
removeRecentFile
Remove a file from recent used file list.- Parameters:
file- file to remove- Returns:
- true if removed, false otherwise
-
getInitConfidParameter
-
getBaseConfigTemplateFile
Get base configuration template file. Overwrite this method if you want your application to be licensed.- Returns:
- base configuration template file
-
getConfigTemplateFile
Get configuration template file.- Returns:
- configuration template file
-
getBaseProperties
Get base properties (properties from 'cfg/base.ifc'). Used for optional runtime checks.- Returns:
- base properties
-
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
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
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 stageconfiguration- loaded configuration properties- Returns:
- the main view
-
initialize
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 stageconfiguration- loaded configuration properties
-
getBaseResourcePath
Get base resource path for application.- Returns:
- base resource path for application
-
getInMemoryConfigName
Get in-memory configuration name.- Returns:
- in-memory configuration name
-
getAppVersion
Get application version. It is also used for online upgrade checks, if applied.- Specified by:
getAppVersionin interfacech.autumo.commons.application.LicensedApplication- Returns:
- application version
-
getAppTitle
Get application title. Part of the online license check, if applied.- Specified by:
getAppTitlein interfacech.autumo.commons.application.LicensedApplication- Returns:
- application title
-
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
Finish program.- Parameters:
primaryStage- primary stage
-
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 validkey(16 hex bytes) and adateentry, otherwise anIllegalStateExceptionis thrown.- Specified by:
getInternalSecurityKeyin interfacech.autumo.commons.security.SecureApplication- See Also:
-
getUniqueSecurityKey
- Specified by:
getUniqueSecurityKeyin interfacech.autumo.commons.security.SecureApplication- See Also:
-
getPassphrase
The pass phrase theEncoderasks for when a value is decoded on the console: the second half of the internal security key.- Specified by:
getPassphrasein interfacech.autumo.commons.security.SecureApplication- See Also:
-
initializeBaseConfig
-
getLicensePath
- Specified by:
getLicensePathin interfacech.autumo.commons.application.LicensedApplication
-
getLicInfoTitle
- Specified by:
getLicInfoTitlein interfacech.autumo.commons.application.LicensedApplication
-
isAllowed2ReadEnvData
public final boolean isAllowed2ReadEnvData()- Specified by:
isAllowed2ReadEnvDatain interfacech.autumo.commons.application.LicensedApplication
-
setAllowed2ReadEnvData
public final void setAllowed2ReadEnvData(boolean allow) - Specified by:
setAllowed2ReadEnvDatain interfacech.autumo.commons.application.LicensedApplication
-
getRuntimeType
Overwrite if there's a specific runtime version; e.g. Trial, Full version.- Specified by:
getRuntimeTypein interfacech.autumo.commons.application.LicensedApplication- See Also:
-
getLicType
Overwrite if there's a specific license version; e.g. Basic, Professional, Enterprise.- Specified by:
getLicTypein interfacech.autumo.commons.application.LicensedApplication
-
getInlineChecks
public ch.autumo.commons.utils.license.InlineChecks getInlineChecks()Overwrite if inline-checks are used!- Specified by:
getInlineChecksin interfacech.autumo.commons.application.LicensedApplication
-
getApiKey
- Specified by:
getApiKeyin interfacech.autumo.commons.application.LicensedApplication
-
getPublicKey
- Specified by:
getPublicKeyin interfacech.autumo.commons.application.LicensedApplication
-
getLicSrvUrl
- Specified by:
getLicSrvUrlin interfacech.autumo.commons.application.LicensedApplication
-
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:
getProductKeyin interfacech.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:
getRegVersionin interfacech.autumo.commons.application.LicensedApplication
-
resolveLanguage
Resolves the language an application starts in.In order: the
-Dapp.langsystem property, thelanguagekey of the application configuration (Constants.PROP_KEY_LANGUAGE) and itslangalias, then the language of the desktop (Locale.getDefault(), which the JVM filled from the operating system — e.g.de_CHon 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 benull- Returns:
- the resolved language code, e.g.
de
-
log
Log debug message if debug file logger is activated. Use-DfileDebug=truefor activating debug file log (Log file is written to user home directory).- Parameters:
message- message
-
log
Log debug exception if debug file logger is activated. Use-DfileDebug=truefor activating debug file log (Log file is written to user home directory).- Parameters:
ex- exception
-
getInternalSecurityKeyDate
Get the date the internal security key was last changed (ISO-8601), read from theISK_RESOURCEresource.- Returns:
- the ISK date
-