Interface CalculationReport
- All Known Implementing Classes:
DummyCalculationReport,FlexibleCalculationReport,HTMLCalculationReport,SwingCalculationReport,TextCalculationReport
public interface CalculationReport
This represents a report for any typical MegaMek suite calculation such as BV, cost or AS conversion. It assumes that
each line will have at most three entries, a sort of header text (Damage:), a calculation (5 + 5 + 7 * 0.2) and a
result on the right side (11.4).
The result can be given as a String or as a double value with a prefix String. When a double value is given, it will be rounded to one decimal digit. Since the second entry (the calculation text) can be more complicated than a single number, it can only be passed as a String and rounding must be performed by the caller if needed.
Classes that implement this interface ideally provide a runtime representation of the resulting report when overriding toJComponent(). This should be displayable in a Swing Panel and not be null. At the worst, a text explaining that the report is not available in this format should be given.
The result can be given as a String or as a double value with a prefix String. When a double value is given, it will be rounded to one decimal digit. Since the second entry (the calculation text) can be more complicated than a single number, it can only be passed as a String and rounding must be performed by the caller if needed.
Classes that implement this interface ideally provide a runtime representation of the resulting report when overriding toJComponent(). This should be displayable in a Swing Panel and not be null. At the worst, a text explaining that the report is not available in this format should be given.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault CalculationReportAdds an empty line to the CalculationReport.Adds a single line to the CalculationReport containing the header for the CalculationReport.default CalculationReportaddInformationalLine(String type, String calculation, String result) Adds a line that provides inputs or context but is not itself part of a report's running total.default CalculationReportAdds a single line to the CalculationReport.default CalculationReportAdds a single line to the CalculationReport.default CalculationReportAdds a single line to the CalculationReport.Adds a single line to the CalculationReport.default CalculationReportAdds a single line to the CalculationReport.default CalculationReportaddResultLine(String resultPrefix, double result) Adds a single line to the CalculationReport in the way addLine() does, except the result has a line above it that may e.g.default CalculationReportaddResultLine(String type, String resultPrefix, double result) Adds a single line to the CalculationReport in the way addLine() does, except the result has a line above it that may e.g.addResultLine(String type, String calculation, String result) Adds a single line to the CalculationReport in the way addLine() does, except the result has a line above it that may e.g.default CalculationReportaddResultLine(String type, String calculation, String resultPrefix, double result) Adds a single line to the CalculationReport in the way addLine() does, except the result has a line above it that may e.g.addSubHeader(String text) Adds a single line to the CalculationReport containing a sub-header.voidDiscard all lines written to this section (all lines added to the report after callingstartTentativeSection()).voidEnd the current section of lines, writing them to the report normally.default voidfinalizeTentativeSection(boolean keepSection) End the current section of lines, keeping or discarding the section depending on the given keepSection.static StringformatForReport(double d) Formats the given double with only the necessary digits and at most three digits.voidStarts a report section that is tentative, i.e.Returns the CalculationReport as a JComponent that can be added to a dialog or other Swing component.
-
Method Details
-
addLine
CalculationReport addLine(@Nullable String type, @Nullable String calculation, @Nullable String result) Adds a single line to the CalculationReport.- Parameters:
type- The first element of this line, such as "Damage: "calculation- A calculation or other info, displayed after the typeresult- A result or other info, displayed on the right side- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addInformationalLine
default CalculationReport addInformationalLine(@Nullable String type, @Nullable String calculation, @Nullable String result) Adds a line that provides inputs or context but is not itself part of a report's running total. Display-oriented reports render this exactly like a regular line; structured report implementations may retain the semantic distinction.- Parameters:
type- The first element of this linecalculation- A calculation or other inforesult- A result or other info displayed on the right side- Returns:
- The CalculationReport itself
-
addLine
default CalculationReport addLine(@Nullable String type, @Nullable String calculation, @Nullable String resultPrefix, double result) Adds a single line to the CalculationReport. This method performs rounding to a single decimal digit on the result and writes resultPrefix in front of it.- Parameters:
type- The first element of this line, such as "Damage: "calculation- A calculation or other info, displayed after the typeresultPrefix- A text to be display immediately in front of the result, such as "= "result- A numerical result which will be rounded to a single decimal, e.g. 25.1- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addLine
default CalculationReport addLine(@Nullable String type, @Nullable String resultPrefix, double result) Adds a single line to the CalculationReport. This method performs rounding to a single decimal digit on the result and writes resultPrefix in front of it. This line has only two elements, the type ("Damage: ") and the result displayed on the right side.- Parameters:
type- The first element of this line, such as "Damage: "resultPrefix- A text to be display immediately in front of the result, such as "= "result- A numerical result which will be rounded to a single decimal, e.g. 25.1- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addResultLine
default CalculationReport addResultLine(@Nullable String type, @Nullable String calculation, @Nullable String resultPrefix, double result) Adds a single line to the CalculationReport in the way addLine() does, except the result has a line above it that may e.g. indicate a summary of previous values. This method performs rounding to a single decimal digit on the result and writes resultPrefix in front of it.- Parameters:
type- The first element of this line, such as "Damage: "calculation- A calculation or other info, displayed after the typeresultPrefix- A text to be display immediately in front of the result, such as "= "result- A numerical result which will be rounded to a single decimal, e.g. 25.1- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addResultLine
default CalculationReport addResultLine(@Nullable String type, @Nullable String resultPrefix, double result) Adds a single line to the CalculationReport in the way addLine() does, except the result has a line above it that may e.g. indicate a summary of previous values. This line has only two elements, the type ("Damage: ") and the result displayed on the right side. This method performs rounding to a single decimal digit on the result and writes resultPrefix in front of it.- Parameters:
type- The first element of this line, such as "Damage: "resultPrefix- A text to be display immediately in front of the result, such as "= "result- A numerical result which will be rounded to a single decimal, e.g. 25.1- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addResultLine
Adds a single line to the CalculationReport in the way addLine() does, except the result has a line above it that may e.g. indicate a summary of previous values. This line has only one element, the result displayed on the right side. This method performs rounding to a single decimal digit on the result and writes resultPrefix in front of it.- Parameters:
resultPrefix- A text to be display immediately in front of the result, such as "= "result- A numerical result which will be rounded to a single decimal, e.g. 25.1- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addEmptyLine
Adds an empty line to the CalculationReport.- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addLine
Adds a single line to the CalculationReport. This line has only two elements, the type ("Damage: ") and a result displayed on the right side.- Parameters:
type- The first element of this line, such as "Damage: "result- A result or other info, displayed on the right side- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addLine
Adds a single line to the CalculationReport. This line only has one element displayed on the right side.- Parameters:
result- A result or other info, displayed on the right side- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addSubHeader
Adds a single line to the CalculationReport containing a sub-header.- Parameters:
text- The header text- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addHeader
Adds a single line to the CalculationReport containing the header for the CalculationReport. This would typically be used as the first line but can be used anywhere in the CalculationReport and multiple times.- Parameters:
text- The header text- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
addResultLine
CalculationReport addResultLine(@Nullable String type, @Nullable String calculation, @Nullable String result) Adds a single line to the CalculationReport in the way addLine() does, except the result has a line above it that may e.g. indicate a summary of previous values.- Parameters:
type- The first element of this line, such as "Damage: "calculation- A calculation or other info, displayed after the typeresult- A result or other info, displayed on the right side- Returns:
- The CalculationReport itself. Enables multiple stringed addLine calls
-
toJComponent
JComponent toJComponent()Returns the CalculationReport as a JComponent that can be added to a dialog or other Swing component.- Returns:
- The CalculationReport wrapped in a JComponent form.
-
formatForReport
Formats the given double with only the necessary digits and at most three digits. Uses the fixed Locale.US as the Java way of converting "" + value seems to use Locale.US by default as well. -
startTentativeSection
void startTentativeSection()Starts a report section that is tentative, i.e. that may be added or discarded depending on whetherendTentativeSection()ordiscardTentativeSection()is called at a later point. All lines added to the report after calling this method are kept separate until eitherendTentativeSection()ordiscardTentativeSection()is called. When subsequentlyendTentativeSection()is called, the lines of the section are written to the report normally. When subsequentlydiscardTentativeSection()is called, all lines in the section are discarded (not written to the report). Note that calling this method multiple times has no further effect. The first consecutive call of this method stays the one that marks the start of the section. Not more than a single section is maintained at any time. -
endTentativeSection
void endTentativeSection()End the current section of lines, writing them to the report normally. Note that when a section has been ended and no new section begun, calling this method again has no effect. -
discardTentativeSection
void discardTentativeSection()Discard all lines written to this section (all lines added to the report after callingstartTentativeSection()). Note that when a section has been ended and no new section begun, calling this method again has no effect. -
finalizeTentativeSection
default void finalizeTentativeSection(boolean keepSection) End the current section of lines, keeping or discarding the section depending on the given keepSection. Calls eitherendTentativeSection()ordiscardTentativeSection().- Parameters:
keepSection- When true, keeps the current section, otherwise discards it.
-