Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin/sticky force view tab on TO&E panel #5025

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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