Class AbstractDialog

All Implemented Interfaces:
WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants
Direct Known Subclasses:
AbstractButtonDialog, AbstractHelpDialog, ASConversionInfoDialog, ASStatsDialog, AutoResolveChanceDialog, AutoResolveProgressDialog, BVDisplayDialog, CostDisplayDialog, EntityReadoutDialog, LiveReadoutDialog, SBFStatsDialog, SBFTargetDialog, TechLevelDisplayDialog, WeightDisplayDialog

public abstract class AbstractDialog extends JDialog implements WindowListener
This is the base class for dialogs in MegaMek. This class handles setting the UI, managing the X button, managing the escape key, and saving the dialog preferences.

Inheriting classes must call initialize() in their constructors and override createCenterPane()

This is directly tied to MekHQ's AbstractMHQDialog, and any changes here MUST be verified there.

See Also:
  • Field Details

  • Constructor Details

    • AbstractDialog

      protected AbstractDialog(JFrame frame, String name, String title)
      This creates a non-modal AbstractDialog using the default resource bundle. This is the normal constructor to use for an AbstractDialog.
    • AbstractDialog

      protected AbstractDialog(JFrame frame, boolean modal, String name, String title)
      This creates an AbstractDialog using the default resource bundle. It allows one to create modal dialogs.
    • AbstractDialog

      protected AbstractDialog(JFrame frame, boolean modal, ResourceBundle resources, String name, String title)
      This creates an AbstractDialog using the specified resource bundle. This is not recommended by default.
      Parameters:
      frame - the dialog's parent frame
      modal - if this dialog is modal
      resources - the resource bundle for this dialog
      name - the dialog's name
      title - the dialog's title resource key. This is required for accessibility reasons, and the method will error out if it isn't valid.
    • AbstractDialog

      protected AbstractDialog(JDialog dialog, JFrame frame, boolean modal, ResourceBundle resources, String name, String title)
      This allows Swing to create the dialog with another dialog as the parent. Which dialog swing renders on top is somewhat undefined, depending on the window manager. This can cause problems in the case of modal dialogs that show up behind other dialogs, and you cannot get to them.
      Parameters:
      dialog - Owning dialog, for dialogs on dialogs
      frame - Owning frame
      modal - if this dialog is modal
      resources - the resource bundle for this dialog
      name - the dialog's name
      title - the dialog's title resource key. This is required for accessibility reasons, and the method will error out if it isn't valid.
  • Method Details

    • getFrame

      public JFrame getFrame()
    • setFrame

      public void setFrame(JFrame frame)
    • initialize

      protected void initialize()
      Initializes the dialog's UI and preferences. Needs to be called by child classes for initial setup.

      Anything that overrides this method MUST end by calling finalizeInitialization()

    • createCenterPane

      protected abstract Container createCenterPane()
      This is used to create the dialog's center pane
      Returns:
      the center pane of the dialog
    • finalizeInitialization

      protected void finalizeInitialization() throws Exception
      This MUST be called at the end of initialization to finalize it. This is the key method for this being the abstract basis for all other dialogs.
      Throws:
      Exception - if there's an issue finishing initialization. Normally this means there's an issue setting the preferences, which normally means that a component has had its name value set.
    • fit

      protected void fit()
      Re-sizes the dialog to a maximum width and height of 80% of the screen size when necessary. If the dialog goes off-screen, center it
    • fitAndCenter

      protected void fitAndCenter()
      Re-sizes the dialog to a maximum width and height of 80% of the screen size when necessary. It then centers the dialog on the screen.
    • setPreferences

      protected void setPreferences() throws Exception
      This is used to set preferences based on the preference node for this class. It is overridden for MekHQ usage.
      Throws:
      Exception - if there's an issue initializing the preferences. Normally this means a component has not had its name value set.
    • setPreferences

      protected void setPreferences(PreferencesNode preferences) throws Exception
      This sets the base preferences for this class, and calls the custom preferences method
      Throws:
      Exception - if there's an issue initializing the preferences. Normally this means a component has not had its name value set.
    • setCustomPreferences

      protected void setCustomPreferences(PreferencesNode preferences) throws Exception
      Adds custom preferences to the child dialog.

      By default, this dialog will track preferences related to the size and position of the dialog. Other preferences can be added by overriding this method.

      Parameters:
      preferences - the preference node for this dialog
      Throws:
      Exception - if there's an issue initializing the preferences. Normally this means a component has not had its name value set.
    • cancelActionPerformed

      protected void cancelActionPerformed(ActionEvent evt)
      Note: Cancelling a dialog should always allow one to close the dialog.
    • cancelAction

      protected void cancelAction()
      Action performed when the Cancel button is clicked, the dialog is closed by the X button, or the escape key is pressed
    • windowClosing

      public void windowClosing(WindowEvent evt)
      Note: Closing the dialog should always allow one to close the dialog.
      Specified by:
      windowClosing in interface WindowListener
    • windowOpened

      public void windowOpened(WindowEvent evt)
      Specified by:
      windowOpened in interface WindowListener
    • windowClosed

      public void windowClosed(WindowEvent evt)
      Specified by:
      windowClosed in interface WindowListener
    • windowIconified

      public void windowIconified(WindowEvent evt)
      Specified by:
      windowIconified in interface WindowListener
    • windowDeiconified

      public void windowDeiconified(WindowEvent evt)
      Specified by:
      windowDeiconified in interface WindowListener
    • windowActivated

      public void windowActivated(WindowEvent evt)
      Specified by:
      windowActivated in interface WindowListener
    • windowDeactivated

      public void windowDeactivated(WindowEvent evt)
      Specified by:
      windowDeactivated in interface WindowListener