diff --git a/MekHQ/build.gradle b/MekHQ/build.gradle index 6c8bfa1884..547c051c4b 100644 --- a/MekHQ/build.gradle +++ b/MekHQ/build.gradle @@ -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' diff --git a/MekHQ/mmconf/shared.properties b/MekHQ/mmconf/shared.properties deleted file mode 100644 index 14cb1f71fe..0000000000 --- a/MekHQ/mmconf/shared.properties +++ /dev/null @@ -1,4 +0,0 @@ -# Properties file used for shared configuration between Megamek and any -# third party applications using Megamek. For example, MekHQ and Mekwars. - -megamek.CommonMenuBar.helpFilePath=docs/1-Readme/readme.txt \ No newline at end of file diff --git a/MekHQ/resources/mekhq/resources/GUI.properties b/MekHQ/resources/mekhq/resources/GUI.properties new file mode 100644 index 0000000000..f2e6e508ec --- /dev/null +++ b/MekHQ/resources/mekhq/resources/GUI.properties @@ -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 diff --git a/MekHQ/resources/mekhq/resources/MekHqOptionsDialog.properties b/MekHQ/resources/mekhq/resources/MekHqOptionsDialog.properties index 3274e777d1..ec80cc3d92 100644 --- a/MekHQ/resources/mekhq/resources/MekHqOptionsDialog.properties +++ b/MekHQ/resources/mekhq/resources/MekHqOptionsDialog.properties @@ -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 diff --git a/MekHQ/src/mekhq/MekHQ.java b/MekHQ/src/mekhq/MekHQ.java index 0254c11f34..f636a47897 100644 --- a/MekHQ/src/mekhq/MekHQ.java +++ b/MekHQ/src/mekhq/MekHQ.java @@ -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; @@ -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; @@ -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 @@ -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; diff --git a/MekHQ/src/mekhq/gui/CampaignGUI.java b/MekHQ/src/mekhq/gui/CampaignGUI.java index ad607609c7..5c525b2216 100644 --- a/MekHQ/src/mekhq/gui/CampaignGUI.java +++ b/MekHQ/src/mekhq/gui/CampaignGUI.java @@ -1,7 +1,8 @@ /* * CampaignGUI.java * - * Copyright (c) 2009 Jay Lawson . All rights reserved. + * Copyright (c) 2009 - Jay Lawson . All Rights Reserved. + * Copyright (c) 2021 - The MegaMek Team. All Rights Reserved. * * This file is part of MekHQ. * @@ -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; @@ -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")); @@ -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) { @@ -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); } diff --git a/MekHQ/src/mekhq/gui/HangarTab.java b/MekHQ/src/mekhq/gui/HangarTab.java index b903833bb1..e2efe3a618 100644 --- a/MekHQ/src/mekhq/gui/HangarTab.java +++ b/MekHQ/src/mekhq/gui/HangarTab.java @@ -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. diff --git a/MekHQ/src/mekhq/gui/MekHqColors.java b/MekHQ/src/mekhq/gui/MekHqColors.java index e5878860ba..6fe7f4265a 100644 --- a/MekHQ/src/mekhq/gui/MekHqColors.java +++ b/MekHQ/src/mekhq/gui/MekHqColors.java @@ -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 { diff --git a/MekHQ/src/mekhq/gui/PersonnelTab.java b/MekHQ/src/mekhq/gui/PersonnelTab.java index 1f58fc7bf9..98932eac0c 100644 --- a/MekHQ/src/mekhq/gui/PersonnelTab.java +++ b/MekHQ/src/mekhq/gui/PersonnelTab.java @@ -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 diff --git a/MekHQ/src/mekhq/gui/RepairTab.java b/MekHQ/src/mekhq/gui/RepairTab.java index ca4aa89bf8..22170a61b3 100644 --- a/MekHQ/src/mekhq/gui/RepairTab.java +++ b/MekHQ/src/mekhq/gui/RepairTab.java @@ -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; diff --git a/MekHQ/src/mekhq/gui/WarehouseTab.java b/MekHQ/src/mekhq/gui/WarehouseTab.java index aa9f157eb2..140ee96d02 100644 --- a/MekHQ/src/mekhq/gui/WarehouseTab.java +++ b/MekHQ/src/mekhq/gui/WarehouseTab.java @@ -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 diff --git a/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQButtonDialog.java b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQButtonDialog.java new file mode 100644 index 0000000000..71ae6e61b5 --- /dev/null +++ b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQButtonDialog.java @@ -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 . + */ +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 { + //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())); + } +} diff --git a/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQDialog.java b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQDialog.java new file mode 100644 index 0000000000..c0cd3a8164 --- /dev/null +++ b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQDialog.java @@ -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 . + */ +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())); + } +} diff --git a/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQScrollPane.java b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQScrollPane.java new file mode 100644 index 0000000000..13bf1ce13d --- /dev/null +++ b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQScrollPane.java @@ -0,0 +1,70 @@ +/* + * 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 . + */ +package mekhq.gui.baseComponents; + +import megamek.client.ui.baseComponents.AbstractScrollPane; +import megamek.common.util.EncodeControl; +import mekhq.MekHQ; + +import javax.swing.*; +import java.util.ResourceBundle; + +/** + * This is the default ScrollPane. It handles preferences, resources, and the frame. + * + * Inheriting classes must call initialize() in their constructors and override initialize(). + */ +public abstract class AbstractMHQScrollPane extends AbstractScrollPane { + //region Constructors + /** + * This creates an AbstractMHQScrollPane using the default MHQ resource bundle and using the + * default of vertical and horizontal scrollbars as required. + */ + protected AbstractMHQScrollPane(final JFrame frame, final String name) { + this(frame, name, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + } + + /** + * This creates an AbstractMHQScrollPane using the default MHQ resource bundle and using the + * specified scrollbar policies. + */ + protected AbstractMHQScrollPane(final JFrame frame, final String name, + final int verticalScrollBarPolicy, final int horizontalScrollBarPolicy) { + this(frame, ResourceBundle.getBundle("mekhq.resources.GUI", new EncodeControl()), + name, verticalScrollBarPolicy, horizontalScrollBarPolicy); + } + + /** + * This creates an AbstractMHQScrollPane using the specified resource bundle and using the + * default of vertical and horizontal scrollbars as required. This is not recommended by default. + */ + protected AbstractMHQScrollPane(final JFrame frame, final ResourceBundle resources, final String name, + final int verticalScrollBarPolicy, final int horizontalScrollBarPolicy) { + super(frame, resources, name, verticalScrollBarPolicy, horizontalScrollBarPolicy); + } + //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())); + } +} diff --git a/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQSplitPane.java b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQSplitPane.java new file mode 100644 index 0000000000..930a12c3fc --- /dev/null +++ b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQSplitPane.java @@ -0,0 +1,60 @@ +/* + * 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 . + */ +package mekhq.gui.baseComponents; + +import megamek.client.ui.baseComponents.AbstractSplitPane; +import megamek.common.util.EncodeControl; +import mekhq.MekHQ; + +import javax.swing.*; +import java.util.ResourceBundle; + +/** + * This is the default SplitPane. It handles preferences, resources, the frame, and setup. + * + * Inheriting classes must call initialize() in their constructors and override createLeftComponent() + * and createRightComponent() + */ +public abstract class AbstractMHQSplitPane extends AbstractSplitPane { + //region Constructors + /** + * This creates an AbstractMHQSplitPane using the default MHQ resource bundle. This is the + * normal constructor to use for an AbstractMHQSplitPane. + */ + protected AbstractMHQSplitPane(final JFrame frame, final String name) { + this(frame, ResourceBundle.getBundle("mekhq.resources.GUI", new EncodeControl()), name); + } + + /** + * This creates an AbstractMHQSplitPane using the specified resource bundle. This is not recommended + * by default. + */ + protected AbstractMHQSplitPane(final JFrame frame, final ResourceBundle resources, final String name) { + super(frame, resources, name); + } + //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())); + } +} diff --git a/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQTabbedPane.java b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQTabbedPane.java new file mode 100644 index 0000000000..bddfec0070 --- /dev/null +++ b/MekHQ/src/mekhq/gui/baseComponents/AbstractMHQTabbedPane.java @@ -0,0 +1,59 @@ +/* + * 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 . + */ +package mekhq.gui.baseComponents; + +import megamek.client.ui.baseComponents.AbstractTabbedPane; +import megamek.common.util.EncodeControl; +import mekhq.MekHQ; + +import javax.swing.*; +import java.util.ResourceBundle; + +/** + * This is the default TabbedPane. It handles preferences, resources, and the frame. + * + * Inheriting classes must call initialize() in their constructors and override initialize() + */ +public abstract class AbstractMHQTabbedPane extends AbstractTabbedPane { + //region Constructors + /** + * This creates an AbstractMHQTabbedPane using the default MHQ resource bundle. This is the + * normal constructor to use for an AbstractMHQTabbedPane. + */ + protected AbstractMHQTabbedPane(final JFrame frame, final String name) { + this(frame, ResourceBundle.getBundle("mekhq.resources.GUI", new EncodeControl()), name); + } + + /** + * This creates an AbstractMHQTabbedPane using the specified resource bundle. This is not recommended + * by default. + */ + protected AbstractMHQTabbedPane(final JFrame frame, final ResourceBundle resources, final String name) { + super(frame, resources, name); + } + //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())); + } +} diff --git a/MekHQ/src/mekhq/gui/dialog/AcquisitionsDialog.java b/MekHQ/src/mekhq/gui/dialog/AcquisitionsDialog.java index f8e286ae16..132f63e201 100644 --- a/MekHQ/src/mekhq/gui/dialog/AcquisitionsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/AcquisitionsDialog.java @@ -37,8 +37,8 @@ import mekhq.gui.CampaignGUI; import mekhq.gui.GuiTabType; import mekhq.gui.RepairTab; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import mekhq.service.PartsAcquisitionService; import mekhq.service.PartsAcquisitionService.PartCountInfo; diff --git a/MekHQ/src/mekhq/gui/dialog/AddFundsDialog.java b/MekHQ/src/mekhq/gui/dialog/AddFundsDialog.java index 5f261f09c9..bc051a5bb2 100644 --- a/MekHQ/src/mekhq/gui/dialog/AddFundsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/AddFundsDialog.java @@ -27,9 +27,9 @@ import mekhq.MekHQ; import mekhq.campaign.finances.Money; import mekhq.campaign.finances.Transaction; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.utilities.JMoneyTextField; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * diff --git a/MekHQ/src/mekhq/gui/dialog/AddOrEditKillEntryDialog.java b/MekHQ/src/mekhq/gui/dialog/AddOrEditKillEntryDialog.java index b512abca43..6c36d3c43a 100644 --- a/MekHQ/src/mekhq/gui/dialog/AddOrEditKillEntryDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/AddOrEditKillEntryDialog.java @@ -31,8 +31,8 @@ import megamek.common.util.EncodeControl; import mekhq.MekHQ; import mekhq.campaign.Kill; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import javax.swing.*; diff --git a/MekHQ/src/mekhq/gui/dialog/AddOrEditMissionEntryDialog.java b/MekHQ/src/mekhq/gui/dialog/AddOrEditMissionEntryDialog.java index 4a3d370a8f..5becdd6349 100644 --- a/MekHQ/src/mekhq/gui/dialog/AddOrEditMissionEntryDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/AddOrEditMissionEntryDialog.java @@ -22,8 +22,8 @@ import mekhq.MekHQ; import mekhq.campaign.log.LogEntry; import mekhq.campaign.log.ServiceLogEntry; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import javax.swing.*; import java.awt.*; diff --git a/MekHQ/src/mekhq/gui/dialog/AddOrEditPersonnelEntryDialog.java b/MekHQ/src/mekhq/gui/dialog/AddOrEditPersonnelEntryDialog.java index 3c8f637db5..7378a23cd8 100644 --- a/MekHQ/src/mekhq/gui/dialog/AddOrEditPersonnelEntryDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/AddOrEditPersonnelEntryDialog.java @@ -34,8 +34,8 @@ import mekhq.MekHQ; import mekhq.campaign.log.LogEntry; import mekhq.campaign.log.PersonalLogEntry; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/AdvanceDaysDialog.java b/MekHQ/src/mekhq/gui/dialog/AdvanceDaysDialog.java index 87eea3a3b9..8c8d7667f2 100644 --- a/MekHQ/src/mekhq/gui/dialog/AdvanceDaysDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/AdvanceDaysDialog.java @@ -41,9 +41,9 @@ import mekhq.campaign.event.ReportEvent; import mekhq.gui.CampaignGUI; import mekhq.gui.DailyReportLogPanel; -import mekhq.gui.preferences.JIntNumberSpinnerPreference; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JIntNumberSpinnerPreference; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Dylan Myers diff --git a/MekHQ/src/mekhq/gui/dialog/BaseDialog.java b/MekHQ/src/mekhq/gui/dialog/BaseDialog.java deleted file mode 100644 index 735892c94d..0000000000 --- a/MekHQ/src/mekhq/gui/dialog/BaseDialog.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * BaseDialog.java - * - * Copyright (c) 2019 - 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 . - */ -package mekhq.gui.dialog; - -import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import java.util.ResourceBundle; - -/* - * Base class for dialogs in MekHQ. This class handles setting the UI, - * managing the Ok/Cancel buttons, managing the X button, and saving the dialog preferences. - * - * A class that inherits from this class needs to at least implement the method - * setCustomUI which will create the custom UI dialog. - * The methods setCustomPreferences, okAction, and cancelAction allow to customize - * further the behavior of the dialog by child classes. - * - * The dialog will be constructed by the child class calling the initialize method. - * - * The resources associated with this dialog need to contain at least the following keys: - * - dialog.text -> title of the dialog - * - okButton.text -> text for the ok button - * - cancelButton.text -> text for the cancel button - */ -public abstract class BaseDialog extends JDialog implements WindowListener { - private ResourceBundle resources; - private DialogResult result; - - protected BaseDialog(JFrame parent) { - this(parent, false); - } - - protected BaseDialog(JFrame parent, boolean isModal) { - super(parent); - - this.addWindowListener(this); - this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - this.setModal(isModal); - } - - /** - * Result of closing the dialog. - * @return - */ - public DialogResult getResult() { - return this.result; - } - - /** - * Initializes the dialog UI and preferences. Needs to be called by - * child classes for initial setup. - * @param resources the resources needed for this dialog - */ - protected final void initialize(ResourceBundle resources) { - assert resources != null; - - this.resources = resources; - this.createUI(); - - this.pack(); - this.setPreferences(); - } - - /** - * Creates the custom UI (body) for the dialog. - * This custom UI will be placed in the BorderLayout.CENTER. - * @return - */ - protected abstract Container createCustomUI(); - - /** - * Adds custom preferences to this dialog. - * - * By default, this dialog will track preferences related to the size - * and position of the dialog. Other preferences should be added by overriding - * this method. - * @param preferences - */ - protected void setCustomPreferences(PreferencesNode preferences) { - } - - /** - * Action performed when the ok button is clicked. - */ - protected void okAction() { - } - - /** - * Action performed when the cancel button is clicked or - * when the dialog is closed by the X button. - */ - protected void cancelAction() { - } - - private void createUI() { - this.setTitle(resources.getString("dialog.text")); - - // Main body of the dialog - this.getContentPane().add(this.createCustomUI(), BorderLayout.CENTER); - - // Ok/Cancel buttons - JButton okButton = new JButton(resources.getString("okButton.text")); - okButton.addActionListener(this::okButtonActionPerformed); - okButton.requestFocus(); - - JButton cancelButton = new JButton(resources.getString("cancelButton.text")); - cancelButton.addActionListener(this::cancelButtonActionPerformed); - - // Layout buttons - JPanel buttonsPanel = new JPanel(new GridLayout(1, 2)); - buttonsPanel.add(okButton); - buttonsPanel.add(cancelButton); - JPanel bottom = new JPanel(new GridBagLayout()); - bottom.add(buttonsPanel); - this.getContentPane().add(bottom, BorderLayout.PAGE_END); - } - - private void setPreferences() { - PreferencesNode preferences = MekHQ.getPreferences().forClass(getClass()); - - preferences.manage(new JWindowPreference(this)); - this.setCustomPreferences(preferences); - } - - private void okButtonActionPerformed(ActionEvent evt) { - this.okAction(); - this.result = DialogResult.OK; - this.dispose(); - } - - /** - * Notes: cancelling a dialog should always allow to close the dialog. - */ - private void cancelButtonActionPerformed(ActionEvent evt) { - try { - this.cancelAction(); - } catch (Exception e) { - MekHQ.getLogger().error(e); - } - finally { - this.result = DialogResult.CANCEL; - this.dispose(); - } - } - - /** - * Notes: closing the dialog should always allow to close the dialog. - */ - @Override - public void windowClosing(WindowEvent e) { - try { - this.cancelAction(); - } catch (Exception ex) { - MekHQ.getLogger().error(ex); - } - finally { - this.result = DialogResult.CANCEL; - } - } - - @Override - public void windowOpened(WindowEvent e) { - } - - @Override - public void windowClosed(WindowEvent e) { - } - - @Override - public void windowIconified(WindowEvent e){ - } - - @Override - public void windowDeiconified(WindowEvent e){ - } - - @Override - public void windowActivated(WindowEvent e) { - } - - @Override - public void windowDeactivated(WindowEvent e) { - } -} diff --git a/MekHQ/src/mekhq/gui/dialog/BatchXPDialog.java b/MekHQ/src/mekhq/gui/dialog/BatchXPDialog.java index e2146ab8d9..a50a1f5fa8 100644 --- a/MekHQ/src/mekhq/gui/dialog/BatchXPDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/BatchXPDialog.java @@ -58,14 +58,14 @@ import mekhq.campaign.personnel.SkillType; import mekhq.gui.model.PersonnelTableModel; import mekhq.gui.model.RankTableModel; -import mekhq.gui.preferences.JComboBoxPreference; -import mekhq.gui.preferences.JIntNumberSpinnerPreference; -import mekhq.gui.preferences.JToggleButtonPreference; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JComboBoxPreference; +import megamek.client.ui.preferences.JIntNumberSpinnerPreference; +import megamek.client.ui.preferences.JToggleButtonPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.sorter.FormattedNumberSorter; import mekhq.gui.sorter.RankSorter; import mekhq.gui.utilities.MekHqTableCellRenderer; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; public final class BatchXPDialog extends JDialog { private static final long serialVersionUID = -7897406116865495209L; diff --git a/MekHQ/src/mekhq/gui/dialog/BombsDialog.java b/MekHQ/src/mekhq/gui/dialog/BombsDialog.java index 1917eb7760..9e2d9336be 100644 --- a/MekHQ/src/mekhq/gui/dialog/BombsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/BombsDialog.java @@ -41,8 +41,8 @@ import mekhq.campaign.Campaign; import mekhq.campaign.parts.AmmoStorage; import mekhq.campaign.parts.equipment.EquipmentPart; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Deric Page (dericpage@users.sourceforge.net) diff --git a/MekHQ/src/mekhq/gui/dialog/CampaignOptionsDialog.java b/MekHQ/src/mekhq/gui/dialog/CampaignOptionsDialog.java index 41597f1988..06b7819d38 100644 --- a/MekHQ/src/mekhq/gui/dialog/CampaignOptionsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/CampaignOptionsDialog.java @@ -105,10 +105,11 @@ import mekhq.gui.SpecialAbilityPanel; import mekhq.gui.model.RankTableModel; import mekhq.gui.model.SortedComboBoxModel; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; +import mekhq.gui.utilities.TableCellListener; import mekhq.module.PersonnelMarketServiceManager; import mekhq.module.api.PersonnelMarketMethod; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Jay Lawson diff --git a/MekHQ/src/mekhq/gui/dialog/ChooseFactionsDialog.java b/MekHQ/src/mekhq/gui/dialog/ChooseFactionsDialog.java index 827872308d..1a7cdaff47 100644 --- a/MekHQ/src/mekhq/gui/dialog/ChooseFactionsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ChooseFactionsDialog.java @@ -41,8 +41,8 @@ import javax.swing.JScrollPane; import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import megamek.common.util.EncodeControl; import mekhq.campaign.universe.Faction; diff --git a/MekHQ/src/mekhq/gui/dialog/ChooseGamePresetDialog.java b/MekHQ/src/mekhq/gui/dialog/ChooseGamePresetDialog.java index ac03d7a724..4482272632 100644 --- a/MekHQ/src/mekhq/gui/dialog/ChooseGamePresetDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ChooseGamePresetDialog.java @@ -38,8 +38,8 @@ import megamek.common.util.EncodeControl; import mekhq.MekHQ; import mekhq.campaign.GamePreset; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * This dialog will allow the users to choose from a set of possible game presets diff --git a/MekHQ/src/mekhq/gui/dialog/ChooseMulFilesDialog.java b/MekHQ/src/mekhq/gui/dialog/ChooseMulFilesDialog.java index 07cf3fb14e..39220bd598 100644 --- a/MekHQ/src/mekhq/gui/dialog/ChooseMulFilesDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ChooseMulFilesDialog.java @@ -29,8 +29,8 @@ import megamek.common.util.EncodeControl; import mekhq.MekHQ; import mekhq.campaign.ResolveScenarioTracker; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/ChooseRefitDialog.java b/MekHQ/src/mekhq/gui/dialog/ChooseRefitDialog.java index 92885bf18c..2afbddcde0 100644 --- a/MekHQ/src/mekhq/gui/dialog/ChooseRefitDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ChooseRefitDialog.java @@ -50,8 +50,8 @@ import mekhq.campaign.Campaign; import mekhq.campaign.parts.Refit; import mekhq.campaign.unit.Unit; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/CompleteMissionDialog.java b/MekHQ/src/mekhq/gui/dialog/CompleteMissionDialog.java index 183d619485..9032bf1c38 100644 --- a/MekHQ/src/mekhq/gui/dialog/CompleteMissionDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/CompleteMissionDialog.java @@ -27,8 +27,8 @@ import mekhq.MekHQ; import mekhq.campaign.mission.Mission; import mekhq.campaign.mission.enums.MissionStatus; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; public class CompleteMissionDialog extends javax.swing.JDialog { //region Variable Declarations diff --git a/MekHQ/src/mekhq/gui/dialog/ContractMarketDialog.java b/MekHQ/src/mekhq/gui/dialog/ContractMarketDialog.java index 76d66dfc22..20a365fbbe 100644 --- a/MekHQ/src/mekhq/gui/dialog/ContractMarketDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ContractMarketDialog.java @@ -33,11 +33,11 @@ import javax.swing.table.TableRowSorter; import mekhq.MekHQ; -import mekhq.gui.preferences.JIntNumberSpinnerPreference; -import mekhq.gui.preferences.JTablePreference; -import mekhq.gui.preferences.JToggleButtonPreference; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JIntNumberSpinnerPreference; +import megamek.client.ui.preferences.JTablePreference; +import megamek.client.ui.preferences.JToggleButtonPreference; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import megamek.common.util.EncodeControl; import mekhq.campaign.Campaign; diff --git a/MekHQ/src/mekhq/gui/dialog/CustomizeAtBContractDialog.java b/MekHQ/src/mekhq/gui/dialog/CustomizeAtBContractDialog.java index f090bb4d84..6bfbd5b772 100644 --- a/MekHQ/src/mekhq/gui/dialog/CustomizeAtBContractDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/CustomizeAtBContractDialog.java @@ -43,10 +43,10 @@ import mekhq.campaign.universe.RandomFactionGenerator; import mekhq.campaign.universe.Systems; import mekhq.gui.FactionComboBox; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.utilities.JSuggestField; import mekhq.gui.utilities.MarkdownEditorPanel; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Neoancient diff --git a/MekHQ/src/mekhq/gui/dialog/CustomizeMissionDialog.java b/MekHQ/src/mekhq/gui/dialog/CustomizeMissionDialog.java index 5831f7af83..ee33711164 100644 --- a/MekHQ/src/mekhq/gui/dialog/CustomizeMissionDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/CustomizeMissionDialog.java @@ -27,12 +27,12 @@ import mekhq.MekHQ; import mekhq.campaign.Campaign; import mekhq.campaign.mission.Mission; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.campaign.universe.PlanetarySystem; import mekhq.campaign.universe.Systems; import mekhq.gui.utilities.JSuggestField; import mekhq.gui.utilities.MarkdownEditorPanel; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/CustomizePersonDialog.java b/MekHQ/src/mekhq/gui/dialog/CustomizePersonDialog.java index 47dd596d1e..9199653b12 100644 --- a/MekHQ/src/mekhq/gui/dialog/CustomizePersonDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/CustomizePersonDialog.java @@ -56,9 +56,9 @@ import mekhq.gui.control.EditKillLogControl; import mekhq.gui.control.EditMissionLogControl; import mekhq.gui.control.EditPersonnelLogControl; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.utilities.MarkdownEditorPanel; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * This dialog is used to both hire new pilots and to edit existing ones diff --git a/MekHQ/src/mekhq/gui/dialog/CustomizeScenarioDialog.java b/MekHQ/src/mekhq/gui/dialog/CustomizeScenarioDialog.java index 99ebda0ecc..6bd7a56a95 100644 --- a/MekHQ/src/mekhq/gui/dialog/CustomizeScenarioDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/CustomizeScenarioDialog.java @@ -60,9 +60,9 @@ import mekhq.campaign.mission.atb.AtBScenarioModifier.EventTiming; import mekhq.gui.FileDialogs; import mekhq.gui.model.LootTableModel; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.utilities.MarkdownEditorPanel; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java b/MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java index 94a6c56fdf..938a9756c4 100644 --- a/MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java @@ -63,8 +63,8 @@ import mekhq.campaign.personnel.ranks.Ranks; import mekhq.campaign.universe.Factions; import mekhq.campaign.universe.RATManager; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import mekhq.campaign.universe.Systems; public class DataLoadingDialog extends JDialog implements PropertyChangeListener { diff --git a/MekHQ/src/mekhq/gui/dialog/DateChooser.java b/MekHQ/src/mekhq/gui/dialog/DateChooser.java index e5e1babbcb..bbbd7c0539 100644 --- a/MekHQ/src/mekhq/gui/dialog/DateChooser.java +++ b/MekHQ/src/mekhq/gui/dialog/DateChooser.java @@ -20,8 +20,8 @@ import javax.swing.text.DefaultFormatterFactory; import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * Hovanes Gambaryan Henry Demirchian CSUN, CS 585 Professor Mike Barnes diff --git a/MekHQ/src/mekhq/gui/dialog/DialogResult.java b/MekHQ/src/mekhq/gui/dialog/DialogResult.java deleted file mode 100644 index 01eaaba339..0000000000 --- a/MekHQ/src/mekhq/gui/dialog/DialogResult.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * DialogResult.java - * - * Copyright (c) 2019 MekHQ 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 . - */ - -package mekhq.gui.dialog; - -public enum DialogResult { - OK(1), - CANCEL(-1); - - private final int value; - - DialogResult(int value) { - this.value = value; - } -} diff --git a/MekHQ/src/mekhq/gui/dialog/EditAssetDialog.java b/MekHQ/src/mekhq/gui/dialog/EditAssetDialog.java index 3ee5a49345..bbf7659ac4 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditAssetDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditAssetDialog.java @@ -1,20 +1,20 @@ /* * EditAssetDialog.java - * + * * Copyright (c) 2009 Jay Lawson . 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 . */ @@ -30,9 +30,9 @@ import mekhq.MekHQ; import mekhq.campaign.finances.Asset; import mekhq.campaign.finances.Finances; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.utilities.JMoneyTextField; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @@ -50,7 +50,7 @@ public class EditAssetDialog extends JDialog { private JMoneyTextField assetIncomeField; private JComboBox choiceSchedule; boolean cancelled; - + public EditAssetDialog(Frame parent, Asset a) { super(parent, true); this.asset = a; @@ -65,7 +65,7 @@ private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(new java.awt.GridBagLayout()); - + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; @@ -86,7 +86,7 @@ private void initComponents() { gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(txtName, gridBagConstraints); - + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; @@ -109,7 +109,7 @@ private void initComponents() { gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(assetValueField, gridBagConstraints); - + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; @@ -132,7 +132,7 @@ private void initComponents() { gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(assetIncomeField, gridBagConstraints); - + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; @@ -140,7 +140,7 @@ private void initComponents() { gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(new JLabel("Income Schedule:"), gridBagConstraints); - + DefaultComboBoxModel scheduleModel = new DefaultComboBoxModel<>(); scheduleModel.addElement(Finances.getScheduleName(Finances.SCHEDULE_MONTHLY)); scheduleModel.addElement(Finances.getScheduleName(Finances.SCHEDULE_YEARLY)); @@ -200,12 +200,12 @@ private void btnOKActionPerformed(java.awt.event.ActionEvent evt) { try { asset.setValue(assetValueField.getMoney()); } catch(Exception ignored) { - + } try { asset.setIncome(assetIncomeField.getMoney()); } catch(Exception ignored) { - + } if(choiceSchedule.getSelectedIndex() == 1) { asset.setSchedule(Finances.SCHEDULE_YEARLY); @@ -219,7 +219,7 @@ private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) { cancelled = true; this.setVisible(false); } - + public boolean wasCancelled() { return cancelled; } diff --git a/MekHQ/src/mekhq/gui/dialog/EditInjuryEntryDialog.java b/MekHQ/src/mekhq/gui/dialog/EditInjuryEntryDialog.java index 230350e7f1..bf0230cf12 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditInjuryEntryDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditInjuryEntryDialog.java @@ -49,8 +49,8 @@ import mekhq.campaign.personnel.Injury; import mekhq.campaign.personnel.InjuryType; import mekhq.gui.model.FilterableComboBoxModel; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * diff --git a/MekHQ/src/mekhq/gui/dialog/EditKillLogDialog.java b/MekHQ/src/mekhq/gui/dialog/EditKillLogDialog.java index ff5346a582..db83e1e9d1 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditKillLogDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditKillLogDialog.java @@ -28,8 +28,8 @@ import mekhq.campaign.Campaign; import mekhq.campaign.personnel.Person; import mekhq.gui.control.EditKillLogControl; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import javax.swing.*; diff --git a/MekHQ/src/mekhq/gui/dialog/EditMissionLogDialog.java b/MekHQ/src/mekhq/gui/dialog/EditMissionLogDialog.java index a492535d81..ee2b93a925 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditMissionLogDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditMissionLogDialog.java @@ -23,8 +23,8 @@ import mekhq.campaign.Campaign; import mekhq.campaign.personnel.Person; import mekhq.gui.control.EditMissionLogControl; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import javax.swing.*; import java.awt.*; diff --git a/MekHQ/src/mekhq/gui/dialog/EditPersonnelHitsDialog.java b/MekHQ/src/mekhq/gui/dialog/EditPersonnelHitsDialog.java index f49fbacbce..0cf28d5c16 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditPersonnelHitsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditPersonnelHitsDialog.java @@ -38,8 +38,8 @@ import megamek.common.util.EncodeControl; import mekhq.MekHQ; import mekhq.campaign.personnel.Person; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * Provides an editor for the number of hits sustained by a person, diff --git a/MekHQ/src/mekhq/gui/dialog/EditPersonnelInjuriesDialog.java b/MekHQ/src/mekhq/gui/dialog/EditPersonnelInjuriesDialog.java index 609f19f722..2a63cbbec2 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditPersonnelInjuriesDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditPersonnelInjuriesDialog.java @@ -46,8 +46,8 @@ import mekhq.campaign.Campaign; import mekhq.campaign.personnel.Injury; import mekhq.campaign.personnel.Person; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Ralgith diff --git a/MekHQ/src/mekhq/gui/dialog/EditPersonnelLogDialog.java b/MekHQ/src/mekhq/gui/dialog/EditPersonnelLogDialog.java index f5fcbb7e6f..0b91c5585e 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditPersonnelLogDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditPersonnelLogDialog.java @@ -30,8 +30,8 @@ import mekhq.campaign.Campaign; import mekhq.campaign.personnel.Person; import mekhq.gui.control.EditPersonnelLogControl; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/EditSkillPrereqDialog.java b/MekHQ/src/mekhq/gui/dialog/EditSkillPrereqDialog.java index 4a657bc11c..ca159a1ca9 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditSkillPrereqDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditSkillPrereqDialog.java @@ -1,20 +1,20 @@ /* * NewSkillPrereqDialog.java - * + * * Copyright (c) 2009 Jay Lawson . 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 . */ @@ -40,8 +40,8 @@ import mekhq.MekHQ; import mekhq.campaign.personnel.SkillPrereq; import mekhq.campaign.personnel.SkillType; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** @@ -50,16 +50,16 @@ */ public class EditSkillPrereqDialog extends JDialog { private static final long serialVersionUID = -8038099101234445018L; - + private SkillPrereq prereq; - + private JButton btnClose; private JButton btnOK; private boolean cancelled; - + private Hashtable> skillLevels = new Hashtable>(); private Hashtable skillChks = new Hashtable(); - + public EditSkillPrereqDialog(Frame parent, SkillPrereq pre) { super(parent, true); cancelled = false; @@ -73,9 +73,9 @@ private void initComponents() { btnOK = new javax.swing.JButton(); btnClose = new javax.swing.JButton(); - + JPanel panMain = new JPanel(new GridLayout(SkillType.skillList.length,2)); - + JCheckBox chkSkill; JComboBox choiceLvl; DefaultComboBoxModel skillLvlModel; @@ -90,7 +90,7 @@ public void itemStateChanged(ItemEvent e) { changeLevelEnabled(type); } }); - + skillLvlModel = new DefaultComboBoxModel(); skillLvlModel.addElement("None"); skillLvlModel.addElement(SkillType.getExperienceLevelName(SkillType.EXP_GREEN)); @@ -104,12 +104,12 @@ public void itemStateChanged(ItemEvent e) { lvl = 0; } choiceLvl.setSelectedIndex(lvl); - + skillLevels.put(type, choiceLvl); panMain.add(chkSkill); panMain.add(choiceLvl); } - + JPanel panButtons = new JPanel(new GridLayout(0,2)); btnOK.setText("Done"); // NOI18N btnOK.addActionListener(new java.awt.event.ActionListener() { @@ -117,24 +117,24 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { done(); } }); - + btnClose.setText("Cancel"); // NOI18N btnClose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancel(); } }); - + panButtons.add(btnOK); panButtons.add(btnClose); - + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Select Abilities"); getContentPane().setLayout(new BorderLayout()); - + getContentPane().add(new JScrollPane(panMain), BorderLayout.CENTER); getContentPane().add(panButtons, BorderLayout.SOUTH); - + this.setPreferredSize(new Dimension(400,700)); pack(); @@ -156,20 +156,20 @@ private void done() { } this.setVisible(false); } - + public SkillPrereq getPrereq() { return prereq; } - + private void cancel() { this.setVisible(false); cancelled = true; } - + public boolean wasCancelled() { return cancelled; } - + private void changeLevelEnabled(String type) { skillLevels.get(type).setEnabled(skillChks.get(type).isSelected()); } diff --git a/MekHQ/src/mekhq/gui/dialog/EditSpecialAbilityDialog.java b/MekHQ/src/mekhq/gui/dialog/EditSpecialAbilityDialog.java index 1ebe626fa7..cf89e26663 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditSpecialAbilityDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditSpecialAbilityDialog.java @@ -30,8 +30,8 @@ import mekhq.MekHQ; import mekhq.campaign.personnel.SkillPrereq; import mekhq.campaign.personnel.SpecialAbility; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/EditTransactionDialog.java b/MekHQ/src/mekhq/gui/dialog/EditTransactionDialog.java index 2327956ca7..b8a093e701 100644 --- a/MekHQ/src/mekhq/gui/dialog/EditTransactionDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/EditTransactionDialog.java @@ -43,9 +43,9 @@ import megamek.common.util.EncodeControl; import mekhq.MekHQ; import mekhq.campaign.finances.Transaction; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.utilities.JMoneyTextField; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; public class EditTransactionDialog extends JDialog implements ActionListener, FocusListener, MouseListener { private static final long serialVersionUID = -8742160448355293487L; diff --git a/MekHQ/src/mekhq/gui/dialog/GMToolsDialog.java b/MekHQ/src/mekhq/gui/dialog/GMToolsDialog.java index 5bc487e83a..2cf9b3053f 100644 --- a/MekHQ/src/mekhq/gui/dialog/GMToolsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/GMToolsDialog.java @@ -56,11 +56,11 @@ import mekhq.campaign.universe.Factions; import mekhq.campaign.universe.IUnitGenerator; import mekhq.gui.CampaignGUI; -import mekhq.gui.preferences.JComboBoxPreference; -import mekhq.gui.preferences.JIntNumberSpinnerPreference; -import mekhq.gui.preferences.JTextFieldPreference; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JComboBoxPreference; +import megamek.client.ui.preferences.JIntNumberSpinnerPreference; +import megamek.client.ui.preferences.JTextFieldPreference; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; public class GMToolsDialog extends JDialog { //region Variable Declarations diff --git a/MekHQ/src/mekhq/gui/dialog/GamePresetDescriptionDialog.java b/MekHQ/src/mekhq/gui/dialog/GamePresetDescriptionDialog.java index 22768c01dd..0d7ec4bddd 100644 --- a/MekHQ/src/mekhq/gui/dialog/GamePresetDescriptionDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/GamePresetDescriptionDialog.java @@ -12,15 +12,15 @@ import megamek.common.util.EncodeControl; import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * * @author Jay Lason */ public class GamePresetDescriptionDialog extends javax.swing.JDialog { - + private static final long serialVersionUID = 3624327778807359294L; private javax.swing.JTextField txtTitle; @@ -33,7 +33,7 @@ public class GamePresetDescriptionDialog extends javax.swing.JDialog { public GamePresetDescriptionDialog(java.awt.Frame parent, boolean modal, String title, String desc) { super(parent, modal); setTitle("Enter description of preset"); - initComponents(); + initComponents(); txtTitle.setText(title); txtDesc.setText(desc); changed = false; @@ -42,7 +42,7 @@ public GamePresetDescriptionDialog(java.awt.Frame parent, boolean modal, String setLocationRelativeTo(parent); setUserPreferences(); } - + private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; @@ -55,12 +55,12 @@ private void initComponents() { ResourceBundle resourceMap = ResourceBundle.getBundle("mekhq.resources.TextAreaDialog", new EncodeControl()); //$NON-NLS-1$ setLayout(new java.awt.GridBagLayout()); - + txtDesc.setName("txtDesc"); txtDesc.setEditable(true); txtDesc.setLineWrap(true); txtDesc.setWrapStyleWord(true); - + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; @@ -70,7 +70,7 @@ private void initComponents() { gridBagConstraints.weighty = 0.0; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; add(new JLabel("Title:"), gridBagConstraints); - + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; @@ -80,9 +80,9 @@ private void initComponents() { gridBagConstraints.weighty = 0.0; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; add(txtTitle, gridBagConstraints); - + scrText.setPreferredSize(new Dimension(450, 100)); - scrText.setViewportView(txtDesc); + scrText.setViewportView(txtDesc); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; @@ -92,7 +92,7 @@ private void initComponents() { gridBagConstraints.weighty = 1.0; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; add(scrText, gridBagConstraints); - + btnOK.setText(resourceMap.getString("btnOK.text")); btnOK.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -107,7 +107,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { gridBagConstraints.weighty = 0.0; gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER; add(btnOK, gridBagConstraints); - + btnCancel.setText(resourceMap.getString("btnCancel.text")); btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -121,7 +121,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { gridBagConstraints.weightx = 0.5; gridBagConstraints.weighty = 0.0; gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER; - add(btnCancel, gridBagConstraints); + add(btnCancel, gridBagConstraints); } private void setUserPreferences() { @@ -134,18 +134,18 @@ private void setUserPreferences() { public String getTitle() { return txtTitle.getText(); } - + public String getDesc() { return txtDesc.getText(); } - + private void btnOKActionPerformed() { changed = true; setVisible(false); } - + public boolean wasChanged() { return changed; } - + } diff --git a/MekHQ/src/mekhq/gui/dialog/HireBulkPersonnelDialog.java b/MekHQ/src/mekhq/gui/dialog/HireBulkPersonnelDialog.java index ca63c68388..5c9ce277dd 100644 --- a/MekHQ/src/mekhq/gui/dialog/HireBulkPersonnelDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/HireBulkPersonnelDialog.java @@ -33,8 +33,8 @@ import javax.swing.event.ChangeListener; import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import megamek.common.Compute; import megamek.common.util.EncodeControl; diff --git a/MekHQ/src/mekhq/gui/dialog/HistoricalDailyReportDialog.java b/MekHQ/src/mekhq/gui/dialog/HistoricalDailyReportDialog.java index 1e38a5e1d7..2b9e74a6c9 100644 --- a/MekHQ/src/mekhq/gui/dialog/HistoricalDailyReportDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/HistoricalDailyReportDialog.java @@ -42,8 +42,8 @@ import mekhq.campaign.log.LogEntry; import mekhq.gui.CampaignGUI; import mekhq.gui.DailyReportLogPanel; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; public class HistoricalDailyReportDialog extends JDialog { private static final long serialVersionUID = -4373796917722483042L; diff --git a/MekHQ/src/mekhq/gui/dialog/ImageChoiceDialog.java b/MekHQ/src/mekhq/gui/dialog/ImageChoiceDialog.java index 7b6e79fa50..49a0e196c1 100644 --- a/MekHQ/src/mekhq/gui/dialog/ImageChoiceDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ImageChoiceDialog.java @@ -49,9 +49,9 @@ import mekhq.MekHQ; import mekhq.campaign.force.Force; import mekhq.gui.enums.LayeredForceIcon; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.utilities.MekHqTableCellRenderer; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Jay Lawson diff --git a/MekHQ/src/mekhq/gui/dialog/LargeCraftAmmoSwapDialog.java b/MekHQ/src/mekhq/gui/dialog/LargeCraftAmmoSwapDialog.java index 5e3b9e8a0f..de122a82d7 100644 --- a/MekHQ/src/mekhq/gui/dialog/LargeCraftAmmoSwapDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/LargeCraftAmmoSwapDialog.java @@ -35,8 +35,8 @@ import mekhq.campaign.parts.equipment.LargeCraftAmmoBin; import mekhq.campaign.unit.Unit; import mekhq.campaign.unit.actions.AdjustLargeCraftAmmoAction; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Neoancient diff --git a/MekHQ/src/mekhq/gui/dialog/LootDialog.java b/MekHQ/src/mekhq/gui/dialog/LootDialog.java index b895a35502..2ba8a2e399 100644 --- a/MekHQ/src/mekhq/gui/dialog/LootDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/LootDialog.java @@ -21,7 +21,6 @@ package mekhq.gui.dialog; -import java.awt.Frame; import java.util.ArrayList; import javax.swing.*; @@ -35,8 +34,8 @@ import mekhq.campaign.finances.Money; import mekhq.campaign.mission.Loot; import mekhq.campaign.parts.Part; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * diff --git a/MekHQ/src/mekhq/gui/dialog/MaintenanceReportDialog.java b/MekHQ/src/mekhq/gui/dialog/MaintenanceReportDialog.java index ae57786f4a..bc62faf3dc 100644 --- a/MekHQ/src/mekhq/gui/dialog/MaintenanceReportDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MaintenanceReportDialog.java @@ -13,15 +13,15 @@ import mekhq.MekHQ; import mekhq.campaign.unit.Unit; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * * @author Jay Lawson */ public class MaintenanceReportDialog extends javax.swing.JDialog { - + private static final long serialVersionUID = 3624327778807359294L; private JTextPane txtReport; @@ -29,27 +29,27 @@ public class MaintenanceReportDialog extends javax.swing.JDialog { public MaintenanceReportDialog(java.awt.Frame parent, Unit unit) { super(parent, false); setTitle("Maintenance Report for " + unit.getName()); - initComponents(); - + initComponents(); + txtReport.setText(unit.getLastMaintenanceReport()); txtReport.setCaretPosition(0); - + setPreferredSize(new Dimension(700, 500)); pack(); setLocationRelativeTo(parent); setUserPreferences(); } - + private void initComponents() { txtReport = new JTextPane(); txtReport.setContentType("text/html"); - + setLayout(new java.awt.BorderLayout()); - + txtReport.setEditable(false); - + getContentPane().add(new JScrollPane(txtReport), BorderLayout.CENTER); } diff --git a/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java b/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java index 3f6f53ee8a..5bc116a502 100644 --- a/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java @@ -47,8 +47,8 @@ import mekhq.campaign.finances.Asset; import mekhq.campaign.finances.Finances; import mekhq.gui.model.DataTableModel; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/MassMothballDialog.java b/MekHQ/src/mekhq/gui/dialog/MassMothballDialog.java index 3a43b7c6e6..9567482295 100644 --- a/MekHQ/src/mekhq/gui/dialog/MassMothballDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MassMothballDialog.java @@ -55,8 +55,8 @@ import mekhq.campaign.personnel.Person; import mekhq.campaign.unit.Unit; import mekhq.gui.adapter.UnitTableMouseAdapter; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * This class handles the display of the Mass Mothball/Reactivate dialog diff --git a/MekHQ/src/mekhq/gui/dialog/MassRepairSalvageDialog.java b/MekHQ/src/mekhq/gui/dialog/MassRepairSalvageDialog.java index 33771bb611..9bb2ec317a 100644 --- a/MekHQ/src/mekhq/gui/dialog/MassRepairSalvageDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MassRepairSalvageDialog.java @@ -54,11 +54,11 @@ import mekhq.gui.model.PartsTableModel; import mekhq.gui.model.UnitTableModel; import mekhq.gui.model.XTableColumnModel; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.sorter.PartsDetailSorter; import mekhq.gui.sorter.UnitStatusSorter; import mekhq.gui.sorter.UnitTypeSorter; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; import mekhq.service.MassRepairOption; import mekhq.service.MassRepairService; import mekhq.service.MassRepairService.MassRepairPartSet; diff --git a/MekHQ/src/mekhq/gui/dialog/MedicalViewDialog.java b/MekHQ/src/mekhq/gui/dialog/MedicalViewDialog.java index a7f2c6af4e..0e538c2028 100644 --- a/MekHQ/src/mekhq/gui/dialog/MedicalViewDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MedicalViewDialog.java @@ -60,9 +60,9 @@ import megamek.common.util.EncodeControl; import mekhq.campaign.log.LogEntryType; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.view.Paperdoll; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; import mekhq.MekHQ; import mekhq.Utilities; import mekhq.campaign.Campaign; diff --git a/MekHQ/src/mekhq/gui/dialog/MekHQAboutBox.java b/MekHQ/src/mekhq/gui/dialog/MekHQAboutBox.java index c630d0639f..363329f098 100644 --- a/MekHQ/src/mekhq/gui/dialog/MekHQAboutBox.java +++ b/MekHQ/src/mekhq/gui/dialog/MekHQAboutBox.java @@ -1,20 +1,20 @@ /* * MekBayAboutBox.java - * + * * Copyright (c) 2009 Jay Lawson . 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 . */ @@ -36,8 +36,8 @@ import megamek.common.util.EncodeControl; import megameklab.com.MegaMekLab; import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; public class MekHQAboutBox extends javax.swing.JDialog { private static final long serialVersionUID = -8514528257894201641L; @@ -71,7 +71,7 @@ private void initComponents() { setName("aboutBox"); // NOI18N setResizable(false); getContentPane().setLayout(new GridBagLayout()); - + appTitleLabel.setText(mekhqProperties.getString("Application.title")); // NOI18N appTitleLabel.setName("appTitleLabel"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); @@ -83,48 +83,48 @@ private void initComponents() { gridBagConstraints.weightx = 0.0; gridBagConstraints.weighty = 0.0; getContentPane().add(appTitleLabel, gridBagConstraints); - + versionLabel.setText(resourceMap.getString("versionLabel.text")); // NOI18N versionLabel.setName("versionLabel"); // NOI18N gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 1; getContentPane().add(versionLabel, gridBagConstraints); - + appVersionLabel.setText(mekhqProperties.getString("Application.version")); // NOI18N appVersionLabel.setName("appVersionLabel"); // NOI18N gridBagConstraints.gridx = 1; getContentPane().add(appVersionLabel, gridBagConstraints); - + versionLabelMegaMek.setText(resourceMap.getString("versionLabelMegaMek.text")); // NOI18N versionLabelMegaMek.setName("versionLabelMegaMek"); // NOI18N gridBagConstraints.gridy = 2; gridBagConstraints.gridx = 0; gridBagConstraints.gridwidth = 1; getContentPane().add(versionLabelMegaMek, gridBagConstraints); - + appVersionLabelMegaMek.setText(MegaMek.VERSION); // NOI18N appVersionLabelMegaMek.setName("appVersionLabelMegaMek"); // NOI18N gridBagConstraints.gridx = 1; getContentPane().add(appVersionLabelMegaMek, gridBagConstraints); - + versionLabelMegaMekLab.setText(resourceMap.getString("versionLabelMegaMekLab.text")); // NOI18N versionLabelMegaMekLab.setName("versionLabelMegaMekLab"); // NOI18N gridBagConstraints.gridy = 3; gridBagConstraints.gridx = 0; gridBagConstraints.gridwidth = 1; getContentPane().add(versionLabelMegaMekLab, gridBagConstraints); - + appVersionLabelMegaMekLab.setText(MegaMekLab.VERSION); // NOI18N appVersionLabelMegaMekLab.setName("appVersionLabelMegaMekLab"); // NOI18N gridBagConstraints.gridx = 1; getContentPane().add(appVersionLabelMegaMekLab, gridBagConstraints); - + homepageLabel.setText(resourceMap.getString("homepageLabel.text")); // NOI18N homepageLabel.setName("homepageLabel"); // NOI18N gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; getContentPane().add(homepageLabel, gridBagConstraints); - + // use a JButton but make it look more like a regular link appHomepage.setText("" + mekhqProperties.getString("Application.homepage") + ""); // NOI18N appHomepage.setName("appHomepageLabel"); // NOI18N @@ -144,27 +144,27 @@ public void mouseClicked(MouseEvent evt) { } } }); - + gridBagConstraints.gridx = 1; getContentPane().add(appHomepage, gridBagConstraints); - + appDescLabel.setText(mekhqProperties.getString("Application.description")); // NOI18N gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.gridwidth = 2; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; - + // add some space at the bottom so the description text is easier to read gridBagConstraints.insets = new Insets(15,15,15,15); appDescLabel.setName("appDescLabel"); // NOI18N getContentPane().add(appDescLabel, gridBagConstraints); - + setSize(200,200); - + pack(); } diff --git a/MekHQ/src/mekhq/gui/dialog/MekHqOptionsDialog.java b/MekHQ/src/mekhq/gui/dialog/MekHqOptionsDialog.java index eb57880ff2..73019758ea 100644 --- a/MekHQ/src/mekhq/gui/dialog/MekHqOptionsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MekHqOptionsDialog.java @@ -1,7 +1,5 @@ /* - * MekHqOptionsDialog.java - * - * Copyright (c) 2019-2020 - The MegaMek Team. All Rights Reserved. + * Copyright (c) 2019-2021 - The MegaMek Team. All Rights Reserved. * * This file is part of MekHQ. * @@ -20,8 +18,10 @@ */ package mekhq.gui.dialog; +import megamek.common.util.EncodeControl; import mekhq.MekHQ; import mekhq.campaign.event.MekHQOptionsChangedEvent; +import mekhq.gui.baseComponents.AbstractMHQButtonDialog; import mekhq.gui.enums.PersonnelFilterStyle; import javax.swing.*; @@ -32,10 +32,8 @@ import java.util.Objects; import java.util.ResourceBundle; -public class MekHqOptionsDialog extends BaseDialog { +public class MekHqOptionsDialog extends AbstractMHQButtonDialog { //region Variable Declaration - private final ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.MekHqOptionsDialog"); - //region Display private JTextField optionDisplayDateFormat; private JTextField optionLongDisplayDateFormat; @@ -78,11 +76,11 @@ public class MekHqOptionsDialog extends BaseDialog { //endregion Variable Declaration //region Constructors - public MekHqOptionsDialog(JFrame parent) { - super(parent); - - this.initialize(resources); - this.setInitialState(); + public MekHqOptionsDialog(final JFrame frame) { + super(frame, true, ResourceBundle.getBundle("mekhq.resources.MekHqOptionsDialog", + new EncodeControl()), "MekHQOptionsDialog", "MekHQOptionsDialog.title"); + initialize(); + setInitialState(); } //endregion Constructors @@ -92,7 +90,7 @@ public MekHqOptionsDialog(JFrame parent) { * C, D, M, M, S, U, W, Y */ @Override - protected Container createCustomUI() { + protected Container createCenterPane() { JTabbedPane optionsTabbedPane = new JTabbedPane(); optionsTabbedPane.setName("optionsTabbedPane"); optionsTabbedPane.add(resources.getString("displayTab.title"), new JScrollPane(createDisplayTab())); diff --git a/MekHQ/src/mekhq/gui/dialog/MekViewDialog.java b/MekHQ/src/mekhq/gui/dialog/MekViewDialog.java index 5cf51fd912..bd9f9fb3ec 100644 --- a/MekHQ/src/mekhq/gui/dialog/MekViewDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MekViewDialog.java @@ -13,8 +13,8 @@ import megamek.common.MechView; import megamek.common.util.EncodeControl; import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @@ -23,11 +23,11 @@ public class MekViewDialog extends javax.swing.JDialog { /** - * + * */ private static final long serialVersionUID = 5894364756899721545L; private MechView mview; - + /** Creates new form MekViewDialog */ public MekViewDialog(java.awt.Frame parent, boolean modal, MechView mv) { super(parent, modal); @@ -41,7 +41,7 @@ private void initComponents() { jScrollPane2 = new javax.swing.JScrollPane(); txtMek = new javax.swing.JTextPane(); btnOkay = new javax.swing.JButton(); - + ResourceBundle resourceMap = ResourceBundle.getBundle("mekhq.resources.MekViewDialog", new EncodeControl()); //$NON-NLS-1$ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setName("Unit View"); // NOI18N @@ -62,7 +62,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { btnOkayActionPerformed(evt); } }); - + getContentPane().add(jScrollPane2, BorderLayout.CENTER); getContentPane().add(btnOkay, BorderLayout.PAGE_END); diff --git a/MekHQ/src/mekhq/gui/dialog/MercRosterDialog.java b/MekHQ/src/mekhq/gui/dialog/MercRosterDialog.java index 6350066fd5..44530108d1 100644 --- a/MekHQ/src/mekhq/gui/dialog/MercRosterDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MercRosterDialog.java @@ -28,8 +28,8 @@ import mekhq.MekHQ; import mekhq.campaign.Campaign; import mekhq.campaign.MercRosterAccess; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * A dialog that sets up a connection with a mysql MercRoster database to upload campaign data diff --git a/MekHQ/src/mekhq/gui/dialog/MissionTypeDialog.java b/MekHQ/src/mekhq/gui/dialog/MissionTypeDialog.java index 01c1545775..2a85cb1dac 100644 --- a/MekHQ/src/mekhq/gui/dialog/MissionTypeDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MissionTypeDialog.java @@ -13,8 +13,8 @@ import megamek.common.util.EncodeControl; import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @@ -23,7 +23,7 @@ public class MissionTypeDialog extends javax.swing.JDialog { private boolean contract; - + private static final long serialVersionUID = 8376874926997734492L; /** Creates new form */ public MissionTypeDialog(Frame parent, boolean modal) { @@ -38,9 +38,9 @@ private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setName("Form"); // NOI18N setTitle(resourceMap.getString("Form.title")); - + getContentPane().setLayout(new java.awt.GridLayout(2,1)); - + JButton btnMission = new javax.swing.JButton(resourceMap.getString("btnMission.text")); btnMission.setToolTipText(resourceMap.getString("btnMission.tooltip")); btnMission.setName("btnMission"); // NOI18N @@ -49,7 +49,7 @@ private void initComponents() { setVisible(false); }); getContentPane().add(btnMission); - + JButton btnContract = new javax.swing.JButton(resourceMap.getString("btnContract.text")); btnContract.setToolTipText(resourceMap.getString("btnContract.tooltip")); btnContract.setName("btnContract"); // NOI18N @@ -69,7 +69,7 @@ private void setUserPreferences() { this.setName("dialog"); preferences.manage(new JWindowPreference(this)); } - + public boolean isContract() { return contract; } diff --git a/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java b/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java index 2da3a96b65..daa5913f22 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java @@ -40,10 +40,10 @@ import mekhq.campaign.universe.Systems; import mekhq.gui.FactionComboBox; import mekhq.gui.model.SortedComboBoxModel; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.utilities.JSuggestField; import mekhq.gui.utilities.MarkdownEditorPanel; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Neoancient diff --git a/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java b/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java index 460d8b909c..f47305c6d6 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java @@ -39,12 +39,12 @@ import mekhq.campaign.mission.Mission; import mekhq.campaign.personnel.Person; import mekhq.campaign.personnel.SkillType; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.campaign.universe.Systems; import mekhq.gui.utilities.JSuggestField; import mekhq.gui.utilities.MarkdownEditorPanel; import mekhq.gui.view.ContractPaymentBreakdown; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/NewLoanDialog.java b/MekHQ/src/mekhq/gui/dialog/NewLoanDialog.java index fd660b70cb..c86861f284 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewLoanDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewLoanDialog.java @@ -45,8 +45,8 @@ import mekhq.campaign.finances.Loan; import mekhq.campaign.finances.Money; import mekhq.campaign.rating.IUnitRating; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/NewPlanetaryEventDialog.java b/MekHQ/src/mekhq/gui/dialog/NewPlanetaryEventDialog.java index ea90bb47db..cb56a0ba68 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewPlanetaryEventDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewPlanetaryEventDialog.java @@ -48,8 +48,8 @@ import mekhq.campaign.universe.Faction; import mekhq.campaign.universe.Factions; import mekhq.campaign.universe.Planet; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; public class NewPlanetaryEventDialog extends JDialog { private static final long serialVersionUID = 6025304629282204159L; diff --git a/MekHQ/src/mekhq/gui/dialog/NewRecruitDialog.java b/MekHQ/src/mekhq/gui/dialog/NewRecruitDialog.java index cfa56fdfff..87b8196e16 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewRecruitDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewRecruitDialog.java @@ -31,9 +31,9 @@ import mekhq.campaign.personnel.Person; import mekhq.campaign.personnel.ranks.Ranks; import mekhq.gui.CampaignGUI; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.view.PersonViewPanel; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; public class NewRecruitDialog extends javax.swing.JDialog { /** diff --git a/MekHQ/src/mekhq/gui/dialog/NewsReportDialog.java b/MekHQ/src/mekhq/gui/dialog/NewsReportDialog.java index ea0dd8c863..d453f19263 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewsReportDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewsReportDialog.java @@ -25,10 +25,9 @@ import javax.swing.border.EmptyBorder; import mekhq.MekHQ; -import mekhq.campaign.Campaign; import mekhq.campaign.universe.NewsItem; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Jay Lawson diff --git a/MekHQ/src/mekhq/gui/dialog/PartsStoreDialog.java b/MekHQ/src/mekhq/gui/dialog/PartsStoreDialog.java index 6c535907f7..a582efe221 100644 --- a/MekHQ/src/mekhq/gui/dialog/PartsStoreDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/PartsStoreDialog.java @@ -84,11 +84,11 @@ import mekhq.campaign.work.IAcquisitionWork; import mekhq.gui.CampaignGUI; import mekhq.gui.dialog.PartsStoreDialog.PartsTableModel.PartProxy; -import mekhq.gui.preferences.JComboBoxPreference; -import mekhq.gui.preferences.JTablePreference; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JComboBoxPreference; +import megamek.client.ui.preferences.JTablePreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.sorter.PartsDetailSorter; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/PayCollateralDialog.java b/MekHQ/src/mekhq/gui/dialog/PayCollateralDialog.java index b1936e811a..2c7b8cdd86 100644 --- a/MekHQ/src/mekhq/gui/dialog/PayCollateralDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/PayCollateralDialog.java @@ -53,8 +53,8 @@ import mekhq.campaign.parts.AmmoStorage; import mekhq.campaign.parts.Part; import mekhq.campaign.unit.Unit; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * A dialog to decide how you want to pay off collateral when you diff --git a/MekHQ/src/mekhq/gui/dialog/PersonnelMarketDialog.java b/MekHQ/src/mekhq/gui/dialog/PersonnelMarketDialog.java index 28a3d50532..b5dab99d57 100644 --- a/MekHQ/src/mekhq/gui/dialog/PersonnelMarketDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/PersonnelMarketDialog.java @@ -46,14 +46,14 @@ import mekhq.gui.enums.PersonnelFilter; 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 mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JComboBoxPreference; +import megamek.client.ui.preferences.JTablePreference; +import megamek.client.ui.preferences.JToggleButtonPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.sorter.FormattedNumberSorter; import mekhq.gui.sorter.LevelSorter; import mekhq.gui.view.PersonViewPanel; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Jay Lawson diff --git a/MekHQ/src/mekhq/gui/dialog/PrincessBehaviorDialog.java b/MekHQ/src/mekhq/gui/dialog/PrincessBehaviorDialog.java index 62bc97ab5b..80e314a688 100644 --- a/MekHQ/src/mekhq/gui/dialog/PrincessBehaviorDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/PrincessBehaviorDialog.java @@ -31,26 +31,26 @@ import megamek.client.ui.swing.BotConfigDialog; import megamek.common.logging.LogLevel; import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; public class PrincessBehaviorDialog extends BotConfigDialog implements ActionListener { /** - * + * */ private static final long serialVersionUID = -1697757949925940582L; public PrincessBehaviorDialog(JFrame parent, BehaviorSettings princessBehavior, String name) { super(parent); - + try { this.princessBehavior = princessBehavior.getCopy(); } catch(Exception e) { handleError("PrincessBehaviorDialog", e); } this.setName(name); - + this.nameField.setText(name); super.setPrincessFields(); setUserPreferences(); @@ -62,7 +62,7 @@ private void setUserPreferences() { this.setName("dialog"); preferences.manage(new JWindowPreference(this)); } - + private void getPrincessFields() { LogLevel logLevel = LogLevel.getLogLevel((String) verbosityCombo.getSelectedItem()); if (null != logLevel) { diff --git a/MekHQ/src/mekhq/gui/dialog/QuirksDialog.java b/MekHQ/src/mekhq/gui/dialog/QuirksDialog.java index aa68c55044..7ac19369fb 100644 --- a/MekHQ/src/mekhq/gui/dialog/QuirksDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/QuirksDialog.java @@ -41,8 +41,8 @@ import megamek.common.options.IOption; import megamek.common.options.WeaponQuirks; import mekhq.MekHQ; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Deric Page (dericpage@users.sourceforge.net) @@ -52,7 +52,7 @@ public class QuirksDialog extends JDialog implements DialogOptionListener, ActionListener { /** - * + * */ private static final long serialVersionUID = -5030866602278329622L; private QuirksPanel qpanel; diff --git a/MekHQ/src/mekhq/gui/dialog/RefitNameDialog.java b/MekHQ/src/mekhq/gui/dialog/RefitNameDialog.java index e4a9ed605c..44f43b0120 100644 --- a/MekHQ/src/mekhq/gui/dialog/RefitNameDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/RefitNameDialog.java @@ -29,8 +29,8 @@ import megamek.common.util.EncodeControl; import mekhq.MekHQ; import mekhq.campaign.parts.Refit; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/ReportDialog.java b/MekHQ/src/mekhq/gui/dialog/ReportDialog.java index 58f9cc9790..37ae02367e 100644 --- a/MekHQ/src/mekhq/gui/dialog/ReportDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ReportDialog.java @@ -28,8 +28,8 @@ import mekhq.MekHQ; import mekhq.campaign.report.Report; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Jay Lawson diff --git a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java index a4c7d63150..6f542f31e1 100644 --- a/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ResolveScenarioWizardDialog.java @@ -55,10 +55,10 @@ import mekhq.campaign.personnel.Person; import mekhq.campaign.unit.TestUnit; import mekhq.campaign.unit.Unit; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.utilities.MarkdownEditorPanel; import mekhq.gui.view.PersonViewPanel; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Taharqa diff --git a/MekHQ/src/mekhq/gui/dialog/RetirementDefectionDialog.java b/MekHQ/src/mekhq/gui/dialog/RetirementDefectionDialog.java index bb9d333386..0f5f139ba5 100644 --- a/MekHQ/src/mekhq/gui/dialog/RetirementDefectionDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/RetirementDefectionDialog.java @@ -76,14 +76,14 @@ import mekhq.gui.model.RetirementTableModel; import mekhq.gui.model.UnitAssignmentTableModel; import mekhq.gui.model.XTableColumnModel; -import mekhq.gui.preferences.JComboBoxPreference; -import mekhq.gui.preferences.JIntNumberSpinnerPreference; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JComboBoxPreference; +import megamek.client.ui.preferences.JIntNumberSpinnerPreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.sorter.BonusSorter; import mekhq.gui.sorter.FormattedNumberSorter; import mekhq.gui.sorter.RankSorter; import mekhq.gui.sorter.WeightClassSorter; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Neoancient diff --git a/MekHQ/src/mekhq/gui/dialog/ScenarioTemplateEditorDialog.java b/MekHQ/src/mekhq/gui/dialog/ScenarioTemplateEditorDialog.java index 77674e2607..bb0cfe768e 100644 --- a/MekHQ/src/mekhq/gui/dialog/ScenarioTemplateEditorDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ScenarioTemplateEditorDialog.java @@ -75,8 +75,8 @@ import mekhq.campaign.mission.atb.AtBScenarioModifier; import mekhq.campaign.mission.ScenarioTemplate; import mekhq.gui.FileDialogs; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * Handles editing, saving and loading of scenario template definitions. diff --git a/MekHQ/src/mekhq/gui/dialog/SelectAbilitiesDialog.java b/MekHQ/src/mekhq/gui/dialog/SelectAbilitiesDialog.java index 3195f1f63b..366f84dbad 100644 --- a/MekHQ/src/mekhq/gui/dialog/SelectAbilitiesDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/SelectAbilitiesDialog.java @@ -1,20 +1,20 @@ /* * SelectAbilitiesDialog.java - * + * * Copyright (c) 2009 Jay Lawson . 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 . */ @@ -35,8 +35,8 @@ import mekhq.MekHQ; import mekhq.campaign.personnel.SpecialAbility; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @@ -44,16 +44,16 @@ */ public class SelectAbilitiesDialog extends JDialog { private static final long serialVersionUID = -8038099101234445018L; - + private JButton btnClose; private JButton btnOK; private ArrayList chkAbil; private Vector selected; private ArrayList spaNames; private boolean cancelled; - + private Hashtable allSPA; - + public SelectAbilitiesDialog(Frame parent, Vector s, Hashtable hash) { super(parent, true); selected = s; @@ -68,17 +68,17 @@ private void initComponents() { btnOK = new javax.swing.JButton(); btnClose = new javax.swing.JButton(); - + chkAbil = new ArrayList(); spaNames = new ArrayList(); - + for(String name: allSPA.keySet()) { spaNames.add(name); } - + int ncol = 3; JPanel panMain = new JPanel(new GridLayout((int)Math.ceil(spaNames.size() / (ncol*1.0)),ncol)); - + JCheckBox chk; for(String name : spaNames) { chk = new JCheckBox(allSPA.get(name).getDisplayName()); @@ -88,7 +88,7 @@ private void initComponents() { chkAbil.add(chk); panMain.add(chk); } - + JPanel panButtons = new JPanel(new GridLayout(0,2)); btnOK.setText("Done"); // NOI18N btnOK.addActionListener(new java.awt.event.ActionListener() { @@ -96,21 +96,21 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { done(); } }); - + btnClose.setText("Cancel"); // NOI18N btnClose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancel(); } }); - + panButtons.add(btnOK); panButtons.add(btnClose); - + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Select Abilities"); getContentPane().setLayout(new BorderLayout()); - + getContentPane().add(panMain, BorderLayout.CENTER); getContentPane().add(panButtons, BorderLayout.SOUTH); @@ -133,16 +133,16 @@ private void done() { } this.setVisible(false); } - + public Vector getSelected() { return selected; } - + private void cancel() { this.setVisible(false); cancelled = true; } - + public boolean wasCancelled() { return cancelled; } diff --git a/MekHQ/src/mekhq/gui/dialog/SelectUnusedAbilityDialog.java b/MekHQ/src/mekhq/gui/dialog/SelectUnusedAbilityDialog.java index bc69dfe47f..78a7ca0c01 100644 --- a/MekHQ/src/mekhq/gui/dialog/SelectUnusedAbilityDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/SelectUnusedAbilityDialog.java @@ -1,20 +1,20 @@ /* * SelectAbilitiesDialog.java - * + * * Copyright (c) 2009 Jay Lawson . 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 . */ @@ -39,8 +39,8 @@ import megamek.common.options.PilotOptions; import mekhq.MekHQ; import mekhq.campaign.personnel.SpecialAbility; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @@ -48,14 +48,14 @@ */ public class SelectUnusedAbilityDialog extends JDialog { private static final long serialVersionUID = -8038099101234445018L; - + private JButton btnClose; private JButton btnOK; private ButtonGroup group; private Vector choices; private boolean cancelled; private Hashtable currentSPA; - + public SelectUnusedAbilityDialog(Frame parent, Vector unused, Hashtable c) { super(parent, true); choices = unused; @@ -70,12 +70,12 @@ private void initComponents() { btnOK = new javax.swing.JButton(); btnClose = new javax.swing.JButton(); - + group = new ButtonGroup(); - + int ncol = 2; JPanel panMain = new JPanel(new GridLayout((int)Math.ceil(choices.size() / (ncol*1.0)),ncol)); - + JRadioButton chk; for(String name : choices) { chk = new JRadioButton(SpecialAbility.getDefaultAbility(name) == null @@ -86,7 +86,7 @@ private void initComponents() { group.add(chk); panMain.add(chk); } - + JPanel panButtons = new JPanel(new GridLayout(0,2)); btnOK.setText("Done"); // NOI18N btnOK.addActionListener(new java.awt.event.ActionListener() { @@ -94,21 +94,21 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { done(); } }); - + btnClose.setText("Cancel"); // NOI18N btnClose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancel(); } }); - + panButtons.add(btnOK); panButtons.add(btnClose); - + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Select Abilities"); getContentPane().setLayout(new BorderLayout()); - + getContentPane().add(panMain, BorderLayout.CENTER); getContentPane().add(panButtons, BorderLayout.SOUTH); @@ -135,7 +135,7 @@ private void done() { if (!group.getKey().equalsIgnoreCase(PilotOptions.LVL3_ADVANTAGES)) { continue; } - + for (Enumeration j = group.getOptions(); j.hasMoreElements();) { IOption option = j.nextElement(); if(option.getName().equals(name)) { @@ -159,16 +159,16 @@ private void done() { } this.setVisible(false); } - + private void cancel() { this.setVisible(false); cancelled = true; } - + public boolean wasCancelled() { return cancelled; } - + private String getDisplayName(String lookup) { PilotOptions poptions = new PilotOptions(); for (Enumeration i = poptions.getGroups(); i.hasMoreElements();) { @@ -177,7 +177,7 @@ private String getDisplayName(String lookup) { if (!group.getKey().equalsIgnoreCase(PilotOptions.LVL3_ADVANTAGES)) { continue; } - + for (Enumeration j = group.getOptions(); j.hasMoreElements();) { IOption option = j.nextElement(); if(option.getName().equals(lookup)) { @@ -187,7 +187,7 @@ private String getDisplayName(String lookup) { } return "??"; } - + private String getDesc(String lookup) { PilotOptions poptions = new PilotOptions(); for (Enumeration i = poptions.getGroups(); i.hasMoreElements();) { @@ -196,7 +196,7 @@ private String getDesc(String lookup) { if (!group.getKey().equalsIgnoreCase(PilotOptions.LVL3_ADVANTAGES)) { continue; } - + for (Enumeration j = group.getOptions(); j.hasMoreElements();) { IOption option = j.nextElement(); if(option.getName().equals(lookup)) { diff --git a/MekHQ/src/mekhq/gui/dialog/ShipSearchDialog.java b/MekHQ/src/mekhq/gui/dialog/ShipSearchDialog.java index ef03034bf3..a38b623469 100644 --- a/MekHQ/src/mekhq/gui/dialog/ShipSearchDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/ShipSearchDialog.java @@ -37,9 +37,9 @@ import mekhq.MekHQ; import mekhq.campaign.finances.Money; import mekhq.gui.CampaignGUI; -import mekhq.gui.preferences.JToggleButtonPreference; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JToggleButtonPreference; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * Manages searches for DropShips or JumpShips for Against the Bot. diff --git a/MekHQ/src/mekhq/gui/dialog/SmallSVAmmoSwapDialog.java b/MekHQ/src/mekhq/gui/dialog/SmallSVAmmoSwapDialog.java index 94de71a8ac..c90c054c7b 100644 --- a/MekHQ/src/mekhq/gui/dialog/SmallSVAmmoSwapDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/SmallSVAmmoSwapDialog.java @@ -25,8 +25,8 @@ import mekhq.campaign.parts.Part; import mekhq.campaign.parts.equipment.InfantryAmmoBin; import mekhq.campaign.unit.Unit; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; import javax.swing.*; import java.awt.*; diff --git a/MekHQ/src/mekhq/gui/dialog/UnitCostReportDialog.java b/MekHQ/src/mekhq/gui/dialog/UnitCostReportDialog.java index 3d34d8a8e7..7153244015 100644 --- a/MekHQ/src/mekhq/gui/dialog/UnitCostReportDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/UnitCostReportDialog.java @@ -13,8 +13,8 @@ import mekhq.MekHQ; import mekhq.campaign.unit.Unit; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author pheonixstorm @@ -24,17 +24,17 @@ public class UnitCostReportDialog extends javax.swing.JDialog { private static final long serialVersionUID = -1423208314297284122L; - + private JTextPane txtReport; public UnitCostReportDialog(java.awt.Frame parent, Unit unit) { super(parent, false); setTitle("Monthly Cost Report for " + unit.getName()); - initComponents(); - + initComponents(); + txtReport.setText(unit.displayMonthlyCost()); txtReport.setCaretPosition(0); - + setPreferredSize(new Dimension(700, 500)); pack(); @@ -46,11 +46,11 @@ private void initComponents() { txtReport = new JTextPane(); txtReport.setContentType("text/html"); - + setLayout(new java.awt.BorderLayout()); - + txtReport.setEditable(false); - + getContentPane().add(new JScrollPane(txtReport), BorderLayout.CENTER); } diff --git a/MekHQ/src/mekhq/gui/dialog/UnitMarketDialog.java b/MekHQ/src/mekhq/gui/dialog/UnitMarketDialog.java index ae6c9adf71..52a9783262 100644 --- a/MekHQ/src/mekhq/gui/dialog/UnitMarketDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/UnitMarketDialog.java @@ -52,12 +52,12 @@ import mekhq.campaign.market.enums.UnitMarketType; import mekhq.gui.model.UnitMarketTableModel; import mekhq.gui.model.XTableColumnModel; -import mekhq.gui.preferences.JToggleButtonPreference; -import mekhq.gui.preferences.JIntNumberSpinnerPreference; -import mekhq.gui.preferences.JTablePreference; -import mekhq.gui.preferences.JWindowPreference; +import megamek.client.ui.preferences.JToggleButtonPreference; +import megamek.client.ui.preferences.JIntNumberSpinnerPreference; +import megamek.client.ui.preferences.JTablePreference; +import megamek.client.ui.preferences.JWindowPreference; import mekhq.gui.sorter.WeightClassSorter; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.PreferencesNode; /** * Code copied heavily from PersonnelMarketDialog diff --git a/MekHQ/src/mekhq/gui/dialog/UnitRatingDialog.java b/MekHQ/src/mekhq/gui/dialog/UnitRatingDialog.java index c5c3760265..a243e95cfc 100644 --- a/MekHQ/src/mekhq/gui/dialog/UnitRatingDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/UnitRatingDialog.java @@ -37,8 +37,8 @@ import mekhq.MekHQ; import mekhq.campaign.Campaign; import mekhq.campaign.rating.IUnitRating; -import mekhq.gui.preferences.JWindowPreference; -import mekhq.preferences.PreferencesNode; +import megamek.client.ui.preferences.JWindowPreference; +import megamek.client.ui.preferences.PreferencesNode; /** * @author Deric Page (deric (dot) page (at) usa.net) diff --git a/MekHQ/src/mekhq/gui/preferences/ColorPreference.java b/MekHQ/src/mekhq/gui/preferences/ColorPreference.java index a9911457b9..f02b1549ce 100644 --- a/MekHQ/src/mekhq/gui/preferences/ColorPreference.java +++ b/MekHQ/src/mekhq/gui/preferences/ColorPreference.java @@ -22,7 +22,7 @@ import java.util.Optional; import megamek.common.annotations.Nullable; -import mekhq.preferences.PreferenceElement; +import megamek.client.ui.preferences.PreferenceElement; /** * Represents a preference which can manage a color and diff --git a/MekHQ/src/mekhq/gui/preferences/JComboBoxPreference.java b/MekHQ/src/mekhq/gui/preferences/JComboBoxPreference.java deleted file mode 100644 index b9bcdb584d..0000000000 --- a/MekHQ/src/mekhq/gui/preferences/JComboBoxPreference.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2019 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 . - */ - -package mekhq.gui.preferences; - -import mekhq.preferences.PreferenceElement; - -import javax.swing.*; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.lang.ref.WeakReference; - -public class JComboBoxPreference extends PreferenceElement implements ItemListener { - private final WeakReference weakRef; - private int selectedIndex; - - public JComboBoxPreference(JComboBox comboBox) { - super(comboBox.getName()); - - this.selectedIndex = comboBox.getSelectedIndex(); - this.weakRef = new WeakReference<>(comboBox); - comboBox.addItemListener(this); - } - - @Override - public void itemStateChanged(ItemEvent e) { - if (e.getStateChange() == ItemEvent.SELECTED) { - JComboBox element = weakRef.get(); - if (element != null) { - this.selectedIndex = element.getSelectedIndex(); - } - } - } - - @Override - protected String getValue() { - return Integer.toString(this.selectedIndex); - } - - @Override - protected void initialize(String value) { - assert value != null && value.trim().length() > 0; - - JComboBox element = weakRef.get(); - if (element != null) { - int index = Integer.parseInt(value); - if (index >= 0 && index < element.getItemCount()) { - this.selectedIndex = index; - element.setSelectedIndex(this.selectedIndex); - } - } - } - - @Override - protected void dispose() { - JComboBox element = weakRef.get(); - if (element != null) { - element.removeItemListener(this); - weakRef.clear(); - } - } -} diff --git a/MekHQ/src/mekhq/gui/preferences/JIntNumberSpinnerPreference.java b/MekHQ/src/mekhq/gui/preferences/JIntNumberSpinnerPreference.java deleted file mode 100644 index 88c35ab59c..0000000000 --- a/MekHQ/src/mekhq/gui/preferences/JIntNumberSpinnerPreference.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2019 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 . - */ - -package mekhq.gui.preferences; - -import mekhq.preferences.PreferenceElement; - -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.lang.ref.WeakReference; - -public class JIntNumberSpinnerPreference extends PreferenceElement implements ChangeListener { - private final WeakReference weakRef; - private int value; - - public JIntNumberSpinnerPreference(JSpinner spinner){ - super (spinner.getName()); - assert spinner.getModel() instanceof SpinnerNumberModel; - - this.value = (Integer)spinner.getValue(); - this.weakRef = new WeakReference<>(spinner); - spinner.addChangeListener(this); - } - - @Override - public void stateChanged(ChangeEvent e) { - JSpinner element = weakRef.get(); - if (element != null) { - this.value = (Integer)element.getValue(); - } - } - - @Override - protected String getValue() { - return Integer.toString(this.value); - } - - @Override - protected void initialize(String value) { - assert value != null && value.trim().length() > 0; - - JSpinner element = weakRef.get(); - if (element != null) { - int newValue = Integer.parseInt(value); - SpinnerNumberModel model = ((SpinnerNumberModel)element.getModel()); - if ((Integer)model.getMinimum() <= newValue && - (Integer)model.getMaximum() >= newValue) { - this.value = newValue; - element.setValue(this.value); - } - } - } - - @Override - protected void dispose() { - JSpinner element = weakRef.get(); - if (element != null) { - element.removeChangeListener(this); - weakRef.clear(); - } - } -} - diff --git a/MekHQ/src/mekhq/gui/preferences/JTablePreference.java b/MekHQ/src/mekhq/gui/preferences/JTablePreference.java deleted file mode 100644 index 24ee0d7706..0000000000 --- a/MekHQ/src/mekhq/gui/preferences/JTablePreference.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2019 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 . - */ - -package mekhq.gui.preferences; - -import mekhq.preferences.PreferenceElement; - -import javax.swing.*; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.lang.ref.WeakReference; -import java.util.ArrayList; - -public class JTablePreference extends PreferenceElement implements MouseListener { - private final WeakReference weakRef; - private int columnIndex; - private SortOrder sortOrder; - - public JTablePreference(JTable table){ - super(table.getName()); - - if (table.getRowSorter().getSortKeys().size() > 0) { - this.columnIndex = table.getRowSorter().getSortKeys().get(0).getColumn(); - this.sortOrder = table.getRowSorter().getSortKeys().get(0).getSortOrder(); - } else { - columnIndex = 0; - sortOrder = SortOrder.ASCENDING; - } - - this.weakRef = new WeakReference<>(table); - table.getTableHeader().addMouseListener(this); - } - - @Override - public void mouseClicked(MouseEvent e) { - JTable table = this.weakRef.get(); - if (table != null) { - int uiIndex = table.getColumnModel().getColumnIndexAtX(e.getX()); - if (uiIndex == -1) { - return; - } - - this.columnIndex = table.getColumnModel().getColumn(uiIndex).getModelIndex(); - for (RowSorter.SortKey key : table.getRowSorter().getSortKeys()) { - if (key.getColumn() == this.columnIndex) { - this.sortOrder = key.getSortOrder(); - break; - } - } - } - } - - @Override - protected String getValue() { - return String.format("%d|%s", this.columnIndex, this.sortOrder.toString()); - } - - @Override - protected void initialize(String value) { - assert value != null && value.trim().length() > 0; - - JTable element = weakRef.get(); - if (element != null) { - String[] parts = value.split("\\|", -1); - - this.columnIndex = Integer.parseInt(parts[0]); - this.sortOrder = SortOrder.valueOf(parts[1]); - - ArrayList sortKeys = new ArrayList<>(); - sortKeys.add(new RowSorter.SortKey(this.columnIndex, this.sortOrder)); - - element.getRowSorter().setSortKeys(sortKeys); - } - } - - @Override - protected void dispose() { - JTable element = weakRef.get(); - if (element != null) { - element.removeMouseListener(this); - weakRef.clear(); - } - } - - @Override - public void mousePressed(MouseEvent e) { - } - - @Override - public void mouseReleased(MouseEvent e) { - } - - @Override - public void mouseEntered(MouseEvent e) { - } - - @Override - public void mouseExited(MouseEvent e) { - } -} diff --git a/MekHQ/src/mekhq/gui/preferences/JTextFieldPreference.java b/MekHQ/src/mekhq/gui/preferences/JTextFieldPreference.java deleted file mode 100644 index c0eada5c3e..0000000000 --- a/MekHQ/src/mekhq/gui/preferences/JTextFieldPreference.java +++ /dev/null @@ -1,68 +0,0 @@ -package mekhq.gui.preferences; - - -import mekhq.preferences.PreferenceElement; - -import javax.swing.*; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import java.lang.ref.WeakReference; - -public class JTextFieldPreference extends PreferenceElement implements DocumentListener { - private final WeakReference weakRef; - private String value; - - public JTextFieldPreference(JTextField textField) { - super(textField.getName()); - - this.value = textField.getText(); - this.weakRef = new WeakReference<>(textField); - textField.getDocument().addDocumentListener(this); - } - - @Override - public void insertUpdate(DocumentEvent e) { - JTextField element = weakRef.get(); - if (element != null) { - this.value = element.getText(); - } - } - - @Override - public void removeUpdate(DocumentEvent e) { - JTextField element = weakRef.get(); - if (element != null) { - this.value = element.getText(); - } - } - - @Override - public void changedUpdate(DocumentEvent e) { - JTextField element = weakRef.get(); - if (element != null) { - this.value = element.getText(); - } - } - - @Override - protected String getValue() { - return this.value; - } - - @Override - protected void initialize(String value) { - JTextField element = weakRef.get(); - if (element != null) { - element.setText(value); - } - } - - @Override - protected void dispose() { - JTextField element = weakRef.get(); - if (element != null) { - element.getDocument().removeDocumentListener(this); - weakRef.clear(); - } - } -} diff --git a/MekHQ/src/mekhq/gui/preferences/JToggleButtonPreference.java b/MekHQ/src/mekhq/gui/preferences/JToggleButtonPreference.java deleted file mode 100644 index 3022e2ba13..0000000000 --- a/MekHQ/src/mekhq/gui/preferences/JToggleButtonPreference.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2019 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 . - */ - -package mekhq.gui.preferences; - -import mekhq.preferences.PreferenceElement; - -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.lang.ref.WeakReference; - -public class JToggleButtonPreference extends PreferenceElement implements ChangeListener { - private final WeakReference weakRef; - private boolean value; - - public JToggleButtonPreference(JToggleButton toggleButton){ - super(toggleButton.getName()); - - this.value = toggleButton.isSelected(); - this.weakRef = new WeakReference<>(toggleButton); - toggleButton.addChangeListener(this); - } - - @Override - public void stateChanged(ChangeEvent e) { - JToggleButton element = weakRef.get(); - if (element != null) { - this.value = element.isSelected(); - } - } - - @Override - protected String getValue() { - return Boolean.toString(this.value); - } - - @Override - protected void initialize(String value) { - assert value != null && value.trim().length() > 0; - - JToggleButton element = weakRef.get(); - if (element != null) { - this.value = Boolean.parseBoolean(value); - element.setSelected(this.value); - } - } - - @Override - protected void dispose() { - JToggleButton element = weakRef.get(); - if (element != null) { - element.removeChangeListener(this); - weakRef.clear(); - } - } -} diff --git a/MekHQ/src/mekhq/gui/preferences/JWindowPreference.java b/MekHQ/src/mekhq/gui/preferences/JWindowPreference.java deleted file mode 100644 index 4d83eb3f27..0000000000 --- a/MekHQ/src/mekhq/gui/preferences/JWindowPreference.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2019 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 . - */ - -package mekhq.gui.preferences; - -import mekhq.preferences.PreferenceElement; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.awt.event.WindowEvent; -import java.awt.event.WindowStateListener; -import java.lang.ref.WeakReference; - -public class JWindowPreference extends PreferenceElement implements WindowStateListener, ComponentListener { - private final WeakReference weakRef; - private int width; - private int height; - private int screenX; - private int screenY; - private boolean isMaximized; - - public JWindowPreference(Window window) { - super (window.getName()); - - this.width = window.getWidth(); - this.height = window.getHeight(); - - if (window.isVisible()) { - this.screenX = window.getLocationOnScreen().x; - this.screenY = window.getLocationOnScreen().y; - } - - if (window instanceof JFrame) { - this.isMaximized = (((JFrame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH; - } else { - this.isMaximized = false; - } - - this.weakRef = new WeakReference<>(window); - window.addWindowStateListener(this); - window.addComponentListener(this); - } - - @Override - public void windowStateChanged(WindowEvent e) { - this.isMaximized = (e.getNewState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH; - } - - @Override - public void componentResized(ComponentEvent e) { - this.width = e.getComponent().getWidth(); - this.height = e.getComponent().getHeight(); - } - - @Override - public void componentMoved(ComponentEvent e) { - if (e.getComponent().isVisible()) { - this.screenX = e.getComponent().getLocationOnScreen().x; - this.screenY = e.getComponent().getLocationOnScreen().y; - } - } - - @Override - protected String getValue() { - return String.format("%d|%d|%d|%d|%s", this.width, this.height, this.screenX, this.screenY, this.isMaximized); - } - - @Override - protected void initialize(String value) { - assert value != null && value.trim().length() > 0; - - Window element = weakRef.get(); - if (element != null) { - String[] parts = value.split("\\|", -1); - - this.width = Integer.parseInt(parts[0]); - this.height = Integer.parseInt(parts[1]); - this.screenX = Integer.parseInt(parts[2]); - this.screenY = Integer.parseInt(parts[3]); - this.isMaximized = Boolean.parseBoolean(parts[4]); - - element.setSize(this.width, this.height); - element.setLocation(this.screenX, this.screenY); - if (this.isMaximized) { - if (element instanceof JFrame) { - ((JFrame)element).setExtendedState(((JFrame)element).getExtendedState() | Frame.MAXIMIZED_BOTH); - } - } - } - } - - @Override - protected void dispose() { - Window element = weakRef.get(); - if (element != null) { - element.removeWindowStateListener(this); - element.removeComponentListener(this); - weakRef.clear(); - } - } - - @Override - public void componentShown(ComponentEvent e) { - } - - @Override - public void componentHidden(ComponentEvent e) { - } -} diff --git a/MekHQ/src/mekhq/gui/preferences/StringPreference.java b/MekHQ/src/mekhq/gui/preferences/StringPreference.java index e18bb4a75f..865a8cee06 100644 --- a/MekHQ/src/mekhq/gui/preferences/StringPreference.java +++ b/MekHQ/src/mekhq/gui/preferences/StringPreference.java @@ -20,7 +20,7 @@ package mekhq.gui.preferences; import mekhq.gui.utilities.ObservableString; -import mekhq.preferences.PreferenceElement; +import megamek.client.ui.preferences.PreferenceElement; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; diff --git a/MekHQ/src/mekhq/preferences/MekHqPreferences.java b/MekHQ/src/mekhq/preferences/MekHqPreferences.java deleted file mode 100644 index 0da17b7ce1..0000000000 --- a/MekHQ/src/mekhq/preferences/MekHqPreferences.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2019-2020 - 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 . - */ -package mekhq.preferences; - -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import mekhq.MekHQ; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -/** - * The root class for MekHQ user nameToPreferencesMap system. - */ -public class MekHqPreferences { - private static final String PREFERENCES_TOKEN = "preferences"; - private static final String CLASS_TOKEN = "class"; - private static final String ELEMENTS_TOKEN = "elements"; - private static final String NAME_TOKEN = "element"; - private static final String VALUE_TOKEN = "value"; - private final Map nameToPreferencesMap; - - public MekHqPreferences() { - this.nameToPreferencesMap = new HashMap<>(); - } - - public void loadFromFile(String filePath) { - try { - try (FileInputStream input = new FileInputStream(filePath)) { - MekHQ.getLogger().info(this, "Loading MekHQ user preferences from: " + filePath); - - JsonFactory factory = new JsonFactory(); - JsonParser parser = factory.createParser(input); - - if (parser.nextToken() != JsonToken.START_OBJECT) { - throw new IOException("Expected an object start ({)" + getParserInformation(parser)); - } else if (parser.nextToken() != JsonToken.FIELD_NAME && !parser.getCurrentName().equals(PREFERENCES_TOKEN)) { - throw new IOException("Expected a field called (" + PREFERENCES_TOKEN + ")" + getParserInformation(parser)); - } else if (parser.nextToken() != JsonToken.START_ARRAY) { - throw new IOException("Expected an array start ([)" + getParserInformation(parser)); - } - - // Parse all PreferencesNode - while (parser.nextToken() != JsonToken.END_ARRAY){ - try { - readPreferencesNode(parser, this.nameToPreferencesMap); - } catch (IOException e) { - MekHQ.getLogger().error(this, "Error reading node. " + getParserInformation(parser), e); - } - } - - parser.close(); - - MekHQ.getLogger().info(this, "Finished loading user preferences"); - } - } - catch (FileNotFoundException e) { - MekHQ.getLogger().error(this, "No MekHQ user preferences file found: " + filePath, e); - } - catch (IOException e) { - MekHQ.getLogger().error(this, "Error reading from the user preferences file: " + filePath, e); - } - } - - public void saveToFile(String filePath) { - try { - try (FileOutputStream output = new FileOutputStream(filePath)) { - MekHQ.getLogger().debug(this, "Saving MekHQ nameToPreferencesMap to: " + filePath); - - JsonFactory factory = new JsonFactory(); - JsonGenerator writer = factory.createGenerator(output); - writer = writer.useDefaultPrettyPrinter(); - writer.enable(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION); - - writer.writeStartObject(); - writer.writeFieldName(PREFERENCES_TOKEN); - writer.writeStartArray(); - - // Write each PreferencesNode - for (Map.Entry preferences : this.nameToPreferencesMap.entrySet()) { - writePreferencesNode(writer, preferences); - } - - writer.writeEndArray(); - writer.writeEndObject(); - - writer.close(); - } - } catch (FileNotFoundException e) { - MekHQ.getLogger().error(this, "Could not save nameToPreferencesMap to: " + filePath, e); - } catch (IOException e) { - MekHQ.getLogger().error(this, "Error writing to the nameToPreferencesMap file: " + filePath, e); - } - } - - public PreferencesNode forClass(Class classToManage) { - PreferencesNode preferences = this.nameToPreferencesMap.getOrDefault(classToManage.getName(), null); - if (preferences == null) { - preferences = new PreferencesNode(classToManage); - this.nameToPreferencesMap.put(classToManage.getName(), preferences); - } - - return preferences; - } - - private static void readPreferencesNode(JsonParser parser, Map nodes) throws IOException { - final String METHOD_NAME = "readPreferencesNode"; - - String className; - HashMap elements = new HashMap<>(); - - if (parser.currentToken() != JsonToken.START_OBJECT) { - return; - } - - if (parser.nextToken() != JsonToken.FIELD_NAME && !parser.getCurrentName().equals(CLASS_TOKEN)) { - return; - } - - className = parser.nextTextValue(); - - if (parser.nextToken() != JsonToken.FIELD_NAME && !parser.getCurrentName().equals(ELEMENTS_TOKEN)) { - return; - } - - if (parser.nextToken() != JsonToken.START_ARRAY) { - return; - } - - // Parse all PreferenceElement in this node - while (parser.nextToken() != JsonToken.END_ARRAY) { - try { - readPreferenceElement(parser, elements); - } - catch (IOException e) { - MekHQ.getLogger().warning(MekHqPreferences.class, METHOD_NAME, - "Error reading elements for node: " + className + ".", e); - } - } - - try { - PreferencesNode node = new PreferencesNode(Class.forName(className)); - node.initialize(elements); - nodes.put(node.getNodeName(), node); - } - catch (ClassNotFoundException e) { - MekHQ.getLogger().error(MekHqPreferences.class, METHOD_NAME, - "No class with name " + className + " found", e); - } - } - - private static void readPreferenceElement(JsonParser parser, HashMap elements) throws IOException { - String name; - String value; - - if (parser.currentToken() != JsonToken.START_OBJECT) { - return; - } - - if (parser.nextToken() != JsonToken.FIELD_NAME && !parser.getCurrentName().equals(NAME_TOKEN)) { - return; - } - - name = parser.nextTextValue(); - - if (parser.nextToken() != JsonToken.FIELD_NAME && !parser.getCurrentName().equals(VALUE_TOKEN)) { - return; - } - - value = parser.nextTextValue(); - - if (parser.nextToken() != JsonToken.END_OBJECT) { - return; - } - - elements.put(name, value); - } - - private static void writePreferencesNode(JsonGenerator writer, Map.Entry nodeInfo) throws IOException { - writer.writeStartObject(); - writer.writeStringField(CLASS_TOKEN, nodeInfo.getKey()); - writer.writeFieldName(ELEMENTS_TOKEN); - writer.writeStartArray(); - - // Write all PreferenceElement in this node - for (Map.Entry element : nodeInfo.getValue().getFinalValues().entrySet()) { - writePreferenceElement(writer, element); - } - - writer.writeEndArray(); - writer.writeEndObject(); - } - - private static void writePreferenceElement(JsonGenerator writer, Map.Entry element) throws IOException { - writer.writeStartObject(); - writer.writeStringField(NAME_TOKEN, element.getKey()); - writer.writeStringField(VALUE_TOKEN, element.getValue()); - writer.writeEndObject(); - } - - private static String getParserInformation(JsonParser parser) throws IOException { - if (parser == null) { - return ""; - } - - return ". Current token: " + parser.getCurrentName() + - ". Line number: " + parser.getCurrentLocation().getLineNr() + - ". Column number: " + parser.getCurrentLocation().getColumnNr(); - } -} diff --git a/MekHQ/src/mekhq/preferences/PreferenceElement.java b/MekHQ/src/mekhq/preferences/PreferenceElement.java deleted file mode 100644 index 65c246b0c6..0000000000 --- a/MekHQ/src/mekhq/preferences/PreferenceElement.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2019 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 . - */ - -package mekhq.preferences; - -/** - * Represents the set of information needed to be part - * of the user preferences system for MekHQ. - * - * A preference is a value that the user can set anywhere in - * MekHQ and that will be persisted between user sessions. - * - * PreferenceElements are contained inside @link PreferenceNodes, - * forming a tree. You can imagine a PreferenceElement as a field, - * and a PreferencesNode as a class. - * - * This class is not thread-safe. - */ -public abstract class PreferenceElement { - private String name; - - protected PreferenceElement(String name) { - assert name != null && name.trim().length() > 0; - this.name = name; - } - - /** - * Name for this preference. - * The name has to be unique for this node. - * @return the name of the preference. - */ - protected String getName() { - return name; - } - - /** - * Gets the current value for the preference. - * @return the value of the preference. - */ - protected abstract String getValue(); - - /** - * Sets the initial value for the preference. - * @param value initial value. - */ - protected abstract void initialize(String value); - - /** - * Cleans the preference resources. - */ - protected abstract void dispose(); -} diff --git a/MekHQ/src/mekhq/preferences/PreferencesNode.java b/MekHQ/src/mekhq/preferences/PreferencesNode.java deleted file mode 100644 index d32e37852c..0000000000 --- a/MekHQ/src/mekhq/preferences/PreferencesNode.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2019 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 . - */ - -package mekhq.preferences; - -import java.util.HashMap; -import java.util.Map; - -/** - * Represents a group of @link PreferenceElement that are part of the same - * @link Class. - * - * This class is not thread-safe. - */ -public class PreferencesNode { - private final Class node; - private final Map elements; - private Map initialValues; - - private boolean initialized = false; - private boolean finalized = false; - - PreferencesNode(Class node) { - assert node != null; - - this.node = node; - this.initialValues = new HashMap<>(); - this.elements = new HashMap<>(); - } - - /** - * Adds a new element to be managed by this node. - * If there are initial vales set for this node, - * we will try to set an initial value for this element. - * @param element element to manage. - */ - public void manage(PreferenceElement element) { - PreferenceElement actual = this.elements.get(element.getName()); - if (actual != null) { - this.initialValues.put(actual.getName(), actual.getValue()); - actual.dispose(); - } - - this.elements.put(element.getName(), element); - - if (this.initialValues.containsKey(element.getName())) { - element.initialize(this.initialValues.get(element.getName())); - } - } - - /** - * Adds new elements to be managed by this node. - * If there are initial vales set for this node, - * we will try to set an initial value for each element. - * @param elements elements to manage. - */ - public void manage(PreferenceElement... elements) { - for (PreferenceElement element : elements) { - manage(element); - } - } - - /** - * The class which preferences we are storing in this node. - * @return the class stored in this node. - */ - String getNodeName() { - return this.node.getName(); - } - - /** - * Sets the initial values for elements managed for this node. - * This method should only be called once. - * @param initialValues initial values for the elements. - */ - void initialize(Map initialValues) { - assert initialValues != null; - assert !initialized; - - this.initialized = true; - this.initialValues = initialValues; - } - - /** - * Gets the values of all the elements managed by this node. - * This method should only be called once. - * @return - */ - Map getFinalValues() { - assert !finalized; - - finalized = true; - Map finalValues = new HashMap<>(this.elements.size()); - - // Use the values we had stored from initialization - for(Map.Entry initialValue : this.initialValues.entrySet()) { - finalValues.put(initialValue.getKey(), initialValue.getValue()); - } - - // Overwrite the initial values with values generated during this - // session - for(PreferenceElement wrapper : this.elements.values()) { - finalValues.put(wrapper.getName(), wrapper.getValue()); - } - - return finalValues; - } -}