Skip to content

MenuBarController Class

Natalie L edited this page Dec 5, 2024 · 1 revision

The MenuBarController class is part of the controllers package (package org.example.globalgoodsindex.controllers) .

It manages the menus in the application’s menu bar, handling user interactions with the settings, view, and help menus. It opens a new window for the "About" section and opens the project's GitHub repository in the default browser.

FXML

menuBarController

Methods

initialize

Purpose:

Initializes the menu items and sets up their actions.

Description:

  • Binds the menu and menu item text properties to localized strings.
  • Sets action handlers for the GitHub menu item and the About menu item.

bindStrings

Purpose:

Binds the menu and menu item text to localized values.

Description:

  • Binds the text of the menu items (settings, view, help, about, and GitHub) to their respective localized strings using L10N.createStringBinding.

openWebsite

Purpose:

Opens a website URL in the default browser.

Description:

  • Creates a new Task to open a URL in the default system browser using Desktop.browse().
  • Runs the task in a new thread to avoid blocking the UI.

Example Usage:

MenuBarController.openWebsite("https://github.com/bruch-alex/Global-Goods-Index");

Error Handling:

  • Catches exceptions like invalid URLs and prints stack traces.

openAboutWindow

Purpose:

Opens the "About" window if it's not already open.

Description:

  • Loads the about.fxml file and displays it in a new stage if not already showing.
  • Sets the title and scene of the window and binds the title to a localized string.
  • Ensures that only one instance of the "About" window can be shown at a time.

Error Handling:

  • Catches IOException for loading issues with about.fxml and logs the error.
  • Catches general exceptions for unexpected errors.

Clone this wiki locally