From c2594742988c0dae4b03c914244e43f1de9e40b9 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 1 Jan 2024 12:16:08 +0100 Subject: [PATCH 1/2] Handle no unit being selected --- megameklab/src/megameklab/ui/MenuBar.java | 23 +++++++++++-------- megameklab/src/megameklab/ui/StartupGUI.java | 11 ++++++--- .../ui/dialog/PrintQueueDialog.java | 3 +-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/megameklab/src/megameklab/ui/MenuBar.java b/megameklab/src/megameklab/ui/MenuBar.java index 3190251be..5b0f27060 100644 --- a/megameklab/src/megameklab/ui/MenuBar.java +++ b/megameklab/src/megameklab/ui/MenuBar.java @@ -808,19 +808,22 @@ private void jMenuGetUnitValidationFromCache_actionPerformed() { UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(owner.getFrame()); unitLoadingDialog.setVisible(true); MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog); - - Entity tempEntity = viewer.getChosenEntity(); - if (null == tempEntity) { - return; + Entity chosenEntity = viewer.getChosenEntity(); + if (null != chosenEntity) { + UnitUtil.showValidation(chosenEntity, owner.getFrame()); } - UnitUtil.showValidation(tempEntity, owner.getFrame()); + viewer.dispose(); } private void jMenuGetUnitBreakdownFromCache_actionPerformed() { UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(owner.getFrame()); unitLoadingDialog.setVisible(true); MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog); - new CostDisplayDialog(owner.getFrame(), viewer.getChosenEntity()).setVisible(true); + Entity chosenEntity = viewer.getChosenEntity(); + if (null != chosenEntity) { + new CostDisplayDialog(owner.getFrame(), chosenEntity).setVisible(true); + } + viewer.dispose(); } private void jMenuGetUnitWeightBreakdownFromCache_actionPerformed() { @@ -828,11 +831,11 @@ private void jMenuGetUnitWeightBreakdownFromCache_actionPerformed() { unitLoadingDialog.setVisible(true); MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog); - Entity tempEntity = viewer.getChosenEntity(); - if (null == tempEntity) { - return; + Entity chosenEntity = viewer.getChosenEntity(); + if (null != chosenEntity) { + UnitUtil.showUnitWeightBreakDown(chosenEntity, owner.getFrame()); } - UnitUtil.showUnitWeightBreakDown(tempEntity, owner.getFrame()); + viewer.dispose(); } private void jMenuGetUnitBVFromFile_actionPerformed() { diff --git a/megameklab/src/megameklab/ui/StartupGUI.java b/megameklab/src/megameklab/ui/StartupGUI.java index 0d3f5637b..925882f78 100644 --- a/megameklab/src/megameklab/ui/StartupGUI.java +++ b/megameklab/src/megameklab/ui/StartupGUI.java @@ -23,6 +23,7 @@ import megamek.client.ui.swing.widget.SkinnedJPanel; import megamek.common.Configuration; import megamek.common.Entity; +import megamek.common.MechSummary; import megameklab.MMLConstants; import megameklab.ui.dialog.MegaMekLabUnitSelectorDialog; import megameklab.ui.dialog.UiLoader; @@ -251,16 +252,20 @@ public static void selectAndLoadUnitFromCache(MenuBarOwner previousFrame) { unitLoadingDialog.setVisible(true); MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(previousFrame.getFrame(), unitLoadingDialog); Entity newUnit = viewer.getChosenEntity(); + MechSummary mechSummary = viewer.getChosenMechSummary(); + viewer.dispose(); + if (mechSummary == null || newUnit == null) { + return; + } + String fileName = viewer.getChosenMechSummary().getSourceFile().toString(); if (fileName.toLowerCase().endsWith(".zip")) { fileName = viewer.getChosenMechSummary().getSourceFile().getAbsolutePath(); fileName = fileName.substring(0, fileName.lastIndexOf(File.separatorChar) + 1); fileName = fileName + MenuBar.createUnitFilename(newUnit); } - viewer.setVisible(false); - viewer.dispose(); - if ((newUnit == null) || !previousFrame.safetyPrompt()) { + if (!previousFrame.safetyPrompt()) { return; } diff --git a/megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java b/megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java index bb4bc7ed5..c80558e71 100644 --- a/megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java +++ b/megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java @@ -144,9 +144,8 @@ private void selectFromCache() { UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(parent); unitLoadingDialog.setVisible(true); MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(parent, unitLoadingDialog, this::entitySelected); - - viewer.setVisible(false); Entity entity = viewer.getChosenEntity(); + viewer.dispose(); if (entity != null) { units.add(entity); From d9feae43582bc33b7dddda1fe4203aa2a8cbbc1a Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 1 Jan 2024 12:20:13 +0100 Subject: [PATCH 2/2] code style --- megameklab/src/megameklab/ui/MenuBar.java | 6 +++--- megameklab/src/megameklab/ui/StartupGUI.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/megameklab/src/megameklab/ui/MenuBar.java b/megameklab/src/megameklab/ui/MenuBar.java index 5b0f27060..1a615bb58 100644 --- a/megameklab/src/megameklab/ui/MenuBar.java +++ b/megameklab/src/megameklab/ui/MenuBar.java @@ -809,7 +809,7 @@ private void jMenuGetUnitValidationFromCache_actionPerformed() { unitLoadingDialog.setVisible(true); MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog); Entity chosenEntity = viewer.getChosenEntity(); - if (null != chosenEntity) { + if (chosenEntity != null) { UnitUtil.showValidation(chosenEntity, owner.getFrame()); } viewer.dispose(); @@ -820,7 +820,7 @@ private void jMenuGetUnitBreakdownFromCache_actionPerformed() { unitLoadingDialog.setVisible(true); MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog); Entity chosenEntity = viewer.getChosenEntity(); - if (null != chosenEntity) { + if (chosenEntity != null) { new CostDisplayDialog(owner.getFrame(), chosenEntity).setVisible(true); } viewer.dispose(); @@ -832,7 +832,7 @@ private void jMenuGetUnitWeightBreakdownFromCache_actionPerformed() { MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog); Entity chosenEntity = viewer.getChosenEntity(); - if (null != chosenEntity) { + if (chosenEntity != null) { UnitUtil.showUnitWeightBreakDown(chosenEntity, owner.getFrame()); } viewer.dispose(); diff --git a/megameklab/src/megameklab/ui/StartupGUI.java b/megameklab/src/megameklab/ui/StartupGUI.java index 925882f78..5088a5ebf 100644 --- a/megameklab/src/megameklab/ui/StartupGUI.java +++ b/megameklab/src/megameklab/ui/StartupGUI.java @@ -254,7 +254,7 @@ public static void selectAndLoadUnitFromCache(MenuBarOwner previousFrame) { Entity newUnit = viewer.getChosenEntity(); MechSummary mechSummary = viewer.getChosenMechSummary(); viewer.dispose(); - if (mechSummary == null || newUnit == null) { + if ((mechSummary == null) || (newUnit == null)) { return; }