diff --git a/megameklab/resources/megameklab/resources/Menu.properties b/megameklab/resources/megameklab/resources/Menu.properties
index d6b3b73d6..904a4431b 100644
--- a/megameklab/resources/megameklab/resources/Menu.properties
+++ b/megameklab/resources/megameklab/resources/Menu.properties
@@ -85,20 +85,8 @@ menu.help.about.info.1=Project Info:
menu.help.about.info.2=https://github.com/MegaMek/megameklab
menu.help.imageHelp.title=Image Help
-menu.help.imageHelp.text=To add a fluff image to a record sheet the following steps need to be taken\n\
-Please Note that currently only 'Mechs use fluff Images\n\
-Place the image you want to use in the data/images/fluff folder\n\
-MegaMekLab will attempt to match the name of the 'Mech you are printing\n\
-with the images in the fluff folder.\n\
-The following is an example of how MegaMekLab look for the image\n\
-Example\n\
-Your 'Mech is called Archer ARC-7Q\n\
-MegaMekLab would look for the following\n\
-\n\
-Archer ARC-7Q.jpg/png/gif\n\
-ARC-7Q.jpg/png/gif\n\
-Archer.jpg/png/gif\n\
-hud.png
+menu.help.imageHelp.text=To add a fluff image to a record sheet. Please see the following link\n\
+https://github.com/MegaMek/megamek/wiki/How-do-I-get-Fluff-Images-to-work
dialog.chooseUnit.title=Choose Unit
dialog.imagePath.title=Image Path
diff --git a/megameklab/src/megameklab/ui/MegaMekLabMainUI.java b/megameklab/src/megameklab/ui/MegaMekLabMainUI.java
index 95f960aaf..37f3af08a 100644
--- a/megameklab/src/megameklab/ui/MegaMekLabMainUI.java
+++ b/megameklab/src/megameklab/ui/MegaMekLabMainUI.java
@@ -21,16 +21,14 @@
import megamek.common.preference.PreferenceManager;
import megameklab.MMLConstants;
import megameklab.MegaMekLab;
-import megameklab.ui.util.AppCloser;
import megameklab.ui.util.ExitOnWindowClosingListener;
import megameklab.ui.util.RefreshListener;
import megameklab.util.CConfig;
import javax.swing.*;
-import javax.swing.UIManager.LookAndFeelInfo;
import java.awt.*;
-public abstract class MegaMekLabMainUI extends JFrame implements RefreshListener, EntitySource, AppCloser {
+public abstract class MegaMekLabMainUI extends JFrame implements RefreshListener, EntitySource, MenuBarOwner {
private Entity entity = null;
protected MenuBar mmlMenuBar;
protected boolean refreshRequired = false;
@@ -72,37 +70,8 @@ protected void setSizeAndLocation() {
setPreferredSize(size);
setLocationRelativeTo(null);
}
-
- /**
- * Sets the look and feel for the application.
- *
- * @param plaf The look and feel to use for the application.
- */
- public void changeTheme(LookAndFeelInfo plaf) {
- SwingUtilities.invokeLater(() -> {
- try {
- UIManager.setLookAndFeel(plaf.getClassName());
- SwingUtilities.updateComponentTreeUI(this);
- } catch (Exception exception) {
- JOptionPane.showMessageDialog(this,
- "Can't change look and feel", "Invalid PLAF",
- JOptionPane.ERROR_MESSAGE);
- }
-
- });
- }
- /**
- * When the setting "Disable save prompts" is active (see Misc Settings), returns true directly.
- * Otherwise, this shows a safety dialog prompting the user to consider saving the currently entered unit.
- * This method returns true only when MML should continue with the action that led to this dialog. This is
- * the case when the user selects NO or selects YES and actually saves the unit.
- * When the user closes the dialog (X or ESC) or presses CANCEL or presses YES but doesn't save the
- * unit, returns false which indicates that the current action (e.g. reset unit or switch unit or quit) should
- * be canceled. See also {@link megameklab.ui.dialog.settings.MiscSettingsPanel}.
- *
- * @return True only when the user agrees to continue or has deactivated these prompts, false otherwise
- */
+ @Override
public boolean safetyPrompt() {
if (CConfig.getBooleanParam(CConfig.MISC_SKIP_SAFETY_PROMPTS)) {
return true;
@@ -186,4 +155,9 @@ private void performRefresh() {
}
public abstract JDialog getFloatingEquipmentDatabase();
+
+ @Override
+ public JFrame getFrame() {
+ return this;
+ }
}
\ No newline at end of file
diff --git a/megameklab/src/megameklab/ui/MenuBar.java b/megameklab/src/megameklab/ui/MenuBar.java
index 12ad4c565..cb1495479 100644
--- a/megameklab/src/megameklab/ui/MenuBar.java
+++ b/megameklab/src/megameklab/ui/MenuBar.java
@@ -1,6 +1,6 @@
/*
* MegaMekLab
- * Copyright (c) 2011-2022 - The MegaMek Team. All Rights Reserved.
+ * Copyright (c) 2011-2023 - The MegaMek Team. All Rights Reserved.
*
* This program 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
@@ -50,42 +50,45 @@
/**
* @author jtighe (torren@users.sourceforge.net)
* @author Justin "Windchild" Bowen
+ * @author Simon (Juliez)
*/
public class MenuBar extends JMenuBar implements ClipboardOwner {
//region Variable Declarations
- private final MegaMekLabMainUI frame;
+ private final MenuBarOwner owner;
private final ResourceBundle resources = ResourceBundle.getBundle("megameklab.resources.Menu");
//endregion Variable Declarations
//region Constructors
- public MenuBar(final MegaMekLabMainUI frame) {
- this.frame = frame;
+ public MenuBar(MenuBarOwner owner) {
+ this.owner = owner;
initialize();
}
//endregion Constructors
//region Getters
- public MegaMekLabMainUI getFrame() {
- return frame;
+ public @Nullable MegaMekLabMainUI getUnitMainUi() {
+ if (owner instanceof MegaMekLabMainUI) {
+ return (MegaMekLabMainUI) owner;
+ } else {
+ return null;
+ }
}
//endregion Getters
- //region Conditional Exit Handler
/**
* The File menu's exit handler pops up a modal that produces a boolean;
* to match the functionality of ExitOnWindowClosingListener, we want to
* exit if that boolean is true.
* Otherwise, do nothing.
- * @param okayToExit
+ *
+ * @param okayToExit When true, will exit MML, otherwise do nothing
*/
- public void conditionalExit( boolean okayToExit){
- if (okayToExit){
+ private void conditionalExit(boolean okayToExit) {
+ if (okayToExit) {
System.exit(0);
}
}
- //endregion Conditional Exit Handler
- //region Initialization
/**
* The main menu bar uses the following Mnemonic keys as of 30-Jun-2022:
* F, H, R, U
@@ -103,8 +106,6 @@ private void initialize() {
//region File Menu
/**
- * This menu uses the following Mnemonic keys as of 30-Jun-2022:
- * C, E, I, L, O, P, R, S, U, X
* @return the created file menu
*/
private JMenu createFileMenu() {
@@ -114,9 +115,9 @@ private JMenu createFileMenu() {
final JMenuItem miResetCurrentUnit = new JMenuItem(resources.getString("miResetCurrentUnit.text"));
miResetCurrentUnit.setName("miResetCurrentUnit");
- miResetCurrentUnit.setMnemonic(KeyEvent.VK_C);
- miResetCurrentUnit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK));
+ miResetCurrentUnit.setMnemonic(KeyEvent.VK_R);
miResetCurrentUnit.addActionListener(this::jMenuResetEntity_actionPerformed);
+ miResetCurrentUnit.setEnabled(isUnitGui());
fileMenu.add(miResetCurrentUnit);
fileMenu.add(createSwitchUnitTypeMenu());
@@ -151,7 +152,7 @@ private JMenu createFileMenu() {
hasCConfigMenuItem = true;
}
- final JMenuItem miCConfig4 = createCConfigMenuItem(CConfig.CONFIG_SAVE_FILE_4, fileNumber++);
+ final JMenuItem miCConfig4 = createCConfigMenuItem(CConfig.CONFIG_SAVE_FILE_4, fileNumber);
if (miCConfig4 != null) {
fileMenu.add(miCConfig4);
hasCConfigMenuItem = true;
@@ -163,104 +164,92 @@ private JMenu createFileMenu() {
final JMenuItem miExit = new JMenuItem(resources.getString("miExit.text"));
miExit.setName("miExit");
- miExit.setMnemonic(KeyEvent.VK_E);
- miExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_DOWN_MASK));
- miExit.addActionListener(evt -> conditionalExit(getFrame().exit()));
+ miExit.setMnemonic(KeyEvent.VK_X);
+ miExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_DOWN_MASK));
+ miExit.addActionListener(evt -> conditionalExit(owner.exit()));
fileMenu.add(miExit);
return fileMenu;
}
/**
- * This menu uses the following Mnemonic keys as of 30-Jun-2022:
- * A, B, C, D, I, J, M, P, R
* @return the created Switch Unit Type menu
*/
private JMenu createSwitchUnitTypeMenu() {
final JMenu switchUnitTypeMenu = new JMenu(resources.getString("switchUnitTypeMenu.text"));
switchUnitTypeMenu.setName("switchUnitTypeMenu");
- switchUnitTypeMenu.setMnemonic(KeyEvent.VK_U);
+ switchUnitTypeMenu.setMnemonic(KeyEvent.VK_W);
- final Entity entity = getFrame().getEntity();
+ final Entity entity = owner.getEntity();
- if (!(entity instanceof Mech) || entity.isPrimitive()) {
+ if ((entity == null) || (!(entity instanceof Mech) || entity.isPrimitive())) {
final JMenuItem miSwitchToMek = new JMenuItem(resources.getString("miSwitchToMek.text"));
miSwitchToMek.setName("miSwitchToMek");
miSwitchToMek.setMnemonic(KeyEvent.VK_M);
- miSwitchToMek.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.ALT_DOWN_MASK));
miSwitchToMek.addActionListener(evt -> newUnit(Entity.ETYPE_MECH, false));
switchUnitTypeMenu.add(miSwitchToMek);
}
- if (!entity.isFighter() || ((entity instanceof Aero) && entity.isPrimitive())) {
+ if ((entity == null) || (!entity.isFighter() || ((entity instanceof Aero) && entity.isPrimitive()))) {
final JMenuItem miSwitchToFighter = new JMenuItem(resources.getString("miSwitchToFighter.text"));
miSwitchToFighter.setName("miSwitchToFighter");
miSwitchToFighter.setMnemonic(KeyEvent.VK_A);
- miSwitchToFighter.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.ALT_DOWN_MASK));
miSwitchToFighter.addActionListener(evt -> newUnit(Entity.ETYPE_AERO, false));
switchUnitTypeMenu.add(miSwitchToFighter);
}
- if (!(entity instanceof SmallCraft) || entity.isPrimitive()) {
+ if ((entity == null) || (!(entity instanceof SmallCraft) || entity.isPrimitive())) {
final JMenuItem item = new JMenuItem(resources.getString("miSwitchToDropShipSmallCraft.text"));
item.setName("miSwitchToDropShipSmallCraft");
item.setMnemonic(KeyEvent.VK_D);
- item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_DOWN_MASK));
item.addActionListener(evt -> newUnit(Entity.ETYPE_DROPSHIP, false));
switchUnitTypeMenu.add(item);
}
- if (!(entity instanceof Jumpship) || entity.isPrimitive()) {
+ if ((entity == null) || (!(entity instanceof Jumpship) || entity.isPrimitive())){
final JMenuItem miSwitchToAdvancedAero = new JMenuItem(resources.getString("miSwitchToAdvancedAero.text"));
miSwitchToAdvancedAero.setName("miSwitchToAdvancedAero");
miSwitchToAdvancedAero.setMnemonic(KeyEvent.VK_J);
- miSwitchToAdvancedAero.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, InputEvent.ALT_DOWN_MASK));
miSwitchToAdvancedAero.addActionListener(evt -> newUnit(Entity.ETYPE_JUMPSHIP, false));
switchUnitTypeMenu.add(miSwitchToAdvancedAero);
}
- if (!(getFrame().getEntity() instanceof Tank)
- || getFrame().getEntity().isSupportVehicle()) {
+ if ((entity == null) || (!(entity instanceof Tank) || entity.isSupportVehicle())) {
final JMenuItem miSwitchToCombatVehicle = new JMenuItem(resources.getString("miSwitchToCombatVehicle.text"));
miSwitchToCombatVehicle.setName("miSwitchToCombatVehicle");
miSwitchToCombatVehicle.setMnemonic(KeyEvent.VK_C);
- miSwitchToCombatVehicle.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
miSwitchToCombatVehicle.addActionListener(evt -> newUnit(Entity.ETYPE_TANK, false));
switchUnitTypeMenu.add(miSwitchToCombatVehicle);
}
- if (!getFrame().getEntity().isSupportVehicle()) {
+ if ((entity == null) || (!entity.isSupportVehicle())) {
final JMenuItem miSwitchToSupportVehicle = new JMenuItem(resources.getString("miSwitchToSupportVehicle.text"));
miSwitchToSupportVehicle.setName("miSwitchToSupportVehicle");
miSwitchToSupportVehicle.setMnemonic(KeyEvent.VK_S);
- miSwitchToSupportVehicle.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_DOWN_MASK));
miSwitchToSupportVehicle.addActionListener(evt -> newUnit(Entity.ETYPE_SUPPORT_TANK, false));
switchUnitTypeMenu.add(miSwitchToSupportVehicle);
}
- if (!(getFrame().getEntity() instanceof BattleArmor)) {
+ if (!(entity instanceof BattleArmor)) {
final JMenuItem miSwitchToBattleArmor = new JMenuItem(resources.getString("miSwitchToBattleArmor.text"));
miSwitchToBattleArmor.setName("miSwitchToBattleArmor");
miSwitchToBattleArmor.setMnemonic(KeyEvent.VK_B);
- miSwitchToBattleArmor.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.ALT_DOWN_MASK));
miSwitchToBattleArmor.addActionListener(evt -> newUnit(Entity.ETYPE_BATTLEARMOR, false));
switchUnitTypeMenu.add(miSwitchToBattleArmor);
}
- if (!getFrame().getEntity().isConventionalInfantry()) {
+ if ((entity == null) || (!entity.isConventionalInfantry())) {
final JMenuItem miSwitchToInfantry = new JMenuItem(resources.getString("miSwitchToInfantry.text"));
miSwitchToInfantry.setName("miSwitchToInfantry");
miSwitchToInfantry.setMnemonic(KeyEvent.VK_I);
- miSwitchToInfantry.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.ALT_DOWN_MASK));
miSwitchToInfantry.addActionListener(evt -> newUnit(Entity.ETYPE_INFANTRY, false));
switchUnitTypeMenu.add(miSwitchToInfantry);
}
- if (!getFrame().getEntity().hasETypeFlag(Entity.ETYPE_PROTOMECH)) {
+ if ((entity == null) || (!entity.hasETypeFlag(Entity.ETYPE_PROTOMECH))) {
final JMenuItem miSwitchToProtoMek = new JMenuItem(resources.getString("miSwitchToProtoMek.text"));
miSwitchToProtoMek.setName("miSwitchToProtoMek");
miSwitchToProtoMek.setMnemonic(KeyEvent.VK_P);
- miSwitchToProtoMek.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_DOWN_MASK));
miSwitchToProtoMek.addActionListener(evt -> newUnit(Entity.ETYPE_PROTOMECH, false));
switchUnitTypeMenu.add(miSwitchToProtoMek);
}
@@ -271,8 +260,6 @@ private JMenu createSwitchUnitTypeMenu() {
}
/**
- * This menu uses the following Mnemonic keys as of 30-Jun-2022:
- * A, D, J, M
* @return the created Primitive menu
*/
private JMenu createPrimitiveMenu(final Entity entity) {
@@ -280,38 +267,34 @@ private JMenu createPrimitiveMenu(final Entity entity) {
primitiveMenu.setName("primitiveMenu");
primitiveMenu.setMnemonic(KeyEvent.VK_R);
- if (!(entity instanceof Mech) || !entity.isPrimitive()) {
+ if ((entity == null) || (!(entity instanceof Mech) || !entity.isPrimitive())) {
final JMenuItem miSwitchToMek = new JMenuItem(resources.getString("miSwitchToMek.text"));
miSwitchToMek.setName("miSwitchToMek");
miSwitchToMek.setMnemonic(KeyEvent.VK_M);
- miSwitchToMek.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.ALT_DOWN_MASK));
miSwitchToMek.addActionListener(evt -> newUnit(Entity.ETYPE_MECH, true));
primitiveMenu.add(miSwitchToMek);
}
- if (!entity.isFighter() || ((entity instanceof Aero) && !entity.isPrimitive())) {
+ if ((entity == null) || (!entity.isFighter() || ((entity instanceof Aero) && !entity.isPrimitive()))) {
final JMenuItem miSwitchToAero = new JMenuItem(resources.getString("miSwitchToAero.text"));
miSwitchToAero.setName("miSwitchToAero");
miSwitchToAero.setMnemonic(KeyEvent.VK_A);
- miSwitchToAero.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.ALT_DOWN_MASK));
miSwitchToAero.addActionListener(evt -> newUnit(Entity.ETYPE_AERO, true));
primitiveMenu.add(miSwitchToAero);
}
- if (!(entity instanceof SmallCraft) || !entity.isPrimitive()) {
+ if ((entity == null) || (!(entity instanceof SmallCraft) || !entity.isPrimitive())) {
final JMenuItem miSwitchToDropShipSmallCraft = new JMenuItem(resources.getString("miSwitchToDropShipSmallCraft.text"));
miSwitchToDropShipSmallCraft.setName("miSwitchToDropShipSmallCraft");
miSwitchToDropShipSmallCraft.setMnemonic(KeyEvent.VK_D);
- miSwitchToDropShipSmallCraft.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_DOWN_MASK));
miSwitchToDropShipSmallCraft.addActionListener(evt -> newUnit(Entity.ETYPE_DROPSHIP, true));
primitiveMenu.add(miSwitchToDropShipSmallCraft);
}
- if (!(entity instanceof Jumpship) || !entity.isPrimitive()) {
+ if ((entity == null) || (!(entity instanceof Jumpship) || !entity.isPrimitive())) {
final JMenuItem miSwitchToJumpShip = new JMenuItem(resources.getString("miSwitchToJumpShip.text"));
miSwitchToJumpShip.setName("miSwitchToJumpShip");
miSwitchToJumpShip.setMnemonic(KeyEvent.VK_J);
- miSwitchToJumpShip.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, InputEvent.ALT_DOWN_MASK));
miSwitchToJumpShip.addActionListener(evt -> newUnit(Entity.ETYPE_JUMPSHIP, true));
primitiveMenu.add(miSwitchToJumpShip);
}
@@ -333,7 +316,7 @@ private JMenu createLoadMenu() {
miLoadUnitFromCache.setName("miLoadUnitFromCache");
miLoadUnitFromCache.setMnemonic(KeyEvent.VK_C);
miLoadUnitFromCache.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_DOWN_MASK));
- miLoadUnitFromCache.addActionListener(evt -> StartupGUI.selectAndLoadUnitFromCache(frame));
+ miLoadUnitFromCache.addActionListener(evt -> StartupGUI.selectAndLoadUnitFromCache(owner.getFrame()));
loadMenu.add(miLoadUnitFromCache);
final JMenuItem miLoadUnitFromFile = new JMenuItem(resources.getString("FromFile.text"));
@@ -361,13 +344,15 @@ private JMenu createSaveMenu() {
miSave.setMnemonic(KeyEvent.VK_S);
miSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
miSave.addActionListener(evt -> saveEntity());
+ miSave.setEnabled(isUnitGui());
saveMenu.add(miSave);
final JMenuItem miSaveAs = new JMenuItem(resources.getString("SaveAs.text"));
miSaveAs.setName("miSaveAs");
miSaveAs.setMnemonic(KeyEvent.VK_A);
- miSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_DOWN_MASK));
- miSaveAs.addActionListener(this::jMenuSaveAsEntity_actionPerformed);
+ miSaveAs.setAccelerator(KeyStroke.getKeyStroke("control shift S"));
+ miSaveAs.addActionListener(evt -> jMenuSaveAsEntity_actionPerformed());
+ miSaveAs.setEnabled(isUnitGui());
saveMenu.add(miSaveAs);
return saveMenu;
@@ -388,6 +373,7 @@ private JMenu createImportMenu() {
miImportFluffImage.setMnemonic(KeyEvent.VK_I);
miImportFluffImage.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.ALT_DOWN_MASK));
miImportFluffImage.addActionListener(evt -> importFluffImageAction());
+ miImportFluffImage.setEnabled(isUnitGui());
importMenu.add(miImportFluffImage);
return importMenu;
@@ -401,7 +387,7 @@ private JMenu createImportMenu() {
private JMenu createExportMenu() {
final JMenu exportMenu = new JMenu(resources.getString("exportMenu.text"));
exportMenu.setName("exportMenu");
- exportMenu.setMnemonic(KeyEvent.VK_X);
+ exportMenu.setMnemonic(KeyEvent.VK_E);
exportMenu.add(createPDFUnitExportMenu());
exportMenu.add(createHTMLUnitExportMenu());
@@ -424,50 +410,44 @@ private JMenu createPDFUnitExportMenu() {
final JMenuItem miExportCurrentUnitToPDF = new JMenuItem(resources.getString("CurrentUnit.text"));
miExportCurrentUnitToPDF.setName("miExportCurrentUnitToPDF");
miExportCurrentUnitToPDF.setMnemonic(KeyEvent.VK_U);
- miExportCurrentUnitToPDF.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_DOWN_MASK));
- miExportCurrentUnitToPDF.addActionListener(evt -> UnitPrintManager.exportEntity(getFrame().getEntity(), getFrame()));
+ miExportCurrentUnitToPDF.addActionListener(evt -> UnitPrintManager.exportEntity(owner.getEntity(), owner.getFrame()));
+ miExportCurrentUnitToPDF.setEnabled(isUnitGui());
pdfUnitExportMenu.add(miExportCurrentUnitToPDF);
final JMenuItem miExportUnitFromCacheToPDF = new JMenuItem(resources.getString("FromCache.text"));
miExportUnitFromCacheToPDF.setName("miExportUnitFromCacheToPDF");
miExportUnitFromCacheToPDF.setMnemonic(KeyEvent.VK_C);
- miExportUnitFromCacheToPDF.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
- miExportUnitFromCacheToPDF.addActionListener(evt -> UnitPrintManager.printSelectedUnit(getFrame(), true));
+ miExportUnitFromCacheToPDF.addActionListener(evt -> UnitPrintManager.printSelectedUnit(owner.getFrame(), true));
pdfUnitExportMenu.add(miExportUnitFromCacheToPDF);
final JMenuItem miExportUnitFromFileToPDF = new JMenuItem(resources.getString("FromFile.text"));
miExportUnitFromFileToPDF.setName("miExportUnitFromFileToPDF");
miExportUnitFromFileToPDF.setMnemonic(KeyEvent.VK_F);
- miExportUnitFromFileToPDF.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.ALT_DOWN_MASK));
- miExportUnitFromFileToPDF.addActionListener(evt -> UnitPrintManager.printUnitFile(getFrame(), false, true));
+ miExportUnitFromFileToPDF.addActionListener(evt -> UnitPrintManager.printUnitFile(owner.getFrame(), false, true));
pdfUnitExportMenu.add(miExportUnitFromFileToPDF);
final JMenuItem miExportUnitFromFileToSinglePDFPage = new JMenuItem(resources.getString("FromFileSingle.text"));
miExportUnitFromFileToSinglePDFPage.setName("miExportUnitFromFileToSinglePDFPage");
miExportUnitFromFileToSinglePDFPage.setMnemonic(KeyEvent.VK_S);
- miExportUnitFromFileToSinglePDFPage.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_DOWN_MASK));
- miExportUnitFromFileToSinglePDFPage.addActionListener(evt -> UnitPrintManager.printUnitFile(getFrame(), true, true));
+ miExportUnitFromFileToSinglePDFPage.addActionListener(evt -> UnitPrintManager.printUnitFile(owner.getFrame(), true, true));
pdfUnitExportMenu.add(miExportUnitFromFileToSinglePDFPage);
final JMenuItem miExportUnitQueueToPDF = new JMenuItem(resources.getString("miExportUnitQueueToPDF.text"));
miExportUnitQueueToPDF.setName("miExportUnitQueueToPDF");
miExportUnitQueueToPDF.setMnemonic(KeyEvent.VK_Q);
- miExportUnitQueueToPDF.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.ALT_DOWN_MASK));
- miExportUnitQueueToPDF.addActionListener(evt -> new PrintQueueDialog(getFrame(), true).setVisible(true));
+ miExportUnitQueueToPDF.addActionListener(evt -> new PrintQueueDialog(owner.getFrame(), true).setVisible(true));
pdfUnitExportMenu.add(miExportUnitQueueToPDF);
final JMenuItem miExportUnitsFromMULFileToPDF = new JMenuItem(resources.getString("FromMUL.text"));
miExportUnitsFromMULFileToPDF.setName("miExportUnitsFromMULFileToPDF");
miExportUnitsFromMULFileToPDF.setMnemonic(KeyEvent.VK_M);
- miExportUnitsFromMULFileToPDF.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.ALT_DOWN_MASK));
- miExportUnitsFromMULFileToPDF.addActionListener(evt -> UnitPrintManager.exportMUL(getFrame(), false));
+ miExportUnitsFromMULFileToPDF.addActionListener(evt -> UnitPrintManager.exportMUL(owner.getFrame(), false));
pdfUnitExportMenu.add(miExportUnitsFromMULFileToPDF);
final JMenuItem miExportUnitsFromMULFileToSinglePDFPages = new JMenuItem(resources.getString("FromMULSingle.text"));
miExportUnitsFromMULFileToSinglePDFPages.setName("miExportUnitsFromMULFileToSinglePDFPages");
miExportUnitsFromMULFileToSinglePDFPages.setMnemonic(KeyEvent.VK_L);
- miExportUnitsFromMULFileToSinglePDFPages.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.ALT_DOWN_MASK));
- miExportUnitsFromMULFileToSinglePDFPages.addActionListener(evt -> UnitPrintManager.exportMUL(getFrame(), true));
+ miExportUnitsFromMULFileToSinglePDFPages.addActionListener(evt -> UnitPrintManager.exportMUL(owner.getFrame(), true));
pdfUnitExportMenu.add(miExportUnitsFromMULFileToSinglePDFPages);
return pdfUnitExportMenu;
@@ -486,8 +466,8 @@ private JMenu createHTMLUnitExportMenu() {
final JMenuItem miExportCurrentUnitToHTML = new JMenuItem(resources.getString("CurrentUnit.text"));
miExportCurrentUnitToHTML.setName("miExportCurrentUnitToHTML");
miExportCurrentUnitToHTML.setMnemonic(KeyEvent.VK_U);
- miExportCurrentUnitToHTML.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_DOWN_MASK));
miExportCurrentUnitToHTML.addActionListener(evt -> exportSummary(true));
+ miExportCurrentUnitToHTML.setEnabled(isUnitGui());
htmlUnitExportMenu.add(miExportCurrentUnitToHTML);
return htmlUnitExportMenu;
@@ -506,8 +486,8 @@ private JMenu createTextUnitExportMenu() {
final JMenuItem miExportCurrentUnitToText = new JMenuItem(resources.getString("CurrentUnit.text"));
miExportCurrentUnitToText.setName("miExportCurrentUnitToText");
miExportCurrentUnitToText.setMnemonic(KeyEvent.VK_U);
- miExportCurrentUnitToText.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_DOWN_MASK));
miExportCurrentUnitToText.addActionListener(evt -> exportSummary(false));
+ miExportCurrentUnitToText.setEnabled(isUnitGui());
textUnitExportMenu.add(miExportCurrentUnitToText);
return textUnitExportMenu;
@@ -526,11 +506,11 @@ private JMenu createClipboardUnitExportMenu() {
final JMenuItem miExportCurrentUnitToClipboard = new JMenuItem(resources.getString("CurrentUnit.text"));
miExportCurrentUnitToClipboard.setName("miExportCurrentUnitToClipboard");
miExportCurrentUnitToClipboard.setMnemonic(KeyEvent.VK_U);
- miExportCurrentUnitToClipboard.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK));
miExportCurrentUnitToClipboard.addActionListener(evt -> {
StringSelection stringSelection = new StringSelection(entitySummaryText(false));
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, this);
});
+ miExportCurrentUnitToClipboard.setEnabled(isUnitGui());
clipboardUnitExportMenu.add(miExportCurrentUnitToClipboard);
return clipboardUnitExportMenu;
@@ -550,49 +530,44 @@ private JMenu createPrintMenu() {
miPrintCurrentUnit.setName("miPrintCurrentUnit");
miPrintCurrentUnit.setMnemonic(KeyEvent.VK_U);
miPrintCurrentUnit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK));
- miPrintCurrentUnit.addActionListener(evt -> UnitPrintManager.printEntity(getFrame().getEntity()));
+ miPrintCurrentUnit.addActionListener(evt -> UnitPrintManager.printEntity(owner.getEntity()));
+ miPrintCurrentUnit.setEnabled(isUnitGui());
printMenu.add(miPrintCurrentUnit);
final JMenuItem miPrintUnitFromCache = new JMenuItem(resources.getString("FromCache.text"));
miPrintUnitFromCache.setName("miPrintUnitFromCache");
miPrintUnitFromCache.setMnemonic(KeyEvent.VK_C);
- miPrintUnitFromCache.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
- miPrintUnitFromCache.addActionListener(evt -> UnitPrintManager.printSelectedUnit(getFrame(), false));
+ miPrintUnitFromCache.addActionListener(evt -> UnitPrintManager.printSelectedUnit(owner.getFrame(), false));
printMenu.add(miPrintUnitFromCache);
final JMenuItem miPrintUnitFromFile = new JMenuItem(resources.getString("FromFile.text"));
miPrintUnitFromFile.setName("miPrintUnitFromFile");
miPrintUnitFromFile.setMnemonic(KeyEvent.VK_F);
- miPrintUnitFromFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.ALT_DOWN_MASK));
- miPrintUnitFromFile.addActionListener(evt -> UnitPrintManager.printUnitFile(getFrame(), false, false));
+ miPrintUnitFromFile.addActionListener(evt -> UnitPrintManager.printUnitFile(owner.getFrame(), false, false));
printMenu.add(miPrintUnitFromFile);
final JMenuItem miPrintUnitFromFileToSinglePage = new JMenuItem(resources.getString("FromFileSingle.text"));
miPrintUnitFromFileToSinglePage.setName("miPrintUnitFromFileToSinglePage");
miPrintUnitFromFileToSinglePage.setMnemonic(KeyEvent.VK_S);
- miPrintUnitFromFileToSinglePage.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_DOWN_MASK));
- miPrintUnitFromFileToSinglePage.addActionListener(evt -> UnitPrintManager.printUnitFile(getFrame(), true, false));
+ miPrintUnitFromFileToSinglePage.addActionListener(evt -> UnitPrintManager.printUnitFile(owner.getFrame(), true, false));
printMenu.add(miPrintUnitFromFileToSinglePage);
final JMenuItem miPrintUnitQueue = new JMenuItem(resources.getString("miPrintUnitQueue.text"));
miPrintUnitQueue.setName("miPrintUnitQueue");
miPrintUnitQueue.setMnemonic(KeyEvent.VK_Q);
- miPrintUnitQueue.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.ALT_DOWN_MASK));
- miPrintUnitQueue.addActionListener(evt -> new PrintQueueDialog(getFrame(), false).setVisible(true));
+ miPrintUnitQueue.addActionListener(evt -> new PrintQueueDialog(owner.getFrame(), false).setVisible(true));
printMenu.add(miPrintUnitQueue);
final JMenuItem miPrintUnitsFromMULFile = new JMenuItem(resources.getString("FromMUL.text"));
miPrintUnitsFromMULFile.setName("miPrintUnitsFromMULFile");
miPrintUnitsFromMULFile.setMnemonic(KeyEvent.VK_M);
- miPrintUnitsFromMULFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.ALT_DOWN_MASK));
- miPrintUnitsFromMULFile.addActionListener(evt -> UnitPrintManager.printMUL(getFrame(), false));
+ miPrintUnitsFromMULFile.addActionListener(evt -> UnitPrintManager.printMUL(owner.getFrame(), false));
printMenu.add(miPrintUnitsFromMULFile);
final JMenuItem miPrintUnitsFromMULFileToSinglePages = new JMenuItem(resources.getString("FromMULSingle.text"));
miPrintUnitsFromMULFileToSinglePages.setName("miPrintUnitsFromMULFileToSinglePages");
miPrintUnitsFromMULFileToSinglePages.setMnemonic(KeyEvent.VK_L);
- miPrintUnitsFromMULFileToSinglePages.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.ALT_DOWN_MASK));
- miPrintUnitsFromMULFileToSinglePages.addActionListener(evt -> UnitPrintManager.printMUL(getFrame(), true));
+ miPrintUnitsFromMULFileToSinglePages.addActionListener(evt -> UnitPrintManager.printMUL(owner.getFrame(), true));
printMenu.add(miPrintUnitsFromMULFileToSinglePages);
return printMenu;
@@ -606,12 +581,11 @@ private JMenu createPrintMenu() {
private JMenu createRefreshMenu() {
final JMenu refreshMenu = new JMenu(resources.getString("refreshMenu.text"));
refreshMenu.setName("refreshMenu");
- refreshMenu.setMnemonic(KeyEvent.VK_R);
+ refreshMenu.setMnemonic(KeyEvent.VK_F);
final JMenuItem miRefreshUnitCache = new JMenuItem(resources.getString("miRefreshUnitCache.text"));
miRefreshUnitCache.setName("miRefreshUnitCache");
miRefreshUnitCache.setMnemonic(KeyEvent.VK_U);
- miRefreshUnitCache.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_DOWN_MASK));
miRefreshUnitCache.addActionListener(evt -> MechSummaryCache.refreshUnitData(false));
refreshMenu.add(miRefreshUnitCache);
@@ -631,10 +605,9 @@ private JMenu createOptionsMenu() {
final JMenuItem miConfiguration = new JMenuItem(resources.getString("miConfiguration.text"));
miConfiguration.setName("miConfiguration");
miConfiguration.setMnemonic(KeyEvent.VK_C);
- miConfiguration.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
miConfiguration.addActionListener(evt -> {
- new SettingsDialog(getFrame()).setVisible(true);
- getFrame().refreshAll();
+ new SettingsDialog(owner.getFrame()).setVisible(true);
+ owner.refreshAll();
});
optionsMenu.add(miConfiguration);
@@ -657,7 +630,7 @@ private JMenu createThemesMenu() {
miLookAndFeel.setName("miLookAndFeel");
miLookAndFeel.setSelected(laf.getName().equalsIgnoreCase(UIManager.getLookAndFeel().getName()));
miLookAndFeel.addActionListener(evt -> {
- getFrame().changeTheme(laf);
+ owner.changeTheme(laf);
for (int i = 0; i < themesMenu.getItemCount(); i++) {
final JMenuItem item = themesMenu.getItem(i);
if (item instanceof JCheckBoxMenuItem) {
@@ -674,7 +647,7 @@ private JMenu createThemesMenu() {
private @Nullable JMenuItem createCConfigMenuItem(final String configSaveFile,
final int fileNumber) {
final String newFile = CConfig.getParam(configSaveFile);
- if (newFile.length() < 1) {
+ if (newFile.isEmpty()) {
return null;
}
final JMenuItem miCConfig;
@@ -685,6 +658,7 @@ private JMenu createThemesMenu() {
}
miCConfig.setName("miCConfig");
miCConfig.addActionListener(evt -> loadUnitFromFile(fileNumber));
+ miCConfig.setMnemonic(KeyEvent.VK_1);
return miCConfig;
}
//endregion File Menu
@@ -703,21 +677,19 @@ private JMenu createUnitValidationMenu() {
final JMenuItem miValidateCurrentUnit = new JMenuItem(resources.getString("CurrentUnit.text"));
miValidateCurrentUnit.setName("miValidateCurrentUnit");
miValidateCurrentUnit.setMnemonic(KeyEvent.VK_U);
- miValidateCurrentUnit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_DOWN_MASK));
- miValidateCurrentUnit.addActionListener(evt -> UnitUtil.showValidation(getFrame().getEntity(), getFrame()));
+ miValidateCurrentUnit.addActionListener(evt -> UnitUtil.showValidation(owner.getEntity(), owner.getFrame()));
+ miValidateCurrentUnit.setEnabled(isUnitGui());
unitValidationMenu.add(miValidateCurrentUnit);
final JMenuItem miValidateUnitFromCache = new JMenuItem(resources.getString("FromCache.text"));
miValidateUnitFromCache.setName("miValidateUnitFromCache");
miValidateUnitFromCache.setMnemonic(KeyEvent.VK_C);
- miValidateUnitFromCache.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
miValidateUnitFromCache.addActionListener(evt -> jMenuGetUnitValidationFromCache_actionPerformed());
unitValidationMenu.add(miValidateUnitFromCache);
final JMenuItem miValidateUnitFromFile = new JMenuItem(resources.getString("FromFile.text"));
miValidateUnitFromFile.setName("miValidateUnitFromFile");
miValidateUnitFromFile.setMnemonic(KeyEvent.VK_F);
- miValidateUnitFromFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.ALT_DOWN_MASK));
miValidateUnitFromFile.addActionListener(evt -> jMenuGetUnitValidationFromFile_actionPerformed());
unitValidationMenu.add(miValidateUnitFromFile);
@@ -745,8 +717,6 @@ private JMenu createReportsMenu() {
}
/**
- * This menu uses the following Mnemonic keys as of 30-Jun-2022:
- * C, F, U
* @return the created Unit Specs Report menu
*/
private JMenu createUnitSpecsReportMenu() {
@@ -754,24 +724,9 @@ private JMenu createUnitSpecsReportMenu() {
unitSpecsReportMenu.setName("unitSpecsReportMenu");
unitSpecsReportMenu.setMnemonic(KeyEvent.VK_S);
- final JMenuItem miCurrentUnitSpecs = new JMenuItem(resources.getString("CurrentUnit.text"));
- miCurrentUnitSpecs.setName("miCurrentUnitSpecs");
- miCurrentUnitSpecs.setMnemonic(KeyEvent.VK_U);
- miCurrentUnitSpecs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_DOWN_MASK));
- miCurrentUnitSpecs.addActionListener(evt -> UnitUtil.showUnitSpecs(getFrame().getEntity(), getFrame()));
- unitSpecsReportMenu.add(miCurrentUnitSpecs);
-
- final JMenuItem miUnitSpecsFromCache = new JMenuItem(resources.getString("FromCache.text"));
- miUnitSpecsFromCache.setName("miUnitSpecsFromCache");
- miUnitSpecsFromCache.setMnemonic(KeyEvent.VK_C);
- miUnitSpecsFromCache.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
- miUnitSpecsFromCache.addActionListener(evt -> jMenuGetUnitSpecsFromCache_actionPerformed());
- unitSpecsReportMenu.add(miUnitSpecsFromCache);
-
final JMenuItem miUnitSpecsFromFile = new JMenuItem(resources.getString("FromFile.text"));
miUnitSpecsFromFile.setName("miUnitSpecsFromFile");
miUnitSpecsFromFile.setMnemonic(KeyEvent.VK_F);
- miUnitSpecsFromFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.ALT_DOWN_MASK));
miUnitSpecsFromFile.addActionListener(evt -> jMenuGetUnitSpecsFromFile_actionPerformed());
unitSpecsReportMenu.add(miUnitSpecsFromFile);
@@ -779,8 +734,6 @@ private JMenu createUnitSpecsReportMenu() {
}
/**
- * This menu uses the following Mnemonic keys as of 30-Jun-2022:
- * C, F, U
* @return the created Unit BV Breakdown menu
*/
private JMenu createUnitBVBreakdownMenu() {
@@ -791,21 +744,13 @@ private JMenu createUnitBVBreakdownMenu() {
final JMenuItem miCurrentUnitBVBreakdown = new JMenuItem(resources.getString("CurrentUnit.text"));
miCurrentUnitBVBreakdown.setName("miCurrentUnitBVBreakdown");
miCurrentUnitBVBreakdown.setMnemonic(KeyEvent.VK_U);
- miCurrentUnitBVBreakdown.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_DOWN_MASK));
- miCurrentUnitBVBreakdown.addActionListener(evt -> UnitUtil.showBVCalculations(getFrame(), getFrame().getEntity()));
+ miCurrentUnitBVBreakdown.addActionListener(evt -> UnitUtil.showBVCalculations(owner.getFrame(), owner.getEntity()));
+ miCurrentUnitBVBreakdown.setEnabled(isUnitGui());
unitBVBreakdownMenu.add(miCurrentUnitBVBreakdown);
- final JMenuItem miUnitBVBreakdownFromCache = new JMenuItem(resources.getString("FromCache.text"));
- miUnitBVBreakdownFromCache.setName("miUnitBVBreakdownFromCache");
- miUnitBVBreakdownFromCache.setMnemonic(KeyEvent.VK_C);
- miUnitBVBreakdownFromCache.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
- miUnitBVBreakdownFromCache.addActionListener(evt -> jMenuGetUnitBVFromCache_actionPerformed());
- unitBVBreakdownMenu.add(miUnitBVBreakdownFromCache);
-
final JMenuItem miUnitBVBreakdownFromFile = new JMenuItem(resources.getString("FromFile.text"));
miUnitBVBreakdownFromFile.setName("miUnitBVBreakdownFromFile");
miUnitBVBreakdownFromFile.setMnemonic(KeyEvent.VK_F);
- miUnitBVBreakdownFromFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.ALT_DOWN_MASK));
miUnitBVBreakdownFromFile.addActionListener(evt -> jMenuGetUnitBVFromFile_actionPerformed());
unitBVBreakdownMenu.add(miUnitBVBreakdownFromFile);
@@ -825,21 +770,19 @@ private JMenu createUnitCostBreakdownMenu() {
final JMenuItem miCurrentUnitCostBreakdown = new JMenuItem(resources.getString("CurrentUnit.text"));
miCurrentUnitCostBreakdown.setName("miCurrentUnitCostBreakdown");
miCurrentUnitCostBreakdown.setMnemonic(KeyEvent.VK_U);
- miCurrentUnitCostBreakdown.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_DOWN_MASK));
- miCurrentUnitCostBreakdown.addActionListener(evt -> new CostDisplayDialog(getFrame(), getFrame().getEntity()).setVisible(true));
+ miCurrentUnitCostBreakdown.addActionListener(evt -> new CostDisplayDialog(owner.getFrame(), owner.getEntity()).setVisible(true));
+ miCurrentUnitCostBreakdown.setEnabled(isUnitGui());
unitCostBreakdownMenu.add(miCurrentUnitCostBreakdown);
final JMenuItem miUnitCostBreakdownFromCache = new JMenuItem(resources.getString("FromCache.text"));
miUnitCostBreakdownFromCache.setName("miUnitCostBreakdownFromCache");
miUnitCostBreakdownFromCache.setMnemonic(KeyEvent.VK_C);
- miUnitCostBreakdownFromCache.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
miUnitCostBreakdownFromCache.addActionListener(evt -> jMenuGetUnitBreakdownFromCache_actionPerformed());
unitCostBreakdownMenu.add(miUnitCostBreakdownFromCache);
final JMenuItem miUnitCostBreakdownFromFile = new JMenuItem(resources.getString("FromFile.text"));
miUnitCostBreakdownFromFile.setName("miUnitCostBreakdownFromFile");
miUnitCostBreakdownFromFile.setMnemonic(KeyEvent.VK_F);
- miUnitCostBreakdownFromFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.ALT_DOWN_MASK));
miUnitCostBreakdownFromFile.addActionListener(evt -> jMenuGetUnitBreakdownFromFile_actionPerformed());
unitCostBreakdownMenu.add(miUnitCostBreakdownFromFile);
@@ -859,21 +802,19 @@ private JMenu createUnitWeightBreakdownMenu() {
final JMenuItem miCurrentUnitWeightBreakdown = new JMenuItem(resources.getString("CurrentUnit.text"));
miCurrentUnitWeightBreakdown.setName("miCurrentUnitWeightBreakdown");
miCurrentUnitWeightBreakdown.setMnemonic(KeyEvent.VK_U);
- miCurrentUnitWeightBreakdown.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_DOWN_MASK));
- miCurrentUnitWeightBreakdown.addActionListener(evt -> UnitUtil.showUnitWeightBreakDown(getFrame().getEntity(), getFrame()));
+ miCurrentUnitWeightBreakdown.addActionListener(evt -> UnitUtil.showUnitWeightBreakDown(owner.getEntity(), owner.getFrame()));
+ miCurrentUnitWeightBreakdown.setEnabled(isUnitGui());
unitWeightBreakdownMenu.add(miCurrentUnitWeightBreakdown);
final JMenuItem miUnitWeightBreakdownFromCache = new JMenuItem(resources.getString("FromCache.text"));
miUnitWeightBreakdownFromCache.setName("miUnitWeightBreakdownFromCache");
miUnitWeightBreakdownFromCache.setMnemonic(KeyEvent.VK_C);
- miUnitWeightBreakdownFromCache.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK));
miUnitWeightBreakdownFromCache.addActionListener(evt -> jMenuGetUnitWeightBreakdownFromCache_actionPerformed());
unitWeightBreakdownMenu.add(miUnitWeightBreakdownFromCache);
final JMenuItem miUnitWeightBreakdownFromFile = new JMenuItem(resources.getString("FromFile.text"));
miUnitWeightBreakdownFromFile.setName("miUnitWeightBreakdownFromFile");
miUnitWeightBreakdownFromFile.setMnemonic(KeyEvent.VK_F);
- miUnitWeightBreakdownFromFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.ALT_DOWN_MASK));
miUnitWeightBreakdownFromFile.addActionListener(evt -> jMenuGetUnitWeightBreakdownFromFile_actionPerformed());
unitWeightBreakdownMenu.add(miUnitWeightBreakdownFromFile);
@@ -895,14 +836,12 @@ private JMenu createHelpMenu() {
final JMenuItem miAbout = new JMenuItem(resources.getString("miAbout.text"));
miAbout.setName("miAbout");
miAbout.setMnemonic(KeyEvent.VK_A);
- miAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.ALT_DOWN_MASK));
miAbout.addActionListener(evt -> aboutAction());
helpMenu.add(miAbout);
final JMenuItem miRecordSheetImages = new JMenuItem(resources.getString("miRecordSheetImages.text"));
miRecordSheetImages.setName("miRecordSheetImages");
miRecordSheetImages.setMnemonic(KeyEvent.VK_R);
- miRecordSheetImages.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_DOWN_MASK));
miRecordSheetImages.addActionListener(evt -> recordSheetImagesAction());
helpMenu.add(miRecordSheetImages);
@@ -911,54 +850,35 @@ private JMenu createHelpMenu() {
//endregion Help Menu
//endregion Initialization
- private void jMenuGetUnitBVFromCache_actionPerformed() {
- UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(getFrame());
- unitLoadingDialog.setVisible(true);
- MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(getFrame(), unitLoadingDialog);
- UnitUtil.showBVCalculations(getFrame(), viewer.getChosenEntity());
- }
-
private void jMenuGetUnitValidationFromCache_actionPerformed() {
- UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(getFrame());
+ UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(owner.getFrame());
unitLoadingDialog.setVisible(true);
- MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(getFrame(), unitLoadingDialog);
+ MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog);
Entity tempEntity = viewer.getChosenEntity();
if (null == tempEntity) {
return;
}
- UnitUtil.showValidation(tempEntity, getFrame());
- }
-
- private void jMenuGetUnitSpecsFromCache_actionPerformed() {
- UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(getFrame());
- unitLoadingDialog.setVisible(true);
- MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(getFrame(), unitLoadingDialog);
-
- Entity tempEntity = viewer.getChosenEntity();
- if (null == tempEntity) {
- return;
- }
- UnitUtil.showUnitSpecs(tempEntity, getFrame());
+ UnitUtil.showValidation(tempEntity, owner.getFrame());
}
private void jMenuGetUnitBreakdownFromCache_actionPerformed() {
- UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(getFrame());
+ UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(owner.getFrame());
unitLoadingDialog.setVisible(true);
- MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(getFrame(), unitLoadingDialog);
- new CostDisplayDialog(getFrame(), viewer.getChosenEntity()).setVisible(true);
+ MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog);
+ new CostDisplayDialog(owner.getFrame(), viewer.getChosenEntity()).setVisible(true);
}
private void jMenuGetUnitWeightBreakdownFromCache_actionPerformed() {
- UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(getFrame());
+ UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(owner.getFrame());
unitLoadingDialog.setVisible(true);
- MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(getFrame(), unitLoadingDialog);
+ MegaMekLabUnitSelectorDialog viewer = new MegaMekLabUnitSelectorDialog(owner.getFrame(), unitLoadingDialog);
Entity tempEntity = viewer.getChosenEntity();
if (null == tempEntity) {
return;
}
- UnitUtil.showUnitWeightBreakDown(tempEntity, getFrame());
+ UnitUtil.showUnitWeightBreakDown(tempEntity, owner.getFrame());
}
private void jMenuGetUnitBVFromFile_actionPerformed() {
@@ -968,9 +888,9 @@ private void jMenuGetUnitBVFromFile_actionPerformed() {
}
try {
- UnitUtil.showBVCalculations(getFrame(), new MechFileParser(unitFile).getEntity());
+ UnitUtil.showBVCalculations(owner.getFrame(), new MechFileParser(unitFile).getEntity());
} catch (Exception ex) {
- JOptionPane.showMessageDialog(getFrame(),
+ JOptionPane.showMessageDialog(owner.getFrame(),
String.format(resources.getString("message.invalidUnit.format"),
ex.getMessage()));
}
@@ -984,9 +904,9 @@ private void jMenuGetUnitValidationFromFile_actionPerformed() {
try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
- UnitUtil.showValidation(tempEntity, getFrame());
+ UnitUtil.showValidation(tempEntity, owner.getFrame());
} catch (Exception ex) {
- JOptionPane.showMessageDialog(getFrame(),
+ JOptionPane.showMessageDialog(owner.getFrame(),
String.format(resources.getString("message.invalidUnit.format"),
ex.getMessage()));
}
@@ -994,10 +914,10 @@ private void jMenuGetUnitValidationFromFile_actionPerformed() {
private @Nullable File loadUnitFile() {
String filePathName = System.getProperty("user.dir") + "/data/mechfiles/"; // TODO : remove inline file path
- FileDialog fDialog = new FileDialog(getFrame(),
+ FileDialog fDialog = new FileDialog(owner.getFrame(),
resources.getString("dialog.chooseUnit.title"),
FileDialog.LOAD);
- fDialog.setLocationRelativeTo(getFrame());
+ fDialog.setLocationRelativeTo(owner.getFrame());
fDialog.setMultipleMode(false);
fDialog.setDirectory(filePathName);
fDialog.setFilenameFilter((dir, filename) -> {
@@ -1016,9 +936,9 @@ private void jMenuGetUnitBreakdownFromFile_actionPerformed() {
}
try {
- new CostDisplayDialog(getFrame(), new MechFileParser(unitFile).getEntity()).setVisible(true);
+ new CostDisplayDialog(owner.getFrame(), new MechFileParser(unitFile).getEntity()).setVisible(true);
} catch (Exception ex) {
- JOptionPane.showMessageDialog(getFrame(),
+ JOptionPane.showMessageDialog(owner.getFrame(),
String.format(resources.getString("message.invalidUnit.format"),
ex.getMessage()));
}
@@ -1032,9 +952,9 @@ private void jMenuGetUnitWeightBreakdownFromFile_actionPerformed() {
try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
- UnitUtil.showUnitWeightBreakDown(tempEntity, getFrame());
+ UnitUtil.showUnitWeightBreakDown(tempEntity, owner.getFrame());
} catch (Exception ex) {
- JOptionPane.showMessageDialog(getFrame(),
+ JOptionPane.showMessageDialog(owner.getFrame(),
String.format(resources.getString("message.invalidUnit.format"),
ex.getMessage()));
}
@@ -1048,9 +968,9 @@ private void jMenuGetUnitSpecsFromFile_actionPerformed() {
try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
- UnitUtil.showUnitSpecs(tempEntity, getFrame());
+ UnitUtil.showUnitSpecs(tempEntity, owner.getFrame());
} catch (Exception ex) {
- JOptionPane.showMessageDialog(getFrame(),
+ JOptionPane.showMessageDialog(owner.getFrame(),
String.format(resources.getString("message.invalidUnit.format"),
ex.getMessage()));
}
@@ -1065,33 +985,33 @@ private void importFluffImageAction() {
try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
- if (!UnitUtil.validateUnit(getFrame().getEntity()).isBlank()) {
- JOptionPane.showMessageDialog(getFrame(),
+ if (!UnitUtil.validateUnit(owner.getEntity()).isBlank()) {
+ JOptionPane.showMessageDialog(owner.getFrame(),
resources.getString("message.invalidUnit.text"));
}
- FileDialog fDialog = new FileDialog(getFrame(),
+ FileDialog fDialog = new FileDialog(owner.getFrame(),
resources.getString("dialog.imagePath.title"), FileDialog.LOAD);
- if (!getFrame().getEntity().getFluff().getMMLImagePath().isBlank()) {
- String fullPath = new File(getFrame().getEntity().getFluff().getMMLImagePath()).getAbsolutePath();
+ if (!owner.getEntity().getFluff().getMMLImagePath().isBlank()) {
+ String fullPath = new File(owner.getEntity().getFluff().getMMLImagePath()).getAbsolutePath();
String imageName = fullPath.substring(fullPath.lastIndexOf(File.separatorChar) + 1);
fullPath = fullPath.substring(0, fullPath.lastIndexOf(File.separatorChar) + 1);
fDialog.setDirectory(fullPath);
fDialog.setFile(imageName);
} else {
fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + "mech" + File.separatorChar);
- fDialog.setFile(getFrame().getEntity().getChassis() + ' ' + getFrame().getEntity().getModel() + ".png");
+ fDialog.setFile(owner.getEntity().getChassis() + ' ' + owner.getEntity().getModel() + ".png");
}
- fDialog.setLocationRelativeTo(getFrame());
+ fDialog.setLocationRelativeTo(owner.getFrame());
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1);
- getFrame().getEntity().getFluff().setMMLImagePath(relativeFilePath);
+ owner.getEntity().getFluff().setMMLImagePath(relativeFilePath);
BLKFile.encode(unitFile.getAbsolutePath(), tempEntity);
}
} catch (Exception ex) {
@@ -1102,7 +1022,7 @@ private void importFluffImageAction() {
// Show data about MegaMekLab
private void aboutAction() {
// make the dialog
- JDialog dlg = new JDialog(getFrame(), resources.getString("menu.help.about.title"));
+ JDialog dlg = new JDialog(owner.getFrame(), resources.getString("menu.help.about.title"));
// set up the contents
JPanel child = new JPanel();
@@ -1136,7 +1056,7 @@ private void aboutAction() {
// then add child panel to the content pane.
dlg.getContentPane().add(child);
- dlg.setLocationRelativeTo(getFrame());
+ dlg.setLocationRelativeTo(owner.getFrame());
dlg.setModal(true);
dlg.setResizable(false);
dlg.pack();
@@ -1146,7 +1066,7 @@ private void aboutAction() {
// Show how to create fluff images for Record Sheets
private void recordSheetImagesAction() {
// make the dialog
- JDialog dlg = new JDialog(getFrame(), resources.getString("menu.help.imageHelp.title"));
+ JDialog dlg = new JDialog(owner.getFrame(), resources.getString("menu.help.imageHelp.title"));
// set up the contents
JPanel child = new JPanel();
@@ -1168,7 +1088,7 @@ private void recordSheetImagesAction() {
dlg.getContentPane().add(child);
// set the location of the dialog
- dlg.setLocationRelativeTo(getFrame());
+ dlg.setLocationRelativeTo(owner.getFrame());
dlg.setModal(true);
dlg.setResizable(false);
dlg.pack();
@@ -1176,43 +1096,43 @@ private void recordSheetImagesAction() {
}
private void jMenuResetEntity_actionPerformed(ActionEvent event) {
- if (!getFrame().safetyPrompt()) {
+ if (!owner.safetyPrompt() || !isUnitGui()) {
return;
}
CConfig.updateSaveFiles("Reset Unit");
CConfig.setParam(CConfig.CONFIG_SAVE_FILE_1, "");
- Entity en = getFrame().getEntity();
+ Entity en = owner.getEntity();
if (en instanceof Tank) {
- getFrame().createNewUnit(Entity.ETYPE_TANK);
+ getUnitMainUi().createNewUnit(Entity.ETYPE_TANK);
} else if (en instanceof Mech) {
- getFrame().createNewUnit(Entity.ETYPE_BIPED_MECH, en.isPrimitive(), ((Mech)en).isIndustrial());
+ getUnitMainUi().createNewUnit(Entity.ETYPE_BIPED_MECH, en.isPrimitive(), ((Mech)en).isIndustrial());
} else if (en.hasETypeFlag(Entity.ETYPE_DROPSHIP)) {
- getFrame().createNewUnit(Entity.ETYPE_DROPSHIP, en.isPrimitive());
+ getUnitMainUi().createNewUnit(Entity.ETYPE_DROPSHIP, en.isPrimitive());
} else if (en.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
- getFrame().createNewUnit(Entity.ETYPE_SMALL_CRAFT, en.isPrimitive());
+ getUnitMainUi().createNewUnit(Entity.ETYPE_SMALL_CRAFT, en.isPrimitive());
} else if (en.hasETypeFlag(Entity.ETYPE_SPACE_STATION)) {
- getFrame().createNewUnit(Entity.ETYPE_SPACE_STATION);
+ getUnitMainUi().createNewUnit(Entity.ETYPE_SPACE_STATION);
} else if (en.hasETypeFlag(Entity.ETYPE_WARSHIP)) {
- getFrame().createNewUnit(Entity.ETYPE_WARSHIP, en.isPrimitive());
+ getUnitMainUi().createNewUnit(Entity.ETYPE_WARSHIP, en.isPrimitive());
} else if (en.hasETypeFlag(Entity.ETYPE_JUMPSHIP)) {
- getFrame().createNewUnit(Entity.ETYPE_JUMPSHIP);
- } else if (getFrame().getEntity() instanceof Aero) {
- getFrame().createNewUnit(Entity.ETYPE_AERO, en.isPrimitive());
- } else if (getFrame().getEntity() instanceof BattleArmor) {
- getFrame().createNewUnit(Entity.ETYPE_BATTLEARMOR);
- } else if (getFrame().getEntity() instanceof Infantry) {
- getFrame().createNewUnit(Entity.ETYPE_INFANTRY);
- } else if (getFrame().getEntity() instanceof Protomech) {
- getFrame().createNewUnit(Entity.ETYPE_PROTOMECH);
+ getUnitMainUi().createNewUnit(Entity.ETYPE_JUMPSHIP);
+ } else if (owner.getEntity() instanceof Aero) {
+ getUnitMainUi().createNewUnit(Entity.ETYPE_AERO, en.isPrimitive());
+ } else if (owner.getEntity() instanceof BattleArmor) {
+ getUnitMainUi().createNewUnit(Entity.ETYPE_BATTLEARMOR);
+ } else if (owner.getEntity() instanceof Infantry) {
+ getUnitMainUi().createNewUnit(Entity.ETYPE_INFANTRY);
+ } else if (owner.getEntity() instanceof Protomech) {
+ getUnitMainUi().createNewUnit(Entity.ETYPE_PROTOMECH);
} else {
LogManager.getLogger().warn("Received unknown entityType!");
}
setVisible(true);
reload();
refresh();
- getFrame().setVisible(true);
- getFrame().repaint();
+ getUnitMainUi().setVisible(true);
+ getUnitMainUi().repaint();
}
/**
@@ -1230,14 +1150,14 @@ public static String createUnitFilename(Entity entity) {
}
private void saveEntity() {
- saveEntity(getFrame().getEntity());
+ saveEntity(owner.getEntity());
}
public boolean saveEntity(final @Nullable Entity entity) {
if (entity == null) {
return false;
} else if (!UnitUtil.validateUnit(entity).isBlank()) {
- JOptionPane.showMessageDialog(getFrame(),
+ JOptionPane.showMessageDialog(owner.getFrame(),
resources.getString("message.invalidUnit.text"));
}
@@ -1247,14 +1167,14 @@ public boolean saveEntity(final @Nullable Entity entity) {
String filePathName = CConfig.getParam(CConfig.CONFIG_SAVE_FILE_1);
if (filePathName.isBlank() || !filePathName.contains(fileName)) {
- FileDialog fDialog = new FileDialog(getFrame(),
+ FileDialog fDialog = new FileDialog(owner.getFrame(),
resources.getString("dialog.saveAs.title"), FileDialog.SAVE);
filePathName = CConfig.getParam(CConfig.CONFIG_SAVE_LOC);
fDialog.setDirectory(filePathName);
fDialog.setFile(fileName);
- fDialog.setLocationRelativeTo(getFrame());
+ fDialog.setLocationRelativeTo(owner.getFrame());
fDialog.setVisible(true);
@@ -1281,29 +1201,29 @@ public boolean saveEntity(final @Nullable Entity entity) {
return false;
}
- JOptionPane.showMessageDialog(getFrame(),
+ JOptionPane.showMessageDialog(owner.getFrame(),
String.format(resources.getString("dialog.saveAs.message.format"),
entity.getChassis(),
entity.getModel(), filePathName));
return true;
}
- private void jMenuSaveAsEntity_actionPerformed(ActionEvent event) {
- if (!UnitUtil.validateUnit(getFrame().getEntity()).isBlank()) {
- JOptionPane.showMessageDialog(getFrame(),
+ private void jMenuSaveAsEntity_actionPerformed() {
+ if (!UnitUtil.validateUnit(owner.getEntity()).isBlank()) {
+ JOptionPane.showMessageDialog(owner.getFrame(),
resources.getString("message.savingInvalidUnit.text"));
}
- UnitUtil.compactCriticals(getFrame().getEntity());
+ UnitUtil.compactCriticals(owner.getEntity());
- FileDialog fDialog = new FileDialog(getFrame(),
+ FileDialog fDialog = new FileDialog(owner.getFrame(),
resources.getString("dialog.saveAs.title"), FileDialog.SAVE);
String filePathName = CConfig.getParam(CConfig.CONFIG_SAVE_LOC);
fDialog.setDirectory(filePathName);
- fDialog.setFile(createUnitFilename(getFrame().getEntity()));
- fDialog.setLocationRelativeTo(getFrame());
+ fDialog.setFile(createUnitFilename(owner.getEntity()));
+ fDialog.setLocationRelativeTo(owner.getFrame());
fDialog.setVisible(true);
@@ -1315,49 +1235,49 @@ private void jMenuSaveAsEntity_actionPerformed(ActionEvent event) {
}
try {
- if (getFrame().getEntity() instanceof Mech) {
+ if (owner.getEntity() instanceof Mech) {
try (FileOutputStream fos = new FileOutputStream(filePathName);
PrintStream ps = new PrintStream(fos)) {
- ps.println(((Mech) getFrame().getEntity()).getMtf());
+ ps.println(((Mech) owner.getEntity()).getMtf());
}
} else {
- BLKFile.encode(filePathName, getFrame().getEntity());
+ BLKFile.encode(filePathName, owner.getEntity());
}
CConfig.updateSaveFiles(filePathName);
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
}
- JOptionPane.showMessageDialog(getFrame(),
+ JOptionPane.showMessageDialog(owner.getFrame(),
String.format(resources.getString("dialog.saveAs.message.format"),
- getFrame().getEntity().getChassis(),
- getFrame().getEntity().getModel(), filePathName));
+ owner.getEntity().getChassis(),
+ owner.getEntity().getModel(), filePathName));
}
private String entitySummaryText(boolean html) {
if (CConfig.getBooleanParam(CConfig.MISC_SUMMARY_FORMAT_TRO)) {
- TROView view = TROView.createView(getFrame().getEntity(), html);
+ TROView view = TROView.createView(owner.getEntity(), html);
return view.processTemplate();
} else {
- MechView view = new MechView(getFrame().getEntity(), !html, false, html);
+ MechView view = new MechView(owner.getEntity(), !html, false, html);
return view.getMechReadout();
}
}
private void exportSummary(boolean html) {
- if (!UnitUtil.validateUnit(getFrame().getEntity()).isBlank()) {
- JOptionPane.showMessageDialog(getFrame(),
+ if (!UnitUtil.validateUnit(owner.getEntity()).isBlank()) {
+ JOptionPane.showMessageDialog(owner.getFrame(),
resources.getString("message.exportingInvalidUnit.text"));
}
- String unitName = getFrame().getEntity().getChassis() + ' ' + getFrame().getEntity().getModel();
+ String unitName = owner.getEntity().getChassis() + ' ' + owner.getEntity().getModel();
- FileDialog fDialog = new FileDialog(getFrame(),
+ FileDialog fDialog = new FileDialog(owner.getFrame(),
resources.getString("dialog.saveAs.title"), FileDialog.SAVE);
String filePathName = new File(System.getProperty("user.dir")).getAbsolutePath();
fDialog.setDirectory(filePathName);
fDialog.setFile(unitName + (html?".html" : ".txt"));
- fDialog.setLocationRelativeTo(getFrame());
+ fDialog.setLocationRelativeTo(owner.getFrame());
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
@@ -1407,42 +1327,42 @@ private void loadUnitFromFile(int fileNumber) {
try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
- if ((null == tempEntity) || !getFrame().safetyPrompt()) {
+ if ((null == tempEntity) || !owner.safetyPrompt()) {
return;
}
if (!UnitUtil.validateUnit(tempEntity).isBlank()) {
- JOptionPane.showMessageDialog(getFrame(), String.format(
+ JOptionPane.showMessageDialog(owner.getFrame(), String.format(
resources.getString("message.invalidUnit.format"),
UnitUtil.validateUnit(tempEntity)));
}
- if (tempEntity.getEntityType() != getFrame().getEntity().getEntityType()) {
- getFrame().setVisible(false);
- getFrame().dispose();
+ if (isStartupGui() || (tempEntity.getEntityType() != owner.getEntity().getEntityType())) {
+ owner.getFrame().setVisible(false);
+ owner.getFrame().dispose();
UiLoader.loadUi(tempEntity);
return;
} else {
- getFrame().setEntity(tempEntity);
- UnitUtil.updateLoadedUnit(getFrame().getEntity());
+ getUnitMainUi().setEntity(tempEntity);
+ UnitUtil.updateLoadedUnit(owner.getEntity());
CConfig.updateSaveFiles(unitFile.getAbsolutePath());
}
} catch (Exception ex) {
- JOptionPane.showMessageDialog(getFrame(), String.format(
+ JOptionPane.showMessageDialog(owner.getFrame(), String.format(
resources.getString("message.invalidUnit.format"),
ex.getMessage()));
}
reload();
refresh();
- getFrame().setVisible(true);
+ getUnitMainUi().setVisible(true);
}
private void refresh() {
- getFrame().refreshAll();
+ owner.refreshAll();
}
private void reload() {
- getFrame().reloadTabs();
+ getUnitMainUi().reloadTabs();
}
/**
@@ -1451,15 +1371,21 @@ private void reload() {
* @param type an int
corresponding to the unit type to construct
*/
private void newUnit(long type, boolean primitive) {
- if (frame.safetyPrompt()) {
- frame.setVisible(false);
- frame.dispose();
+ if (owner.safetyPrompt()) {
+ owner.getFrame().setVisible(false);
+ owner.getFrame().dispose();
UiLoader.loadUi(type, primitive, false);
}
}
@Override
- public void lostOwnership(Clipboard arg0, Transferable arg1) {
+ public void lostOwnership(Clipboard arg0, Transferable arg1) { }
+
+ private boolean isStartupGui() {
+ return owner instanceof StartupGUI;
+ }
+ private boolean isUnitGui() {
+ return !isStartupGui();
}
-}
+}
\ No newline at end of file
diff --git a/megameklab/src/megameklab/ui/MenuBarOwner.java b/megameklab/src/megameklab/ui/MenuBarOwner.java
new file mode 100644
index 000000000..9adcdd9e6
--- /dev/null
+++ b/megameklab/src/megameklab/ui/MenuBarOwner.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2023 - The MegaMek Team. All Rights Reserved.
+ *
+ * This file is part of MegaMekLab.
+ *
+ * MegaMek 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.
+ *
+ * MegaMek 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 MegaMek. If not, see .
+ */
+package megameklab.ui;
+
+import megamek.common.Entity;
+import megamek.common.annotations.Nullable;
+import megameklab.ui.util.AppCloser;
+
+import javax.swing.*;
+
+/**
+ * This interface must be implemented by classes that display the {@link MenuBar}.
+ */
+public interface MenuBarOwner extends AppCloser {
+
+ /** @return A frame of this menubar owner to use as a parent for dialogs. */
+ JFrame getFrame();
+
+ /** @return The entity currently worked on or null. */
+ @Nullable Entity getEntity();
+
+ /**
+ * This method is called when an action will cause the currently edited unit to be discarded (exit MML,
+ * load a new unit or switch unit type).
+ *
+ * It should return true only when MML should continue with the action that called this method. If there is
+ * any data to be lost by this menubar owner, then this method should display a safety dialog prompting
+ * the user to consider saving the currently entered unit. If the user selects NO or selects YES and
+ * actually saves the unit, true should be returned.
+ *
+ * If there is no data to be lost or when the setting "Disable save prompts" is active (see Misc Settings), it
+ * may directly return true. See also {@link megameklab.ui.dialog.settings.MiscSettingsPanel}.
+ *
+ * By default, this method directly returns true.
+ *
+ * @return True only when the user agrees to continue or has deactivated these prompts, false otherwise
+ */
+ default boolean safetyPrompt() {
+ return true;
+ }
+
+ /**
+ * This method is called when this menubar owner should refresh all displayed content (all tabs in the
+ * unit main UIs). By default, this method does nothing.
+ */
+ default void refreshAll() { }
+
+ /**
+ * Sets the look and feel for the application.
+ *
+ * @param plaf The look and feel to use for the application.
+ */
+ default void changeTheme(UIManager.LookAndFeelInfo plaf) {
+ SwingUtilities.invokeLater(() -> {
+ try {
+ UIManager.setLookAndFeel(plaf.getClassName());
+ SwingUtilities.updateComponentTreeUI(getFrame());
+ } catch (Exception exception) {
+ JOptionPane.showMessageDialog(getFrame(),
+ "Can't change look and feel", "Invalid PLAF",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/megameklab/src/megameklab/ui/StartupGUI.java b/megameklab/src/megameklab/ui/StartupGUI.java
index 32a3f9232..e0ea7cfbc 100644
--- a/megameklab/src/megameklab/ui/StartupGUI.java
+++ b/megameklab/src/megameklab/ui/StartupGUI.java
@@ -28,7 +28,6 @@
import megameklab.MMLConstants;
import megameklab.ui.dialog.MegaMekLabUnitSelectorDialog;
import megameklab.ui.dialog.UiLoader;
-import megameklab.ui.util.AppCloser;
import megameklab.ui.util.ExitOnWindowClosingListener;
import megameklab.util.CConfig;
import megameklab.util.UnitUtil;
@@ -45,7 +44,7 @@
* A startup splash screen for MegaMekLab
* @author Taharqa
*/
-public class StartupGUI extends JPanel implements AppCloser {
+public class StartupGUI extends JPanel implements MenuBarOwner {
JFrame frame;
BufferedImage backgroundIcon;
@@ -68,6 +67,7 @@ private void initComponents() {
frame = new JFrame("MegaMekLab");
setBackground(UIManager.getColor("controlHighlight"));
+ frame.setJMenuBar(new MenuBar(this));
Dimension scaledMonitorSize = UIUtil.getScaledScreenSize(frame);
JLabel splash = UIUtil.createSplashComponent(startupScreenImages, frame);
@@ -320,4 +320,14 @@ public static void selectAndLoadUnitFromCache(@Nullable JFrame previousFrame) {
previousUI.setVisible(true);
}
}
+
+ @Override
+ public JFrame getFrame() {
+ return frame;
+ }
+
+ @Override
+ public Entity getEntity() {
+ return null;
+ }
}
\ No newline at end of file