SyntaxScheme using hex strings

General Discussion on RSyntaxTextArea.

Moderator: robert

SyntaxScheme using hex strings

Postby GwynEvans » Fri Sep 11, 2009 7:52 pm

It struck me that the SyntaxScheme CSV text descriptions could be converted to also support HEX via a few tweaks, specifically...
Code: Select all
// Extract from loadFromString()
               String temp = tokens[pos+1];
               Color fg = "-".equals(temp) ?
                     null :
                     temp.charAt(0) == '$' ?
                         new Color(Integer.parseInt(temp.substring(1),16)) :
                         new Color(Integer.parseInt(temp));
               temp = tokens[pos+2];
               Color bg = "-".equals(temp) ?
                     null :
                     temp.charAt(0) == '$' ?
                         new Color(Integer.parseInt(temp.substring(1),16)) :
                         new Color(Integer.parseInt(temp));


and
Code: Select all
// Extract from toCommaSeparatedString()
         Color c = ss.foreground;
         retVal += c!=null ? ("$"+Integer.toHexString((c.getRGB() & 0xffffff)+0x1000000).substring(1)+",") : "-,";
         c = ss.background;
         retVal += c!=null ? ("$"+Integer.toHexString((c.getRGB() & 0xffffff)+0x1000000).substring(1)+",") : "-,";

Sorry, can't easily generate a patch at the moment...

Anyway, it'll import the existing format, but also formats such as "0,-,-,f,-,,,1,$008000,-,f,Monospaced,2,13,2,$008000,-,f,Monospaced,2,13,3,$a40000,-,f,Monospaced,2,13,4,$0000ff,-,f,Monospaced,1,13,5,$ad8000", which might make it easier to tweak colours, if that's useful at any time...
GwynEvans
 

Re: SyntaxScheme using hex strings

Postby robert » Fri Sep 11, 2009 11:25 pm

Good idea Gwyn! It's a nice improvement and I'll be sure and add it in ASAP.
User avatar
robert
 
Posts: 805
Joined: Sat May 10, 2008 5:16 pm


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron