Skip to content

Commit 7360abe

Browse files
authored
Some more clean up of action panels buttons UI. (#10437)
* Some more clean up of action panels buttons UI. My previous refactoring in #10435 introduces a few layout issues I noticed in testing. This change fixes that and consolidates some similar code into a helper method.
1 parent 2037e2a commit 7360abe

File tree

6 files changed

+19
-33
lines changed

6 files changed

+19
-33
lines changed

game-app/game-core/src/main/java/games/strategy/triplea/ui/ActionPanel.java

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ public static JLabel createIndentedLabel() {
5858
return new JLabelBuilder().border(BorderFactory.createEmptyBorder(0, 5, 0, 0)).build();
5959
}
6060

61+
protected static JPanel createButtonsPanel(JButton... buttons) {
62+
JPanel buttonsPanel = new JPanel();
63+
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
64+
for (JButton button : buttons) {
65+
buttonsPanel.add(button);
66+
}
67+
return buttonsPanel;
68+
}
69+
6170
/**
6271
* Wait for another thread to call release. If the thread is interrupted, we will return silently.
6372
*

game-app/game-core/src/main/java/games/strategy/triplea/ui/PoliticsPanel.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,14 @@ public void display(final GamePlayer gamePlayer) {
176176
() -> {
177177
removeAll();
178178
actionLabel.setText(gamePlayer.getName() + " Politics");
179-
add(actionLabel);
180179
add(SwingComponents.leftBox(actionLabel));
181180

182181
selectPoliticalActionButton = new JButton(selectPoliticalActionAction);
183182
selectPoliticalActionButton.setEnabled(false);
184183
doneButton = createDoneButton();
185184
doneButton.setEnabled(false);
186185

187-
final JPanel buttonsPanel = new JPanel();
188-
buttonsPanel.add(selectPoliticalActionButton);
189-
buttonsPanel.add(doneButton);
190-
add(buttonsPanel);
186+
add(createButtonsPanel(selectPoliticalActionButton, doneButton));
191187

192188
SwingUtilities.invokeLater(() -> doneButton.requestFocusInWindow());
193189
});

game-app/game-core/src/main/java/games/strategy/triplea/ui/PurchasePanel.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import javax.swing.JFrame;
2424
import javax.swing.JLabel;
2525
import javax.swing.JOptionPane;
26-
import javax.swing.JPanel;
2726
import javax.swing.SwingUtilities;
2827
import org.triplea.java.collections.CollectionUtils;
2928
import org.triplea.java.collections.IntegerMap;
@@ -92,34 +91,30 @@ public void display(final GamePlayer gamePlayer) {
9291
() -> {
9392
removeAll();
9493
actionLabel.setText(gamePlayer.getName() + " production");
95-
add(actionLabel);
9694
add(SwingComponents.leftBox(actionLabel));
9795

9896
buyButton.setText(BUY);
99-
final JPanel buttonsPanel = new JPanel();
100-
buttonsPanel.add(buyButton);
101-
buttonsPanel.add(createDoneButton());
102-
add(buttonsPanel);
97+
add(createButtonsPanel(buyButton, createDoneButton()));
10398

10499
add(Box.createVerticalStrut(9));
105100

106101
purchasedLabel.setText("");
107-
add(purchasedLabel);
102+
add(SwingComponents.leftBox(purchasedLabel));
108103

109104
add(Box.createVerticalStrut(4));
110105

111106
purchasedUnits.setUnitsFromProductionRuleMap(new IntegerMap<>(), gamePlayer);
112-
add(purchasedUnits);
107+
add(SwingComponents.leftBox(purchasedUnits));
113108

114109
getData().acquireReadLock();
115110
try {
116111
purchasedPreviousRoundsUnits.setUnitsFromCategories(
117112
UnitSeparator.categorize(gamePlayer.getUnits()));
118113
add(Box.createVerticalStrut(4));
119114
if (!gamePlayer.getUnitCollection().isEmpty()) {
120-
add(purchasedPreviousRoundsLabel);
115+
add(SwingComponents.leftBox(purchasedPreviousRoundsLabel));
121116
}
122-
add(purchasedPreviousRoundsUnits);
117+
add(SwingComponents.leftBox(purchasedPreviousRoundsUnits));
123118
} finally {
124119
getData().releaseReadLock();
125120
}

game-app/game-core/src/main/java/games/strategy/triplea/ui/RepairPanel.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import javax.swing.JFrame;
1717
import javax.swing.JLabel;
1818
import javax.swing.JOptionPane;
19-
import javax.swing.JPanel;
2019
import javax.swing.SwingUtilities;
2120
import org.triplea.java.collections.IntegerMap;
2221
import org.triplea.swing.SwingComponents;
@@ -75,14 +74,10 @@ public void display(final GamePlayer gamePlayer) {
7574
() -> {
7675
removeAll();
7776
actionLabel.setText(gamePlayer.getName() + " repair");
78-
add(actionLabel);
7977
add(SwingComponents.leftBox(actionLabel));
8078

8179
buyButton.setText(BUY);
82-
final JPanel buttonsPanel = new JPanel();
83-
buttonsPanel.add(buyButton);
84-
buttonsPanel.add(createDoneButton());
85-
add(buttonsPanel);
80+
add(createButtonsPanel(buyButton, createDoneButton()));
8681

8782
repairedSoFar.setText("");
8883
add(Box.createVerticalStrut(9));

game-app/game-core/src/main/java/games/strategy/triplea/ui/TechPanel.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,13 @@ public void display(final GamePlayer gamePlayer) {
224224
() -> {
225225
removeAll();
226226
actionLabel.setText(gamePlayer.getName() + " Tech Roll");
227-
add(actionLabel);
228227
add(SwingComponents.leftBox(actionLabel));
229228

230-
final JPanel buttonsPanel = new JPanel();
231229
if (Properties.getWW2V3TechModel(getData().getProperties())) {
232-
buttonsPanel.add(new JButton(getTechTokenAction));
233-
buttonsPanel.add(new JButton(justRollTech));
230+
add(createButtonsPanel(new JButton(getTechTokenAction), new JButton(justRollTech)));
234231
} else {
235-
buttonsPanel.add(new JButton(getTechRollsAction));
236-
buttonsPanel.add(createDoneButton());
232+
add(createButtonsPanel(new JButton(getTechRollsAction), createDoneButton()));
237233
}
238-
add(buttonsPanel);
239234
});
240235
}
241236

game-app/game-core/src/main/java/games/strategy/triplea/ui/UserActionPanel.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,14 @@ public void display(final GamePlayer gamePlayer) {
121121
() -> {
122122
removeAll();
123123
actionLabel.setText(gamePlayer.getName() + " Actions and Operations");
124-
add(actionLabel);
125124
add(SwingComponents.leftBox(actionLabel));
126125

127126
selectUserActionButton = new JButton(selectUserActionAction);
128127
selectUserActionButton.setEnabled(false);
129128
doneButton = createDoneButton();
130129
doneButton.setEnabled(false);
131130

132-
final JPanel buttonsPanel = new JPanel();
133-
buttonsPanel.add(selectUserActionButton);
134-
buttonsPanel.add(doneButton);
135-
add(buttonsPanel);
131+
add(createButtonsPanel(selectUserActionButton, doneButton));
136132

137133
SwingUtilities.invokeLater(() -> doneButton.requestFocusInWindow());
138134
});

0 commit comments

Comments
 (0)