Skip to content

Commit

Permalink
Merge pull request #6068 from SJuliez/replace-gui-scaling
Browse files Browse the repository at this point in the history
Replace Manual GUI scaling with FlatLaf Scaling
  • Loading branch information
HammerGS authored Oct 5, 2024
2 parents d80c42a + a5f5c84 commit dbc041b
Show file tree
Hide file tree
Showing 89 changed files with 768 additions and 1,743 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ private ASConversionInfoDialog(final JFrame frame, CalculationReport report, @Nu
@Override
protected void finalizeInitialization() throws Exception {
super.finalizeInitialization();
adaptToGUIScale();
if (!StringUtility.isNullOrBlank(unitName)) {
setTitle(getTitle() + " (" + unitName + ")");
}
Expand Down Expand Up @@ -119,9 +118,5 @@ private void copyToClipboard(String reportString) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(reportString), null);
}

private void adaptToGUIScale() {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
}
}

8 changes: 1 addition & 7 deletions megamek/src/megamek/client/ui/dialogs/ASStatsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public ASStatsDialog(JFrame frame, Collection<Entity> entities) {
super(frame, "AlphaStrikeStatsDialog", "AlphaStrikeStatsDialog.title");
this.entities = new ArrayList<>(entities);
initialize();
adaptToGUIScale();
}

@Override
Expand Down Expand Up @@ -105,7 +104,6 @@ private void setupTable() {
tablePanel = new ASStatsTablePanel(getFrame()).add(entities, "Selected Units");
scrollPane.setViewportView(tablePanel.getPanel());
centerPanel.add(scrollPane);
adaptToGUIScale();
}

private void copyToClipboard() {
Expand Down Expand Up @@ -197,11 +195,7 @@ private void save() {
}
}

private void adaptToGUIScale() {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
}

private void printCards() {
new ASCardPrinter(tablePanel.getSortedElements(), getFrame()).printCards();
}
}
}
5 changes: 0 additions & 5 deletions megamek/src/megamek/client/ui/dialogs/BVDisplayDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public BVDisplayDialog(final JFrame frame, final boolean modal, final Entity ent
protected void finalizeInitialization() throws Exception {
super.finalizeInitialization();
setTitle(getTitle() + " (" + entity.getShortName() + ")");
adaptToGUIScale();
pack();
Dimension screenSize = UIUtil.getScaledScreenSize(this);
setSize(new Dimension(getSize().width, Math.min(getHeight(), (int) (screenSize.getHeight() * 0.8))));
Expand Down Expand Up @@ -88,8 +87,4 @@ private void copyToClipboard(String reportString) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(reportString), null);
}

private void adaptToGUIScale() {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
}
}
5 changes: 0 additions & 5 deletions megamek/src/megamek/client/ui/dialogs/BotConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public BotConfigDialog(JFrame parent, @Nullable String botName,
updatePresets();
initialize();
updateDialogFields();
adaptToGUIScale();
}

@Override
Expand Down Expand Up @@ -918,8 +917,4 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
public void stateChanged(ChangeEvent e) {
updateEnabledStates();
}

private void adaptToGUIScale() {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
}
}
31 changes: 13 additions & 18 deletions megamek/src/megamek/client/ui/dialogs/BotConfigTargetHexDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public class BotConfigTargetHexDialog extends AbstractButtonDialog {

private static final String OK_ACTION = "Ok_Action";

private final TipTextField coordsField = new TipTextField("", 5, "x, y");
private final JLabel coordsLabel = new JLabel(Messages.getString("BotConfigDialog.hexCoordsLabel"));
private final JLabel listLabel = new JLabel(Messages.getString("BotConfigDialog.hexListLabel"));
Expand Down Expand Up @@ -85,15 +85,14 @@ public void windowOpened(WindowEvent e) {
coordsField.requestFocus();
}
});
adaptToGUIScale();
}

