Class BayWeaponCriticalTree

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class BayWeaponCriticalTree extends JTree
Variant of DropTargetCriticalList for aerospace units that groups weapons into bays. Also includes support for treating spheroid small craft and dropships firing arcs separately from their locations.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • setFacing

      public void setFacing(int facing)
      Sets whether this arc should show only forward-mounted, rear-mounted, or both
      Parameters:
      facing - Either FORWARD, AFT, or BOTH
    • updateRefresh

      public void updateRefresh(RefreshListener refresh)
    • rebuild

      public void rebuild()
    • getSlotCount

      public int getSlotCount()
      Returns:
      The number of weapon slots required by equipment allocated to this arc.
    • getMinimumSize

      public Dimension getMinimumSize()
      Overrides:
      getMinimumSize in class JComponent
    • getLocationName

      public String getLocationName()
      Used by the unallocated equipment list to show the name of the location on the popup menu
      Returns:
      The name of the location
    • validForUnit

      public boolean validForUnit(megamek.common.units.Aero aero)
      Used by the unallocated equipment list to determine whether the arc represented by this tree is valid for the aero unit. This filters out aft side arcs for aerodyne small craft and broadsides for non-warships.
      Parameters:
      aero - The unit to check
      Returns:
      Whether the arc is valid for the unit.
    • baysFor

      public List<megamek.common.equipment.WeaponMounted> baysFor(megamek.common.equipment.Mounted<?> eq)
      Finds all bays in this arc where the given equipment can be added based on type and current AV.
      Parameters:
      eq - An equipment mount
      Returns:
      A list of valid bays for the equipment
    • canAdd

      public boolean canAdd(megamek.common.equipment.Mounted<?> eq)
      Determines whether equipment can be added to this location. Ammo requires a bay with a suitable weapon, as do weapon enhancements. All other equipment can be added.
      Parameters:
      eq - Potential equipment to be added to the location.
      Returns:
      Whether the equipment can be added to the location.
    • addToNewBay

      public void addToNewBay(megamek.common.equipment.EquipmentType bayType, megamek.common.equipment.WeaponMounted eq)
      Adds a new bay of the appropriate type to the unit and adds the equipment to the bay.
      Parameters:
      bayType - The type of bay to be added.
      eq - The equipment to be added.
    • addToBay

      public void addToBay(@Nullable megamek.common.equipment.WeaponMounted bay, megamek.common.equipment.Mounted<?> eq)
      Adds an equipment mount to a bay. Changes the equipment mount's location and updates the bay's weapon or ammo list if necessary.
      Parameters:
      bay - The receiving weapon bay
      eq - The equipment to add to the bay
    • addAmmoToBay

      public void addAmmoToBay(megamek.common.equipment.WeaponMounted bay, megamek.common.equipment.AmmoMounted eq, int shots)
    • addToLocation

      public void addToLocation(megamek.common.equipment.Mounted<?> eq)
      Adds equipment to a location without a bay.
      Parameters:
      eq - The equipment to add to the location of this tree
    • addToLocation

      public void addToLocation(List<megamek.common.equipment.Mounted<?>> eqList)
      Adds multiple equipment mounts to this location. Weapons and ammo will go into the first available bay. Ammo that does not have a legal bay will be skipped.
      Parameters:
      eqList - The equipment to add
    • addToArc

      public void addToArc(megamek.common.equipment.Mounted<?> eq, TreePath path)
      Called by the transfer handler when equipment is dropped on this location.
      Parameters:
      eq - The equipment dropped on this location
      path - The tree node under the drop point
    • addAmmo

      public void addAmmo(megamek.common.equipment.AmmoMounted eq, int shots, TreePath path)
      Called by the transfer handler when ammo is dropped on this location as a move command, indicating a single slot should be moved. A copy command (ctrl key held) will transfer all ammo using addToArc.
    • addBay

      public void addBay(megamek.common.equipment.WeaponMounted bay)
      Moves a bay and all its contents from another location
      Parameters:
      bay - The bay to move in
    • isValidDropLocation

      public boolean isValidDropLocation(JTree.DropLocation loc, megamek.common.equipment.Mounted<?> eq)
      Determines whether the equipment can be dropped here. In the case of ammo or weapon enhancement, there must be a matching weapon in the bay. A weapon that doesn't fit the bay will be placed in a new bay.
      Parameters:
      loc - The drop location from the TransferSupport object passed to the TransferHandler
      eq - The equipment to be dropped
      Returns:
      Whether the equipment can be dropped in the location
    • getBayFromPath

      public megamek.common.equipment.WeaponMounted getBayFromPath(TreePath path)
    • encodeSelection

      public String encodeSelection()
      Builds a String representation of the selected node that can be used by the transfer handler to find the node to be removed after export.
      Returns:
      A String in the format equipmentNum,nodeIndex[,bayNodeIndex]
    • removeExported

      public void removeExported(String selection, int action)