-
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathSyntaxStyle.java
More file actions
68 lines (51 loc) · 1.61 KB
/
SyntaxStyle.java
File metadata and controls
68 lines (51 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* SyntaxStyle.java - A simple text style class
* Copyright (C) 1999 Slava Pestov
*
* You may use and modify this package for any purpose. Redistribution is
* permitted, in both source and binary form, provided that this notice
* remains intact in all source distributions of this package.
*/
package processing.app.syntax;
import java.awt.Color;
import java.util.StringTokenizer;
/**
* A simple text style class that specifies the color and bold flag of a run of text.
* @author Slava Pestov
* @version $Id$
*/
public class SyntaxStyle {
final private Color color;
final private boolean bold;
/**
* Creates a new SyntaxStyle.
* @param color The text color
* @param bold True if the text should be bold
*/
public SyntaxStyle(Color color, boolean bold) {
this.color = color;
this.bold = bold;
}
static public SyntaxStyle fromString(String str) {
StringTokenizer st = new StringTokenizer(str, ",");
String s = st.nextToken();
if (s.indexOf("#") == 0) s = s.substring(1);
Color color = new Color(Integer.parseInt(s, 16));
s = st.nextToken();
boolean bold = s.contains("bold");
//boolean italic = s.contains("italic");
return new SyntaxStyle(color, bold);
}
/** Returns the color specified in this style. */
public Color getColor() {
return color;
}
/** Returns true if boldface is enabled for this style. */
public boolean isBold() {
return bold;
}
/** Returns a string representation of this object. */
public String toString() {
return getClass().getName() + "[color=" + color + (bold ? ",bold" : "") + "]";
}
}