diff --git a/MekHQ/src/mekhq/MekHQ.java b/MekHQ/src/mekhq/MekHQ.java index e49d9c3cd8..936c33cd02 100644 --- a/MekHQ/src/mekhq/MekHQ.java +++ b/MekHQ/src/mekhq/MekHQ.java @@ -39,6 +39,7 @@ import megamek.server.Server; import megamek.server.totalwarfare.TWGameManager; import megameklab.MegaMekLab; +import megameklab.util.CConfig; import mekhq.campaign.Campaign; import mekhq.campaign.CampaignController; import mekhq.campaign.Kill; @@ -173,6 +174,8 @@ private MekHQ() { * At startup create and show the main frame of the application. */ protected void startup() { + updateGuiScaling(); // also sets the look-and-feel + // Setup user preferences MegaMek.getMMPreferences().loadFromFile(SuiteConstants.MM_PREFERENCES_FILE); MegaMekLab.getMMLPreferences().loadFromFile(SuiteConstants.MML_PREFERENCES_FILE); @@ -667,13 +670,7 @@ private static void setLookAndFeel(String themeName) { addOSXKeyStrokes((InputMap) UIManager.get("TextArea.focusInputMap")); } - for (final Frame frame : Frame.getFrames()) { - SwingUtilities.updateComponentTreeUI(frame); - } - - for (Window window : Window.getWindows()) { - SwingUtilities.updateComponentTreeUI(window); - } + updateAfterUiChange(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { logger.error(e, "setLookAndFeel()"); @@ -682,6 +679,25 @@ private static void setLookAndFeel(String themeName) { SwingUtilities.invokeLater(runnable); } + public static void updateGuiScaling() { + System.setProperty("flatlaf.uiScale", Double.toString(GUIPreferences.getInstance().getGUIScale())); + setLookAndFeel(GUIPreferences.getInstance().getUITheme()); + updateAfterUiChange(); + } + + /** + * Updates all existing windows and frames. Use after a gui scale change or look-and-feel change. + */ + public static void updateAfterUiChange() { + for (Window window : Window.getWindows()) { + SwingUtilities.updateComponentTreeUI(window); + window.pack(); + window.invalidate(); + window.validate(); + window.repaint(); + } + } + private static class MekHqPropertyChangedListener implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent evt) { diff --git a/MekHQ/src/mekhq/campaign/parts/AmmoStorage.java b/MekHQ/src/mekhq/campaign/parts/AmmoStorage.java index 71b2fcda88..fa3193028d 100644 --- a/MekHQ/src/mekhq/campaign/parts/AmmoStorage.java +++ b/MekHQ/src/mekhq/campaign/parts/AmmoStorage.java @@ -45,7 +45,7 @@ * This will be a special type of part that will only exist as spares * It will determine the amount of ammo of a particular type that * is available - * + * * @author Jay Lawson (jaylawson39 at yahoo.com) */ public class AmmoStorage extends EquipmentPart implements IAcquisitionWork { @@ -130,7 +130,7 @@ public boolean isSamePartType(@Nullable Part part) { /** * Gets a value indicating whether or an {@code AmmoType} is * the same as this instance's ammo. - * + * * @param otherAmmoType The other {@code AmmoType}. */ public boolean isSameAmmoType(AmmoType otherAmmoType) { @@ -142,7 +142,7 @@ public boolean isSameAmmoType(AmmoType otherAmmoType) { /** * Gets a value indicating whether or not an {@code AmmoType} * is compatible with this instance's ammo. - * + * * @param otherAmmoType The other {@code AmmoType}. */ public boolean isCompatibleAmmo(AmmoType otherAmmoType) { @@ -229,7 +229,7 @@ public boolean needsFixing() { @Override public String getDesc() { - String toReturn = " " + getAcquisitionBonus() + "
"; diff --git a/MekHQ/src/mekhq/campaign/parts/Armor.java b/MekHQ/src/mekhq/campaign/parts/Armor.java index cba9d91126..d284bb07ec 100644 --- a/MekHQ/src/mekhq/campaign/parts/Armor.java +++ b/MekHQ/src/mekhq/campaign/parts/Armor.java @@ -126,7 +126,7 @@ public String getDesc() { if (getAllMods(null).getValue() > -1) { bonus = '+' + bonus; } - String toReturn = " " + getAcquisitionBonus() + "
"; diff --git a/MekHQ/src/mekhq/campaign/parts/MekLocation.java b/MekHQ/src/mekhq/campaign/parts/MekLocation.java index d46abfab84..070af8ada2 100644 --- a/MekHQ/src/mekhq/campaign/parts/MekLocation.java +++ b/MekHQ/src/mekhq/campaign/parts/MekLocation.java @@ -864,7 +864,7 @@ public String getDesc() { if ((!isBreached() && !isBlownOff()) || isSalvaging()) { return super.getDesc(); } - String toReturn = " -1) { bonus = '+' + bonus; } - String toReturn = " " + getAcquisitionBonus() + "
"; diff --git a/MekHQ/src/mekhq/campaign/parts/Part.java b/MekHQ/src/mekhq/campaign/parts/Part.java index 8217b928a4..e84081be09 100644 --- a/MekHQ/src/mekhq/campaign/parts/Part.java +++ b/MekHQ/src/mekhq/campaign/parts/Part.java @@ -427,7 +427,7 @@ public String getDesc() { if (getAllMods(null).getValue() > -1) { bonus = '+' + bonus; } - String toReturn = " -1) { bonus = '+' + bonus; } - String toReturn = " " + getAcquisitionBonus() + "
"; diff --git a/MekHQ/src/mekhq/campaign/parts/equipment/BattleArmorAmmoBin.java b/MekHQ/src/mekhq/campaign/parts/equipment/BattleArmorAmmoBin.java index 1a7880ec33..797f0acab0 100644 --- a/MekHQ/src/mekhq/campaign/parts/equipment/BattleArmorAmmoBin.java +++ b/MekHQ/src/mekhq/campaign/parts/equipment/BattleArmorAmmoBin.java @@ -192,7 +192,7 @@ public AmmoStorage getNewPart() { @Override public String getAcquisitionDesc() { - String toReturn = " " + getAcquisitionBonus() + "
"; diff --git a/MekHQ/src/mekhq/campaign/parts/equipment/LargeCraftAmmoBin.java b/MekHQ/src/mekhq/campaign/parts/equipment/LargeCraftAmmoBin.java index cd877437c3..a2f1730df4 100644 --- a/MekHQ/src/mekhq/campaign/parts/equipment/LargeCraftAmmoBin.java +++ b/MekHQ/src/mekhq/campaign/parts/equipment/LargeCraftAmmoBin.java @@ -379,7 +379,7 @@ public String getDesc() { if (shotsNeeded >= 0) { return super.getDesc(); } - String toReturn = "" + s + ""); + lblImage.setText("" + s + ""); } public void setText(String s) { - lblImage.setText("" + s + ""); + lblImage.setText("" + s + ""); } public void setHtmlText(String s) { diff --git a/MekHQ/src/mekhq/gui/CampaignGUI.java b/MekHQ/src/mekhq/gui/CampaignGUI.java index a86193246f..221047f798 100644 --- a/MekHQ/src/mekhq/gui/CampaignGUI.java +++ b/MekHQ/src/mekhq/gui/CampaignGUI.java @@ -25,6 +25,7 @@ import megamek.client.generator.RandomUnitGenerator; import megamek.client.ui.preferences.JWindowPreference; import megamek.client.ui.preferences.PreferencesNode; +import megamek.client.ui.swing.GUIPreferences; import megamek.client.ui.swing.GameOptionsDialog; import megamek.client.ui.swing.UnitLoadingDialog; import megamek.client.ui.swing.dialog.AbstractUnitSelectorDialog; @@ -1061,7 +1062,7 @@ private void initTopButtons() { gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.NONE; - gridBagConstraints.weightx = 0.0; + gridBagConstraints.weightx = 1; gridBagConstraints.weighty = 0.0; gridBagConstraints.gridheight = 2; gridBagConstraints.anchor = GridBagConstraints.WEST; @@ -1072,14 +1073,11 @@ private void initTopButtons() { btnGMMode.setToolTipText(resourceMap.getString("btnGMMode.toolTipText")); btnGMMode.setSelected(getCampaign().isGM()); btnGMMode.addActionListener(e -> getCampaign().setGMMode(btnGMMode.isSelected())); - btnGMMode.setMinimumSize(new Dimension(150, 25)); - btnGMMode.setPreferredSize(new Dimension(150, 25)); - btnGMMode.setMaximumSize(new Dimension(150, 25)); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; - gridBagConstraints.fill = GridBagConstraints.NONE; - gridBagConstraints.weightx = 1.0; + gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 0; gridBagConstraints.weighty = 0.0; gridBagConstraints.anchor = GridBagConstraints.EAST; gridBagConstraints.insets = new Insets(3, 3, 3, 3); @@ -1088,25 +1086,22 @@ private void initTopButtons() { btnOvertime = new JToggleButton(resourceMap.getString("btnOvertime.text")); btnOvertime.setToolTipText(resourceMap.getString("btnOvertime.toolTipText")); btnOvertime.addActionListener(evt -> getCampaign().setOvertime(btnOvertime.isSelected())); - btnOvertime.setMinimumSize(new Dimension(150, 25)); - btnOvertime.setPreferredSize(new Dimension(150, 25)); - btnOvertime.setMaximumSize(new Dimension(150, 25)); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; - gridBagConstraints.fill = GridBagConstraints.NONE; - gridBagConstraints.weightx = 1.0; + gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 0; gridBagConstraints.weighty = 0.0; gridBagConstraints.anchor = GridBagConstraints.EAST; gridBagConstraints.insets = new Insets(3, 3, 3, 3); btnPanel.add(btnOvertime, gridBagConstraints); // This button uses a mnemonic that is unique and listed in the initMenu JavaDoc - JButton btnAdvanceDay = new JButton(resourceMap.getString("btnAdvanceDay.text")); + String padding = " "; + JButton btnAdvanceDay = new JButton(padding + resourceMap.getString("btnAdvanceDay.text") + padding); btnAdvanceDay.setToolTipText(resourceMap.getString("btnAdvanceDay.toolTipText")); btnAdvanceDay.addActionListener(evt -> getCampaignController().advanceDay()); btnAdvanceDay.setMnemonic(KeyEvent.VK_A); - btnAdvanceDay.setPreferredSize(new Dimension(250, 50)); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; @@ -1254,14 +1249,18 @@ private void refreshThemeChoices() { menuThemes.removeAll(); JCheckBoxMenuItem miPlaf; for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) { - miPlaf = new JCheckBoxMenuItem(laf.getName()); - if (laf.getClassName().equalsIgnoreCase(MekHQ.getSelectedTheme().getValue())) { - miPlaf.setSelected(true); - } + // intentionally only limits the themes in the menu; as a last resort for GUI problems, other laf can be used by + // hand-editing mhq.preferences + if (GUIPreferences.isSupportedLookAndFeel(laf)) { + miPlaf = new JCheckBoxMenuItem(laf.getName()); + if (laf.getClassName().equalsIgnoreCase(MekHQ.getSelectedTheme().getValue())) { + miPlaf.setSelected(true); + } - menuThemes.add(miPlaf); - miPlaf.setActionCommand(laf.getClassName()); - miPlaf.addActionListener(this::changeTheme); + menuThemes.add(miPlaf); + miPlaf.setActionCommand(laf.getClassName()); + miPlaf.addActionListener(this::changeTheme); + } } } diff --git a/MekHQ/src/mekhq/gui/HangarTab.java b/MekHQ/src/mekhq/gui/HangarTab.java index 16aef350a0..fb70d2b2d8 100644 --- a/MekHQ/src/mekhq/gui/HangarTab.java +++ b/MekHQ/src/mekhq/gui/HangarTab.java @@ -22,9 +22,12 @@ import megamek.client.ui.preferences.JComboBoxPreference; import megamek.client.ui.preferences.JTablePreference; import megamek.client.ui.preferences.PreferencesNode; +import megamek.client.ui.swing.GUIPreferences; +import megamek.client.ui.swing.util.UIUtil; import megamek.common.Entity; import megamek.common.UnitType; import megamek.common.event.Subscribe; +import megamek.common.preference.IPreferenceChangeListener; import megamek.common.util.sorter.NaturalOrderComparator; import megamek.logging.MMLogger; import mekhq.MekHQ; @@ -71,6 +74,8 @@ public final class HangarTab extends CampaignGuiTab { private UnitTableModel unitModel; private TableRowSorter unitSorter; + private final IPreferenceChangeListener scalingChangeListener = e -> changeUnitView(); + private static final ResourceBundle resourceMap = ResourceBundle.getBundle("mekhq.resources.CampaignGUI", MekHQ.getMHQOptions().getLocale()); @@ -79,6 +84,7 @@ public HangarTab(CampaignGUI gui, String name) { super(gui, name); MekHQ.registerHandler(this); setUserPreferences(); + GUIPreferences.getInstance().addPreferenceChangeListener(scalingChangeListener); } // endregion Constructors @@ -291,7 +297,7 @@ public static String getUnitViewName(int group) { public void changeUnitView() { int view = choiceUnitView.getSelectedIndex(); XTableColumnModel columnModel = (XTableColumnModel) unitTable.getColumnModel(); - unitTable.setRowHeight(15); + unitTable.setRowHeight(UIUtil.scaleForGUI(15)); // set the renderer TableColumn column; @@ -311,7 +317,7 @@ public void changeUnitView() { } if (view == UV_GRAPHIC) { - unitTable.setRowHeight(80); + unitTable.setRowHeight(UIUtil.scaleForGUI(60)); columnModel.setColumnVisible(columnModel.getColumnByModelIndex(UnitTableModel.COL_NAME), false); columnModel.setColumnVisible(columnModel.getColumnByModelIndex(UnitTableModel.COL_TYPE), false); columnModel.setColumnVisible(columnModel.getColumnByModelIndex(UnitTableModel.COL_WCLASS), true); @@ -404,6 +410,12 @@ public void changeUnitView() { } } + @Override + public void disposeTab() { + super.disposeTab(); + GUIPreferences.getInstance().removePreferenceChangeListener(scalingChangeListener); + } + public void focusOnUnit(UUID id) { splitUnit.resetToPreferredSizes(); int row = -1; diff --git a/MekHQ/src/mekhq/gui/InfirmaryTab.java b/MekHQ/src/mekhq/gui/InfirmaryTab.java index 67b7df44e9..8ec1696748 100644 --- a/MekHQ/src/mekhq/gui/InfirmaryTab.java +++ b/MekHQ/src/mekhq/gui/InfirmaryTab.java @@ -18,6 +18,7 @@ */ package mekhq.gui; +import megamek.client.ui.swing.util.UIUtil; import megamek.common.TargetRoll; import megamek.common.event.Subscribe; import mekhq.MekHQ; @@ -79,7 +80,7 @@ public void initTab() { doctorsModel = new DocTableModel(getCampaign()); docTable = new JTable(doctorsModel); - docTable.setRowHeight(60); + docTable.setRowHeight(UIUtil.scaleForGUI(60)); docTable.getColumnModel().getColumn(0).setCellRenderer(doctorsModel.getRenderer()); docTable.getSelectionModel().addListSelectionListener(ev -> docTableValueChanged()); docTable.setOpaque(false); diff --git a/MekHQ/src/mekhq/gui/PersonnelTab.java b/MekHQ/src/mekhq/gui/PersonnelTab.java index 491a5eca71..bc167eb3ba 100644 --- a/MekHQ/src/mekhq/gui/PersonnelTab.java +++ b/MekHQ/src/mekhq/gui/PersonnelTab.java @@ -39,7 +39,10 @@ import megamek.client.ui.preferences.JTablePreference; import megamek.client.ui.preferences.JToggleButtonPreference; import megamek.client.ui.preferences.PreferencesNode; +import megamek.client.ui.swing.GUIPreferences; +import megamek.client.ui.swing.util.UIUtil; import megamek.common.event.Subscribe; +import megamek.common.preference.IPreferenceChangeListener; import megamek.logging.MMLogger; import mekhq.MHQOptionsChangedEvent; import mekhq.MekHQ; @@ -71,11 +74,14 @@ public final class PersonnelTab extends CampaignGuiTab { private PersonnelTableModel personModel; private TableRowSorter personnelSorter; + private final IPreferenceChangeListener scalingChangeListener = e -> changePersonnelView(); + // region Constructors public PersonnelTab(CampaignGUI gui, String name) { super(gui, name); MekHQ.registerHandler(this); setUserPreferences(); + GUIPreferences.getInstance().addPreferenceChangeListener(scalingChangeListener); } // endregion Constructors @@ -229,6 +235,12 @@ public Component getListCellRendererComponent(final JList list, final Object filterPersonnel(); } + @Override + public void disposeTab() { + super.disposeTab(); + GUIPreferences.getInstance().removePreferenceChangeListener(scalingChangeListener); + } + private DefaultComboBoxModel createPersonGroupModel() { final DefaultComboBoxModel personGroupModel = new DefaultComboBoxModel<>(); for (PersonnelFilter filter : MekHQ.getMHQOptions().getPersonnelFilterStyle().getFilters(false)) { @@ -297,7 +309,7 @@ private void changePersonnelView() { ? PersonnelTabView.GENERAL : choicePersonView.getSelectedItem(); final XTableColumnModel columnModel = (XTableColumnModel) getPersonnelTable().getColumnModel(); - getPersonnelTable().setRowHeight(15); + getPersonnelTable().setRowHeight(UIUtil.scaleForGUI(15)); // set the renderer for (final PersonnelTableModelColumn column : PersonnelTableModel.PERSONNEL_COLUMNS) { diff --git a/MekHQ/src/mekhq/gui/RepairTab.java b/MekHQ/src/mekhq/gui/RepairTab.java index 67a77a81e3..6150faf858 100644 --- a/MekHQ/src/mekhq/gui/RepairTab.java +++ b/MekHQ/src/mekhq/gui/RepairTab.java @@ -45,6 +45,7 @@ import megamek.client.ui.models.XTableColumnModel; import megamek.client.ui.preferences.JTablePreference; import megamek.client.ui.preferences.PreferencesNode; +import megamek.client.ui.swing.util.UIUtil; import megamek.common.MekView; import megamek.common.TargetRoll; import megamek.common.event.Subscribe; @@ -265,7 +266,7 @@ public void initTab() { techsModel = new TechTableModel(getCampaignGui(), this); techTable = new JTable(techsModel); - techTable.setRowHeight(60); + techTable.setRowHeight(UIUtil.scaleForGUI(60)); techTable.getColumnModel().getColumn(0).setCellRenderer(techsModel.getRenderer()); techTable.getSelectionModel().addListSelectionListener(this::techTableValueChanged); techSorter = new TableRowSorter<>(techsModel); @@ -279,9 +280,9 @@ public void initTab() { scrollTechTable.setPreferredSize(new Dimension(300, 300)); panDoTask = new JPanel(new GridBagLayout()); - panDoTask.setMinimumSize(new Dimension(100, 100)); + panDoTask.setMinimumSize(UIUtil.scaleForGUI(100, 100)); panDoTask.setName("panelDoTask"); - panDoTask.setPreferredSize(new Dimension(100, 100)); + panDoTask.setPreferredSize(UIUtil.scaleForGUI(100, 100)); btnDoTask = new JButton(resourceMap.getString("btnDoTask.text")); btnDoTask.setToolTipText(resourceMap.getString("btnDoTask.toolTipText")); @@ -382,7 +383,7 @@ public void initTab() { taskModel = new TaskTableModel(getCampaignGui(), this); taskTable = new JTable(taskModel); - taskTable.setRowHeight(70); + taskTable.setRowHeight(UIUtil.scaleForGUI(70)); taskTable.getColumnModel().getColumn(0).setCellRenderer(taskModel.getRenderer(getIconPackage())); taskTable.getSelectionModel().addListSelectionListener(ev -> taskTableValueChanged()); taskSorter = new TableRowSorter<>(taskModel); @@ -744,7 +745,7 @@ public boolean include(Entry entry) /** * Focuses on the unit with the given ID if it exists. - * + * * @param id The unique identifier of the unit. * @return A value indicating whether or not the unit was focused. */ diff --git a/MekHQ/src/mekhq/gui/RepairTaskInfo.java b/MekHQ/src/mekhq/gui/RepairTaskInfo.java index bb7d977ecd..92bfe05d05 100644 --- a/MekHQ/src/mekhq/gui/RepairTaskInfo.java +++ b/MekHQ/src/mekhq/gui/RepairTaskInfo.java @@ -81,7 +81,7 @@ public RepairTaskInfo(IconPackage i) { } public void setText(String s) { - lblImage.setText("" + s + ""); + lblImage.setText("" + s + ""); } public void highlightBorder() { diff --git a/MekHQ/src/mekhq/gui/WarehouseTab.java b/MekHQ/src/mekhq/gui/WarehouseTab.java index 03ef5eb977..e01c40ac9b 100644 --- a/MekHQ/src/mekhq/gui/WarehouseTab.java +++ b/MekHQ/src/mekhq/gui/WarehouseTab.java @@ -34,6 +34,7 @@ import megamek.client.ui.preferences.JComboBoxPreference; import megamek.client.ui.preferences.JTablePreference; import megamek.client.ui.preferences.PreferencesNode; +import megamek.client.ui.swing.util.UIUtil; import megamek.common.MiscType; import megamek.common.TargetRoll; import megamek.common.WeaponType; @@ -273,7 +274,7 @@ public void initTab() { techsModel = new TechTableModel(getCampaignGui(), this); techTable = new JTable(techsModel); - techTable.setRowHeight(60); + techTable.setRowHeight(UIUtil.scaleForGUI(60)); techTable.getColumnModel().getColumn(0).setCellRenderer(techsModel.getRenderer()); techTable.getSelectionModel().addListSelectionListener(ev -> updateTechTarget()); techSorter = new TableRowSorter<>(techsModel); diff --git a/MekHQ/src/mekhq/gui/dialog/AcquisitionsDialog.java b/MekHQ/src/mekhq/gui/dialog/AcquisitionsDialog.java index ea3f796f8c..f650acdf9a 100644 --- a/MekHQ/src/mekhq/gui/dialog/AcquisitionsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/AcquisitionsDialog.java @@ -194,7 +194,7 @@ private JPanel createSummaryPanel() { private String generateSummaryText() { StringBuilder sbText = new StringBuilder(); - sbText.append(""); + sbText.append(""); sbText.append("Required: "); sbText.append(PartsAcquisitionService.getRequiredCount()); @@ -337,7 +337,7 @@ private void refresh() { private String generateText() { StringBuilder sbText = new StringBuilder(); - sbText.append(""); + sbText.append(""); sbText.append(""); sbText.append(targetWork.getAcquisitionDisplayName()); diff --git a/MekHQ/src/mekhq/gui/dialog/MHQOptionsDialog.java b/MekHQ/src/mekhq/gui/dialog/MHQOptionsDialog.java index b9bdbabd4d..8282bf0906 100644 --- a/MekHQ/src/mekhq/gui/dialog/MHQOptionsDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MHQOptionsDialog.java @@ -25,6 +25,7 @@ import megamek.client.ui.displayWrappers.FontDisplay; import megamek.client.ui.swing.ColourSelectorButton; import megamek.client.ui.swing.CommonSettingsDialog; +import megamek.client.ui.swing.GUIPreferences; import megamek.client.ui.swing.HelpDialog; import megamek.common.preference.PreferenceManager; import megamek.logging.MMLogger; @@ -45,6 +46,7 @@ import java.net.URL; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.Hashtable; import java.util.Objects; /** @@ -72,6 +74,7 @@ public class MHQOptionsDialog extends AbstractMHQButtonDialog { private JCheckBox optionHistoricalDailyLog; private JCheckBox chkCompanyGeneratorStartup; private JCheckBox chkShowCompanyGenerator; + private final JSlider guiScale = new JSlider(); // region Command Center Tab private JCheckBox optionCommandCenterUseUnitMarket; @@ -221,6 +224,25 @@ protected Container createCenterPane() { } private JPanel createDisplayTab() { + guiScale.setMajorTickSpacing(3); + guiScale.setMinimum(7); + guiScale.setMaximum(24); + Hashtable table = new Hashtable<>(); + table.put(7, new JLabel("70%")); + table.put(10, new JLabel("100%")); + table.put(16, new JLabel("160%")); + table.put(22, new JLabel("220%")); + guiScale.setLabelTable(table); + guiScale.setPaintTicks(true); + guiScale.setPaintLabels(true); + guiScale.setValue((int) (GUIPreferences.getInstance().getGUIScale() * 10)); + guiScale.setToolTipText(Messages.getString("CommonSettingsDialog.guiScaleTT")); + JLabel guiScaleLabel = new JLabel(Messages.getString("CommonSettingsDialog.guiScale")); + JPanel scaleLine = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); + scaleLine.add(guiScaleLabel); + scaleLine.add(Box.createHorizontalStrut(5)); + scaleLine.add(guiScale); + // Initialize Components Used in ActionListeners final JLabel lblInterstellarMapShowJumpRadiusMinimumZoom = new JLabel(); final JLabel lblInterstellarMapShowPlanetaryAcquisitionRadiusMinimumZoom = new JLabel(); @@ -410,6 +432,7 @@ public Component getListCellRendererComponent(final JList list, final Object .addComponent(optionLongDisplayDateFormat) .addComponent(labelLongDisplayDateFormatExample, Alignment.TRAILING)) + .addComponent(scaleLine) .addComponent(optionHistoricalDailyLog) .addComponent(chkCompanyGeneratorStartup) .addComponent(chkShowCompanyGenerator) @@ -449,6 +472,7 @@ public Component getListCellRendererComponent(final JList list, final Object .addComponent(labelLongDisplayDateFormat) .addComponent(optionLongDisplayDateFormat) .addComponent(labelLongDisplayDateFormatExample)) + .addComponent(scaleLine) .addComponent(optionHistoricalDailyLog) .addComponent(chkCompanyGeneratorStartup) .addComponent(chkShowCompanyGenerator) @@ -1256,6 +1280,8 @@ public Component getListCellRendererComponent(final JList list, final Object @Override protected void okAction() { + GUIPreferences.getInstance().setValue(GUIPreferences.GUI_SCALE, 0.1 * guiScale.getValue()); + MekHQ.updateGuiScaling(); if (validateDateFormat(optionDisplayDateFormat.getText())) { MekHQ.getMHQOptions().setDisplayDateFormat(optionDisplayDateFormat.getText()); } @@ -1401,6 +1427,7 @@ protected void okAction() { } private void setInitialState() { + guiScale.setValue((int) (GUIPreferences.getInstance().getGUIScale() * 10)); optionDisplayDateFormat.setText(MekHQ.getMHQOptions().getDisplayDateFormat()); optionLongDisplayDateFormat.setText(MekHQ.getMHQOptions().getLongDisplayDateFormat()); optionHistoricalDailyLog.setSelected(MekHQ.getMHQOptions().getHistoricalDailyLog()); diff --git a/MekHQ/src/mekhq/gui/enums/PersonnelTableModelColumn.java b/MekHQ/src/mekhq/gui/enums/PersonnelTableModelColumn.java index 8b42f7fd2c..efe8efcda6 100644 --- a/MekHQ/src/mekhq/gui/enums/PersonnelTableModelColumn.java +++ b/MekHQ/src/mekhq/gui/enums/PersonnelTableModelColumn.java @@ -18,6 +18,7 @@ */ package mekhq.gui.enums; +import megamek.client.ui.swing.util.UIUtil; import megamek.codeUtilities.StringUtility; import megamek.common.Entity; import megamek.common.Jumpship; @@ -806,7 +807,7 @@ public boolean isVisible(final Campaign campaign, final PersonnelTabView view, final JTable table) { return switch (view) { case GRAPHIC -> { - table.setRowHeight(80); + table.setRowHeight(UIUtil.scaleForGUI(60)); yield switch (this) { case PERSON, UNIT_ASSIGNMENT, FORCE -> true; default -> false; diff --git a/MekHQ/src/mekhq/gui/model/CrewListModel.java b/MekHQ/src/mekhq/gui/model/CrewListModel.java index 7b39a5b8d6..bde88909d0 100644 --- a/MekHQ/src/mekhq/gui/model/CrewListModel.java +++ b/MekHQ/src/mekhq/gui/model/CrewListModel.java @@ -128,7 +128,7 @@ public Component getListCellRendererComponent(JList list, Pers Person p = getElementAt(index); String gunSkill = SkillType.getGunnerySkillFor(unit.getEntity()); String driveSkill = SkillType.getDrivingSkillFor(unit.getEntity()); - String sb = "" + p.getFullTitle() + "
" + String sb = "" + p.getFullTitle() + "
" + CrewRole.getCrewRole(p, unit).getDisplayName() + " (" + (p.hasSkill(gunSkill) ? p.getSkill(gunSkill).getFinalSkillValue() : "-") diff --git a/MekHQ/src/mekhq/gui/model/DocTableModel.java b/MekHQ/src/mekhq/gui/model/DocTableModel.java index 69dbb30f8e..ddfbbe81f9 100644 --- a/MekHQ/src/mekhq/gui/model/DocTableModel.java +++ b/MekHQ/src/mekhq/gui/model/DocTableModel.java @@ -50,7 +50,7 @@ public Object getValueAt(int row, int col) { private String getDocDesc(Person doc) { StringBuilder toReturn = new StringBuilder(128); - toReturn.append("").append(doc.getFullTitle()).append("
"); + toReturn.append("").append(doc.getFullTitle()).append("
"); Skill skill = doc.getSkill(SkillType.S_DOCTOR); if (null != skill) { @@ -61,10 +61,10 @@ private String getDocDesc(Person doc) { toReturn.append(String.format(" (%d XP)", doc.getXP())); if (campaign.requiresAdditionalMedics()) { - toReturn.append("
, ") .append(campaign.getMedicsPerDoctor()) - .append(" medics
"); + .append(" medics

"); } else { toReturn.append(String.format(", %d medics
", campaign.getMedicsPerDoctor())); } diff --git a/MekHQ/src/mekhq/gui/model/PatientTableModel.java b/MekHQ/src/mekhq/gui/model/PatientTableModel.java index 8187077ba4..21b4eb738f 100644 --- a/MekHQ/src/mekhq/gui/model/PatientTableModel.java +++ b/MekHQ/src/mekhq/gui/model/PatientTableModel.java @@ -101,7 +101,7 @@ public Component getListCellRendererComponent( } private String getInjuriesDesc(Person p) { - StringBuilder toReturn = new StringBuilder("").append(p.getFullTitle()) + StringBuilder toReturn = new StringBuilder("").append(p.getFullTitle()) .append("
").append("   Injuries:"); String sep = "
      "; for (Injury injury : p.getInjuries()) { @@ -117,7 +117,7 @@ private String getInjuriesDesc(Person p) { } private String getPatientDesc(Person p) { - String toReturn = "" + p.getFullTitle() + "
"; + String toReturn = "" + p.getFullTitle() + "
"; toReturn += p.getHits() + " hit(s)
[next check in " + p.getDaysToWaitForHealing() + " days]"; toReturn += "
"; return toReturn; diff --git a/MekHQ/src/mekhq/gui/model/TechTableModel.java b/MekHQ/src/mekhq/gui/model/TechTableModel.java index ebce04d646..f5533e2928 100644 --- a/MekHQ/src/mekhq/gui/model/TechTableModel.java +++ b/MekHQ/src/mekhq/gui/model/TechTableModel.java @@ -103,7 +103,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole public String getTechDesc(Person tech, boolean overtimeAllowed, IPartWork part) { StringBuilder toReturn = new StringBuilder(128); - toReturn.append("@"); } else { diff --git a/MekHQ/src/mekhq/gui/view/ForceViewPanel.java b/MekHQ/src/mekhq/gui/view/ForceViewPanel.java index f268cd5710..d1ce6ce964 100644 --- a/MekHQ/src/mekhq/gui/view/ForceViewPanel.java +++ b/MekHQ/src/mekhq/gui/view/ForceViewPanel.java @@ -458,7 +458,7 @@ private void fillSubUnits() { } public String getForceSummary(Person person, Unit unit) { - String toReturn = "" + person.getFullTitle() + "
"; + String toReturn = "" + person.getFullTitle() + "
"; toReturn += person.getSkillLevel(campaign, false) + " " + person.getRoleDesc(); if (null != unit && null != unit.getEntity() && null != unit.getEntity().getCrew() && unit.getEntity().getCrew().getHits() > 0) { @@ -470,7 +470,7 @@ public String getForceSummary(Person person, Unit unit) { public String getForceSummary(Unit unit) { String toReturn = "" + unit.getName() + "
"; - toReturn += "BV: " + unit.getEntity().calculateBattleValue(true, null == unit.getEntity().getCrew()) + "
"; + toReturn += "BV: " + unit.getEntity().calculateBattleValue(true, null == unit.getEntity().getCrew()) + "
"; toReturn += unit.getStatus(); Entity entity = unit.getEntity(); if (entity.hasNavalC3()) { @@ -566,7 +566,7 @@ public String getForceSummary(Force force) { StringBuilder summary = new StringBuilder(); summary.append("").append(force.getName()).append(" (").append(commander).append(")
"); - summary.append(""); + summary.append(""); appendSummary(summary, "Number of Units", number); appendSummary(summary, "BV", battleValue); appendSummary(summary, "Tonnage", DecimalFormat.getInstance().format(tonnage));