From f53302cb18f732218ba2094d32263212903ab878 Mon Sep 17 00:00:00 2001 From: Zukero Date: Thu, 24 Aug 2017 18:37:30 +0200 Subject: [PATCH] Font scaling is now also scaling icons, and works in most of the UI. --- packaging/Linux/ATCS/ATCS.cmd | 2 +- packaging/Linux/ATCS/ATCS.sh | 2 +- packaging/Windows/ATCS.cmd | 2 +- .../rpg/atcontentstudio/ATContentStudio.java | 57 ++++++++++--------- .../model/sprites/Spritesheet.java | 3 +- .../rpg/atcontentstudio/ui/DefaultIcons.java | 3 +- .../atcontentstudio/ui/NotificationsPane.java | 3 +- .../rpg/atcontentstudio/ui/StudioFrame.java | 2 +- .../rpg/atcontentstudio/ui/WorkerDialog.java | 5 +- .../ui/gamedataeditors/JSONElementEditor.java | 1 + .../atcontentstudio/ui/map/TMXMapEditor.java | 1 + .../ui/map/WorldMapEditor.java | 1 + 12 files changed, 46 insertions(+), 36 deletions(-) diff --git a/packaging/Linux/ATCS/ATCS.cmd b/packaging/Linux/ATCS/ATCS.cmd index 1bfb88d..8506aed 100644 --- a/packaging/Linux/ATCS/ATCS.cmd +++ b/packaging/Linux/ATCS/ATCS.cmd @@ -4,7 +4,7 @@ set "ATCS_DIR=%~dp0" set "MAX_MEM=512M" set "CP=%ATCS_DIR%lib\*" set "JAVA=javaw.exe" -set "JAVA_OPTS=-DFONT_SCALE=1.0" +set "JAVA_OPTS=-DFONT_SCALE=1.0 -Dswing.aatext=true" set "ENV_FILE=%ATCS_DIR%ATCS.env.bat" set "MAIN_CLASS=com.gpl.rpg.atcontentstudio.ATContentStudio" diff --git a/packaging/Linux/ATCS/ATCS.sh b/packaging/Linux/ATCS/ATCS.sh index 3e158b1..16f4398 100644 --- a/packaging/Linux/ATCS/ATCS.sh +++ b/packaging/Linux/ATCS/ATCS.sh @@ -3,7 +3,7 @@ ATCS_DIR=$(dirname $(readlink -f "$0" || greadlink -f "$0" || stat -f "$0")) MAX_MEM=512M CP=$(find ${ATCS_DIR}/lib/ -name '*.jar' | paste -sd: -) JAVA=java -JAVA_OPTS=-DFONT_SCALE=1.0 +JAVA_OPTS='-DFONT_SCALE=1.0 -Dswing.aatext=true' ENV_FILE=${ATCS_DIR}/ATCS.env MAIN_CLASS=com.gpl.rpg.atcontentstudio.ATContentStudio diff --git a/packaging/Windows/ATCS.cmd b/packaging/Windows/ATCS.cmd index 1bfb88d..8506aed 100644 --- a/packaging/Windows/ATCS.cmd +++ b/packaging/Windows/ATCS.cmd @@ -4,7 +4,7 @@ set "ATCS_DIR=%~dp0" set "MAX_MEM=512M" set "CP=%ATCS_DIR%lib\*" set "JAVA=javaw.exe" -set "JAVA_OPTS=-DFONT_SCALE=1.0" +set "JAVA_OPTS=-DFONT_SCALE=1.0 -Dswing.aatext=true" set "ENV_FILE=%ATCS_DIR%ATCS.env.bat" set "MAIN_CLASS=com.gpl.rpg.atcontentstudio.ATContentStudio" diff --git a/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java b/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java index 3d7f868..e790b27 100644 --- a/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java +++ b/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java @@ -51,6 +51,7 @@ public class ATContentStudio { public static final String FONT_SCALE_ENV_VAR_NAME = "FONT_SCALE"; public static boolean STARTED = false; + public static float SCALING=1.0f; public static StudioFrame frame = null; //Need to keep a strong reference to it, to avoid garbage collection that'll reset these loggers. @@ -60,6 +61,17 @@ public class ATContentStudio { * @param args */ public static void main(String[] args) { + String fontScaling = System.getProperty(FONT_SCALE_ENV_VAR_NAME); + Float fontScale = null; + if (fontScaling != null) { + try { + fontScale = Float.parseFloat(fontScaling); + SCALING=fontScale; + } catch (NumberFormatException e) { + System.err.println("Failed to parse font scaling parameter. Using default."); + e.printStackTrace(); + } + } ConfigCache.init(); @@ -77,6 +89,7 @@ public class ATContentStudio { e.printStackTrace(); } + scaleUIFont(); //Need to keep a strong reference to it, to avoid garbage collection that'll reset this setting. @@ -189,35 +202,25 @@ public class ATContentStudio { } public static void scaleUIFont() { - String fontScaling = System.getProperty(FONT_SCALE_ENV_VAR_NAME); - Float fontScale = null; - if (fontScaling != null) { - try { - fontScale = Float.parseFloat(fontScaling); - } catch (NumberFormatException e) { - System.err.println("Failed to parse font scaling parameter. Using default."); - e.printStackTrace(); - } - if (fontScale != null) { - System.out.println("Scaling fonts to "+fontScale); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - Map newDefaults = new HashMap(); - for (Enumeration e = defaults.keys(); e.hasMoreElements();) { - Object key = e.nextElement(); - Object value = defaults.get(key); - if (value instanceof Font) { - Font font = (Font) value; - int newSize = (int)(font.getSize() * fontScale); - if (value instanceof FontUIResource) { - newDefaults.put(key, new FontUIResource(font.getName(), font.getStyle(), newSize)); - } else { - newDefaults.put(key, new Font(font.getName(), font.getStyle(), newSize)); - } + if (SCALING != 1.0f) { + System.out.println("Scaling fonts to "+SCALING); + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + Map newDefaults = new HashMap(); + for (Enumeration e = defaults.keys(); e.hasMoreElements();) { + Object key = e.nextElement(); + Object value = defaults.get(key); + if (value instanceof Font) { + Font font = (Font) value; + int newSize = (int)(font.getSize() * SCALING); + if (value instanceof FontUIResource) { + newDefaults.put(key, new FontUIResource(font.getName(), font.getStyle(), newSize)); + } else { + newDefaults.put(key, new Font(font.getName(), font.getStyle(), newSize)); } } - for (Object key : newDefaults.keySet()) { - defaults.put(key, newDefaults.get(key)); - } + } + for (Object key : newDefaults.keySet()) { + defaults.put(key, newDefaults.get(key)); } } } diff --git a/src/com/gpl/rpg/atcontentstudio/model/sprites/Spritesheet.java b/src/com/gpl/rpg/atcontentstudio/model/sprites/Spritesheet.java index 60e3177..4ddb231 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/sprites/Spritesheet.java +++ b/src/com/gpl/rpg/atcontentstudio/model/sprites/Spritesheet.java @@ -14,6 +14,7 @@ import java.util.Map; import javax.imageio.ImageIO; import javax.swing.tree.TreeNode; +import com.gpl.rpg.atcontentstudio.ATContentStudio; import com.gpl.rpg.atcontentstudio.Notification; import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.GameSource.Type; @@ -174,7 +175,7 @@ public class Spritesheet extends GameDataElement { } Image result = getImage(index); if (result == null) return null; - result = result.getScaledInstance(16, 16, BufferedImage.SCALE_SMOOTH); + result = result.getScaledInstance((int)(16*ATContentStudio.SCALING), (int)(16*ATContentStudio.SCALING), Image.SCALE_SMOOTH); cache_icon.put(index, result); return result; } diff --git a/src/com/gpl/rpg/atcontentstudio/ui/DefaultIcons.java b/src/com/gpl/rpg/atcontentstudio/ui/DefaultIcons.java index bbe9d40..cec0dbe 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/DefaultIcons.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/DefaultIcons.java @@ -7,6 +7,7 @@ import java.util.Map; import javax.imageio.ImageIO; +import com.gpl.rpg.atcontentstudio.ATContentStudio; import com.gpl.rpg.atcontentstudio.Notification; public class DefaultIcons { @@ -287,7 +288,7 @@ public class DefaultIcons { private static Image getIcon(String res) { if (iconCache.get(res) == null) { - Image icon = getImage(res).getScaledInstance(16, 16, Image.SCALE_SMOOTH); + Image icon = getImage(res).getScaledInstance((int)(16*ATContentStudio.SCALING), (int)(16*ATContentStudio.SCALING), Image.SCALE_SMOOTH); iconCache.put(res, icon); } return iconCache.get(res); diff --git a/src/com/gpl/rpg/atcontentstudio/ui/NotificationsPane.java b/src/com/gpl/rpg/atcontentstudio/ui/NotificationsPane.java index 49766e5..80436a5 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/NotificationsPane.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/NotificationsPane.java @@ -18,6 +18,7 @@ import javax.swing.ListModel; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; +import com.gpl.rpg.atcontentstudio.ATContentStudio; import com.gpl.rpg.atcontentstudio.Notification; import com.gpl.rpg.atcontentstudio.NotificationListener; @@ -54,7 +55,7 @@ public class NotificationsPane extends JList { label.setBorder(BorderFactory.createLineBorder(Color.BLUE)); // label.setForeground(Color.WHITE); } - f = f.deriveFont(10f); + f = f.deriveFont(10f*ATContentStudio.SCALING); label.setFont(f); return label; } diff --git a/src/com/gpl/rpg/atcontentstudio/ui/StudioFrame.java b/src/com/gpl/rpg/atcontentstudio/ui/StudioFrame.java index f194085..2af28da 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/StudioFrame.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/StudioFrame.java @@ -40,7 +40,7 @@ public class StudioFrame extends JFrame { private static final long serialVersionUID = -3391514100319186661L; - + final ProjectsTree projectTree; final EditorsArea editors; diff --git a/src/com/gpl/rpg/atcontentstudio/ui/WorkerDialog.java b/src/com/gpl/rpg/atcontentstudio/ui/WorkerDialog.java index 94f79ef..d4725f1 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/WorkerDialog.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/WorkerDialog.java @@ -9,6 +9,7 @@ import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; +import com.gpl.rpg.atcontentstudio.ATContentStudio; import com.jidesoft.swing.JideBoxLayout; @@ -19,7 +20,7 @@ private static final long serialVersionUID = 8239669104275145995L; super(parent, "Loading..."); this.setIconImage(DefaultIcons.getMainIconImage()); this.getContentPane().setLayout(new JideBoxLayout(this.getContentPane(), JideBoxLayout.PAGE_AXIS, 6)); - this.getContentPane().add(new JLabel("Please wait.
"+message+"
"), JideBoxLayout.VARY); + this.getContentPane().add(new JLabel("Please wait.
"+message+"
"), JideBoxLayout.VARY); JMovingIdler idler = new JMovingIdler(); idler.setBackground(Color.WHITE); idler.setForeground(Color.GREEN); @@ -46,7 +47,7 @@ private static final long serialVersionUID = 8239669104275145995L; info.setVisible(true); workload.run(); info.dispose(); - if (showConfirm) JOptionPane.showMessageDialog(parent, "Done !"); + if (showConfirm) JOptionPane.showMessageDialog(parent, "Done !"); }; }.start(); } diff --git a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/JSONElementEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/JSONElementEditor.java index 45b0e34..48f4316 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/JSONElementEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/gamedataeditors/JSONElementEditor.java @@ -95,6 +95,7 @@ public abstract class JSONElementEditor extends Editor { jsonEditorPane.setText(((JSONElement)target).toJsonString()); jsonEditorPane.setEditable(((JSONElement)target).writable); jsonEditorPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON); + jsonEditorPane.setFont(jsonEditorPane.getFont().deriveFont(ATContentStudio.SCALING * jsonEditorPane.getFont().getSize())); JPanel result = new JPanel(); result.setLayout(new BorderLayout()); result.add(jsonEditorPane, BorderLayout.CENTER); diff --git a/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java index 4b2666b..0ebf936 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/map/TMXMapEditor.java @@ -765,6 +765,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe editorPane.setText(((TMXMap)target).toXml()); editorPane.setEditable(false); editorPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML); + editorPane.setFont(editorPane.getFont().deriveFont(ATContentStudio.SCALING * editorPane.getFont().getSize())); pane.add(editorPane, JideBoxLayout.VARY); return pane; diff --git a/src/com/gpl/rpg/atcontentstudio/ui/map/WorldMapEditor.java b/src/com/gpl/rpg/atcontentstudio/ui/map/WorldMapEditor.java index 4a3b91e..3b60527 100644 --- a/src/com/gpl/rpg/atcontentstudio/ui/map/WorldMapEditor.java +++ b/src/com/gpl/rpg/atcontentstudio/ui/map/WorldMapEditor.java @@ -130,6 +130,7 @@ public class WorldMapEditor extends Editor implements FieldUpdateListener { editorPane.setText(((WorldmapSegment)target).toXml()); editorPane.setEditable(false); editorPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML); + editorPane.setFont(editorPane.getFont().deriveFont(ATContentStudio.SCALING * editorPane.getFont().getSize())); pane.add(editorPane, JideBoxLayout.VARY); return pane;