From e378770578030bee05388a749c51dc3fc5777afd Mon Sep 17 00:00:00 2001 From: Sam Pottinger Date: Thu, 20 Aug 2020 12:08:38 -0700 Subject: [PATCH] Started migrating to zoomed fonts. --- .../app/platform/DefaultPlatform.java | 60 +++++++++++++++++++ app/src/processing/app/tools/CreateFont.java | 21 +++++-- java/src/processing/mode/java/JavaEditor.java | 7 ++- 3 files changed, 81 insertions(+), 7 deletions(-) diff --git a/app/src/processing/app/platform/DefaultPlatform.java b/app/src/processing/app/platform/DefaultPlatform.java index 630080e2c..934ed293e 100644 --- a/app/src/processing/app/platform/DefaultPlatform.java +++ b/app/src/processing/app/platform/DefaultPlatform.java @@ -26,9 +26,12 @@ package processing.app.platform; import java.awt.Color; import java.awt.Component; import java.awt.Desktop; +import java.awt.Font; import java.awt.Graphics; import java.io.File; import java.net.URI; +import java.util.ArrayList; +import java.util.List; import javax.swing.Icon; import javax.swing.UIManager; @@ -38,6 +41,7 @@ import com.sun.jna.Native; import processing.app.Base; import processing.app.Preferences; +import processing.app.ui.Toolkit; /** @@ -56,6 +60,38 @@ import processing.app.Preferences; * know if name is proper Java package syntax.) */ public class DefaultPlatform { + + private final List FONT_SCALING_WIDGETS =new ArrayList(){{ + add("Button"); + add("CheckBox"); + add("CheckBoxMenuItem"); + add("ComboBox"); + add("Label"); + add("List"); + add("Menu"); + add("MenuBar"); + add("MenuItem"); + add("OptionPane"); + add("Panel"); + add("PopupMenu"); + add("ProgressBar"); + add("RadioButton"); + add("RadioButtonMenuItem"); + add("ScrollPane"); + add("TabbedPane"); + add("Table"); + add("TableHeader"); + add("TextArea"); + add("TextField"); + add("TextPane"); + add("TitledBorder"); + add("ToggleButton"); + add("ToolBar"); + add("ToolTip"); + add("Tree"); + add("Viewport"); + }}; + Base base; private final float ZOOM_DEFAULT_SIZING = 1; @@ -97,6 +133,13 @@ public class DefaultPlatform { } else { UIManager.setLookAndFeel(laf); } + + // Specify font when scaling is active. + if (!Preferences.getBoolean("editor.zoom.auto")) { + for (String widgetName : FONT_SCALING_WIDGETS) { + scaleDefaultFont(widgetName); + } + } } @@ -237,6 +280,23 @@ public class DefaultPlatform { public void paintIcon(Component c, Graphics g, int x, int y) {} } + /** + * Set the default font for the widget by the given name. + * + * @param name The name of the widget whose font will be set to a scaled version of its current + * default font in the selected look and feel. This must match the system widget name like + * "Button" or "CheckBox" + */ + private void scaleDefaultFont(String name) { + String fontPropertyName = name + ".font"; + + Font currentFont = (Font) UIManager.get(fontPropertyName); + int newSize = Toolkit.zoom(currentFont.getSize()); + Font newFont = currentFont.deriveFont(newSize); + + UIManager.put(fontPropertyName, newFont); + } + /** * Replacement tree icon for mac when using Vaqua. * diff --git a/app/src/processing/app/tools/CreateFont.java b/app/src/processing/app/tools/CreateFont.java index aff82e191..7c207df01 100644 --- a/app/src/processing/app/tools/CreateFont.java +++ b/app/src/processing/app/tools/CreateFont.java @@ -101,7 +101,7 @@ public class CreateFont extends JFrame implements Tool { textarea.setBackground(null); textarea.setEditable(false); textarea.setHighlighter(null); - textarea.setFont(new Font("Dialog", Font.PLAIN, 12)); + textarea.setFont(new Font("Dialog", Font.PLAIN, Toolkit.zoom(12))); pain.add(textarea); // don't care about families starting with . or # @@ -174,6 +174,8 @@ public class CreateFont extends JFrame implements Tool { System.arraycopy(fontList, 0, list, 0, index); fontSelector = new JList(list); + fontSelector.setFont(new Font("Dialog", Font.PLAIN, Toolkit.zoom(12))); + fontSelector.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { @@ -194,9 +196,11 @@ public class CreateFont extends JFrame implements Tool { sample = new SampleComponent(this); + Font dialogBottomFont = new Font("Dialog", Font.PLAIN, Toolkit.zoom(12)); + // Seems that in some instances, no default font is set // http://dev.processing.org/bugs/show_bug.cgi?id=777 - sample.setFont(new Font("Dialog", Font.PLAIN, 12)); + sample.setFont(dialogBottomFont); pain.add(sample); @@ -204,8 +208,13 @@ public class CreateFont extends JFrame implements Tool { pain.add(new Box.Filler(d2, d2, d2)); JPanel panel = new JPanel(); - panel.add(new JLabel(Language.text("create_font.size") + ":" )); + + JLabel sizeLabel = new JLabel(Language.text("create_font.size") + ":" ); + sizeLabel.setFont(dialogBottomFont); + panel.add(sizeLabel); + sizeSelector = new JTextField(" 48 "); + sizeSelector.setFont(dialogBottomFont); sizeSelector.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { update(); } public void removeUpdate(DocumentEvent e) { update(); } @@ -214,6 +223,7 @@ public class CreateFont extends JFrame implements Tool { panel.add(sizeSelector); smoothBox = new JCheckBox(Language.text("create_font.smooth")); + smoothBox.setFont(dialogBottomFont); smoothBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { smooth = smoothBox.isSelected(); @@ -232,6 +242,7 @@ public class CreateFont extends JFrame implements Tool { // allBox.setSelected(all); // panel.add(allBox); charsetButton = new JButton(Language.text("create_font.characters")); + charsetButton.setFont(dialogBottomFont); charsetButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //showCharacterList(); @@ -282,7 +293,7 @@ public class CreateFont extends JFrame implements Tool { //System.out.println(getPreferredSize()); // do this after pack so it doesn't affect layout - sample.setFont(new Font(list[0], Font.PLAIN, 48)); + sample.setFont(new Font(list[0], Font.PLAIN, Toolkit.zoom(48))); fontSelector.setSelectedIndex(0); @@ -512,7 +523,7 @@ class CharacterSelector extends JFrame { textarea.setBackground(null); textarea.setEditable(false); textarea.setHighlighter(null); - textarea.setFont(new Font("Dialog", Font.PLAIN, 12)); + textarea.setFont(new Font("Dialog", Font.PLAIN, Toolkit.zoom(12))); pain.add(textarea); ActionListener listener = new ActionListener() { diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index d77fc8ae9..ea111a617 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -1750,8 +1750,11 @@ public class JavaEditor extends Editor { + " changes in your sketch.
" + "    Do you want to save it before" + " running? "); - label.setFont(new Font(label.getFont().getName(), - Font.PLAIN, label.getFont().getSize() + 1)); + label.setFont(new Font( + label.getFont().getName(), + Font.PLAIN, + Toolkit.zoom(label.getFont().getSize() + 1) + )); panelLabel.add(label); panelMain.add(panelLabel); final JCheckBox dontRedisplay = new JCheckBox("Remember this decision");