Class Desktop

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public final class Desktop extends JDesktopPane
The MDI desktop pane that hosts all BaseView internal frames.

Background rendering

An optional background color and/or tiled background image can be supplied at creation time via createDesktop(Color, String).

Layout persistence

The desktop can save and restore the position, size, and visibility of every registered BaseView to/from an XML properties file whose location is determined by Environment.getConfigurationFile().

Two save methods are provided:

See Also:
  • Field Details

    • ALL_VIEWS

      public static final int ALL_VIEWS
      Sentinel passed to operate-on-views methods to target all views.
      See Also:
    • TOP_VIEW

      public static final int TOP_VIEW
      Sentinel passed to operate-on-views methods to target only the top-most view.
      See Also:
  • Method Details

    • createDesktop

      public static Desktop createDesktop(Color background, String backgroundImage)
      Create the singleton desktop pane.

      If the singleton already exists this method returns the existing instance unchanged; the arguments are ignored on subsequent calls.

      Parameters:
      background - optional background color
      backgroundImage - optional path of a tiled background image resource
      Returns:
      the singleton Desktop
    • getInstance

      public static Desktop getInstance()
      Returns the singleton Desktop instance.
      Returns:
      the singleton, or null if createDesktop(Color, String) has not yet been called
    • paintComponent

      public void paintComponent(Graphics g)
      Paints the desktop background, tiling the background image if one was configured.
      Overrides:
      paintComponent in class JComponent
      Parameters:
      g - the graphics context
    • loadConfigurationFile

      public void loadConfigurationFile()
      Load the layout configuration file into memory.

      The file path is determined by Environment.getConfigurationFile(). If the file does not exist, cannot be read, cannot be parsed, or is empty, this method is a no-op (the internal property set is cleared so that a subsequent configureViews() call is also a no-op).

      Call configureViews() after this method to apply the loaded state to the registered views.

    • getSavedProperties

      public Properties getSavedProperties()
      Returns the properties loaded by the most recent call to loadConfigurationFile(), or null if no configuration has been loaded.

      This is used by ViewConfiguration to apply saved state to lazily-created views at the moment they are realized, since those views do not exist as frames when configureViews() runs at startup.

      The returned object is the live internal instance; callers must not modify it.

      Returns:
      the loaded configuration properties, or null
    • configureViews

      public void configureViews()
      Apply the loaded configuration properties to all registered views.

      Each JInternalFrame on the desktop that is a BaseView has its state restored via BaseView.setFromProperties(Properties). This is a no-op if loadConfigurationFile() has not been called or if the load produced no usable properties.

      VirtualView is intentionally excluded: its position is always fixed at (0, 0) upper-left by the framework and must not be overridden by a saved layout.

    • writeConfigurationFile

      public void writeConfigurationFile()
      Write the current view layout to the configuration file without prompting the user.

      This is the preferred path for automatic saves (e.g. on application exit or via a toolbar button). It overwrites any existing file silently. For a save that confirms before overwriting, use writeConfigurationFileInteractive().

      The file path is determined by Environment.getConfigurationFile(). If the path cannot be determined, or if the write fails, the failure is logged and this method returns without throwing.

    • writeConfigurationFileInteractive

      public void writeConfigurationFileInteractive()
      Write the current view layout to the configuration file, prompting the user to confirm before overwriting an existing file.

      This method is intended for an explicit "Save Layout…" menu action where user confirmation is appropriate. For automatic/silent saves use writeConfigurationFile() instead.

      On success a confirmation dialog informs the user of the saved path.

    • deleteConfigurationFile

      public void deleteConfigurationFile()
      Delete the layout configuration file after confirming with the user.

      This is a no-op if no configuration file path can be determined or if the file does not exist.

    • prepareForExit

      public void prepareForExit()
      Notify all registered BaseViews that the application is about to exit, giving each view a chance to stop running tasks, flush state, etc.

      If this method is called from a thread other than the EDT it re-dispatches itself via SwingUtilities.invokeLater(Runnable).