Skip to content

Commit

Permalink
Some more clean up of action panels buttons UI. (#10437)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
asvitkine authored May 12, 2022
1 parent 2037e2a commit 7360abe
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public static JLabel createIndentedLabel() {
return new JLabelBuilder().border(BorderFactory.createEmptyBorder(0, 5, 0, 0)).build();
}

protected static JPanel createButtonsPanel(JButton... buttons) {
JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
for (JButton button : buttons) {
buttonsPanel.add(button);
}
return buttonsPanel;
}

/**
* Wait for another thread to call release. If the thread is interrupted, we will return silently.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,14 @@ public void display(final GamePlayer gamePlayer) {
() -> {
removeAll();
actionLabel.setText(gamePlayer.getName() + " Politics");
add(actionLabel);
add(SwingComponents.leftBox(actionLabel));

selectPoliticalActionButton = new JButton(selectPoliticalActionAction);
selectPoliticalActionButton.setEnabled(false);
doneButton = createDoneButton();
doneButton.setEnabled(false);

final JPanel buttonsPanel = new JPanel();
buttonsPanel.add(selectPoliticalActionButton);
buttonsPanel.add(doneButton);
add(buttonsPanel);
add(createButtonsPanel(selectPoliticalActionButton, doneButton));

SwingUtilities.invokeLater(() -> doneButton.requestFocusInWindow());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.triplea.java.collections.CollectionUtils;
import org.triplea.java.collections.IntegerMap;
Expand Down Expand Up @@ -92,34 +91,30 @@ public void display(final GamePlayer gamePlayer) {
() -> {
removeAll();
actionLabel.setText(gamePlayer.getName() + " production");
add(actionLabel);
add(SwingComponents.leftBox(actionLabel));

buyButton.setText(BUY);
final JPanel buttonsPanel = new JPanel();
buttonsPanel.add(buyButton);
buttonsPanel.add(createDoneButton());
add(buttonsPanel);
add(createButtonsPanel(buyButton, createDoneButton()));

add(Box.createVerticalStrut(9));

purchasedLabel.setText("");
add(purchasedLabel);
add(SwingComponents.leftBox(purchasedLabel));

add(Box.createVerticalStrut(4));

purchasedUnits.setUnitsFromProductionRuleMap(new IntegerMap<>(), gamePlayer);
add(purchasedUnits);
add(SwingComponents.leftBox(purchasedUnits));

getData().acquireReadLock();
try {
purchasedPreviousRoundsUnits.setUnitsFromCategories(
UnitSeparator.categorize(gamePlayer.getUnits()));
add(Box.createVerticalStrut(4));
if (!gamePlayer.getUnitCollection().isEmpty()) {
add(purchasedPreviousRoundsLabel);
add(SwingComponents.leftBox(purchasedPreviousRoundsLabel));
}
add(purchasedPreviousRoundsUnits);
add(SwingComponents.leftBox(purchasedPreviousRoundsUnits));
} finally {
getData().releaseReadLock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.triplea.java.collections.IntegerMap;
import org.triplea.swing.SwingComponents;
Expand Down Expand Up @@ -75,14 +74,10 @@ public void display(final GamePlayer gamePlayer) {
() -> {
removeAll();
actionLabel.setText(gamePlayer.getName() + " repair");
add(actionLabel);
add(SwingComponents.leftBox(actionLabel));

buyButton.setText(BUY);
final JPanel buttonsPanel = new JPanel();
buttonsPanel.add(buyButton);
buttonsPanel.add(createDoneButton());
add(buttonsPanel);
add(createButtonsPanel(buyButton, createDoneButton()));

repairedSoFar.setText("");
add(Box.createVerticalStrut(9));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,13 @@ public void display(final GamePlayer gamePlayer) {
() -> {
removeAll();
actionLabel.setText(gamePlayer.getName() + " Tech Roll");
add(actionLabel);
add(SwingComponents.leftBox(actionLabel));

final JPanel buttonsPanel = new JPanel();
if (Properties.getWW2V3TechModel(getData().getProperties())) {
buttonsPanel.add(new JButton(getTechTokenAction));
buttonsPanel.add(new JButton(justRollTech));
add(createButtonsPanel(new JButton(getTechTokenAction), new JButton(justRollTech)));
} else {
buttonsPanel.add(new JButton(getTechRollsAction));
buttonsPanel.add(createDoneButton());
add(createButtonsPanel(new JButton(getTechRollsAction), createDoneButton()));
}
add(buttonsPanel);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,14 @@ public void display(final GamePlayer gamePlayer) {
() -> {
removeAll();
actionLabel.setText(gamePlayer.getName() + " Actions and Operations");
add(actionLabel);
add(SwingComponents.leftBox(actionLabel));

selectUserActionButton = new JButton(selectUserActionAction);
selectUserActionButton.setEnabled(false);
doneButton = createDoneButton();
doneButton.setEnabled(false);

final JPanel buttonsPanel = new JPanel();
buttonsPanel.add(selectUserActionButton);
buttonsPanel.add(doneButton);
add(buttonsPanel);
add(createButtonsPanel(selectUserActionButton, doneButton));

SwingUtilities.invokeLater(() -> doneButton.requestFocusInWindow());
});
Expand Down

7 comments on commit 7360abe

@TheDog-GH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asvitkine
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for all your work.

I dont know to send you a private message, but it would be great to have this in 2.6 https://forums.triplea-game.org/topic/2798/achievable-improvements-to-the-triplea-user-interface

Main changes are seen here https://forums.triplea-game.org/topic/2798/achievable-improvements-to-the-triplea-user-interface/78?page=4

The code is here https://forums.triplea-game.org/topic/2798/achievable-improvements-to-the-triplea-user-interface/48

Why doesn't the author submit a pull request themselves?

@TheDog-GH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know they stopped posting on the TripleA forums, so its half done. I use their version almost daily for my map making and testing.
Also its stuck in 2.5, not 2.6.

@asvitkine
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know they stopped posting on the TripleA forums, so its half done. I use their version almost daily for my map making and testing. Also its stuck in 2.5, not 2.6.

Have you tried messaging them on the forums? Ideally the author of the change can submit it, since then there's full clarity that they're agreeing to give the code to the TripleA project.

@TheDog-GH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RaiNova has already done it, 4 months ago.
https://forums.triplea-game.org/topic/2798/achievable-improvements-to-the-triplea-user-interface/130?page=7

I have just sent a TripleA Private chat to butterw, hopefully they will get an email in their inbox and reply.

But we will probably not get a reply, given RaiNova asked 4 months ago.

@asvitkine
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheDog-GH
I downloaded the zip from that post and it doesn't have the actual code for the changes. It's just a jar file. Technically a jar file could be produced with source code inside, but that one doesn't have it. So it seems the author did not share the code to his changes, unfortunately.

@TheDog-GH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look.

Please sign in to comment.