Class Helper

java.lang.Object
ch.autumo.ui.utils.Helper

public class Helper extends Object
Helper.
  • Field Details

    • APPLICATION_ICON_SIZES

      public static final int[] APPLICATION_ICON_SIZES
      Icon sizes of an application icon, ascending: 16, 32, 48, 64, 128 and 256 pixels.
  • Method Details

    • loadAppConfiguration

      public static Properties loadAppConfiguration(BaseApp app)
      Load configuration properties / app settings.
      Parameters:
      app - the application
      Returns:
      configuration properties
    • storeBaseConfiguration

      public static void storeBaseConfiguration(BaseApp app, Properties baseSettings)
      Store BASE configuration properties 'base.ifc'.
      Parameters:
      app - the application
      baseSettings - the settings
    • storeAppConfiguration

      public static void storeAppConfiguration(BaseApp app, Properties settings, String comment)
      Store application configuration 'app.cfg'.
      Parameters:
      app - the application
      settings - the settings
      comment - the settings
    • getPropertiesPath

      public static String getPropertiesPath(BaseApp app)
      Get base configuration/settings path for the application.
      Parameters:
      app - the application
      Returns:
      the base configuration directory
    • loadTemplateBaseConfiguration

      public static Properties loadTemplateBaseConfiguration(BaseApp app)
      Load template base configuration properties 'base.ifc' if any.
      Parameters:
      app - the application
      Returns:
      configuration properties
    • loadTemplateConfiguration

      public static Properties loadTemplateConfiguration(BaseApp app)
      Load template configuration properties 'app.cfg'
      Parameters:
      app - the application
      Returns:
      configuration properties
    • getBaseStyle

      public static String getBaseStyle()
      Get style resource from the autumo-ui base.
      Returns:
      resource
    • getBaseHTMLStyleURL

      public static URL getBaseHTMLStyleURL()
      Get style resource from the autumo-ui base.
      Returns:
      resource
    • getBaseHTMLStyle

      public static String getBaseHTMLStyle()
      Get style resource from the autumo-ui base.
      Returns:
      resource
    • getBaseStyleURL

      public static URL getBaseStyleURL()
      Get style resource from the autumo-ui base.
      Returns:
      resource
    • getBaseResource

      public static String getBaseResource(String relativeResourcePath)
      Get a resource from the autumo-ui base.
      Parameters:
      relativeResourcePath - relative resource path
      Returns:
      resource
    • getBaseResourceURL

      public static URL getBaseResourceURL(String relativeResourcePath)
      Get a resource from the autumo-ui base.
      Parameters:
      relativeResourcePath - relative resource path
      Returns:
      resource
    • getBaseResourceStream

      public static InputStream getBaseResourceStream(String relativeResourcePath)
      Get a resource stream from the autumo-ui base.
      Parameters:
      relativeResourcePath - relative resource path
      Returns:
      resource stream
    • getAppResource

      public static String getAppResource(BaseApp app, String resourcePath)
      Get a resource path in external form.

      The resource must be an application resource; if it may be missing because the autumo-ui base ships a default, use getAppResourceOrBase(BaseApp, String) instead. A missing resource is reported here with a readable exception instead of a NullPointerException deep inside the call chain.

      Parameters:
      app - the application
      resourcePath - relative or absolute resource path
      Returns:
      resource path in external form
    • getAppResourceOrBase

      public static String getAppResourceOrBase(BaseApp app, String resourcePath)
      Get a resource path in external form: the application's resource if it has one, otherwise the autumo-ui base resource of the same path.

      This is the lookup for framework panes whose content an application may, but does not have to, provide: the default html/remove_<lang>.html of the 'Remove App Data' pane lives in the autumo-ui base, and an application ships its own file only if it wants different wording. Without this fallback such a pane would fail with a NullPointerException for every application that ships nothing.

      A resource that neither the application nor the autumo-ui base ships is reported with a readable MissingResourceException instead.

      Parameters:
      app - the application
      resourcePath - relative or absolute resource path
      Returns:
      resource path in external form
    • getApplicationStyleSheets

      public static List<String> getApplicationStyleSheets(BaseApp app)
      Get the style sheets of an application scene: the autumo-ui base style first and, if the application ships one, its own application stylesheet (style/application.css) on top.

      This is the combination the main window has — a base look, extended by the application — and dialogs must use the same combination to match it: an application stylesheet that only carries overrides (navigation tree, fonts, colours of its own) still gets the framework's palette, and an application without any sheet gets the framework look instead of an unstyled dialog.

      Parameters:
      app - the application
      Returns:
      style sheet URLs, base style first, application style second or none
    • getApplicationIcons

      public static List<URL> getApplicationIcons(BaseApp app)
      Get the application icons of an application: the application's own icons if it ships any, otherwise the default autumo-ui logo.

      An application defines its own icon by shipping any of:

      • icons/app-16.png ... icons/app-256.png — any subset of APPLICATION_ICON_SIZES, the sharp icon for each window-manager size,
      • icons/app.png — a single icon (at least 256×256 pixels) that is used for every size.

      Both are application resources, resolved relative to the application class. If the application ships neither, the framework's default logo (icons/autumo-ui-logo-16.png ... icons/autumo-ui-logo-256.png) is used, so every autumo-ui application has an application icon on all operating systems without any further effort. The images are returned in ascending size order — the last one is the largest and is what the macOS dock icon of a packaged application is built from (jpackage --icon).

      Parameters:
      app - the application
      Returns:
      application icon resource URLs in ascending size order, possibly empty
    • getAppResourceURL

      public static URL getAppResourceURL(BaseApp app, String resourcePath)
      Get a resource URL.
      Parameters:
      app - the application
      resourcePath - relative or absolute resource path
      Returns:
      resource path in external form
    • getAppResourceStream

      public static InputStream getAppResourceStream(BaseApp app, String resourcePath)
      Get a resource stream from the application.
      Parameters:
      app - the application
      resourcePath - relative or absolute resource path
      Returns:
      resource stream
    • getTranslatedText

      public static String getTranslatedText(BaseApp app, String translationId)
      Get a text translation.
      Parameters:
      app - the application
      translationId - translation ID
      Returns:
      translated text
    • getTranslatedText

      public static String getTranslatedText(BaseApp app, String translationId, Object... variables)
      Get a text translation.
      Parameters:
      app - the application
      translationId - translation ID
      variables - format variables
      Returns:
      translated text
    • getMessageBundle

      public static ResourceBundle getMessageBundle(String baseResourcePath)
      Get the message bundle of the active language.

      Two gettext catalogues are merged, the application's one wins: its own lang/messages.<lang>.po and the autumo-ui framework's /ch/autumo/ui/lang/messages.<lang>.po. An application therefore only has to translate its own texts; the framework's keys (its panes, dialogs and the installer) always resolve, and the application may still override any framework text by defining the key in its own catalogue. There are no .properties catalogues anymore.

      The merged bundle is cached per base resource path and language; a language change (setLanguage(String)) clears the cache.

      Parameters:
      baseResourcePath - base resource path, e.g. '/ch/autumo/.../', no backslashes! If null or empty, the autumo-ui base resource path is used
      Returns:
      resource bundle
    • getLanguage

      public static String getLanguage()
      Get the language the UI is currently displayed in. It is derived from the 'user.language' system property on first use and can be changed at runtime with setLanguage(String).
      Returns:
      language code, e.g. 'en'; always one of getSupportedLanguages()
    • getSupportedLanguages

      public static String[] getSupportedLanguages()
      Get all languages supported by autumo-ui.
      Returns:
      language codes, e.g. 'de', 'en'
    • setLanguage

      public static void setLanguage(String lang)
      Switch the UI language at runtime. This sets the JVM default locale and the 'user.language' system property, drops the cached resource bundles and notifies all registered language listeners. A region is ignored (de_CH selects de); unsupported or null values fall back to English.

      This covers the framework resources only (window titles, About/HTML panes, dialogs). An application that translates its own texts has to re-apply them in a language listener.

      Parameters:
      lang - language code, e.g. 'de'
    • addLanguageListener

      public static void addLanguageListener(Runnable listener)
      Register a listener that is called after the language changed.
      Parameters:
      listener - listener, e.g. one that re-applies the application texts
    • removeLanguageListener

      public static void removeLanguageListener(Runnable listener)
      Remove a language listener again.
      Parameters:
      listener - listener to remove
    • isSupportedLang

      public static boolean isSupportedLang(String lang)
      Is the language supported by the app?

      A region is ignored, i.e. 'de_CH' is supported because 'de' is (autumo-ui's own Constants.LOCALE_DE is 'de_CH').

      Parameters:
      lang - lang code, e.g. 'en'
      Returns:
      true if so
    • hasExtension

      public static boolean hasExtension(Path file)
      File has an extension.
      Parameters:
      file - file
      Returns:
      true if there's an extension
    • extensionDotIndex

      public static int extensionDotIndex(Path file)
      Get extension dot index.
      Parameters:
      file - file
      Returns:
      extension dot index
    • getWebVersions

      public static ch.autumo.commons.versioning.Versions getWebVersions(BaseApp app)
      Get web versions for current application.
      Parameters:
      app - application
      Returns:
      timeout read and connection timeout in seconds
    • createWebView

      public static WebView createWebView(BaseApp app)
      Create a web view with a proper local storage for the underlying web engine.
      Parameters:
      app - application
      Returns:
      web view
    • getCountryData

      public static CountryData getCountryData()
      Get loaded country data.
      Returns:
      country data
    • nameFromPath

      public static String nameFromPath(Path path)
      File name without extension from path.
      Parameters:
      path - path
      Returns:
      name without extension from path
    • openURL

      public static void openURL(String url)
      Open an URL on the desktop.
      Parameters:
      url - URL
    • openFolder

      public static boolean openFolder(String folder)
      Open a folder on the desktop.
      Parameters:
      folder - folder
      Returns:
      true, if folder could be opened
    • editFile

      public static void editFile(String file)
      Edit a file on the desktop.
      Parameters:
      file - file
    • openFile

      public static void openFile(String file)
      Open a file on the desktop.
      Parameters:
      file - file
    • chooseFolder

      public static String chooseFolder(String defaultDir, Stage parent, String title, String desc)
      Choose a folder.
      Parameters:
      defaultDir - default directory or null
      parent - parent stage
      title - title
      desc - description
      Returns:
      absolute directory path
    • chooseFile

      public static String chooseFile(String defaultDir, Stage parent, String title, String desc, String extension)
      Choose a file.
      Parameters:
      defaultDir - default directory or null
      parent - parent stage
      title - title
      desc - description
      extension - allowed extension
      Returns:
      absolute file path
    • saveFile

      public static String saveFile(String defaultDir, Stage parent, String title, String desc, String extension)
      Choose a file for saving.
      Parameters:
      defaultDir - default directory or null
      parent - parent stage
      title - title
      desc - description
      extension - allowed extension
      Returns:
      absolute file path
    • atariBusy

      public static Cursor atariBusy()
      Return an Atari-busy-cursor!
      Returns:
      Atari-busy-cursor
    • startTime

      public static void startTime()
      Start timer.
    • stopTime

      public static void stopTime(String id, Class clazz)
      Stop timer.
      Parameters:
      id - id foe info logging
      clazz - class for info clogging
    • getText

      public static String getText(BaseApp app, String translationId, String fallback)
      Get a text translation with fallback.
      Parameters:
      app - the application
      translationId - translation ID
      fallback - fallback text if not found
      Returns:
      translated text