@Override
protected Container createCenterPane() {
JPanel result = new JPanel();
result.setLayout(new BoxLayout(result, BoxLayout.PAGE_AXIS));
result.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

var coordsFieldPanel = new UIUtil.FixedYPanel();
coordsFieldPanel.setAlignmentX(JComponent.CENTER_ALIGNMENT);
coordsField.setToolTipText(Messages.getString("BotConfigDialog.hexCoordsTip"));
Expand All @@ -102,21 +101,21 @@ protected Container createCenterPane() {
coordsFieldPanel.add(coordsLabel);
coordsFieldPanel.add(coordsField);

var listLabelPanel = new UIUtil.FixedYPanel();
var listLabelPanel = new UIUtil.FixedYPanel();
listLabel.setLabelFor(coordsList);
listLabel.setDisplayedMnemonic(KeyEvent.VK_S);
listLabelPanel.add(listLabel);

coordsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
coordsList.setLayoutOrientation(JList.VERTICAL);
coordsList.setCellRenderer(new BuildingHexRenderer());
coordsList.setFont(UIUtil.getScaledFont());
coordsList.setVisibleRowCount(6);
coordsList.setPrototypeCellValue(new Coords(-21, 22));

if (clientGui == null) {
listLabel.setEnabled(false);
coordsList.setEnabled(false);
coordsList.setEnabled(false);
} else {
board.getBuildingsVector().stream().map(Building::getCoordsList).forEach(coordsListModel::addAll);
}
Expand All @@ -127,10 +126,10 @@ protected Container createCenterPane() {
result.add(listLabelPanel);
result.add(Box.createVerticalStrut(25));
result.add(new JScrollPane(coordsList));

return result;
}

public List<Coords> getSelectedCoords() {
List<Coords> result = new ArrayList<>();
// Parse the Coords text field
Expand All @@ -144,11 +143,11 @@ public List<Coords> getSelectedCoords() {
} catch (Exception ignored) {
// No coords if it cannot be parsed
}
// Add the marked list entries
// Add the marked list entries
result.addAll(coordsList.getSelectedValuesList());
return result;
}

/** Shows building info for the hexes in the list model. */
private class BuildingHexRenderer extends DefaultListCellRenderer {

Expand All @@ -158,13 +157,13 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
Coords coords = (Coords) value;
String content = Messages.getString("BotConfigDialog.hexListIntro", coords.getX() + 1, coords.getY() + 1);
if (board != null && board.getHex(coords) != null) {
final Hex hex = board.getHex(coords);
final Hex hex = board.getHex(coords);
final Building bldg = board.getBuildingAt(coords);
if (hex.containsTerrain(BUILDING)) {
content += Messages.getString("BotConfigDialog.hexListBldg", Building.typeName(bldg.getType()),
Building.className(bldg.getBldgClass()), hex.terrainLevel(BLDG_ELEV), hex.terrainLevel(BLDG_CF));
} else if (hex.containsTerrain(FUEL_TANK)) {
content += Messages.getString("BotConfigDialog.hexListFuel",
content += Messages.getString("BotConfigDialog.hexListFuel",
hex.terrainLevel(FUEL_TANK_CF), hex.terrainLevel(FUEL_TANK_MAGN));
} else {
content += Messages.getString("BotConfigDialog.hexListBrdg", Building.typeName(bldg.getType()),
Expand All @@ -174,8 +173,4 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
return super.getListCellRendererComponent(list, content, index, isSelected, cellHasFocus);
}
}

private void adaptToGUIScale() {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
import megamek.client.ui.swing.util.UIUtil;
import megamek.client.ui.swing.util.UIUtil.TipTextField;

/** A dialog for entering one or more entity IDs that are to be used as strategic targets by Princess. */
/** A dialog for entering one or more entity IDs that are to be used as strategic targets by Princess. */
public class BotConfigTargetUnitDialog extends AbstractButtonDialog {

private static final String OK_ACTION = "Ok_Action";

private final TipTextField unitIDField = new TipTextField(5, "..., ...");
private final JLabel unitIDLabel = new JLabel(Messages.getString("BotConfigDialog.unitIdLabel"));
private final JLabel noteLabel = new JLabel("<HTML><CENTER>" + Messages.getString("BotConfigDialog.noteLabel"));

protected BotConfigTargetUnitDialog(JFrame frame) {
super(frame, "BotConfigTargetUnitDialog", "BotConfigDialog.bctudTitle");
initialize();
// Catch the Enter key as "OK"
// Catch the Enter key as "OK"
final KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(enter, OK_ACTION);
getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(enter, OK_ACTION);
Expand All @@ -58,22 +58,21 @@ public void windowOpened(WindowEvent e) {
unitIDField.requestFocus();
}
});
adaptToGUIScale();
}

@Override
protected Container createCenterPane() {
JPanel result = new JPanel();
result.setLayout(new BoxLayout(result, BoxLayout.PAGE_AXIS));
result.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

JPanel unitIDPanel = new UIUtil.FixedYPanel();
unitIDField.setToolTipText(Messages.getString("BotConfigDialog.unitIdTip"));
unitIDLabel.setLabelFor(unitIDField);
unitIDLabel.setDisplayedMnemonic(KeyEvent.VK_I);
unitIDPanel.add(unitIDLabel);
unitIDPanel.add(unitIDField);

noteLabel.setBorder(new EmptyBorder(0, 20, 0, 20));
noteLabel.setAlignmentX(JComponent.CENTER_ALIGNMENT);

Expand All @@ -83,7 +82,7 @@ protected Container createCenterPane() {
result.add(noteLabel);
return result;
}

/** Returns a list of entered entity IDs. The list may be empty but not null. */
public Set<Integer> getSelectedIDs() {
Set<Integer> result = new HashSet<>();
Expand All @@ -97,8 +96,4 @@ public Set<Integer> getSelectedIDs() {
}
return result;
}

private void adaptToGUIScale() {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
}
}
18 changes: 4 additions & 14 deletions megamek/src/megamek/client/ui/dialogs/CamoChooserDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ protected JPanel createButtonPanel() {
entityImage = new EntityImagePanel(null, null);

JPanel rotationPanel = new JPanel();
rotationPanel.add(UIUtil.scaledHorizontalSpacer(20));
rotationPanel.add(Box.createHorizontalStrut(20));
rotationPanel.add(new JLabel(Messages.getString("CamoChoiceDialog.rotation") + ":"));
rotationPanel.add(rotationSlider);

JPanel scalePanel = new JPanel();
scalePanel.add(UIUtil.scaledHorizontalSpacer(30));
scalePanel.add(Box.createHorizontalStrut(30));
scalePanel.add(new JLabel(Messages.getString("CamoChoiceDialog.scale") + ":"));
scalePanel.add(scaleSlider);

Expand Down Expand Up @@ -142,7 +142,7 @@ protected JPanel createButtonPanel() {
buttonPanel.setName("buttonPanel");
buttonPanel.add(parentCamoButton);
buttonPanel.add(refreshButton);
buttonPanel.add(UIUtil.scaledHorizontalSpacer(30));
buttonPanel.add(Box.createHorizontalStrut(30));
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);

Expand All @@ -169,16 +169,6 @@ public Camouflage getSelectedItem() {
return result;
}

@Override
protected void finalizeInitialization() throws Exception {
super.finalizeInitialization();
adaptToGUIScale();
}

private void adaptToGUIScale() {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
}

@Override
public void setVisible(boolean b) {
if ((originalCamo != null) && b) {
Expand All @@ -196,4 +186,4 @@ private void updatePreview() {
entityImage.updateDisplayedEntity(entity, getSelectedItem());
}
}
}
}
5 changes: 0 additions & 5 deletions megamek/src/megamek/client/ui/dialogs/CostDisplayDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ private void updateCalculation() {

/** Does gui-scaling, packs the dialog and reduces the height if its too big. */
private void updateDialogSize() {
adaptToGUIScale();
pack();
Dimension screenSize = UIUtil.getScaledScreenSize(this);
setSize(new Dimension(getSize().width, Math.min(getHeight(), (int) (screenSize.getHeight() * 0.8))));
Expand All @@ -125,8 +124,4 @@ private void copyToClipboard(String reportString) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(reportString), null);
}

private void adaptToGUIScale() {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
}
}
16 changes: 3 additions & 13 deletions megamek/src/megamek/client/ui/dialogs/EntityReadoutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import megamek.client.ui.panes.EntityViewPane;
import megamek.client.ui.preferences.JTabbedPanePreference;
import megamek.client.ui.preferences.PreferencesNode;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.*;

/**
Expand All @@ -37,7 +36,7 @@ public class EntityReadoutDialog extends AbstractDialog {
private final Entity entity;
private EntityViewPane entityView;

/** Constructs a non-modal dialog showing the readout (TRO) of the given entity. */
/** Constructs a non-modal dialog showing the readout (TRO) of the given entity. */
public EntityReadoutDialog(final JFrame frame, final Entity entity) {
this(frame, false, entity);
}
Expand All @@ -55,19 +54,10 @@ protected Container createCenterPane() {
entityView = new EntityViewPane(getFrame(), entity);
return entityView;
}

@Override
protected void setCustomPreferences(final PreferencesNode preferences) throws Exception {
super.setCustomPreferences(preferences);
preferences.manage(new JTabbedPanePreference(entityView));
}

@Override
public void setVisible(boolean visible) {
if (visible) {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
}

super.setVisible(visible);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/
package megamek.client.ui.dialogs;

import megamek.client.ui.swing.util.FlatLafStyleBuilder;
import megamek.client.ui.swing.util.FontHandler;
import megamek.client.ui.swing.util.UIUtil;
import megamek.server.scriptedevent.NarrativeDisplayProvider;

import javax.swing.*;
Expand Down Expand Up @@ -50,7 +52,7 @@ protected Container getMainPanel() {
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.BOTH;
JTextPane txtDesc = new JTextPane();
txtDesc.setFont(FontHandler.notoFont());
new FlatLafStyleBuilder(FontHandler.notoFont()).apply(txtDesc);
txtDesc.setEditable(false);
txtDesc.setContentType("text/html");
txtDesc.setText(getStoryPoint().text());
Expand All @@ -59,7 +61,7 @@ protected Container getMainPanel() {
JScrollPane scrollPane = new JScrollPane(txtDesc) {
@Override
public Dimension getPreferredSize() {
return new Dimension(400, super.getPreferredSize().height);
return new Dimension(UIUtil.scaleForGUI(400), super.getPreferredSize().height);
}
};
scrollPane.setBorder(null);
Expand Down
Loading

0 comments on commit dbc041b

Please sign in to comment.