diff --git a/MekHQ/src/mekhq/gui/dialog/MekHQUnitSelectorDialog.java b/MekHQ/src/mekhq/gui/dialog/MekHQUnitSelectorDialog.java index 4bfbb81f80f..041eb386a1b 100644 --- a/MekHQ/src/mekhq/gui/dialog/MekHQUnitSelectorDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MekHQUnitSelectorDialog.java @@ -27,11 +27,33 @@ */ package mekhq.gui.dialog; +import static mekhq.utilities.EntityUtilities.isUnsupportedEntity; +import static mekhq.utilities.ReportingUtilities.CLOSING_SPAN_TAG; +import static mekhq.utilities.ReportingUtilities.spanOpeningWithCustomColor; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; +import java.util.regex.PatternSyntaxException; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.RowFilter; + import megamek.client.ui.Messages; import megamek.client.ui.advancedsearch.MekSearchFilter; import megamek.client.ui.swing.UnitLoadingDialog; import megamek.client.ui.swing.dialog.AbstractUnitSelectorDialog; -import megamek.common.*; +import megamek.common.Entity; +import megamek.common.EntityWeightClass; +import megamek.common.ITechnology; +import megamek.common.MekSummary; +import megamek.common.TargetRoll; +import megamek.common.TechConstants; +import megamek.common.UnitType; import mekhq.MekHQ; import mekhq.campaign.Campaign; import mekhq.campaign.parts.enums.PartQuality; @@ -39,17 +61,6 @@ import mekhq.campaign.unit.UnitTechProgression; import mekhq.utilities.MHQInternationalization; -import javax.swing.*; -import java.awt.*; -import java.util.ArrayList; -import java.util.List; -import java.util.ResourceBundle; -import java.util.regex.PatternSyntaxException; - -import static mekhq.utilities.EntityUtilities.isUnsupportedEntity; -import static mekhq.utilities.ReportingUtilities.CLOSING_SPAN_TAG; -import static mekhq.utilities.ReportingUtilities.spanOpeningWithCustomColor; - public class MekHQUnitSelectorDialog extends AbstractUnitSelectorDialog { //region Variable Declarations private Campaign campaign; @@ -59,8 +70,8 @@ public class MekHQUnitSelectorDialog extends AbstractUnitSelectorDialog { private static final String TARGET_UNKNOWN = "--"; //endregion Variable Declarations - public MekHQUnitSelectorDialog(JFrame frame, UnitLoadingDialog unitLoadingDialog, - Campaign campaign, boolean addToCampaign) { + public MekHQUnitSelectorDialog(JFrame frame, UnitLoadingDialog unitLoadingDialog, Campaign campaign, + boolean addToCampaign) { super(frame, unitLoadingDialog); this.campaign = campaign; this.addToCampaign = addToCampaign; @@ -79,7 +90,8 @@ public void updateOptionValues() { gameTechLevel = campaign.getCampaignOptions().getTechLevel(); eraBasedTechLevel = campaign.getCampaignOptions().isVariableTechLevel(); - if (campaign.getCampaignOptions().isAllowClanPurchases() && campaign.getCampaignOptions().isAllowISPurchases()) { + if (campaign.getCampaignOptions().isAllowClanPurchases() && + campaign.getCampaignOptions().isAllowISPurchases()) { techLevelDisplayType = TECH_LEVEL_DISPLAY_IS_CLAN; } else if (campaign.getCampaignOptions().isAllowClanPurchases()) { techLevelDisplayType = TECH_LEVEL_DISPLAY_CLAN; @@ -98,6 +110,7 @@ protected JPanel createButtonsPanel() { buttonSelect = new JButton(Messages.getString("MekSelectorDialog.Buy", TARGET_UNKNOWN)); buttonSelect.setName("buttonBuy"); buttonSelect.addActionListener(this); + buttonSelect.setEnabled(false); panelButtons.add(buttonSelect, new GridBagConstraints()); if (campaign.isGM()) { @@ -105,6 +118,7 @@ protected JPanel createButtonsPanel() { buttonSelectClose = new JButton(Messages.getString("MekSelectorDialog.AddGM")); buttonSelectClose.setName("buttonAddGM"); buttonSelectClose.addActionListener(this); + buttonSelectClose.setEnabled(false); panelButtons.add(buttonSelectClose, new GridBagConstraints()); } @@ -146,24 +160,23 @@ protected void select(boolean isGM) { if (entity == null || isUnsupportedEntity(entity)) { final ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.CampaignGUI", - MekHQ.getMHQOptions().getLocale()); + MekHQ.getMHQOptions().getLocale()); String reason; if (entity == null) { reason = MHQInternationalization.getTextAt(resources.getBaseBundleName(), - "mekSelectorDialog.unsupported.null"); + "mekSelectorDialog.unsupported.null"); } else if (entity.getUnitType() == UnitType.GUN_EMPLACEMENT) { reason = MHQInternationalization.getTextAt(resources.getBaseBundleName(), - "mekSelectorDialog.unsupported.gunEmplacement"); + "mekSelectorDialog.unsupported.gunEmplacement"); } else { reason = MHQInternationalization.getTextAt(resources.getBaseBundleName(), - "mekSelectorDialog.unsupported.droneOs"); + "mekSelectorDialog.unsupported.droneOs"); } - campaign.addReport(String.format( - reason, - spanOpeningWithCustomColor(MekHQ.getMHQOptions().getFontColorNegativeHexColor()), - CLOSING_SPAN_TAG)); + campaign.addReport(String.format(reason, + spanOpeningWithCustomColor(MekHQ.getMHQOptions().getFontColorNegativeHexColor()), + CLOSING_SPAN_TAG)); dispose(); return; @@ -185,8 +198,8 @@ protected void select(boolean isGM) { //endregion Button Methods /** - * We need to override this to add some MekHQ specific functionality, namely changing button - * names when the selected entity is chosen + * We need to override this to add some MekHQ specific functionality, namely changing button names when the selected + * entity is chosen * * @return selectedEntity, or null if there isn't one */ @@ -199,15 +212,16 @@ public Entity getSelectedEntity() { buttonSelect.setEnabled(false); buttonSelect.setText(Messages.getString("MekSelectorDialog.Buy", TARGET_UNKNOWN)); buttonSelect.setToolTipText(null); + buttonSelectClose.setEnabled(false); } } else { selectedUnit = new UnitOrder(entity, campaign); if (addToCampaign) { buttonSelect.setEnabled(true); final TargetRoll target = campaign.getTargetForAcquisition(selectedUnit); - buttonSelect.setText(Messages.getString("MekSelectorDialog.Buy", - target.getValueAsString())); + buttonSelect.setText(Messages.getString("MekSelectorDialog.Buy", target.getValueAsString())); buttonSelect.setToolTipText(target.getDesc()); + buttonSelectClose.setEnabled(true); } } @@ -240,7 +254,7 @@ protected void filterUnits() { final int nClass = comboWeight.getSelectedIndex(); final int nUnit = comboUnitType.getSelectedIndex() - 1; final boolean checkSupportVee = Messages.getString("MekSelectorDialog.SupportVee") - .equals(comboUnitType.getSelectedItem()); + .equals(comboUnitType.getSelectedItem()); // If the current expression doesn't parse, don't update. try { unitTypeFilter = new RowFilter<>() { @@ -259,25 +273,26 @@ public boolean include(Entry entry) } if ( - /* year limits */ - (!enableYearLimits || (mek.getYear() <= allowedYear)) - /* Clan/IS limits */ - && (campaign.getCampaignOptions().isAllowClanPurchases() || !TechConstants.isClan(mek.getType())) - && (campaign.getCampaignOptions().isAllowISPurchases() || TechConstants.isClan(mek.getType())) - /* Canon */ - && (!canonOnly || mek.isCanon()) - /* Weight */ - && ((nClass == mek.getWeightClass()) || (nClass == EntityWeightClass.SIZE)) - /* Technology Level */ - && ((null != tech) && campaign.isLegal(tech)) - && (techLevelMatch) - /* Support Vehicles */ - && ((nUnit == -1) - || (!checkSupportVee && mek.getUnitType().equals(UnitType.getTypeName(nUnit))) - || (checkSupportVee && mek.isSupport())) - /* Advanced Search */ - && ((searchFilter == null) || MekSearchFilter.isMatch(mek, searchFilter)) - ) { + /* year limits */ + (!enableYearLimits || (mek.getYear() <= allowedYear)) + /* Clan/IS limits */ && + (campaign.getCampaignOptions().isAllowClanPurchases() || + !TechConstants.isClan(mek.getType())) && + (campaign.getCampaignOptions().isAllowISPurchases() || + TechConstants.isClan(mek.getType())) + /* Canon */ && + (!canonOnly || mek.isCanon()) + /* Weight */ && + ((nClass == mek.getWeightClass()) || (nClass == EntityWeightClass.SIZE)) + /* Technology Level */ && + ((null != tech) && campaign.isLegal(tech)) && + (techLevelMatch) + /* Support Vehicles */ && + ((nUnit == -1) || + (!checkSupportVee && mek.getUnitType().equals(UnitType.getTypeName(nUnit))) || + (checkSupportVee && mek.isSupport())) + /* Advanced Search */ && + ((searchFilter == null) || MekSearchFilter.isMatch(mek, searchFilter))) { if (!textFilter.getText().isBlank()) { String text = textFilter.getText(); return mek.getName().toLowerCase().contains(text.toLowerCase());