From 2af16d2d51b948dac59891a7f22037feaf2e5031 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Fri, 19 Jul 2024 19:40:44 -0500 Subject: [PATCH 1/2] Reordered asset removal and event trigger in ManageAssetsDialog The sequence of actions in the deleteAsset() method of ManageAssetsDialog was rearranged. The AssetRemovedEvent is now triggered before the actual asset removal from the assets list to ensure proper event handling. --- MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java b/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java index f82dff1ccb..d5ae585eed 100644 --- a/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java @@ -163,14 +163,15 @@ private void editAsset() { } private void deleteAsset() { - campaign.getFinances().getAssets().remove(assetTable.getSelectedRow()); MekHQ.triggerEvent(new AssetRemovedEvent(assetModel.getAssetAt(assetTable.getSelectedRow()))); + campaign.getFinances().getAssets().remove(assetTable.getSelectedRow()); refreshTable(); } private void refreshTable() { int selectedRow = assetTable.getSelectedRow(); assetModel.setData(campaign.getFinances().getAssets()); + if (selectedRow != -1) { if (assetTable.getRowCount() > 0) { if (assetTable.getRowCount() == selectedRow) { @@ -277,8 +278,8 @@ public String getTooltip(int row, int col) { } } - public AssetTableModel.Renderer getRenderer() { - return new AssetTableModel.Renderer(); + public Renderer getRenderer() { + return new Renderer(); } public class Renderer extends DefaultTableCellRenderer { From f80a68f29c165d766abbdda0ebf0c6766ecb8079 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Fri, 19 Jul 2024 19:42:17 -0500 Subject: [PATCH 2/2] Minor refactoring --- .../mekhq/gui/dialog/ManageAssetsDialog.java | 37 ++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java b/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java index d5ae585eed..4f19eb804e 100644 --- a/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java @@ -209,18 +209,13 @@ public int getColumnCount() { @Override public String getColumnName(int column) { - switch (column) { - case COL_NAME: - return "Name"; - case COL_VALUE: - return "Value"; - case COL_SCHEDULE: - return "Pay Frequency"; - case COL_INCOME: - return "Income"; - default: - return "?"; - } + return switch (column) { + case COL_NAME -> "Name"; + case COL_VALUE -> "Value"; + case COL_SCHEDULE -> "Pay Frequency"; + case COL_INCOME -> "Income"; + default -> "?"; + }; } @Override @@ -256,26 +251,18 @@ public Asset getAssetAt(int row) { } public int getColumnWidth(int c) { - switch (c) { - default: - return 10; - } + return 10; } public int getAlignment(int col) { - switch (col) { - case COL_NAME: - return SwingConstants.LEFT; - default: - return SwingConstants.RIGHT; + if (col == COL_NAME) { + return SwingConstants.LEFT; } + return SwingConstants.RIGHT; } public String getTooltip(int row, int col) { - switch (col) { - default: - return null; - } + return null; } public Renderer getRenderer() {