Skip to content

Commit

Permalink
Refactored force rendering logic in ForceRenderer.java
Browse files Browse the repository at this point in the history
Consolidated text formatting into a single String based on formation status. Improved readability and maintainability by reducing repetitive code.
  • Loading branch information
IllianiCBT committed Nov 25, 2024
1 parent bc13555 commit 5b00e18
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion MekHQ/src/mekhq/gui/ForceRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.*;

import static mekhq.campaign.force.Force.STRATEGIC_FORMATION_OVERRIDE_NONE;

public class ForceRenderer extends DefaultTreeCellRenderer {
private static final MMLogger logger = MMLogger.create(ForceRenderer.class);

Expand Down Expand Up @@ -147,9 +149,16 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
setOpaque(true);
}

String format;
if (force.isStrategicFormation()) {
setText("<html><u>" + force.getName() + "</u></html>");
format = (force.getOverrideStrategicFormation() != STRATEGIC_FORMATION_OVERRIDE_NONE) ?
"<html><b><u>%s</u></b></html>" : "<html><b>%s</b></html>";
} else {
format = (force.getOverrideStrategicFormation() != STRATEGIC_FORMATION_OVERRIDE_NONE) ?
"<html><u>%s</u></html>" : "%s";
}

setText(String.format(format, force.getName()));
} else {
logger.error("Attempted to render node with unknown node class of "
+ ((value != null) ? value.getClass() : "null"));
Expand Down

0 comments on commit 5b00e18

Please sign in to comment.