Package megameklab.ui

Class MegaMekLabTabbedUI

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, ChangeListener, RootPaneContainer, WindowConstants, MenuBarOwner, AppCloser

public class MegaMekLabTabbedUI extends JFrame implements MenuBarOwner, ChangeListener
Replaces MegaMekLabMainUI as the top-level window for MML. Holds several MegaMekLabMainUIs as tabs, allowing many units to be open at once.
See Also:
  • Constructor Details

    • MegaMekLabTabbedUI

      public MegaMekLabTabbedUI(MegaMekLabMainUI... entities)
      Constructs a new MegaMekLabTabbedUI instance, which serves as the main tabbed UI for managing multiple MegaMekLabMainUI editors. Automatically initializes a default BMMainUI instance if no entities are provided.
      Parameters:
      entities - A variable number of MegaMekLabMainUI instances that will be added as tabs to the UI. If no entities are provided, a default BMMainUI instance will be created and added.
  • Method Details

    • isOpen

      public static boolean isOpen()
    • isTabEditorSelected

      public boolean isTabEditorSelected(MegaMekLabMainUI editor)
      Checks if the given editor is the currently selected tab in the tabbed UI.
      Parameters:
      editor - The MegaMekLabMainUI instance to check against the currently selected
      Returns:
      True if the given editor is the currently selected tab, false otherwise.
    • refreshEntity

      public static void refreshEntity(megamek.common.units.Entity entityToFind)
      Refreshes the display of the given entity. This method is called when the entity is modified externally.
      Parameters:
      entityToFind - Entity to be refreshed.
    • getEditorForEntity

      public static MegaMekLabMainUI getEditorForEntity(megamek.common.units.Entity entityToFind)
      Finds an open editor tab for the given entity
      Parameters:
      entityToFind - The entity
    • showEditorForEntity

      public static void showEditorForEntity(megamek.common.units.Entity entityToFind)
      Finds an open editor tab for the given entity, brings its window to the front, and selects the tab. If no editor is found, creates a new tab in the first available window.
      Parameters:
      entityToFind - The entity to show the editor for.
    • getActiveEditor

      public MegaMekLabMainUI getActiveEditor()
      Retrieves the currently selected editor from the tabbed user interface.
      Returns:
      The currently selected MegaMekLabMainUI instance, which represents the active editor in the tabbed UI, or null if no tab is selected.
    • setTabName

      public void setTabName(MegaMekLabMainUI editor, String tabName)
      Updates the name of the currently selected tab in the tabbed user interface. Should typically be called when the name of the unit being edited changes.
      Parameters:
      editor - The editor for which the tab name needs to be set
      tabName - The new name to be set for the currently selected tab.
    • createNewUnit

      public void createNewUnit(long type, boolean primitive, boolean industrial)
      Create a new blank editor of the given unit type.
      Parameters:
      type - the type of unit to load for the new editor UI
      primitive - whether the unit is primitive
      industrial - whether the unit is an IndustrialMek
    • switchUnit

      public void switchUnit(long type, boolean primitive)
      Replaces the current editor with a new blank one of the given unit type. Disposes of the old editor UI after the new one is initialized.
      Parameters:
      type - the type of unit to load for the new editor UI
      primitive - whether the unit is primitive
    • addUnit

      public void addUnit(megamek.common.units.Entity entity, String filename, boolean setSelected)
      Adds a new tab with the given unit to the tabbed user interface.
      Parameters:
      entity - The Entity object representing the unit to be added.
      filename - The name of the file associated with the unit being added.
      setSelected - Whether to set the new tab as the currently selected tab.
    • exit

      public boolean exit()
      Description copied from interface: AppCloser
      Override to provide specific exit handling. Return false to prevent exiting the application, true to confirm it. By default, this method does nothing and returns true.
      Specified by:
      exit in interface AppCloser
      Returns:
      False to prevent exiting, true to confirm
    • refreshAll

      public void refreshAll()
      Description copied from interface: MenuBarOwner
      This method is called when this menubar owner should refresh all displayed content (all tabs in the unit main UIs). By default, this method does nothing.
      Specified by:
      refreshAll in interface MenuBarOwner
    • newTab

      public void newTab()
    • closeCurrentTab

      public void closeCurrentTab()
      Deletes the current tab. This does not issue the safety prompt, it is up to the caller to do so!
    • reopenTab

      public void reopenTab()
    • hasClosedTabs

      public boolean hasClosedTabs()
    • getFrame

      public JFrame getFrame()
      Specified by:
      getFrame in interface MenuBarOwner
      Returns:
      A frame of this menubar owner to use as a parent for dialogs.
    • getEntity

      public megamek.common.units.Entity getEntity()
      Specified by:
      getEntity in interface MenuBarOwner
      Returns:
      The entity currently worked on or null.
    • getFileName

      public String getFileName()
      Specified by:
      getFileName in interface MenuBarOwner
      Returns:
      The file name of the currently worked on unit or an empty String.
    • hasEntityNameChanged

      public boolean hasEntityNameChanged()
      Specified by:
      hasEntityNameChanged in interface MenuBarOwner
      Returns:
      True if the entity's name has changed since load.
    • refreshMenuBar

      public void refreshMenuBar()
      Description copied from interface: MenuBarOwner
      Refreshes the menu bar. Updates the recent units in the File menu.
      Specified by:
      refreshMenuBar in interface MenuBarOwner
    • getMMLMenuBar

      public MenuBar getMMLMenuBar()
      Specified by:
      getMMLMenuBar in interface MenuBarOwner
    • stateChanged

      public void stateChanged(ChangeEvent e)
      Specified by:
      stateChanged in interface ChangeListener
    • getAllEntities

      public List<megamek.common.units.Entity> getAllEntities()