Skip to content

Commit

Permalink
Fix delay between "Calculating Data" and unit dialog shown. (#11958)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvitkine committed Sep 13, 2023
1 parent 190c090 commit 5d47dc2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
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);
});
}
}

0 comments on commit 5d47dc2

Please sign in to comment.