Skip to content

Commit 50ca1ed

Browse files
committed
Improvement: Added Close Dialog Button to New Personnel Market
1 parent b464db8 commit 50ca1ed

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

MekHQ/resources/mekhq/resources/PersonnelMarket.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ title.personnelMarket.clan=++ACCESSING CASTE ASSIGNMENT TERMINAL++
44
title.personnelMarket.comStarOrWoB=++WELCOME {0}, PRAISE BLAKE++
55
title.personnelMarket.mercenary=++ACCESSING MERCNET RECRUITMENT SERVICES++
66
title.personnelMarket.normal=++ACCESSING PERSONNEL REQUISITIONS++
7-
button.personnelMarket.hire.normal=<html><b>Recruit</b></html>
7+
button.personnelMarket.close=Close
8+
button.personnelMarket.hire.normal=Recruit
89
button.personnelMarket.hire.gm=Recruit (GM)
910
checkbox.personnelMarket.goldenHello=Offer Golden Hello
1011
label.personnelMarket.filter=Role:

MekHQ/src/mekhq/gui/dialog/markets/personnelMarket/PersonnelMarketDialog.java

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
* @author Illiani
107107
* @since 0.50.06
108108
*/
109-
public class PersonnelMarketDialog {
109+
public class PersonnelMarketDialog extends JDialog {
110110
private static final String RESOURCE_BUNDLE = "mekhq.resources.PersonnelMarket";
111111

112112
private static final int MAXIMUM_DAYS_IN_MONTH = 31;
@@ -153,14 +153,11 @@ public PersonnelMarketDialog(NewPersonnelMarket market) {
153153
* @since 0.50.06
154154
*/
155155
public void initializeComponents() {
156-
JDialog dialog = new JDialog(parent);
157-
setDialogTitle(dialog);
158-
dialog.addWindowListener(new WindowAdapter() {
156+
setDialogTitle();
157+
addWindowListener(new WindowAdapter() {
159158
@Override
160159
public void windowClosing(WindowEvent e) {
161-
market.setOfferingGoldenHello(goldenHelloCheckbox.isSelected());
162-
market.setCurrentApplicants(currentApplicants);
163-
dialog.dispose();
160+
closeAction();
164161
}
165162
});
166163

@@ -194,13 +191,28 @@ public void windowClosing(WindowEvent e) {
194191

195192
// This handles the initializing and display of the applicant panel
196193
JSplitPane splitPane = initializePersonView(selectedPerson, mainPanel);
197-
dialog.getContentPane().add(splitPane, BorderLayout.CENTER);
194+
getContentPane().add(splitPane, BorderLayout.CENTER);
198195

199196
// Finalize the dialog
200-
dialog.setModal(true);
201-
dialog.pack();
202-
dialog.setLocationRelativeTo(parent);
203-
dialog.setVisible(true);
197+
setModal(true);
198+
pack();
199+
setLocationRelativeTo(parent);
200+
setVisible(true);
201+
}
202+
203+
/**
204+
* Applies the current UI settings to the {@link NewPersonnelMarket} object and closes the dialog.
205+
*
206+
* <p>This method updates the market's "golden hello" offering status and the list of current applicants based on
207+
* the user selections, then disposes of the dialog.</p>
208+
*
209+
* @author Illiani
210+
* @since 0.50.07
211+
*/
212+
private void closeAction() {
213+
market.setOfferingGoldenHello(goldenHelloCheckbox.isSelected());
214+
market.setCurrentApplicants(currentApplicants);
215+
dispose();
204216
}
205217

206218

@@ -335,6 +347,10 @@ private JPanel initializeButtonPanel() {
335347
boolean isGM = campaign.isGM();
336348

337349
JPanel buttonPanel = new JPanel();
350+
JButton closeButton = new JButton(getTextAt(RESOURCE_BUNDLE, "button.personnelMarket.close"));
351+
closeButton.addActionListener(e -> closeAction());
352+
buttonPanel.add(closeButton);
353+
338354
JButton hireButton = new JButton(getTextAt(RESOURCE_BUNDLE, "button.personnelMarket.hire.normal"));
339355
hireButton.addActionListener(e -> hireActionListener(isGM));
340356
buttonPanel.add(hireButton);
@@ -480,25 +496,23 @@ private void hireActionListener(boolean isGM) {
480496
/**
481497
* Sets the dialog's title based on market and campaign context.
482498
*
483-
* @param dialog the dialog window to set the title on
484-
*
485499
* @author Illiani
486500
* @since 0.50.06
487501
*/
488-
private void setDialogTitle(JDialog dialog) {
502+
private void setDialogTitle() {
489503
Faction campaignFaction = campaign.getFaction();
490504
if (campaignFaction.isClan()) {
491-
dialog.setTitle(getTextAt(RESOURCE_BUNDLE, "title.personnelMarket.clan"));
505+
setTitle(getTextAt(RESOURCE_BUNDLE, "title.personnelMarket.clan"));
492506
} else if (campaignFaction.isComStarOrWoB()) {
493507
Person commander = campaign.getFlaggedCommander();
494508
String address = commander != null ? commander.getTitleAndSurname() : campaign.getCommanderAddress(false);
495-
dialog.setTitle(getFormattedTextAt(RESOURCE_BUNDLE,
509+
setTitle(getFormattedTextAt(RESOURCE_BUNDLE,
496510
"title.personnelMarket.comStarOrWoB",
497511
address.toUpperCase()));
498512
} else if (campaignFaction.isMercenary()) {
499-
dialog.setTitle(getTextAt(RESOURCE_BUNDLE, "title.personnelMarket.mercenary"));
513+
setTitle(getTextAt(RESOURCE_BUNDLE, "title.personnelMarket.mercenary"));
500514
} else if (campaignFaction.isMercenary()) {
501-
dialog.setTitle(getTextAt(RESOURCE_BUNDLE, "title.personnelMarket.normal"));
515+
setTitle(getTextAt(RESOURCE_BUNDLE, "title.personnelMarket.normal"));
502516
}
503517
}
504518

0 commit comments

Comments
 (0)