33 case Command.Status.FINISHED => new Color(234, 248, 255) |
33 case Command.Status.FINISHED => new Color(234, 248, 255) |
34 case Command.Status.FAILED => new Color(255, 192, 192) |
34 case Command.Status.FAILED => new Color(255, 192, 192) |
35 case _ => Color.red |
35 case _ => Color.red |
36 } |
36 } |
37 } |
37 } |
38 |
|
39 def choose_color(markup: String): Color = { |
|
40 // TODO: as properties |
|
41 markup match { |
|
42 // logical entities |
|
43 case Markup.TCLASS | Markup.TYCON | Markup.FIXED_DECL | Markup.FIXED | Markup.CONST_DECL |
|
44 | Markup.CONST | Markup.FACT_DECL | Markup.FACT | Markup.DYNAMIC_FACT |
|
45 | Markup.LOCAL_FACT_DECL | Markup.LOCAL_FACT => new Color(255, 0, 255) |
|
46 // inner syntax |
|
47 case Markup.TFREE | Markup.FREE => Color.blue |
|
48 case Markup.TVAR | Markup.SKOLEM | Markup.BOUND | Markup.VAR => Color.green |
|
49 case Markup.NUM | Markup.FLOAT | Markup.XNUM | Markup.XSTR | Markup.LITERAL |
|
50 | Markup.INNER_COMMENT => new Color(255, 128, 128) |
|
51 case Markup.SORT | Markup.TYP | Markup.TERM | Markup.PROP |
|
52 | Markup.ATTRIBUTE | Markup.METHOD => Color.yellow |
|
53 // embedded source text |
|
54 case Markup.ML_SOURCE | Markup.DOC_SOURCE | Markup.ANTIQ | Markup.ML_ANTIQ |
|
55 | Markup.DOC_ANTIQ => new Color(0, 192, 0) |
|
56 // outer syntax |
|
57 case Markup.IDENT | Markup.COMMAND | Markup.KEYWORD => Color.blue |
|
58 case Markup.VERBATIM => Color.green |
|
59 case Markup.COMMENT => Color.gray |
|
60 case Markup.CONTROL => Color.white |
|
61 case Markup.MALFORMED => Color.red |
|
62 case Markup.STRING | Markup.ALTSTRING => Color.orange |
|
63 // other |
|
64 case _ => Color.white |
|
65 } |
|
66 } |
|
67 } |
38 } |
68 |
39 |
69 |
40 |
70 class TheoryView (text_area: JEditTextArea) |
41 class TheoryView (text_area: JEditTextArea) |
71 extends TextAreaExtension with Text with BufferListener { |
42 extends TextAreaExtension with Text with BufferListener { |
88 private val phase_overview = new PhaseOverviewPanel(prover, to_current(_)) |
59 private val phase_overview = new PhaseOverviewPanel(prover, to_current(_)) |
89 |
60 |
90 |
61 |
91 /* activation */ |
62 /* activation */ |
92 |
63 |
93 Isabelle.plugin.font_changed += (_ => update_font()) |
64 Isabelle.plugin.font_changed += (_ => update_styles) |
94 |
65 |
95 private def update_font() = { |
66 private def update_styles = { |
96 if (text_area != null) { |
67 if (text_area != null) { |
97 if (Isabelle.plugin.font != null) { |
68 if (Isabelle.plugin.font != null) { |
98 val painter = text_area.getPainter |
69 text_area.getPainter.setStyles(DynamicTokenMarker.styles) |
99 painter.setStyles(painter.getStyles.map(style => |
70 repaint_all |
100 new SyntaxStyle(style.getForegroundColor, style.getBackgroundColor, Isabelle.plugin.font) |
|
101 )) |
|
102 painter.setFont(Isabelle.plugin.font) |
|
103 repaint_all() |
|
104 } |
71 } |
105 } |
72 } |
106 } |
73 } |
107 |
74 |
108 private val selected_state_controller = new CaretListener { |
75 private val selected_state_controller = new CaretListener { |
117 def activate() = { |
84 def activate() = { |
118 text_area.addCaretListener(selected_state_controller) |
85 text_area.addCaretListener(selected_state_controller) |
119 phase_overview.textarea = text_area |
86 phase_overview.textarea = text_area |
120 text_area.addLeftOfScrollBar(phase_overview) |
87 text_area.addLeftOfScrollBar(phase_overview) |
121 text_area.getPainter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, this) |
88 text_area.getPainter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, this) |
122 update_font() |
89 buffer.setTokenMarker(new DynamicTokenMarker(buffer, prover.document)) |
|
90 update_styles |
123 } |
91 } |
124 |
92 |
125 def deactivate() = { |
93 def deactivate() = { |
126 text_area.getPainter.removeExtension(this) |
94 text_area.getPainter.removeExtension(this) |
127 text_area.removeLeftOfScrollBar(phase_overview) |
95 text_area.removeLeftOfScrollBar(phase_overview) |
132 /* painting */ |
100 /* painting */ |
133 |
101 |
134 val repaint_delay = new isabelle.utils.Delay(100, () => repaint_all()) |
102 val repaint_delay = new isabelle.utils.Delay(100, () => repaint_all()) |
135 prover.command_info += (_ => repaint_delay.delay_or_ignore()) |
103 prover.command_info += (_ => repaint_delay.delay_or_ignore()) |
136 |
104 |
137 private def from_current(pos: Int) = |
105 def from_current (pos: Int) = |
138 if (col != null && col.start <= pos) |
106 if (col != null && col.start <= pos) |
139 if (pos < col.start + col.added) col.start |
107 if (pos < col.start + col.added) col.start |
140 else pos - col.added + col.removed |
108 else pos - col.added + col.removed |
141 else pos |
109 else pos |
142 |
110 |
143 private def to_current(pos : Int) = |
111 def to_current (pos : Int) = |
144 if (col != null && col.start <= pos) |
112 if (col != null && col.start <= pos) |
145 if (pos < col.start + col.removed) col.start |
113 if (pos < col.start + col.removed) col.start |
146 else pos + col.added - col.removed |
114 else pos + col.added - col.removed |
147 else pos |
115 else pos |
148 |
116 |
204 // paint details of command |
172 // paint details of command |
205 for (node <- e.root_node.dfs) { |
173 for (node <- e.root_node.dfs) { |
206 val begin = to_current(node.start + e.start) |
174 val begin = to_current(node.start + e.start) |
207 val finish = to_current(node.stop + e.start) |
175 val finish = to_current(node.stop + e.start) |
208 if (finish > start && begin < end) { |
176 if (finish > start && begin < end) { |
209 encolor(gfx, y + metrics.getHeight - 4, 2, begin max start, finish min end, |
177 encolor(gfx, y + metrics.getHeight - 2, 1, begin max start, finish min end - 1, |
210 TheoryView.choose_color(node.kind), true) |
178 DynamicTokenMarker.choose_color(node.kind), true) |
211 } |
179 } |
212 } |
180 } |
213 e = e.next |
181 e = e.next |
214 } |
182 } |
215 |
183 |