Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base Components #2440

Merged
merged 18 commits into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion MekHQ/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ dependencies {
implementation 'org.apache.commons:commons-csv:1.4'
implementation 'javax.vecmath:vecmath:1.5.2'
implementation 'com.atlassian.commonmark:commonmark:0.13.0'
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.8'

jarbundler 'com.ultramixer.jarbundler:jarbundler-core:3.3.0'

Expand Down
4 changes: 0 additions & 4 deletions MekHQ/mmconf/shared.properties

This file was deleted.

19 changes: 19 additions & 0 deletions MekHQ/resources/mekhq/resources/GUI.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is used to store any mekhq/gui Resources

#### General GUI Resources
#### These are repeated multiple times across the GUI to mean the same thing, and thus can be kept here
AddGM.text=Add (GM)
Apply.text=Apply
Cancel.text=Cancel
Cancel.toolTipText=Cancel out of the dialog. No changes made will be saved.
Close.text=Close
Export.text=Export
Faction.text=Faction
FactionSpecific.text=Faction Specific
Generate.text=Generate
Import.text=Import
Ok.text=Ok
Ok.toolTipText=Confirm the changes and close the dialog.
Purchase.text=Purchase
Remove.text=Remove
RestoreDefaults.text=Restore Defaults
8 changes: 5 additions & 3 deletions MekHQ/resources/mekhq/resources/MekHqOptionsDialog.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
dialog.text=MekHQ Options
okButton.text=Ok
cancelButton.text=Cancel
MekHQOptionsDialog.title=MekHQ Options
Ok.text=Ok
Ok.toolTipText=Confirm the changes and close the dialog.
Cancel.text=Cancel
Cancel.toolTipText=Cancel out of the dialog. No changes made will be saved.

#Display Tab
displayTab.title=Display Options
Expand Down
12 changes: 6 additions & 6 deletions MekHQ/src/mekhq/MekHQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import megamek.client.Client;
import megamek.client.generator.RandomNameGenerator;
import megamek.client.generator.RandomUnitGenerator;
import megamek.client.ui.preferences.MMPreferences;
import megamek.client.ui.swing.gameConnectionDialogs.ConnectDialog;
import megamek.client.ui.swing.gameConnectionDialogs.HostDialog;
import megamek.common.event.EventBus;
Expand Down Expand Up @@ -84,8 +85,7 @@
import mekhq.gui.dialog.RetirementDefectionDialog;
import mekhq.gui.preferences.StringPreference;
import mekhq.gui.utilities.ObservableString;
import mekhq.preferences.MekHqPreferences;
import mekhq.preferences.PreferencesNode;
import megamek.client.ui.preferences.PreferencesNode;
import mekhq.service.AutosaveService;
import mekhq.service.IAutosaveService;

Expand All @@ -106,7 +106,7 @@ public class MekHQ implements GameListener {
private static ObservableString selectedTheme;

private static MMLogger logger = null;
private static MekHqPreferences preferences = null;
private static MMPreferences preferences = null;
private static MekHQOptions mekHQOptions = new MekHQOptions();

// Directory options
Expand Down Expand Up @@ -179,9 +179,9 @@ public static MMLogger getLogger() {
return logger;
}

public static MekHqPreferences getPreferences() {
if (null == preferences) {
preferences = new MekHqPreferences();
public static MMPreferences getPreferences() {
if (preferences == null) {
preferences = new MMPreferences();
}

return preferences;
Expand Down
24 changes: 8 additions & 16 deletions MekHQ/src/mekhq/gui/CampaignGUI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* CampaignGUI.java
*
* Copyright (c) 2009 Jay Lawson <jaylawson39 at yahoo.com>. All rights reserved.
* Copyright (c) 2009 - Jay Lawson <jaylawson39 at yahoo.com>. All Rights Reserved.
* Copyright (c) 2021 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
Expand Down Expand Up @@ -41,8 +42,8 @@
import mekhq.MekHqConstants;
import mekhq.campaign.finances.Money;
import mekhq.gui.dialog.*;
import mekhq.gui.preferences.JWindowPreference;
import mekhq.preferences.PreferencesNode;
import megamek.client.ui.preferences.JWindowPreference;
import megamek.client.ui.preferences.PreferencesNode;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -665,24 +666,24 @@ private void initMenu() {
menuFile.add(menuExport);
//endregion menuExport

JMenuItem miMercRoster = new JMenuItem(resourceMap.getString("miMercRoster.text")); // NOI18N
JMenuItem miMercRoster = new JMenuItem(resourceMap.getString("miMercRoster.text"));
miMercRoster.setMnemonic(KeyEvent.VK_U);
miMercRoster.addActionListener(evt -> showMercRosterDialog());
menuFile.add(miMercRoster);

JMenuItem menuOptions = new JMenuItem(resourceMap.getString("menuOptions.text")); // NOI18N
JMenuItem menuOptions = new JMenuItem(resourceMap.getString("menuOptions.text"));
menuOptions.setMnemonic(KeyEvent.VK_C);
menuOptions.addActionListener(this::menuOptionsActionPerformed);
menuFile.add(menuOptions);

JMenuItem menuOptionsMM = new JMenuItem(resourceMap.getString("menuOptionsMM.text")); // NOI18N
JMenuItem menuOptionsMM = new JMenuItem(resourceMap.getString("menuOptionsMM.text"));
menuOptionsMM.setMnemonic(KeyEvent.VK_M);
menuOptionsMM.addActionListener(this::menuOptionsMMActionPerformed);
menuFile.add(menuOptionsMM);

JMenuItem menuMekHqOptions = new JMenuItem(resourceMap.getString("menuMekHqOptions.text"));
menuMekHqOptions.setMnemonic(KeyEvent.VK_H);
menuMekHqOptions.addActionListener(this::menuMekHqOptionsActionPerformed);
menuMekHqOptions.addActionListener(evt -> new MekHqOptionsDialog(getFrame()).setVisible(true));
menuFile.add(menuMekHqOptions);

menuThemes = new JMenu(resourceMap.getString("menuThemes.text"));
Expand Down Expand Up @@ -1341,10 +1342,6 @@ private File selectSaveCampaignFile() {
return FileDialogs.saveCampaign(frame, getCampaign()).orElse(null);
}

private String getExtensionForSaveFile(Campaign c) {
return MekHQ.getMekHQOptions().getPreferGzippedOutput() ? ".cpnx.gz" : ".cpnx";
}

private void menuLoadXmlActionPerformed(java.awt.event.ActionEvent evt) {
File f = selectLoadCampaignFile();
if (null == f) {
Expand Down Expand Up @@ -1468,11 +1465,6 @@ private void menuOptionsMMActionPerformed(java.awt.event.ActionEvent evt) {
}
}

private void menuMekHqOptionsActionPerformed(ActionEvent evt) {
MekHqOptionsDialog dialog = new MekHqOptionsDialog(getFrame());
dialog.setVisible(true);
}

private void miLoadForcesActionPerformed(java.awt.event.ActionEvent evt) {
loadListFile(true);
}
Expand Down
6 changes: 3 additions & 3 deletions MekHQ/src/mekhq/gui/HangarTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
import mekhq.gui.adapter.UnitTableMouseAdapter;
import mekhq.gui.model.UnitTableModel;
import mekhq.gui.model.XTableColumnModel;
import mekhq.gui.preferences.JComboBoxPreference;
import mekhq.gui.preferences.JTablePreference;
import megamek.client.ui.preferences.JComboBoxPreference;
import megamek.client.ui.preferences.JTablePreference;
import mekhq.gui.sorter.*;
import mekhq.gui.view.UnitViewPanel;
import mekhq.preferences.PreferencesNode;
import megamek.client.ui.preferences.PreferencesNode;

/**
* Displays table of all units in the force.
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/gui/MekHqColors.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import mekhq.MekHQ;
import mekhq.gui.preferences.ColorPreference;
import mekhq.preferences.PreferencesNode;
import megamek.client.ui.preferences.PreferencesNode;

public class MekHqColors {

Expand Down
8 changes: 4 additions & 4 deletions MekHQ/src/mekhq/gui/PersonnelTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
import mekhq.gui.enums.PersonnelTabView;
import mekhq.gui.model.PersonnelTableModel;
import mekhq.gui.model.XTableColumnModel;
import mekhq.gui.preferences.JComboBoxPreference;
import mekhq.gui.preferences.JTablePreference;
import mekhq.gui.preferences.JToggleButtonPreference;
import megamek.client.ui.preferences.JComboBoxPreference;
import megamek.client.ui.preferences.JTablePreference;
import megamek.client.ui.preferences.JToggleButtonPreference;
import mekhq.gui.sorter.*;
import mekhq.gui.view.PersonViewPanel;
import mekhq.preferences.PreferencesNode;
import megamek.client.ui.preferences.PreferencesNode;

/**
* Tab for interacting with all personnel
Expand Down
4 changes: 2 additions & 2 deletions MekHQ/src/mekhq/gui/RepairTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
import mekhq.gui.model.TechTableModel;
import mekhq.gui.model.UnitTableModel;
import mekhq.gui.model.XTableColumnModel;
import mekhq.gui.preferences.JTablePreference;
import megamek.client.ui.preferences.JTablePreference;
import mekhq.gui.sorter.TaskSorter;
import mekhq.gui.sorter.TechSorter;
import mekhq.gui.sorter.UnitStatusSorter;
import mekhq.gui.sorter.UnitTypeSorter;
import mekhq.preferences.PreferencesNode;
import megamek.client.ui.preferences.PreferencesNode;
import mekhq.service.MassRepairService;
import mekhq.service.PartsAcquisitionService;

Expand Down
6 changes: 3 additions & 3 deletions MekHQ/src/mekhq/gui/WarehouseTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
import mekhq.gui.adapter.PartsTableMouseAdapter;
import mekhq.gui.model.PartsTableModel;
import mekhq.gui.model.TechTableModel;
import mekhq.gui.preferences.JComboBoxPreference;
import mekhq.gui.preferences.JTablePreference;
import megamek.client.ui.preferences.JComboBoxPreference;
import megamek.client.ui.preferences.JTablePreference;
import mekhq.gui.sorter.FormattedNumberSorter;
import mekhq.gui.sorter.PartsDetailSorter;
import mekhq.gui.sorter.TechSorter;
import mekhq.preferences.PreferencesNode;
import megamek.client.ui.preferences.PreferencesNode;

/**
* Displays all spare parts in stock, parts on order, and permits repair of damaged
Expand Down
77 changes: 77 additions & 0 deletions MekHQ/src/mekhq/gui/baseComponents/AbstractMHQButtonDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2021 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
* MekHQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MekHQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MekHQ. If not, see <http://www.gnu.org/licenses/>.
*/
package mekhq.gui.baseComponents;

import megamek.client.ui.baseComponents.AbstractButtonDialog;
import megamek.common.util.EncodeControl;
import mekhq.MekHQ;

import javax.swing.*;
import java.util.ResourceBundle;

/**
* This is the Base Dialog for a dialog with buttons in MegaMek. It extends Base Dialog, and adds a
* button panel with base Ok and Cancel buttons. It also includes an enum tracker for the result of
* the dialog.
*
* Inheriting classes must call initialize() in their constructors and override createCenterPane()
*
* The resources associated with this dialog need to contain at least the following keys:
* - "Ok.text" -> text for the ok button
* - "Ok.toolTipText" -> toolTipText for the ok button
* - "Cancel.text" -> text for the cancel button
* - "Cancel.toolTipText" -> toolTipText for the cancel button
*/
public abstract class AbstractMHQButtonDialog extends AbstractButtonDialog {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta ask, what's different about a MekHQ button from a MegaMek button?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solely tracking on MHQ's preferencez instead of MM's.

Otherwise the dialogs are identical.

//region Constructors
/**
* This creates a modal AbstractMHQButtonDialog using the default MHQ resource bundle. This is
* the normal constructor to use for an AbstractMHQButtonDialog.
*/
protected AbstractMHQButtonDialog(final JFrame frame, final String name, final String title) {
this(frame, true, name, title);
}

/**
* This creates an AbstractMHQButtonDialog using the default MHQ resource bundle. It allows one
* to create non-modal button dialogs, which is not recommended by default.
*/
protected AbstractMHQButtonDialog(final JFrame frame, final boolean modal, final String name,
final String title) {
this(frame, modal, ResourceBundle.getBundle("mekhq.resources.GUI", new EncodeControl()), name, title);
}

/**
* This creates an AbstractMHQButtonDialog using the specified resource bundle. This is not
* recommended by default.
*/
protected AbstractMHQButtonDialog(final JFrame frame, final boolean modal, final ResourceBundle resources,
final String name, final String title) {
super(frame, modal, resources, name, title);
}
//endregion Constructors

/**
* This override forces the preferences for this class to be tracked in MekHQ instead of MegaMek
*/
@Override
protected void setPreferences() {
setPreferences(MekHQ.getPreferences().forClass(getClass()));
}
}
69 changes: 69 additions & 0 deletions MekHQ/src/mekhq/gui/baseComponents/AbstractMHQDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2021 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
* MekHQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MekHQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MekHQ. If not, see <http://www.gnu.org/licenses/>.
*/
package mekhq.gui.baseComponents;

import megamek.client.ui.baseComponents.AbstractDialog;
import megamek.common.util.EncodeControl;
import mekhq.MekHQ;

import javax.swing.*;
import java.util.ResourceBundle;

/**
* This is the base class for dialogs in MegaMek. This class handles setting the UI, managing the X
* button, managing the escape key, and saving the dialog preferences.
*
* Inheriting classes must call initialize() in their constructors and override createCenterPane()
*/
public abstract class AbstractMHQDialog extends AbstractDialog {
//region Constructors
/**
* This creates a non-modal AbstractMHQDialog using the default MHQ resource bundle. This is
* the normal constructor to use for an AbstractMHQDialog.
*/
protected AbstractMHQDialog(final JFrame frame, final String name, final String title) {
this(frame, false, name, title);
}

/**
* This creates an AbstractMHQDialog using the default MHQ resource bundle. It allows one
* to create modal dialogs.
*/
protected AbstractMHQDialog(final JFrame frame, final boolean modal, final String name, final String title) {
this(frame, modal, ResourceBundle.getBundle("mekhq.resources.GUI", new EncodeControl()), name, title);
}

/**
* This creates an AbstractMHQDialog using the specified resource bundle. This is not recommended
* by default.
*/
protected AbstractMHQDialog(final JFrame frame, final boolean modal, final ResourceBundle resources,
final String name, final String title) {
super(frame, modal, resources, name, title);
}
//endregion Constructors

/**
* This override forces the preferences for this class to be tracked in MekHQ instead of MegaMek
*/
@Override
protected void setPreferences() {
setPreferences(MekHQ.getPreferences().forClass(getClass()));
}
}
Loading