From 5f41dfd1167499cf3bf907aaeaa765fc2a547bfd Mon Sep 17 00:00:00 2001 From: asvitkine Date: Fri, 14 Jul 2023 22:47:52 -0400 Subject: [PATCH] Fix objectives tab name disappearing after switching to history. This was broken by https://github.com/triplea-game/triplea/pull/10839 which removed one call to objectivePanel.getName() but not two others. This PR refactors the code to not duplicate logic and makes all three places use the correct logic for the name of that tab. --- .../strategy/triplea/ui/TripleAFrame.java | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/game-app/game-headed/src/main/java/games/strategy/triplea/ui/TripleAFrame.java b/game-app/game-headed/src/main/java/games/strategy/triplea/ui/TripleAFrame.java index 224b14dd7f0..28c360b894d 100644 --- a/game-app/game-headed/src/main/java/games/strategy/triplea/ui/TripleAFrame.java +++ b/game-app/game-headed/src/main/java/games/strategy/triplea/ui/TripleAFrame.java @@ -379,23 +379,17 @@ public void focusGained(final FocusEvent e) { SwingUtilities.invokeLater(() -> mapPanel.addKeyListener(getArrowKeyListener())); - addTab("Actions", actionButtons, KeyCode.C); actionButtons.setBorder(null); statsPanel = new StatPanel(data, uiContext); - addTab("Players", statsPanel, KeyCode.P); economyPanel = new EconomyPanel(data, uiContext); - addTab("Resources", economyPanel, KeyCode.R); objectivePanel = new ObjectivePanel(data, uiContext); if (objectivePanel.isEmpty()) { objectivePanel.removeDataChangeListener(); objectivePanel = null; - } else { - String objectivePanelName = new ObjectiveProperties(uiContext.getResourceLoader()).getName(); - addTab(objectivePanelName, objectivePanel, KeyCode.O); } territoryDetails = new TerritoryDetailPanel(mapPanel, data, uiContext, this); - addTab("Territory", territoryDetails, KeyCode.T); editPanel = new EditPanel(data, mapPanel, this); + addTabs(true); // Register a change listener tabsPanel.addChangeListener( evt -> { @@ -1776,15 +1770,7 @@ private void showHistory() { new HistoryDetailsPanel(clonedGameData, mapPanel); tabsPanel.removeAll(); tabsPanel.add("History", historyDetailPanel); - addTab("Players", statsPanel, KeyCode.P); - addTab("Resources", economyPanel, KeyCode.R); - if (objectivePanel != null && !objectivePanel.isEmpty()) { - addTab(objectivePanel.getName(), objectivePanel, KeyCode.O); - } - addTab("Territory", territoryDetails, KeyCode.T); - if (mapPanel.getEditMode()) { - tabsPanel.add("Edit", editPanel); - } + addTabs(false); actionButtons.getCurrent().ifPresent(actionPanel -> actionPanel.setActive(false)); historyComponent.removeAll(); historyComponent.setLayout(new BorderLayout()); @@ -1952,16 +1938,7 @@ private void showGame() { tabsPanel.removeAll(); } setWidgetActivation(); - addTab("Actions", actionButtons, KeyCode.C); - addTab("Players", statsPanel, KeyCode.P); - addTab("Resources", economyPanel, KeyCode.R); - if (objectivePanel != null && !objectivePanel.isEmpty()) { - addTab(objectivePanel.getName(), objectivePanel, KeyCode.O); - } - addTab("Territory", territoryDetails, KeyCode.T); - if (mapPanel.getEditMode()) { - tabsPanel.add("Edit", editPanel); - } + addTabs(true); actionButtons.getCurrent().ifPresent(actionPanel -> actionPanel.setActive(true)); gameMainPanel.removeAll(); gameMainPanel.setLayout(new BorderLayout()); @@ -1975,6 +1952,22 @@ private void showGame() { mapPanel.setRoute(null); } + private void addTabs(boolean includeActionsTab) { + if (includeActionsTab) { + addTab("Actions", actionButtons, KeyCode.C); + } + addTab("Players", statsPanel, KeyCode.P); + addTab("Resources", economyPanel, KeyCode.R); + if (objectivePanel != null && !objectivePanel.isEmpty()) { + String objectivePanelName = new ObjectiveProperties(uiContext.getResourceLoader()).getName(); + addTab(objectivePanelName, objectivePanel, KeyCode.O); + } + addTab("Territory", territoryDetails, KeyCode.T); + if (mapPanel.getEditMode()) { + tabsPanel.add("Edit", editPanel); + } + } + private void setWidgetActivation() { SwingAction.invokeNowOrLater( () -> {