Skip to content

Commit

Permalink
Pin/sticky force view tab on TO&E panel
Browse files Browse the repository at this point in the history
  • Loading branch information
WeaverThree committed Oct 11, 2024
1 parent 2a8f5f5 commit 6735093
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion MekHQ/src/mekhq/gui/TOETab.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ public final class TOETab extends CampaignGuiTab {
private JTree orgTree;
private JSplitPane splitOrg;
private JPanel panForceView;
private JTabbedPane tabUnit;

private OrgTreeModel orgModel;

private int tabUnitLastSelectedIndex;

//region Constructors
public TOETab(CampaignGUI gui, String name) {
super(gui, name);
Expand Down Expand Up @@ -95,6 +98,8 @@ public void initTab() {
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
add(splitOrg, gridBagConstraints);

tabUnitLastSelectedIndex = 0;
}

@Override
Expand All @@ -109,6 +114,11 @@ public void refreshOrganization() {
});
}


public void forceViewTabChange() {
tabUnitLastSelectedIndex = tabUnit.getSelectedIndex();
}

public void refreshForceView() {
panForceView.removeAll();
Object node = orgTree.getLastSelectedPathComponent();
Expand All @@ -117,7 +127,7 @@ public void refreshForceView() {
}
if (node instanceof Unit) {
Unit u = ((Unit) node);
JTabbedPane tabUnit = new JTabbedPane();
tabUnit = new JTabbedPane();
int crewSize = u.getCrew().size();
if (crewSize > 0) {
JPanel crewPanel = new JPanel(new BorderLayout());
Expand Down Expand Up @@ -164,6 +174,8 @@ public Dimension getPreferredScrollableViewportSize() {
tabUnit.add("Unit", scrollUnit);
panForceView.add(tabUnit, BorderLayout.CENTER);
SwingUtilities.invokeLater(() -> scrollUnit.getVerticalScrollBar().setValue(0));
tabUnit.setSelectedIndex(tabUnitLastSelectedIndex);
tabUnit.addChangeListener(evt -> forceViewTabChange()); // added late so it won't overwrite
} else if (node instanceof Force) {
final JScrollPane scrollForce = new JScrollPane(new ForceViewPanel((Force) node, getCampaign()));
panForceView.add(scrollForce, BorderLayout.CENTER);
Expand Down

0 comments on commit 6735093

Please sign in to comment.