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

Fix delay between "Calculating Data" and unit dialog shown. #11958

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package games.strategy.triplea.ui.menubar.help;

import games.strategy.engine.framework.ui.GameNotesView;
import java.awt.Dimension;
import java.nio.file.Path;
import javax.swing.Action;
import javax.swing.JComponent;
Expand All @@ -24,18 +25,12 @@ Action buildMenu(final String gameNotes, final Path mapLocation) {
final JDialog dialog =
InformationDialog.createDialog(
notesPanel(gameNotes, mapLocation), gameNotesTitle);
if (dialog.getWidth() < 400) {
dialog.setSize(400, dialog.getHeight());
}
if (dialog.getHeight() < 300) {
dialog.setSize(dialog.getWidth(), 300);
}
if (dialog.getWidth() > 800) {
dialog.setSize(800, dialog.getHeight());
}
if (dialog.getHeight() > 600) {
dialog.setSize(dialog.getWidth(), 600);
}
Dimension size = dialog.getSize();
size.width = Math.min(size.width, 400);
size.height = Math.min(size.height, 300);
size.width = Math.max(size.width, 800);
size.height = Math.max(size.height, 600);
dialog.setSize(size);
dialog.setVisible(true);
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import games.strategy.triplea.ui.UiContext;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import lombok.experimental.UtilityClass;
Expand All @@ -20,19 +21,21 @@ Action buildMenu(final GameData gameData, final UiContext uiContext) {
return SwingAction.of(
unitHelpTitle,
e -> {
final Result<String> result =
final Result<JDialog> result =
Interruptibles.awaitResult(
() ->
BackgroundTaskRunner.runInBackgroundAndReturn(
"Calculating Data",
() -> UnitStatsTable.getUnitStatsTable(gameData, uiContext)));
final JEditorPane editorPane =
new JEditorPane("text/html", result.result.orElse("Failed to calculate Data"));
editorPane.setEditable(false);
editorPane.setCaretPosition(0);
final JScrollPane scroll = new JScrollPane(editorPane);
scroll.setBorder(BorderFactory.createEmptyBorder());
InformationDialog.createDialog(scroll, unitHelpTitle).setVisible(true);
() -> {
String text = UnitStatsTable.getUnitStatsTable(gameData, uiContext);
JEditorPane editorPane = new JEditorPane("text/html", text);
editorPane.setEditable(false);
editorPane.setCaretPosition(0);
JScrollPane scroll = new JScrollPane(editorPane);
scroll.setBorder(BorderFactory.createEmptyBorder());
return InformationDialog.createDialog(scroll, unitHelpTitle);
}));
result.result.orElseThrow().setVisible(true);
});
}
}