Class InventoryWriter

java.lang.Object
megameklab.printing.InventoryWriter

public class InventoryWriter extends Object
Formats text for the record sheet's "Weapons and Equipment Inventory" section. For most units, an instance is created for the sheet using InventoryWriter(PrintEntity, SVGRectElement), then the text is added to the SVG document using writeEquipment(). This adds the appropriate header, for the unit, equipment table, and quirks/features/ammo at the bottom of the space. Large craft can have multiple sections and should invoke the appropriate section writers, using each return value for the vertical placement of the next section. Multipage record sheets can instantiate using InventoryWriter(PrintEntity) to process the equipment and find the size of each section, then call setRegion(SVGRectElement) for each page before calling the section writers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
    The amount of space between lines, as a factor of the font height determined by FontMetrics
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance, determines column positions, and parses equipment.
    InventoryWriter(PrintEntity sheet, org.w3c.dom.svg.SVGRectElement svgRect)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    int
    extraCapitalBayLines(float fontSize)
    Calculates the number of additional lines required to print the capital scale weapon bay block due to wrapping long names to another line.
    int
    extraStandardBayLines(float fontSize)
    Calculates the number of additional lines required to print the standard scale weapon bay block due to wrapping long names to another line.
    int
    footerLines(float fontSize)
     
    double
    printAR10Block(float fontSize, double lineHeight, double currY)
    Adds a static table showing the details of the types of AR10 missiles.
    double
    printBayInfo(float fontSize, double lineHeight, double currY)
    Convenience method for printing information related to cargo and transport bays.
    double
    printGravityDecks(megamek.common.units.Jumpship ship, float fontSize, double lineHeight, double currY)
    Prints the gravity deck block
    double
    printReverseSideMessage(double lineHeight, double currY)
    Add single line of text explaining where to find the standard scale bays for ships that cannot fit both capital and standard on the obverse.
    float[]
    scaleText(double height, Function<Float,Integer> calcLines)
    If the lines do not fit in the available space, we will need to reduce the font size and possible the amount of space between lines.
    float[]
    Rescales text to allow space for a fixed number of lines using the entire region.
    void
    setRegion(org.w3c.dom.svg.SVGRectElement svgRect)
    Recalculates column positions for a new page
    int
     
    double
     
    int
     
    double
    writeCapitalBays(float fontSize, double lineHeight, double currY)
    Adds the text for the capital scale weapon bays.
    void
     
    void
    writeFooterBlock(float fontSize, float lineHeight)
    Displays ammo, fuel, features, and quirks as free-flowing text at the bottom of the inventory box
    double
    writeStandardBays(float fontSize, double lineHeight, double currY)
    Adds the text for the standard scale weapon bays.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MIN_LINE_SPACING

      public static final float MIN_LINE_SPACING
      The amount of space between lines, as a factor of the font height determined by FontMetrics
      See Also:
  • Constructor Details

    • InventoryWriter

      public InventoryWriter(PrintEntity sheet)
      Creates a new instance, determines column positions, and parses equipment.
      Parameters:
      sheet - The record sheet layout instance
    • InventoryWriter

      public InventoryWriter(PrintEntity sheet, org.w3c.dom.svg.SVGRectElement svgRect)
  • Method Details

    • setRegion

      public void setRegion(org.w3c.dom.svg.SVGRectElement svgRect)
      Recalculates column positions for a new page
      Parameters:
      svgRect - The bounding rectangle of the print region
    • startingY

      public double startingY()
    • capitalBayLines

      public int capitalBayLines()
    • extraCapitalBayLines

      public int extraCapitalBayLines(float fontSize)
      Calculates the number of additional lines required to print the capital scale weapon bay block due to wrapping long names to another line.
      Parameters:
      fontSize - The font size used to print
      Returns:
      The number of extra lines required by the table
    • extraStandardBayLines

      public int extraStandardBayLines(float fontSize)
      Calculates the number of additional lines required to print the standard scale weapon bay block due to wrapping long names to another line.
      Parameters:
      fontSize - The font size used to print
      Returns:
      The number of extra lines required by the table
    • transportBayLines

      public int transportBayLines()
      Returns:
      The size of the transport bay block, not including header
    • standardBayLines

      public int standardBayLines()
    • writeEquipment

      public void writeEquipment()
    • writeStandardBays

      public double writeStandardBays(float fontSize, double lineHeight, double currY)
      Adds the text for the standard scale weapon bays.
      Parameters:
      fontSize - The size of font to size for the table text
      lineHeight - The amount to increase the y coordinate for each line
      currY - The starting y coordinate
      Returns:
      The y coordinate of the bottom of the table
    • writeCapitalBays

      public double writeCapitalBays(float fontSize, double lineHeight, double currY)
      Adds the text for the capital scale weapon bays.
      Parameters:
      fontSize - The size of font to size for the table text
      lineHeight - The amount to increase the y coordinate for each line
      currY - The starting y coordinate
      Returns:
      The y coordinate of the bottom of the table
    • scaleText

      public float[] scaleText(Function<Float,Integer> calcLines)
      Rescales text to allow space for a fixed number of lines using the entire region. Used for large craft, which have a number of possible block types and may need a second page.
      Parameters:
      calcLines - A supplier for the number of lines. Since reducing the font size may allow for fewer lines, the supplier gives an opportunity to recalculate after each resizing.
      Returns:
      A tuple of the new font height and line height, in that order
    • scaleText

      public float[] scaleText(double height, Function<Float,Integer> calcLines)
      If the lines do not fit in the available space, we will need to reduce the font size and possible the amount of space between lines. We first try to reduce the line spacing factor until a certain threshold, and if it fails we start an alternate cycle of attempts between font size and line spacing reduction.
      Parameters:
      height - The height of the region the text needs to fit in
      calcLines - A supplier for the number of lines. Since reducing the font size may allow for fewer lines, the supplier gives an opportunity to recalculate after each resizing.
      Returns:
      A tuple of the new font height and line height, in that order
    • writeFooterBlock

      public void writeFooterBlock(float fontSize, float lineHeight)
      Displays ammo, fuel, features, and quirks as free-flowing text at the bottom of the inventory box
      Parameters:
      fontSize - The size of the font for the text
      lineHeight - The height of each line of text
    • footerLines

      public int footerLines(float fontSize)
    • printAR10Block

      public double printAR10Block(float fontSize, double lineHeight, double currY)
      Adds a static table showing the details of the types of AR10 missiles.
      Parameters:
      fontSize - The font size to use for the table rows
      lineHeight - The height of each table row
      currY - The y coordinate of the top of the table
      Returns:
      The y coordinate of the bottom of the table
    • printGravityDecks

      public double printGravityDecks(megamek.common.units.Jumpship ship, float fontSize, double lineHeight, double currY)
      Prints the gravity deck block
      Parameters:
      ship - The jumpship, warship, or space station
      fontSize - The font size to use for the table rows
      lineHeight - The height of each table row
      currY - The y coordinate of the top of the table
      Returns:
      The y coordinate of the bottom of the table
    • printBayInfo

      public double printBayInfo(float fontSize, double lineHeight, double currY)
      Convenience method for printing information related to cargo and transport bays.
      Parameters:
      fontSize - The font size to use for the table rows
      lineHeight - The height of each table row
      currY - The y coordinate of the top of the table
      Returns:
      The y coordinate of the bottom of the table
    • printReverseSideMessage

      public double printReverseSideMessage(double lineHeight, double currY)
      Add single line of text explaining where to find the standard scale bays for ships that cannot fit both capital and standard on the obverse.
      Parameters:
      lineHeight - The height of each table row
      currY - The y coordinate of the top of the table
      Returns:
      The y coordinate of the bottom of the table