|
23 | 23 |
|
24 | 24 | package processing.app.platform; |
25 | 25 |
|
| 26 | +import java.awt.Color; |
| 27 | +import java.awt.Component; |
26 | 28 | import java.awt.Desktop; |
| 29 | +import java.awt.Graphics; |
27 | 30 | import java.io.File; |
28 | 31 | import java.net.URI; |
29 | 32 |
|
| 33 | +import javax.swing.Icon; |
30 | 34 | import javax.swing.UIManager; |
31 | 35 |
|
32 | 36 | import com.sun.jna.Library; |
33 | 37 | import com.sun.jna.Native; |
| 38 | +import org.violetlib.aqua.AquaLookAndFeel; |
34 | 39 |
|
35 | 40 | import processing.app.Base; |
36 | 41 | import processing.app.Preferences; |
@@ -75,7 +80,21 @@ public void initBase(Base base) { |
75 | 80 | public void setLookAndFeel() throws Exception { |
76 | 81 | String laf = Preferences.get("editor.laf"); |
77 | 82 | if (laf == null || laf.length() == 0) { // normal situation |
78 | | - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 83 | + boolean isMac = System.getProperty("os.name", "").startsWith("Mac OS"); |
| 84 | + if (isMac && Preferences.getBoolean("editor.allow_vaqua")) { |
| 85 | + UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel"); |
| 86 | + |
| 87 | + Icon collapse = new MacTreeIcon(true); |
| 88 | + Icon open = new MacTreeIcon(false); |
| 89 | + Icon leaf = new MacEmptyIcon(); |
| 90 | + UIManager.put("Tree.closedIcon", leaf); |
| 91 | + UIManager.put("Tree.openIcon", leaf); |
| 92 | + UIManager.put("Tree.collapsedIcon", open); |
| 93 | + UIManager.put("Tree.expandedIcon", collapse); |
| 94 | + UIManager.put("Tree.leafIcon", leaf); |
| 95 | + } else { |
| 96 | + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 97 | + } |
79 | 98 | } else { |
80 | 99 | UIManager.setLookAndFeel(laf); |
81 | 100 | } |
@@ -188,4 +207,80 @@ public float getSystemZoom() { |
188 | 207 | return ZOOM_DEFAULT_SIZING; |
189 | 208 | } |
190 | 209 |
|
| 210 | + /** |
| 211 | + * Spacer icon for mac when using Vaqua. |
| 212 | + * |
| 213 | + * <p> |
| 214 | + * Due to potential rendering issues, this small spacer is used to ensure that rendering is stable |
| 215 | + * while using Vaqua with non-standard swing components. Without this, some sizing calculations |
| 216 | + * non-standard components may fail or become unreliable. |
| 217 | + * </p> |
| 218 | + */ |
| 219 | + class MacEmptyIcon implements Icon { |
| 220 | + private final int SIZE = 1; |
| 221 | + |
| 222 | + /** |
| 223 | + * Create a new single pixel spacer icon. |
| 224 | + */ |
| 225 | + public MacEmptyIcon() {} |
| 226 | + |
| 227 | + @Override |
| 228 | + public int getIconWidth() { |
| 229 | + return SIZE; |
| 230 | + } |
| 231 | + |
| 232 | + @Override |
| 233 | + public int getIconHeight() { |
| 234 | + return SIZE; |
| 235 | + } |
| 236 | + |
| 237 | + @Override |
| 238 | + public void paintIcon(Component c, Graphics g, int x, int y) {} |
| 239 | + } |
| 240 | + |
| 241 | + /** |
| 242 | + * Replacement tree icon for mac when using Vaqua. |
| 243 | + * |
| 244 | + * <p> |
| 245 | + * Due to potential rendering issues with the regular tree icon set, this replacement tree icon |
| 246 | + * for mac ensures stable rendering when using Vaqua with non-standard swing components. Without |
| 247 | + * this, some sizing calculations within non-standard components may fail or become unreliable. |
| 248 | + * </p> |
| 249 | + */ |
| 250 | + private class MacTreeIcon implements Icon { |
| 251 | + private final int SIZE = 12; |
| 252 | + private final boolean isOpen; |
| 253 | + |
| 254 | + /** |
| 255 | + * Create a new tree icon. |
| 256 | + * |
| 257 | + * @param newIsOpen Flag indicating if the icon should be in the open or closed state at |
| 258 | + * construction. True if open false otherwise. |
| 259 | + */ |
| 260 | + public MacTreeIcon(boolean newIsOpen) { |
| 261 | + isOpen = newIsOpen; |
| 262 | + } |
| 263 | + |
| 264 | + @Override |
| 265 | + public int getIconWidth() { |
| 266 | + return SIZE; |
| 267 | + } |
| 268 | + |
| 269 | + @Override |
| 270 | + public int getIconHeight() { |
| 271 | + return SIZE; |
| 272 | + } |
| 273 | + |
| 274 | + @Override |
| 275 | + public void paintIcon(Component c, Graphics g, int x, int y) { |
| 276 | + g.setColor(Color.GRAY); |
| 277 | + |
| 278 | + g.drawLine(x + SIZE / 2 - 3, y + SIZE / 2, x + SIZE / 2 + 3, y + SIZE / 2); |
| 279 | + |
| 280 | + if (!isOpen) { |
| 281 | + g.drawLine(x + SIZE / 2, y + SIZE / 2 - 3, x + SIZE / 2, y + SIZE / 2 + 3); |
| 282 | + } |
| 283 | + } |
| 284 | + } |
| 285 | + |
191 | 286 | } |
0 commit comments