Skip to content

Commit 044f1ba

Browse files
committed
clean up Platform, add workaround for getSystemZoom() (fixes #143)
1 parent 4153e4f commit 044f1ba

File tree

10 files changed

+140
-115
lines changed

10 files changed

+140
-115
lines changed

app/src/processing/app/Base.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ static private void createAndShowGUI(String[] args) {
195195
// Set the look and feel before opening the window
196196
try {
197197
Platform.setLookAndFeel();
198+
Platform.setInterfaceZoom();
198199
} catch (Exception e) {
199-
Messages.loge("Could not set the Look & Feel", e); //$NON-NLS-1$
200+
Messages.loge("Error while setting up the interface", e); //$NON-NLS-1$
200201
}
201202

202203
boolean sketchbookPrompt = false;

app/src/processing/app/BaseSplash.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static public void main(String[] args) {
1515
SplashWindow.splash(splashFile.toURI().toURL(), hidpi);
1616
SplashWindow.invokeMain("processing.app.Base", args);
1717
SplashWindow.disposeSplash();
18+
1819
} catch (Exception e) {
1920
e.printStackTrace();
2021
// !@#!@$$! umm

app/src/processing/app/Platform.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2012-15 The Processing Foundation
6+
Copyright (c) 2012-20 The Processing Foundation
77
Copyright (c) 2008-12 Ben Fry and Casey Reas
88
99
This program is free software; you can redistribute it and/or modify
@@ -75,7 +75,8 @@ public class Platform {
7575

7676
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7777

78-
static public boolean isInit() {
78+
79+
static public boolean isAvailable() {
7980
return inst != null;
8081
}
8182

@@ -109,6 +110,16 @@ static public void setLookAndFeel() throws Exception {
109110
}
110111

111112

113+
static public void setInterfaceZoom() throws Exception {
114+
inst.setInterfaceZoom();
115+
}
116+
117+
118+
static public float getSystemZoom() {
119+
return inst == null ? 1 : inst.getSystemZoom();
120+
}
121+
122+
112123
static public File getSettingsFolder() throws Exception {
113124
return inst.getSettingsFolder();
114125
}
@@ -405,12 +416,4 @@ static public String getenv(String variable) {
405416
static public int unsetenv(String variable) {
406417
return inst.unsetenv(variable);
407418
}
408-
409-
410-
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
411-
412-
static public float getSystemZoom() {
413-
return inst.getSystemZoom();
414-
}
415-
416419
}

app/src/processing/app/platform/DefaultPlatform.java

Lines changed: 8 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,17 @@
2323

2424
package processing.app.platform;
2525

26-
import java.awt.Color;
27-
import java.awt.Component;
2826
import java.awt.Desktop;
2927
import java.awt.Font;
30-
import java.awt.Graphics;
3128
import java.io.File;
3229
import java.net.URI;
3330

34-
import javax.swing.Icon;
3531
import javax.swing.UIManager;
3632

3733
import com.sun.jna.Library;
3834
import com.sun.jna.Native;
3935

4036
import processing.app.Base;
41-
import processing.app.Platform;
4237
import processing.app.Preferences;
4338
import processing.app.ui.Toolkit;
4439

@@ -91,7 +86,6 @@ public class DefaultPlatform {
9186

9287
Base base;
9388

94-
private final float ZOOM_DEFAULT_SIZING = 1;
9589

9690
public void initBase(Base base) {
9791
this.base = base;
@@ -112,24 +106,14 @@ public void initBase(Base base) {
112106
public void setLookAndFeel() throws Exception {
113107
String laf = Preferences.get("editor.laf");
114108
if (laf == null || laf.length() == 0) { // normal situation
115-
if (Platform.isMacOS() && Preferences.getBoolean("editor.laf.vaqua")) {
116-
UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
117-
118-
Icon collapse = new MacTreeIcon(true);
119-
Icon open = new MacTreeIcon(false);
120-
Icon leaf = new MacEmptyIcon();
121-
UIManager.put("Tree.closedIcon", leaf);
122-
UIManager.put("Tree.openIcon", leaf);
123-
UIManager.put("Tree.collapsedIcon", open);
124-
UIManager.put("Tree.expandedIcon", collapse);
125-
UIManager.put("Tree.leafIcon", leaf);
126-
} else {
127-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
128-
}
109+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
129110
} else {
130111
UIManager.setLookAndFeel(laf);
131112
}
113+
}
132114

115+
116+
public void setInterfaceZoom() throws Exception {
133117
// Specify font when scaling is active.
134118
if (!Preferences.getBoolean("editor.zoom.auto")) {
135119
for (String widgetName : FONT_SCALING_WIDGETS) {
@@ -245,39 +229,10 @@ public int unsetenv(String variable) {
245229
* 125% (25% additional zoom).
246230
*/
247231
public float getSystemZoom() {
248-
return ZOOM_DEFAULT_SIZING;
232+
return 1;
249233
}
250234

251-
/**
252-
* Spacer icon for mac when using Vaqua.
253-
*
254-
* <p>
255-
* Due to potential rendering issues, this small spacer is used to ensure that rendering is stable
256-
* while using Vaqua with non-standard swing components. Without this, some sizing calculations
257-
* non-standard components may fail or become unreliable.
258-
* </p>
259-
*/
260-
class MacEmptyIcon implements Icon {
261-
private final int SIZE = 1;
262-
263-
/**
264-
* Create a new single pixel spacer icon.
265-
*/
266-
public MacEmptyIcon() {}
267-
268-
@Override
269-
public int getIconWidth() {
270-
return SIZE;
271-
}
272-
273-
@Override
274-
public int getIconHeight() {
275-
return SIZE;
276-
}
277235

278-
@Override
279-
public void paintIcon(Component c, Graphics g, int x, int y) {}
280-
}
281236

282237
/**
283238
* Set the default font for the widget by the given name.
@@ -290,58 +245,12 @@ private void scaleDefaultFont(String name) {
290245
String fontPropertyName = name + ".font";
291246

292247
Font currentFont = (Font) UIManager.get(fontPropertyName);
293-
System.out.println(currentFont);
248+
// System.out.println(currentFont);
294249
float newSize = Toolkit.zoom(currentFont.getSize());
295-
System.out.println(newSize);
250+
// System.out.println(newSize);
296251
Font newFont = currentFont.deriveFont(newSize);
297-
System.out.println(newFont);
252+
// System.out.println(newFont);
298253

299254
UIManager.put(fontPropertyName, newFont);
300255
}
301-
302-
/**
303-
* Replacement tree icon for mac when using Vaqua.
304-
*
305-
* <p>
306-
* Due to potential rendering issues with the regular tree icon set, this replacement tree icon
307-
* for mac ensures stable rendering when using Vaqua with non-standard swing components. Without
308-
* this, some sizing calculations within non-standard components may fail or become unreliable.
309-
* </p>
310-
*/
311-
private class MacTreeIcon implements Icon {
312-
private final int SIZE = 12;
313-
private final boolean isOpen;
314-
315-
/**
316-
* Create a new tree icon.
317-
*
318-
* @param newIsOpen Flag indicating if the icon should be in the open or closed state at
319-
* construction. True if open false otherwise.
320-
*/
321-
public MacTreeIcon(boolean newIsOpen) {
322-
isOpen = newIsOpen;
323-
}
324-
325-
@Override
326-
public int getIconWidth() {
327-
return SIZE;
328-
}
329-
330-
@Override
331-
public int getIconHeight() {
332-
return SIZE;
333-
}
334-
335-
@Override
336-
public void paintIcon(Component c, Graphics g, int x, int y) {
337-
g.setColor(Color.GRAY);
338-
339-
g.drawLine(x + SIZE / 2 - 3, y + SIZE / 2, x + SIZE / 2 + 3, y + SIZE / 2);
340-
341-
if (!isOpen) {
342-
g.drawLine(x + SIZE / 2, y + SIZE / 2 - 3, x + SIZE / 2, y + SIZE / 2 + 3);
343-
}
344-
}
345-
}
346-
347256
}

app/src/processing/app/platform/MacPlatform.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,23 @@
2222

2323
package processing.app.platform;
2424

25+
import java.awt.Color;
26+
import java.awt.Component;
2527
import java.awt.Desktop;
28+
import java.awt.Graphics;
2629
import java.io.File;
2730
import java.io.FileNotFoundException;
2831
import java.io.IOException;
2932
import java.net.URI;
3033

34+
import javax.swing.Icon;
3135
import javax.swing.JMenu;
3236
import javax.swing.JMenuBar;
37+
import javax.swing.UIManager;
3338

3439
import processing.app.Base;
3540
import processing.app.Messages;
41+
import processing.app.Preferences;
3642
import processing.app.ui.About;
3743

3844

@@ -96,6 +102,24 @@ public void initBase(Base base) {
96102
}
97103

98104

105+
@Override
106+
public void setLookAndFeel() throws Exception {
107+
super.setLookAndFeel();
108+
109+
String laf = Preferences.get("editor.laf");
110+
if ("org.violetlib.aqua.AquaLookAndFeel".equals(laf)) {
111+
Icon collapse = new VAquaTreeIcon(true);
112+
Icon open = new VAquaTreeIcon(false);
113+
Icon leaf = new VAquaEmptyIcon();
114+
UIManager.put("Tree.closedIcon", leaf);
115+
UIManager.put("Tree.openIcon", leaf);
116+
UIManager.put("Tree.collapsedIcon", open);
117+
UIManager.put("Tree.expandedIcon", collapse);
118+
UIManager.put("Tree.leafIcon", leaf);
119+
}
120+
}
121+
122+
99123
public File getSettingsFolder() throws Exception {
100124
return new File(getLibraryFolder(), "Processing");
101125
}
@@ -173,4 +197,80 @@ protected String getDocumentsFolder() throws FileNotFoundException {
173197
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
174198
}
175199
*/
200+
201+
202+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
203+
204+
// VAQUA WORKAROUNDS FROM SAM
205+
206+
207+
/**
208+
* Spacer icon for macOS when using Vaqua.
209+
210+
* Due to potential rendering issues, this small spacer is used
211+
* to ensure that rendering is stable while using Vaqua with non-standard
212+
* Swing components. Without this, some sizing calculations non-standard
213+
* components may fail or become unreliable.
214+
*/
215+
class VAquaEmptyIcon implements Icon {
216+
private final int SIZE = 1;
217+
218+
@Override
219+
public int getIconWidth() {
220+
return SIZE;
221+
}
222+
223+
@Override
224+
public int getIconHeight() {
225+
return SIZE;
226+
}
227+
228+
@Override
229+
public void paintIcon(Component c, Graphics g, int x, int y) { }
230+
}
231+
232+
233+
/**
234+
* Replacement tree icon for macOS when using Vaqua.
235+
*
236+
* Due to potential rendering issues with the regular tree icon set,
237+
* this replacement tree icon for macOS ensures stable rendering when using
238+
* Vaqua with non-standard swing components. Without this, some sizing
239+
* calculations within non-standard components may fail or become unreliable.
240+
*/
241+
private class VAquaTreeIcon implements Icon {
242+
private final int SIZE = 12;
243+
private final boolean isOpen;
244+
245+
/**
246+
* Create a new tree icon.
247+
*
248+
* @param newIsOpen Flag indicating if the icon should be in the open or closed state at
249+
* construction. True if open false otherwise.
250+
*/
251+
public VAquaTreeIcon(boolean newIsOpen) {
252+
isOpen = newIsOpen;
253+
}
254+
255+
@Override
256+
public int getIconWidth() {
257+
return SIZE;
258+
}
259+
260+
@Override
261+
public int getIconHeight() {
262+
return SIZE;
263+
}
264+
265+
@Override
266+
public void paintIcon(Component c, Graphics g, int x, int y) {
267+
g.setColor(Color.GRAY);
268+
269+
g.drawLine(x + SIZE / 2 - 3, y + SIZE / 2, x + SIZE / 2 + 3, y + SIZE / 2);
270+
271+
if (!isOpen) {
272+
g.drawLine(x + SIZE / 2, y + SIZE / 2 - 3, x + SIZE / 2, y + SIZE / 2 + 3);
273+
}
274+
}
275+
}
176276
}

app/src/processing/app/platform/WindowsPlatform.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,15 @@ public int unsetenv(String variable) {
636636

637637
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
638638

639+
639640
public float getSystemZoom() {
640641
if (cachedDisplayScaling.isEmpty()) {
641642
cachedDisplayScaling = Optional.of(calculateSystemZoom());
642643
}
643-
644644
return cachedDisplayScaling.get();
645645
}
646646

647+
647648
private float calculateSystemZoom() {
648649
WinDef.HDC hdc = GDI32.INSTANCE.CreateCompatibleDC(null);
649650

@@ -659,5 +660,4 @@ private float calculateSystemZoom() {
659660

660661
return logicalResolution / virtualResolution;
661662
}
662-
663663
}

build/shared/lib/defaults.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ editor.untitled.suffix=yyMMdd
239239
# is to do a Synth LAF that gives us something not awful.
240240
editor.laf.linux = javax.swing.plaf.nimbus.NimbusLookAndFeel
241241

242-
# enable/disable vaqua on mac
243-
editor.laf.vaqua = false
242+
# use this to enable the VAqua Look and Feel (may be removed later)
243+
#editor.laf.macosx = org.violetlib.aqua.AquaLookAndFeel
244244

245245

246246
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

0 commit comments

Comments
 (0)