Class BaseController

java.lang.Object
ch.autumo.ui.fx.controller.BaseController
All Implemented Interfaces:
Initializable
Direct Known Subclasses:
DefaultInfoController

public abstract class BaseController extends Object implements Initializable
FX Base Controller.
  • Field Details

    • app

      protected BaseApp app
      Application.
    • stage

      protected Stage stage
      Stage.
    • model

      protected BaseModel model
      Model.
    • view

      protected Pane view
      View.
  • Constructor Details

    • BaseController

      public BaseController(BaseApp app, Stage stage, BaseModel model, Pane view)
      Main controller.
      Parameters:
      app - app
      stage - stage
      model - model
      view - view
  • Method Details

    • getApp

      public BaseApp getApp()
      Get the application.
      Returns:
      application
    • getStage

      public Stage getStage()
      Get the stage.
      Returns:
      stage
    • getModel

      public BaseModel getModel()
      Get model.
      Returns:
      model
    • getView

      public Pane getView()
      Get view.
      Returns:
      model
    • keyPressed

      public void keyPressed(KeyEvent key)
      Override if you want to execute more actions on specific keyboard shortcuts for the stage/scene associated.
      Parameters:
      key - key pressed
    • escKeyPressed

      public void escKeyPressed(KeyEvent key)
      Override if you want to execute actions on ESC key pressed.
      Parameters:
      key - key pressed
    • initializeRecentMenu

      public void initializeRecentMenu(Menu menuRecent, MenuItem menuItemClearAllRecent)
      Initialize recent menu structure.
      Parameters:
      menuRecent - the 'recent' sub-menu
      menuItemClearAllRecent - the 'clear all entry' menu entry or null (will be created)
    • getMenuRecent

      public Menu getMenuRecent()
      Get the 'recent' sub-menu.
      Returns:
      'recent' sub-menu
    • getMenuItemClearAllRecent

      public MenuItem getMenuItemClearAllRecent()
      Get the 'clear all entry' menu entry.
      Returns:
      'clear all entry' menu entry
    • getMenuLanguage

      public Menu getMenuLanguage()
      Get the language sub-menu.
      Returns:
      language sub-menu or null, if initializeLanguageMenu(Menu) was not called
    • initializeLanguageMenu

      public void initializeLanguageMenu(Menu menuLanguage)
      Initialize the language sub-menu: one radio item per language supported by autumo-ui, each with the language's flag and its name in that language ('English', 'Deutsch'). The item of the current language is selected, so an application does not have to care about the language it was started with. The sub-menu itself gets the framework's language icon, unless the application has already set its own graphic on it.

      Selecting an item switches the language of the whole application, see switchLanguage(String). Call this while the application builds its menu bar.

      Parameters:
      menuLanguage - language sub-menu, e.g. 'Help > Language'
    • selectLanguageItem

      public void selectLanguageItem(String lang)
      Marks the radio item of the given language as selected.
      Parameters:
      lang - language code, e.g. 'de'
    • isLanguageSelected

      public boolean isLanguageSelected(String lang)
      Is the radio item of the given language the selected one?
      Parameters:
      lang - language code, e.g. 'de'
      Returns:
      true, if initializeLanguageMenu(Menu) added the language and it is selected
    • switchLanguage

      public void switchLanguage(String lang)
      Switch the application language at runtime.

      The framework does its part here: the language of autumo-ui follows (framework bundles, framework dialogs, the window title and the About/license panes), the choice is stored as an application configuration parameter in the user's application configuration ('cfg/app.cfg', see BaseApp.setConfigurationParameter(String, String)) so the next start comes up in it, and the language menu selection is moved.

      Afterwards languageChanged() lets the application re-apply the texts it sets itself.

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

      protected void languageChanged()
      Called after the language was switched, so an application can re-apply the texts of its own controls; the framework texts, the window title, the language menu and the stored application parameter already follow.

      The default does nothing; an application with own texts overrides it.

    • rebuildRecentList

      public void rebuildRecentList()
      Rebuild recent file list.
    • disableMacOSMenuDetach

      public final void disableMacOSMenuDetach()
      Prevent macOS menu detach.
    • getMenuBar

      public MenuBar getMenuBar()
      Only called on macOS. Get menu bar; implement this, if you want to detach the application menu on macOS system and to add it to macOS its desktop menu. If you implement this, you might want to implement the method getToolBar()! Note: This is usually used for main views only! If this method returns null, the menu bar stays attached to the application and getToolBar() is not called. Overwrite if necessary.
      Returns:
      menu bar.
    • getToolBar

      public Pane getToolBar()
      Only called on macOS. Returns the tool bar; see getMenuBar(). It is only called if getMenuBar() returns not null! It repositions the tool bar after detaching the menu bar. The tool bar should be inside a pane with a shifted top anchor ('AnchorPane.topAnchor'); it is set to zero!
      Returns:
      tool bar pane.
    • confirmDiscardChanges

      public boolean confirmDiscardChanges()
      Whether it is safe to leave app: false when the user cancels the platform exit.
      Returns:
      true when the caller may proceed and discard the state
    • toolButton

      public Button toolButton(String iconName, String text, String tip, Runnable action)
      Create a tool buttonm for the tool bar.
      Parameters:
      iconName - Phosphor glyph name
      text - text
      tip - tool-tip id any
      action - action to be executed id any
      Returns:
      styled button.
    • toolSeparator

      public Separator toolSeparator()
      Create a tool separator for the tool bar.
      Returns:
      styled separator.
    • icon

      public ImageView icon(String iconFile)
      Create an image with specified iconf name found in app-resources or base-app-resoruces icons-path; e.g. 'open-folder-48.png' -> 'ch/autumo/ui/icons/open-folder-48.png'.
      Parameters:
      iconFile - icon file name
      Returns:
      image view
    • innerOpen

      protected void innerOpen(File file)
      Overwrite to open a file from recent list.
      Parameters:
      file - file
    • initialize

      public final void initialize(URL location, ResourceBundle resources)
      Specified by:
      initialize in interface Initializable
    • init

      public abstract void init(URL location, ResourceBundle resources, double toolBarShift)
      Delegated initialization. See Initializable.initialize(URL, ResourceBundle).
      Parameters:
      location - The location used to resolve relative paths for the root object, or null if the location is not known.
      resources - The resources used to localize the root object, or null if the root object was not localized.
      toolBarShift - if the tool bar has been shifted, this value is bigger than zero and can be used to adjust the UI layout.