Class AbstractUnitSelectorDialog

java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Dialog
javax.swing.JDialog
megamek.client.ui.dialogs.unitSelectorDialogs.AbstractUnitSelectorDialog
All Implemented Interfaces:
ActionListener, KeyListener, ImageObserver, MenuContainer, Serializable, Runnable, EventListener, Accessible, ListSelectionListener, RootPaneContainer, WindowConstants
Direct Known Subclasses:
MainMenuUnitBrowserDialog, MegaMekUnitSelectorDialog

public abstract class AbstractUnitSelectorDialog extends JDialog implements Runnable, KeyListener, ActionListener, ListSelectionListener
This is a heavily reworked version of the original MekSelectorDialog which brings up a list of units for the player to select to add to their forces. The original list has been changed to a sortable table and a text filter is used for advanced searching.
See Also:
  • Field Details

    • CLOSE_ACTION

      public static final String CLOSE_ACTION
      See Also:
    • SELECT_ACTION

      public static final String SELECT_ACTION
      See Also:
    • ALLOWED_YEAR_ANY

      public static final int ALLOWED_YEAR_ANY
      See Also:
    • TECH_LEVEL_DISPLAY_IS

      protected static final int TECH_LEVEL_DISPLAY_IS
      See Also:
    • TECH_LEVEL_DISPLAY_CLAN

      protected static final int TECH_LEVEL_DISPLAY_CLAN
      See Also:
    • TECH_LEVEL_DISPLAY_IS_CLAN

      protected static final int TECH_LEVEL_DISPLAY_IS_CLAN
      See Also:
    • buttonSelectClose

      protected JButton buttonSelectClose
    • buttonSelect

      protected JButton buttonSelect
    • buttonClose

      protected JButton buttonClose
    • buttonShowBV

      protected JButton buttonShowBV
    • listTechLevel

      protected JList<String> listTechLevel
    • techLevelListToIndex

      protected Map<Integer,Integer> techLevelListToIndex
      We need to map the selected index of listTechLevel to the actual TL it belongs to
    • comboUnitType

      protected JComboBox<String> comboUnitType
    • comboWeight

      protected JComboBox<String> comboWeight
    • labelImage

      protected JLabel labelImage
    • tableUnits

      protected JTable tableUnits
    • textFilter

      protected JTextField textFilter
    • textGunnery

      protected JTextField textGunnery
    • textPilot

      protected JTextField textPilot
    • panePreview

      protected EntityViewPane panePreview
    • multiSelect

      protected final boolean multiSelect
    • mscInstance

      protected static MekSummaryCache mscInstance
    • meks

      protected MekSummary[] meks
    • searchFilter

      protected MekSearchFilter searchFilter
    • frame

      protected JFrame frame
    • sorter

    • gameOptions

      protected GameOptions gameOptions
    • enableYearLimits

      protected boolean enableYearLimits
    • allowedYear

      protected int allowedYear
    • canonOnly

      protected boolean canonOnly
    • allowInvalid

      protected boolean allowInvalid
    • gameTechLevel

      protected int gameTechLevel
    • techLevelDisplayType

      protected int techLevelDisplayType
    • eraBasedTechLevel

      protected boolean eraBasedTechLevel
  • Constructor Details

    • AbstractUnitSelectorDialog

      protected AbstractUnitSelectorDialog(JFrame frame, UnitLoadingDialog unitLoadingDialog)
    • AbstractUnitSelectorDialog

      protected AbstractUnitSelectorDialog(JFrame frame, UnitLoadingDialog unitLoadingDialog, boolean multiSelect)
  • Method Details

    • updateOptionValues

      public abstract void updateOptionValues()
      This is used to update any values that are set based on individual options
    • initialize

      protected void initialize()
    • createButtonsPanel

      protected abstract JPanel createButtonsPanel()
      This is used to create the bottom row of buttons for the interface
      Returns:
      the panel containing the buttons to place in the interface
    • select

      protected abstract void select(boolean modifier)
      This is the function to add a unit to the current interface. That could be a purchase (MekHQ), addition (MekHQ), or unit selection (MegaMek/MegaMekLab)
      Parameters:
      modifier - a boolean to modify how the function will work. In MegaMek this is used to close the dialog, in MekHQ to GM add.
    • filterUnits

      protected void filterUnits()
      This filters the units on the display. It is overwritten for MekHQ
    • unitTypeCodeForComboIndex

      protected int unitTypeCodeForComboIndex(int comboIndex)
      Resolves a unit-type filter combo index to its UnitType code (or a sentinel: UNIT_TYPE_ALL, UNIT_TYPE_SUPPORT_VEE). Robust to the AERO gap in the combo.
      Parameters:
      comboIndex - the selected combo index
      Returns:
      the type code, or UNIT_TYPE_ALL if the index is out of range
    • matchesUnitTypeSelection

      protected boolean matchesUnitTypeSelection(MekSummary mek, int typeCode)
      Parameters:
      mek - the unit summary to test
      typeCode - the selected unit-type code (see unitTypeCodeForComboIndex(int))
      Returns:
      whether the unit matches the selected unit-type filter. The Battlefield Support Asset filter matches an asset OR a base unit that has a linked asset, so a linked base/asset pair (shown as the base unit's row) appears under both its own type filter and the Asset filter.
    • updateUnitCount

      protected void updateUnitCount()
    • matchesTextFilter

      protected boolean matchesTextFilter(MekSummary unit)
    • setUnitSelectionScopeFilter

      protected void setUnitSelectionScopeFilter(Predicate<MekSummary> unitSelectionScopeFilter)
      Sets additional unit-list restrictions beyond the shared selector controls. The base selector accepts every candidate that passed the built-in filters; callers can use this to constrain specialized pickers without duplicating the full filter pipeline.
      Parameters:
      unitSelectionScopeFilter - Predicate that returns true when a candidate should remain visible
    • configureUnitSelectionScope

      protected void configureUnitSelectionScope()
      Allows subclasses to keep filter controls in sync with additional unit-list restrictions after persisted user preferences have been restored.
    • refreshUnitView

      protected Entity refreshUnitView()
      Returns:
      the selected entity (required for MekHQ/MegaMek overrides)
    • getSelectedEntity

      @Nullable public Entity getSelectedEntity()
      Returns:
      the selected entity
    • loadEntity

      @Nullable protected Entity loadEntity(@Nullable MekSummary ms)
      Loads the Entity for the given unit summary.
      Parameters:
      ms - the unit summary to load, or null
      Returns:
      the loaded entity, or null if the summary is null or cannot be loaded
    • getSelectedEntities

      public ArrayList<Entity> getSelectedEntities()
    • getSelectedAssetEntities

      public ArrayList<Entity> getSelectedAssetEntities()
      Returns the Battlefield Support Asset form of every selected row that has one. For a standalone asset row this is the asset itself; for a base unit row with a linked asset this is the linked asset; rows with no asset form are skipped. Callers that offer a "Select as Asset" action use this to obtain the asset entities for the selection.
      Returns:
      the asset entities for the selection (may be empty)
    • hasSelectedRows

      public boolean hasSelectedRows()
      Returns:
      true when at least one row is selected for the standard selection actions.
    • selectionCanSelectAsAsset

      public boolean selectionCanSelectAsAsset()
      Returns:
      true if the current selection is non-empty and every selected row has a Battlefield Support Asset form (either it is an asset itself or has a linked asset). Callers use this to enable a "Select as Asset" action.
    • getSelectedMekSummary

      @Nullable public MekSummary getSelectedMekSummary()
      Returns:
      The MekSummary for the selected unit.
    • getSelectedAssetSummary

      @Nullable public MekSummary getSelectedAssetSummary()
      Returns the Battlefield Support Asset form of the selected row, if any. For a standalone asset row this is the row itself; for a base unit row that has a linked asset this is the linked asset; otherwise null. Callers that offer a "Select as Asset" action use this to obtain the asset summary.
      Returns:
      the selected asset summary, or null if the selection has no asset form
    • assetSummaryFor

      @Nullable protected MekSummary assetSummaryFor(@Nullable MekSummary ms)
      Returns the Battlefield Support Asset form of the given unit summary, if any. For an asset summary this is the summary itself; for a base unit that has a linked asset this is the linked asset; otherwise null.
      Parameters:
      ms - a unit summary, or null
      Returns:
      the asset form of the given summary, or null if it has none
    • assetCostBv

      protected int assetCostBv(@Nullable MekSummary asset)
      Returns the cost, in Battle Value, to display for the given asset summary, honoring the selected Regular/Veteran asset skill. When Veteran is selected and the asset has a Veteran variant, its Veteran cost is returned; otherwise the Regular cost is returned (for a Veteran selection on an asset with no Veteran variant, the Regular cost is shown with an asterisk by the renderer).
      Parameters:
      asset - an asset summary, or null
      Returns:
      the asset cost in Battle Value, or 0 if asset is null
    • showVeteranAssetCost

      protected boolean showVeteranAssetCost()
      Returns:
      true if the asset skill selector is set to Veteran (so Veteran asset costs are shown).
    • getSelectedGunnery

      public int getSelectedGunnery()
      Returns:
      the Gunnery skill currently entered in the Skills controls (default 4).
    • getSelectedPiloting

      public int getSelectedPiloting()
      Returns:
      the Piloting skill currently entered in the Skills controls (default 5).
    • isVeteranAssetSkillSelected

      public boolean isVeteranAssetSkillSelected()
      Returns:
      true if the asset skill selector is set to Veteran (rather than Regular).
    • isAssetCostVeteranFallback

      protected boolean isAssetCostVeteranFallback(@Nullable MekSummary asset)
      Parameters:
      asset - an asset summary, or null
      Returns:
      true if the asset cost shown for this row is a Regular cost standing in for a missing Veteran cost (i.e. Veteran is selected but the asset has no Veteran variant) and should therefore be marked with an asterisk
    • selectionHasAssetForm

      public boolean selectionHasAssetForm()
      Returns:
      true if the current selection has a Battlefield Support Asset form (see getSelectedAssetSummary()).
    • getSelectedMekSummaries

      public List<MekSummary> getSelectedMekSummaries()
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • condenseLinkedAssets

      protected MekSummary[] condenseLinkedAssets(MekSummary[] allMeks)
      Removes Battlefield Support Asset summaries that have a linked base unit, so that a linked base/asset pair is shown as a single row (the base unit's). Standalone assets (no base unit) and all non-asset units are kept. When there are no assets this returns the input unchanged.
      Parameters:
      allMeks - the full set of unit summaries
      Returns:
      the condensed set, or null if the input was null
    • setVisible

      public void setVisible(boolean visible)
      Overrides:
      setVisible in class Dialog
      Parameters:
      visible - whether to make the GUI visible
    • processWindowEvent

      protected void processWindowEvent(WindowEvent e)
      This handles processing windows events
      Overrides:
      processWindowEvent in class JDialog
      Parameters:
      e - the event to process
    • keyReleased

      public void keyReleased(KeyEvent ke)
      This handles key released events
      Specified by:
      keyReleased in interface KeyListener
      Parameters:
      ke - the key that was released
    • keyPressed

      public void keyPressed(KeyEvent ke)
      This handles key pressed events
      Specified by:
      keyPressed in interface KeyListener
      Parameters:
      ke - the pressed key
    • keyTyped

      public void keyTyped(KeyEvent ke)
      This handles key typed events
      Specified by:
      keyTyped in interface KeyListener
      Parameters:
      ke - the typed key
    • actionPerformed

      public void actionPerformed(ActionEvent ev)
      This handles the primary action events (any that can come from buttons in this class)
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      ev - the event containing the performed action
    • valueChanged

      public void valueChanged(ListSelectionEvent evt)
      This handles list selection events, which are only thrown by MegaMek/MegaMekLab
      Specified by:
      valueChanged in interface ListSelectionListener
      Parameters:
      evt - the event to process