7 package org.libcsdbg.jtracer;
9 import java.util.Hashtable;
10 import java.util.Enumeration;
11 import java.util.regex.Pattern;
12 import java.util.regex.Matcher;
15 import java.awt.Color;
17 import javax.swing.JTextPane;
18 import javax.swing.text.Style;
19 import javax.swing.text.StyleContext;
20 import javax.swing.text.StyleConstants;
21 import javax.swing.text.Document;
31 private Hashtable<String, String>
details = null;
40 Registry conf = Registry.getCurrent();
41 StyleContext sc = StyleContext.getDefaultStyleContext();
42 Style s = addStyle(
"plain", sc.getStyle(sc.DEFAULT_STYLE));
45 Integer padding = (Integer) conf.
get(
"text",
"padding");
46 if (padding != null) {
47 StyleConstants.setLeftIndent(s, padding);
48 StyleConstants.setRightIndent(s, padding);
51 Float spacing = (Float) conf.
get(
"text",
"line-height");
53 StyleConstants.setLineSpacing(s, spacing);
55 StyleConstants.setAlignment(s, StyleConstants.ALIGN_JUSTIFIED);
56 setParagraphAttributes(s,
true);
59 Font fnt = (Font) conf.
get(
"text",
"font-trace");
61 StyleConstants.setFontFamily(s, fnt.getFamily());
62 StyleConstants.setFontSize(s, fnt.getSize());
63 StyleConstants.setBold(s, fnt.isBold());
64 StyleConstants.setItalic(s, fnt.isItalic());
67 Color fg = (Color) conf.
get(
"text",
"fgcolor-plain");
68 StyleConstants.setForeground(s, fg);
71 fg = (Color) conf.
get(
"text",
"fgcolor-keyword");
72 s = addStyle(
"keyword", s);
73 StyleConstants.setForeground(s, fg);
75 fg = (Color) conf.
get(
"text",
"fgcolor-type");
76 s = addStyle(
"type", s);
77 StyleConstants.setForeground(s, fg);
79 fg = (Color) conf.
get(
"text",
"fgcolor-number");
80 s = addStyle(
"number", s);
81 StyleConstants.setForeground(s, fg);
83 fg = (Color) conf.
get(
"text",
"fgcolor-file");
84 s = addStyle(
"file", s);
85 StyleConstants.setForeground(s, fg);
87 fg = (Color) conf.
get(
"text",
"fgcolor-delimiter");
88 s = addStyle(
"delimiter", s);
89 StyleConstants.setForeground(s, fg);
91 fg = (Color) conf.
get(
"text",
"fgcolor-scope");
92 s = addStyle(
"scope", s);
93 StyleConstants.setForeground(s, fg);
95 fg = (Color) conf.
get(
"text",
"fgcolor-function");
96 s = addStyle(
"function", s);
97 StyleConstants.setForeground(s, fg);
100 Color bg = (Color) conf.
get(
"text",
"bgcolor-selection");
101 fg = (Color) conf.
get(
"text",
"fgcolor-selection");
102 setSelectionColor(bg);
103 setSelectedTextColor(fg);
106 setAutoscrolls(
true);
112 return details.get(key);
123 return details.keys();
135 String expr =
"[\\s\\{\\}\\(\\)\\*&,:<>]+";
137 Pattern regexp = Pattern.compile(expr);
138 Matcher parser = regexp.matcher(trace);
143 while (parser.find()) {
144 String grp = parser.group();
145 String token = trace.substring(offset, parser.start());
146 offset = parser.end();
153 if (offset < trace.length() - 1)
154 append(trace.substring(offset), prev, null);
167 public void append(String token, String prev, String next)
170 String num =
"(0x)?\\p{XDigit}+$";
173 if (token.matches(num))
177 else if (h.
lookup(token,
"extension",
true))
181 else if (h.
lookup(token,
"type",
false))
185 else if (h.
lookup(token,
"keyword",
false))
189 else if (next.equals(
"::"))
193 else if (next.equals(
"(") || next.equals(
"<") || next.startsWith(
"\n"))
194 append(token,
"function");
208 public void append(String ln, String tag)
211 Document doc = getDocument();
212 int len = doc.getLength();
213 doc.insertString(len, ln, getStyle(tag));
214 setCaretPosition(len + ln.length());
217 catch (Throwable t) {
242 Document doc = getDocument();
243 doc.remove(0, doc.getLength());
247 catch (Throwable t) {
boolean lookup(String token, String nm, boolean regex)
Check if a word belongs in a dictionary.
void append(String ln, String tag)
Append a line of formatted text.
Object get(String section, String key)
Get an entry.
String getField(String key)
Enumeration getFieldKeys()
Get all the keys of the request fields.
void append(String trace)
Append a trace using the syntax highlighter.
static final long serialVersionUID
Object version.
C++ stack trace syntax highlighter.
Hashtable< String, String > details
void appendln(String ln, String tag)
Append a line of formatted text and a line break.
void append(String token, String prev, String next)
Append a single trace token.
Rich text pane for trace visualization with syntax highlighting.
void clear()
Remove all contents.