Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

GUI scaling fixes #1637

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions megameklab/src/megameklab/MegaMekLab.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package megameklab;

import java.awt.*;
import java.io.File;
import java.io.ObjectInputFilter;
import java.util.Locale;
Expand All @@ -30,6 +29,7 @@
import megamek.MegaMek;
import megamek.SuiteConstants;
import megamek.client.ui.preferences.SuitePreferences;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.Entity;
import megamek.common.EquipmentType;
import megamek.common.MekFileParser;
Expand Down Expand Up @@ -129,7 +129,7 @@ private static void setLookAndFeel() {
try {
String plaf = CConfig.getParam(CConfig.GUI_PLAF, UIManager.getSystemLookAndFeelClassName());
UIManager.setLookAndFeel(plaf);
updateAfterUiChange();
UIUtil.updateAfterUiChange();
} catch (Exception ex) {
logger.error("setLookAndFeel() Exception {}", ex);
}
Expand All @@ -138,20 +138,6 @@ private static void setLookAndFeel() {
public static void updateGuiScaling() {
System.setProperty("flatlaf.uiScale", Double.toString(GUIPreferences.getInstance().getGUIScale()));
setLookAndFeel();
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();
}
}

public static SuitePreferences getMMLPreferences() {
Expand Down
11 changes: 6 additions & 5 deletions megameklab/src/megameklab/ui/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import megamek.client.ui.dialogs.WeightDisplayDialog;
import megamek.client.ui.swing.GUIPreferences;
import megamek.client.ui.swing.UnitLoadingDialog;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.loaders.BLKFile;
Expand Down Expand Up @@ -625,8 +626,7 @@ private JMenu createThemesMenu() {
return themesMenu;
}

private @Nullable JMenuItem createCConfigMenuItem(final String recentFileName,
final int fileNumber) {
private @Nullable JMenuItem createCConfigMenuItem(final String recentFileName, final int fileNumber) {
File recent = new File(recentFileName);
String path = recent.getParent();
String mmlDirectory = System.getProperty("user.dir");
Expand All @@ -636,9 +636,10 @@ private JMenu createThemesMenu() {
path = path.substring(0, 40) + "...";
}
}

String text = "<HTML><NOBR>" + fileNumber + ". " + recent.getName() + "<BR><FONT SIZE=\"-2\">" + path;
final JMenuItem miCConfig = new JMenuItem(text);
String html = "<HTML><HEAD><STYLE>%s</STYLE></HEAD><BODY>%s</BODY></HTML>";
String style = ".small { font-size:smaller; color:gray; }";
String content = "<NOBR>%d. %s<BR>".formatted(fileNumber, recent.getName()) + UIUtil.spanCSS("small", path);
final JMenuItem miCConfig = new JMenuItem(html.formatted(style, content));
miCConfig.setName("miCConfig");
miCConfig.addActionListener(evt -> loadUnitFromFile(fileNumber));
miCConfig.setMnemonic(48 + fileNumber); // the number itself, i.e. 1, 2, 3 etc.
Expand Down
7 changes: 3 additions & 4 deletions megameklab/src/megameklab/ui/MenuBarOwner.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*/
package megameklab.ui;

import megamek.MegaMek;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.Entity;
import megamek.common.annotations.Nullable;
import megameklab.MegaMekLab;
import megameklab.ui.dialog.UiLoader;
import megameklab.ui.util.AppCloser;
import megameklab.util.CConfig;
Expand Down Expand Up @@ -128,10 +127,10 @@ default void changeTheme(String lookAndFeelInfo) {
SwingUtilities.invokeLater(() -> {
try {
UIManager.setLookAndFeel(lookAndFeelInfo);
MegaMekLab.updateAfterUiChange();
UIUtil.updateAfterUiChange();
} catch (Exception ex) {
PopupMessages.showLookAndFeelError(getFrame(), ex.getMessage());
}
});
}
}
}