mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
trying out flatlaf, set ui font to source sans, language selector fixes
This commit is contained in:
+32
-3
@@ -100,8 +100,34 @@
|
||||
|
||||
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
|
||||
|
||||
<property name="flatlaf.version" value="2.2" />
|
||||
|
||||
<fileset id="flatlaf.files" dir="lib">
|
||||
<include name="flatlaf.jar" />
|
||||
</fileset>
|
||||
|
||||
<!-- TODO implement a fallback URL that points to a location
|
||||
on download.processing.org so it's available forever. -->
|
||||
<property name="flatlaf.url"
|
||||
value="https://repo1.maven.org/maven2/com/formdev/flatlaf/${flatlaf.version}/flatlaf-${flatlaf.version}.jar" />
|
||||
|
||||
<available file="lib/flatlaf.jar" property="flatlaf.present" />
|
||||
|
||||
<!-- ok to ignore failed downloads if we at least have a version that's local -->
|
||||
<condition property="flatlaf.ignorable" value="false" else="true">
|
||||
<isset property="flatlaf.present" />
|
||||
</condition>
|
||||
|
||||
<target name="download-flatlaf" unless="flatlaf.present">
|
||||
<get src="${flatlaf.url}" dest="lib/flatlaf.jar"
|
||||
ignoreerrors="${flatlaf.ignorable}"
|
||||
usetimestamp="true" />
|
||||
</target>
|
||||
|
||||
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
|
||||
|
||||
<target name="compile" description="Compile sources"
|
||||
depends="download-ant, download-jna">
|
||||
depends="download-ant, download-jna, download-flatlaf">
|
||||
<condition property="core-built">
|
||||
<available file="../core/library/core.jar" />
|
||||
</condition>
|
||||
@@ -133,6 +159,7 @@
|
||||
../core/apple.jar;
|
||||
lib/ant.jar;
|
||||
lib/ant-launcher.jar;
|
||||
lib/flatlaf.jar;
|
||||
lib/jna.jar;
|
||||
lib/jna-platform.jar"
|
||||
debug="on"
|
||||
@@ -146,13 +173,15 @@
|
||||
<jar basedir="bin" destfile="pde.jar" />
|
||||
</target>
|
||||
|
||||
<target name="update" description="Update the downloaded libraries">
|
||||
<target name="update" description="Update the downloaded libraries">
|
||||
<delete>
|
||||
<fileset refid="jna.files" />
|
||||
<fileset refid="ant.files" />
|
||||
<fileset refid="flatlaf.files" />
|
||||
<fileset refid="jna.files" />
|
||||
</delete>
|
||||
|
||||
<antcall target="download-ant" />
|
||||
<antcall target="download-flatlaf" />
|
||||
<antcall target="download-jna" />
|
||||
</target>
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
ant.jar
|
||||
ant-launcher.jar
|
||||
|
||||
flatlaf.jar
|
||||
|
||||
jna.jar
|
||||
jna-platform.jar
|
||||
|
||||
VAqua*.jar
|
||||
@@ -55,5 +55,14 @@
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module" module-name="processing4-core" />
|
||||
<orderEntry type="module-library">
|
||||
<library name="flatlaf">
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/lib/flatlaf.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
@@ -209,7 +209,7 @@ class StatusPanel extends JPanel {
|
||||
return "body { " +
|
||||
" margin: 0; " +
|
||||
" padding: 0;" +
|
||||
" font-family: " + Toolkit.getSansFontName() + ", Helvetica, Arial, sans-serif;" +
|
||||
" font-family: " + Toolkit.getSansFont().getName() + ", Helvetica, Arial, sans-serif;" +
|
||||
" font-size: 11px;" +
|
||||
"}" +
|
||||
"a { color: #444; text-decoration: none; }";
|
||||
|
||||
@@ -27,10 +27,10 @@ import java.awt.Desktop;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import javax.swing.text.StyleContext;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
@@ -110,16 +110,34 @@ public class DefaultPlatform {
|
||||
public void setLookAndFeel() throws Exception {
|
||||
String laf = Preferences.get("editor.laf");
|
||||
if (laf == null || laf.length() == 0) { // normal situation
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
|
||||
// dummy font call so that it's registered for the LaF
|
||||
Toolkit.getSansFont(12, Font.PLAIN);
|
||||
|
||||
com.formdev.flatlaf.FlatLaf.registerCustomDefaultsSource("processing.app.ui");
|
||||
UIManager.setLookAndFeel(new com.formdev.flatlaf.FlatLightLaf());
|
||||
|
||||
} else {
|
||||
UIManager.setLookAndFeel(laf);
|
||||
}
|
||||
|
||||
/*
|
||||
UIDefaults defaults = UIManager.getDefaults();
|
||||
for (Map.Entry<Object, Object> entry : defaults.entrySet()) {
|
||||
System.out.println(entry.getKey() + " = " + entry.getValue());
|
||||
}
|
||||
*/
|
||||
|
||||
// If the default has been overridden in the preferences, set the font
|
||||
String fontName = Preferences.get("ui.font.family");
|
||||
int fontSize = Preferences.getInteger("ui.font.size");
|
||||
// fontName = "Processing Sans Pro";
|
||||
if (!"Dialog".equals(fontName) || fontSize != 12) {
|
||||
setUIFont(new FontUIResource(fontName, Font.PLAIN, fontSize));
|
||||
// setUIFont(new FontUIResource(createFallingFont(fontName, Font.PLAIN, fontSize)));
|
||||
// setUIFont((FontUIResource) StyleContext.getDefaultStyleContext().getFont(fontName, Font.PLAIN, fontSize));
|
||||
|
||||
// Map<TextAttribute, Object> attributes = new HashMap<>();
|
||||
// attributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
|
||||
// Font font = new Font(fontName, Font.PLAIN, fontSize).deriveFont(attributes);
|
||||
@@ -129,9 +147,19 @@ public class DefaultPlatform {
|
||||
// Default was 8x8, but that's not enough with the insets and rounded rect
|
||||
// https://github.com/processing/processing4/issues/473
|
||||
//System.out.println(UIManager.get("ScrollBar.minimumThumbSize"));
|
||||
UIManager.put("ScrollBar.minimumThumbSize", new Dimension(8, 24));
|
||||
UIManager.put("ScrollBar.minimumThumbSize", new Dimension(16, 24));
|
||||
}
|
||||
|
||||
// // Adapted from https://stackoverflow.com/a/64667581/18247494
|
||||
// static Font createFallingFont(final String family, final int style, final int size) {
|
||||
// return new NonUIResourceFont(StyleContext.getDefaultStyleContext().getFont(family, style, size));
|
||||
// }
|
||||
//
|
||||
// static class NonUIResourceFont extends Font {
|
||||
// public NonUIResourceFont(final Font font) {
|
||||
// super(font);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Rewritten from https://stackoverflow.com/a/7434935
|
||||
static private void setUIFont(FontUIResource f) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
defaultFont = 14 "Processing Sans Pro", "Open Sans", "Noto Sans", Roboto, Arial
|
||||
@@ -134,12 +134,13 @@ public class PreferencesFrame {
|
||||
languageSelection[0] = languages.get(Language.getLanguage());
|
||||
int i = 1;
|
||||
for (Map.Entry<String, String> lang : languages.entrySet()) {
|
||||
if(!lang.getKey().equals(Language.getLanguage())){
|
||||
if (!lang.getKey().equals(Language.getLanguage())){
|
||||
languageSelection[i++] = lang.getValue();
|
||||
}
|
||||
}
|
||||
languageSelectionBox.setModel(new DefaultComboBoxModel<>(languageSelection));
|
||||
languageRestartLabel = new JLabel(" (" + Language.text("preferences.requires_restart") + ")");
|
||||
languageSelectionBox.setRenderer(new LanguageRenderer());
|
||||
|
||||
|
||||
// Editor and console font [ Source Code Pro ]
|
||||
@@ -548,6 +549,27 @@ public class PreferencesFrame {
|
||||
}
|
||||
|
||||
|
||||
class LanguageRenderer extends JLabel implements ListCellRenderer<String> {
|
||||
final int fontSize = languageSelectionBox.getFont().getSize();
|
||||
final Font sansFont = Toolkit.getSansFont(fontSize, Font.PLAIN);
|
||||
final Font fallbackFont = new Font("Dialog", Font.PLAIN,fontSize);
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<? extends String> list, String text, int index,
|
||||
boolean isSelected, boolean cellHasFocus) {
|
||||
if (sansFont.canDisplayUpTo(text) == -1) {
|
||||
// if the sans font can display the chars, use it
|
||||
setFont(sansFont);
|
||||
} else {
|
||||
// otherwise, use the fallback font (Dialog)
|
||||
setFont(fallbackFont);
|
||||
}
|
||||
setText(text);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Callback for the folder selector. */
|
||||
public void sketchbookCallback(File file) {
|
||||
if (file != null) { // null if cancel or closed
|
||||
|
||||
@@ -1147,6 +1147,7 @@ public class Toolkit {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
static public String getSansFontName() {
|
||||
if (sansFont == null) {
|
||||
// create a dummy version if the font has never been loaded (rare)
|
||||
@@ -1154,6 +1155,12 @@ public class Toolkit {
|
||||
}
|
||||
return sansFont.getName();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static public Font getSansFont() {
|
||||
return getSansFont(0, Font.PLAIN);
|
||||
}
|
||||
|
||||
|
||||
static public Font getSansFont(int size, int style) {
|
||||
@@ -1180,13 +1187,13 @@ public class Toolkit {
|
||||
}
|
||||
}
|
||||
if (style == Font.BOLD) {
|
||||
if (size == sansBoldFont.getSize()) {
|
||||
if (size == sansBoldFont.getSize() || size == 0) {
|
||||
return sansBoldFont;
|
||||
} else {
|
||||
return sansBoldFont.deriveFont((float) size);
|
||||
}
|
||||
} else {
|
||||
if (size == sansFont.getSize()) {
|
||||
if (size == sansFont.getSize() || size == 0) {
|
||||
return sansFont;
|
||||
} else {
|
||||
return sansFont.deriveFont((float) size);
|
||||
|
||||
@@ -182,6 +182,7 @@
|
||||
<include name="app/lib/jna-platform.jar" />
|
||||
<include name="app/lib/ant.jar" />
|
||||
<include name="app/lib/ant-launcher.jar" />
|
||||
<include name="app/lib/flatlaf.jar" />
|
||||
</fileset>
|
||||
|
||||
<target name="build" description="Build Processing.">
|
||||
@@ -525,6 +526,7 @@
|
||||
<classpath file="../app/lib/jna-platform.jar" />
|
||||
<classpath file="../app/lib/ant.jar" />
|
||||
<classpath file="../app/lib/ant-launcher.jar" />
|
||||
<classpath file="../app/lib/flatlaf.jar" />
|
||||
|
||||
|
||||
<!-- Creates a copy of core.jar, but that's simplest for now. For 4.0a5
|
||||
|
||||
@@ -14,7 +14,12 @@ X add updateTheme() to contrib.ListPanel
|
||||
X right now pulling Theme.getColor() directly
|
||||
X but need to make sure repaint() is called anyway
|
||||
X use errors.row.bgcolor as bgcolor for the error list
|
||||
X change errors.row to errors.list in theme.txt
|
||||
o change errors.row to errors.list in theme.txt
|
||||
X add errors.bgcolor instead
|
||||
X look and feel plus fonts
|
||||
X trying out https://www.formdev.com/flatlaf/ to clean things up
|
||||
X using Source Sans Pro as interface font
|
||||
X rewrite language selector to use fallback fonts
|
||||
|
||||
contrib
|
||||
X Double-clicking a .pde file also opens an untitled/empty sketch
|
||||
|
||||
Reference in New Issue
Block a user