From 100b3cf78465fb859e2bbafc8a11392bdc07bb8b Mon Sep 17 00:00:00 2001 From: mikera Date: Sat, 7 Dec 2024 15:35:41 +0000 Subject: [PATCH] Highl;ighting for digits in large numbers with CVM gold --- .../convex/gui/components/BalanceLabel.java | 4 ++-- .../java/convex/gui/utils/CVXHighlighter.java | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/convex-gui/src/main/java/convex/gui/components/BalanceLabel.java b/convex-gui/src/main/java/convex/gui/components/BalanceLabel.java index 4cf8bec06..252857284 100644 --- a/convex-gui/src/main/java/convex/gui/components/BalanceLabel.java +++ b/convex-gui/src/main/java/convex/gui/components/BalanceLabel.java @@ -44,8 +44,8 @@ public BalanceMenu() { public static final Color GOLD=new Color(255,255,0); public static final Color SILVER=new Color(200,200,230); - public static final Color BRONZE=new Color(180,120,60); - public static final Color COPPER=new Color(150,80,30); + public static final Color BRONZE=new Color(200,120,60); + public static final Color COPPER=new Color(150,100,30); protected int decimals=9; private Color balanceColour=GOLD; diff --git a/convex-gui/src/main/java/convex/gui/utils/CVXHighlighter.java b/convex-gui/src/main/java/convex/gui/utils/CVXHighlighter.java index df3a79d21..91326d788 100644 --- a/convex-gui/src/main/java/convex/gui/utils/CVXHighlighter.java +++ b/convex-gui/src/main/java/convex/gui/utils/CVXHighlighter.java @@ -16,6 +16,7 @@ import org.antlr.v4.runtime.Token; import convex.core.lang.reader.AntlrReader; +import convex.gui.components.BalanceLabel; /** * Tools for highlighting Convex Lisp code in Swing @@ -31,6 +32,12 @@ public class CVXHighlighter { static AttributeSet SYMBOL = NORMAL; static AttributeSet NUMBER = sc.addAttribute(BASE, StyleConstants.Foreground, Color.ORANGE); + static AttributeSet GOLD = sc.addAttribute(BASE, StyleConstants.Foreground, BalanceLabel.GOLD); + static AttributeSet SILVER = sc.addAttribute(BASE, StyleConstants.Foreground, BalanceLabel.SILVER); + static AttributeSet BRONZE = sc.addAttribute(BASE, StyleConstants.Foreground, BalanceLabel.BRONZE); + static AttributeSet COPPER = sc.addAttribute(BASE, StyleConstants.Foreground, BalanceLabel.COPPER); + + private static final AttributeSet[] PARENS = new AttributeSet[10]; static { @@ -110,8 +117,21 @@ public static void highlight(JTextPane inputArea, int start, int end) { default: { if (Character.isDigit(c)) { - aset=NUMBER; break; + aset=NUMBER; } + if (tlen>3) try { + // Might be worth formatting as a quantity + String fullNum=d.getText(tstart,tlen); + Long.parseLong(fullNum); + if (tlen>9) d.setCharacterAttributes(tstart, tlen-9, GOLD, true); + if (tlen>6) d.setCharacterAttributes(tstart+Math.max(0, tlen-9), Math.min(3, tlen-6), SILVER, true); + if (tlen>3) d.setCharacterAttributes(tstart+Math.max(0, tlen-6), Math.min(3, tlen-3), BRONZE, false); + d.setCharacterAttributes(tstart+tlen-3, tlen, COPPER, false); + continue; + } catch (NumberFormatException e) { + // OK + } + break; } }