Best way to add SyntaxConstants into ComboBox?

Post a reply

Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: Best way to add SyntaxConstants into ComboBox?

Re: Best way to add SyntaxConstants into ComboBox?

Post by robert » Wed Jan 08, 2014 1:36 pm

You'd have to roll your own to do that. One way is perhaps a HashMap mapping user-friendly Strings for language names to the SyntaxConstants property names.

You might be able to programmatically get "user-friendly" names from the constant values. It's up to you if they're "friendly" enough. Something like this:

java code:

Field[] fields = SyntaxConstants.class.getFields();
for (Field field : fields) {
String name = field.getName();
String userFriendlyName = name.substring("SYNTAX_STYLE_".length());
// Sentence-case it
boolean lowerCaseNext = true;
StringBuilder sb = new StringBuilder();
sb.append(userFriendlyName.charAt(0));
for (int i=1; i<userFriendlyName.length(); i++) {
char ch = userFriendlyName.charAt(i);
if (ch=='_') {
sb.append(' ');
lowerCaseNext = false;
}
else {
if (lowerCaseNext) {
ch = Character.toLowerCase(ch);
}
else {
lowerCaseNext = true;
}
sb.append(ch);
}
}
userFriendlyName = sb.toString();
System.out.println(userFriendlyName);
}

Best way to add SyntaxConstants into ComboBox?

Post by Endogen » Sat Jan 04, 2014 10:35 am

First of all, this is a great library! I found this thing a week ago and really enjoy using it. Thanks for all the great work!

What i try to do is, add all the available constants in "SyntaxConstants" into a JComboBox so that i have the possibility to choose the highlighting that i want to use for my text. Also i don't necessarily want to see the exact same values as in "SyntaxConstants". Something like "Java" or "Delphi" would be great!
Could someone give me some ideas how to achieve this?

Top