From 5f41dfd1167499cf3bf907aaeaa765fc2a547bfd Mon Sep 17 00:00:00 2001 From: asvitkine Date: Fri, 14 Jul 2023 22:47:52 -0400 Subject: [PATCH 1/2] 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( () -> { From f99a335f36994d56e8990f5ad102a9883d05b9aa Mon Sep 17 00:00:00 2001 From: asvitkine Date: Fri, 14 Jul 2023 22:57:57 -0400 Subject: [PATCH 2/2] Tweaks. --- .../strategy/triplea/ui/TripleAFrame.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 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 28c360b894d..f90935578b4 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 @@ -389,7 +389,7 @@ public void focusGained(final FocusEvent e) { } territoryDetails = new TerritoryDetailPanel(mapPanel, data, uiContext, this); editPanel = new EditPanel(data, mapPanel, this); - addTabs(true); + addTabs(null); // Register a change listener tabsPanel.addChangeListener( evt -> { @@ -516,6 +516,24 @@ private void addZoomKeyboardShortcuts() { mapPanel.getScale() - (ClientSetting.mapZoomFactor.getValueOrThrow() / 100f))); } + private void addTabs(HistoryDetailsPanel historyDetailPanel) { + if (historyDetailPanel != null) { + tabsPanel.add("History", historyDetailPanel); + } else { + 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 addTab(final String title, final Component component, final KeyCode hotkey) { tabsPanel.addTab(title, null, component, "Hotkey: CTRL+" + hotkey); SwingKeyBinding.addKeyBindingWithMetaAndCtrlMasks( @@ -1769,8 +1787,7 @@ private void showHistory() { final HistoryDetailsPanel historyDetailPanel = new HistoryDetailsPanel(clonedGameData, mapPanel); tabsPanel.removeAll(); - tabsPanel.add("History", historyDetailPanel); - addTabs(false); + addTabs(historyDetailPanel); actionButtons.getCurrent().ifPresent(actionPanel -> actionPanel.setActive(false)); historyComponent.removeAll(); historyComponent.setLayout(new BorderLayout()); @@ -1938,7 +1955,7 @@ private void showGame() { tabsPanel.removeAll(); } setWidgetActivation(); - addTabs(true); + addTabs(null); actionButtons.getCurrent().ifPresent(actionPanel -> actionPanel.setActive(true)); gameMainPanel.removeAll(); gameMainPanel.setLayout(new BorderLayout()); @@ -1952,22 +1969,6 @@ 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( () -> {