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

Use unmodifiable collection in UnitSeparator in Swing Event Thread Task #7070

Merged
merged 1 commit into from Jul 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,7 +4,10 @@
import games.strategy.engine.data.GameDataEvent;
import games.strategy.engine.data.GamePlayer;
import games.strategy.engine.data.GameStep;
import games.strategy.engine.data.Unit;
import games.strategy.triplea.util.UnitSeparator;
import java.util.Collection;
import java.util.List;
import javax.swing.SwingUtilities;
import lombok.Getter;
import org.triplea.swing.CollapsiblePanel;
Expand All @@ -28,18 +31,19 @@ class PlacementUnitsCollapsiblePanel {
private void updateStep() {
final GameStep step = gameData.getSequence().getStep();

SwingUtilities.invokeLater(
() -> {
if (GameStep.isPlaceStep(step.getName()) || isInitializationStep(step)) {
panel.setVisible(false);
return;
}
// Compute data now so that the swing event task is working with unmodifiable data.
final boolean shouldRenderPanelForThisGameStep =
!GameStep.isPlaceStep(step.getName())
&& !isInitializationStep(step)
&& stepIsAfterPurchaseAndBeforePlacement(step);

final boolean hasUnitsToPlace = !step.getPlayerId().getUnits().isEmpty();
final Collection<Unit> playerUnits =
shouldRenderPanelForThisGameStep ? List.copyOf(step.getPlayerId().getUnits()) : List.of();

if (hasUnitsToPlace || stepIsAfterPurchaseAndBeforePlacement(step)) {
unitsToPlacePanel.setUnitsFromCategories(
UnitSeparator.categorize(step.getPlayerId().getUnits()));
SwingUtilities.invokeLater(
() -> {
if (shouldRenderPanelForThisGameStep && !playerUnits.isEmpty()) {
unitsToPlacePanel.setUnitsFromCategories(UnitSeparator.categorize(playerUnits));
panel.setVisible(true);
} else {
panel.setVisible(false);
Expand Down