Class ForceGeneratorOptionsView

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
megamek.client.ui.dialogs.randomArmy.ForceGeneratorOptionsView
All Implemented Interfaces:
ActionListener, FocusListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class ForceGeneratorOptionsView extends JPanel implements FocusListener, ActionListener
Controls to set options for force generator.
See Also:
  • Constructor Details

  • Method Details

    • buildForceDescriptor

      public ForceDescriptor buildForceDescriptor()
      Builds a ForceDescriptor from the current state of this options view's controls. Public so embedders (e.g. MekHQ's company-generation dialog) can reuse the same input mapping without going through generateForce()'s SwingWorker plumbing. Does not run Ruleset.processRoot(megamek.client.ratgenerator.ForceDescriptor, megamek.client.ratgenerator.Ruleset.ProgressListener) or any IO.
    • actionPerformed

      public void actionPerformed(ActionEvent ev)
      Specified by:
      actionPerformed in interface ActionListener
    • setGenerateButtonVisible

      public void setGenerateButtonVisible(boolean visible)
      Shows or hides the Generate button. Embedders that drive generation through their own controls (e.g. an OK button on a parent dialog) hide the built-in button.
    • setExportMULButtonVisible

      public void setExportMULButtonVisible(boolean visible)
      Shows or hides the Export MUL button. Embedders that route the export through their own UI hide it.
    • setClearButtonVisible

      public void setClearButtonVisible(boolean visible)
      Shows or hides the Clear button.
    • setOnExportMUL

      public void setOnExportMUL(Consumer<ForceDescriptor> handler)
      Sets a custom handler for the Export-MUL button. When non-null, the built-in exportMUL(megamek.client.ratgenerator.ForceDescriptor) call is replaced by this consumer; the panel passes the live ForceDescriptor for the embedder to handle. Pass null to restore default behavior.
    • setYearFieldEditable

      public void setYearFieldEditable(boolean editable)
      Makes the year text field read-only. Use this when an embedder anchors the year to an external value (e.g. MekHQ's campaign year) and doesn't want the user editing it on this panel.
    • setSelectedFaction

      public boolean setSelectedFaction(String factionCode)
      Programmatically picks a faction in the embedded picker. Embedders (e.g. MekHQ) call this to seed the picker with their campaign's faction so the dialog opens pre-aligned instead of defaulting to "IS". Looks up the FactionRecord from the loaded RATGenerator data; if the code doesn't match a known faction, the picker is left unchanged and false is returned.

      The picker's existing ActionListener fires as a result of the setSelectedItem call, so the descriptor is updated as if the user had picked the faction by hand.

      Parameters:
      factionCode - the short-name faction code (e.g. "CHH", "LC", "FS")
      Returns:
      true if a matching faction was found and selected; false otherwise
    • exportMUL

      public void exportMUL(ForceDescriptor fd)
    • setCurrentYear

      public void setCurrentYear(int year)
    • focusGained

      public void focusGained(FocusEvent evt)
      Specified by:
      focusGained in interface FocusListener
    • focusLost

      public void focusLost(FocusEvent evt)
      Specified by:
      focusLost in interface FocusListener