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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassRenderer for the Battlefield Support asset cost columns: right-aligned, blank when the unit has no asset.classRenderer for the BV and PV columns: centered, but blank for Battlefield Support Asset rows, which have no BV or PV of their own (their cost lives in the asset cost column; PV is an Alpha Strike concept).protected classA table model for displaying work itemsstatic classA specialized renderer for the mek table (formats the unit price).static classA specialized renderer for the mek table (formats the unit tonnage).Nested classes/interfaces inherited from class javax.swing.JDialog
JDialog.AccessibleJDialogNested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityTypeNested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.TypeNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprotected intprotected booleanprotected JButtonprotected JButtonprotected JButtonprotected JButtonprotected booleanstatic final Stringprotected booleanprotected booleanprotected JFrameprotected GameOptionsprotected intprotected JLabelprotected MekSummary[]protected static MekSummaryCacheprotected final booleanprotected EntityViewPaneprotected MekSearchFilterstatic final Stringprotected JTableprotected static final intprotected static final intprotected static final intprotected intWe need to map the selected index of listTechLevel to the actual TL it belongs toprotected JTextFieldprotected JTextFieldprotected JTextFieldFields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabledFields inherited from class java.awt.Dialog
DEFAULT_MODALITY_TYPEFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractUnitSelectorDialog(JFrame frame, UnitLoadingDialog unitLoadingDialog) protectedAbstractUnitSelectorDialog(JFrame frame, UnitLoadingDialog unitLoadingDialog, boolean multiSelect) -
Method Summary
Modifier and TypeMethodDescriptionvoidThis handles the primary action events (any that can come from buttons in this class)protected intassetCostBv(MekSummary asset) Returns the cost, in Battle Value, to display for the given asset summary, honoring the selected Regular/Veteran asset skill.protected MekSummaryReturns the Battlefield Support Asset form of the given unit summary, if any.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).protected voidAllows subclasses to keep filter controls in sync with additional unit-list restrictions after persisted user preferences have been restored.protected abstract JPanelThis is used to create the bottom row of buttons for the interfaceprotected voidThis filters the units on the display.Returns the Battlefield Support Asset form of every selected row that has one.Returns the Battlefield Support Asset form of the selected row, if any.intintbooleanprotected voidprotected booleanbooleanvoidkeyPressed(KeyEvent ke) This handles key pressed eventsvoidkeyReleased(KeyEvent ke) This handles key released eventsvoidThis handles key typed eventsprotected EntityloadEntity(MekSummary ms) Loads theEntityfor the given unit summary.protected booleanmatchesTextFilter(MekSummary unit) protected booleanmatchesUnitTypeSelection(MekSummary mek, int typeCode) protected voidThis handles processing windows eventsprotected Entityvoidrun()protected abstract voidselect(boolean modifier) This is the function to add a unit to the current interface.booleanbooleanprotected voidsetUnitSelectionScopeFilter(Predicate<MekSummary> unitSelectionScopeFilter) Sets additional unit-list restrictions beyond the shared selector controls.voidsetVisible(boolean visible) protected booleanprotected intunitTypeCodeForComboIndex(int comboIndex) Resolves a unit-type filter combo index to itsUnitTypecode (or a sentinel:UNIT_TYPE_ALL,UNIT_TYPE_SUPPORT_VEE).abstract voidThis is used to update any values that are set based on individual optionsprotected voidvoidThis handles list selection events, which are only thrown by MegaMek/MegaMekLabMethods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, updateMethods inherited from class java.awt.Dialog
addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, show, toBackMethods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, toFrontMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
CLOSE_ACTION
- See Also:
-
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
-
buttonSelect
-
buttonClose
-
buttonShowBV
-
listTechLevel
-
techLevelListToIndex
We need to map the selected index of listTechLevel to the actual TL it belongs to -
comboUnitType
-
comboWeight
-
labelImage
-
tableUnits
-
textFilter
-
textGunnery
-
textPilot
-
panePreview
-
multiSelect
protected final boolean multiSelect -
mscInstance
-
meks
-
searchFilter
-
frame
-
sorter
-
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
-
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
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 itsUnitTypecode (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_ALLif the index is out of range
-
matchesUnitTypeSelection
- Parameters:
mek- the unit summary to testtypeCode- the selected unit-type code (seeunitTypeCodeForComboIndex(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
-
setUnitSelectionScopeFilter
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
- Returns:
- the selected entity (required for MekHQ/MegaMek overrides)
-
getSelectedEntity
- Returns:
- the selected entity
-
loadEntity
Loads theEntityfor the given unit summary.- Parameters:
ms- the unit summary to load, ornull- Returns:
- the loaded entity, or
nullif the summary isnullor cannot be loaded
-
getSelectedEntities
-
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
- Returns:
- The MekSummary for the selected unit.
-
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; otherwisenull. Callers that offer a "Select as Asset" action use this to obtain the asset summary.- Returns:
- the selected asset summary, or
nullif the selection has no asset form
-
assetSummaryFor
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; otherwisenull.- Parameters:
ms- a unit summary, ornull- Returns:
- the asset form of the given summary, or
nullif it has none
-
assetCostBv
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, ornull- Returns:
- the asset cost in Battle Value, or 0 if
assetisnull
-
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
- Parameters:
asset- an asset summary, ornull- 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
-
run
public void run() -
condenseLinkedAssets
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
nullif the input wasnull
-
setVisible
public void setVisible(boolean visible) - Overrides:
setVisiblein classDialog- Parameters:
visible- whether to make the GUI visible
-
processWindowEvent
This handles processing windows events- Overrides:
processWindowEventin classJDialog- Parameters:
e- the event to process
-
keyReleased
This handles key released events- Specified by:
keyReleasedin interfaceKeyListener- Parameters:
ke- the key that was released
-
keyPressed
This handles key pressed events- Specified by:
keyPressedin interfaceKeyListener- Parameters:
ke- the pressed key
-
keyTyped
This handles key typed events- Specified by:
keyTypedin interfaceKeyListener- Parameters:
ke- the typed key
-
actionPerformed
This handles the primary action events (any that can come from buttons in this class)- Specified by:
actionPerformedin interfaceActionListener- Parameters:
ev- the event containing the performed action
-
valueChanged
This handles list selection events, which are only thrown by MegaMek/MegaMekLab- Specified by:
valueChangedin interfaceListSelectionListener- Parameters:
evt- the event to process
-