comparison anagram/vaclgui/statwin.cpp @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /*
2 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * scon.cpp
7 */
8
9 #include <ifont.hpp>
10
11 #include "data.h"
12 #include "dict.h"
13 #include "dspar.hpp"
14 #include "error.h"
15 #include "statwin.hpp"
16 #include "p.h"
17 #include "pgg24-defs.h"
18 #include "pgg24.h"
19 #include "q1glbl.h"
20 #include "q5.h"
21
22 //#define INCLUDE_LOGGING
23 #include "log.h"
24
25
26 static int nparts;
27 static int errorCount;
28
29 static int sconConstructorCalls = 0;
30 static int sconDestructorCalls = 0;
31
32
33 StatisticsWindow::Parameter StatisticsWindow::parameter[8] = {
34 {"Lines scanned", &pgcb.line},
35 {"Tokens identified", (int *)&ntkns},
36 {"Rules identified", (int *)&nforms},
37 {"Partition sets", (int *)&nparts},
38 {"States defined", (int *)&nits},
39 {"States analyzed", (int *)&kits},
40 {"Conflicts", (int *)&n_conflicts},
41 {"Warnings", (int *)&errorCount},
42 };
43
44 Boolean StatisticsWindow::paintWindow(IPaintEvent &event) {
45 LOGSECTION("StatisticsWindow::paintWindow");
46 LOGV((int) this) LCV(event.rect().asString());
47 event.clearBackground(ColorSpec::data.bg());
48 return false;
49 }
50
51 IStaticText *StatisticsWindow::statisticsField(IWindow *owner) {
52 IStaticText *field = new IStaticText(nextChildId(), owner, owner);
53 field->setAlignment(IStaticText::centerLeft);
54 field->setFont(FontSpec::dataTable);
55 field->setBackgroundColor(ColorSpec::data.bg());
56 field->setForegroundColor(ColorSpec::data.fg());
57 return field;
58 }
59
60 void StatisticsWindow::resize() {
61 LOGSECTION("StatisticsWindow::resize");
62 IFont f = FontSpec::dataTable;
63 int nameWidth = f.textWidth("Tokens Identified");
64 int height = f.maxSize().height();
65 int valueWidth = f.textWidth("00000");
66 LOGV(height) LCV(nameWidth) LCV(valueWidth);
67 ISize nameSize(nameWidth, height);
68 ISize valueSize(valueWidth, height);
69 int i;
70 for (i = 0; i < nLines; i++) {
71 line[i].name->setMinimumSize(nameSize);
72 line[i].value->setMinimumSize(valueSize);
73 }
74 ISize frameSize = frameRectFor(clientArea.minimumSize()).size();
75 LOGV(frameSize.asString());
76 sizeTo(frameSize);
77 }
78
79 void StatisticsWindow::onColorChange() {
80 setBackgroundColor(ColorSpec::data.bg());
81 int i;
82 for (i = 0; i < nLines; i++) {
83 line[i].name->setBackgroundColor(ColorSpec::data.bg());
84 line[i].name->setForegroundColor(ColorSpec::data.fg());
85 line[i].value->setBackgroundColor(ColorSpec::data.bg());
86 line[i].value->setForegroundColor(ColorSpec::data.fg());
87 }
88 refresh();
89 }
90
91 void StatisticsWindow::onFontChange() {
92 LOGSECTION("StatisticsWindow::onFontChange");
93 int i;
94 for (i = 0; i < nLines; i++) {
95 line[i].name->setFont(FontSpec::dataTable);
96 line[i].value->setFont(FontSpec::dataTable);
97 }
98 IFont f = FontSpec::dataTable;
99 int margin = f.avgCharWidth();
100 clientArea.setColumnWidth(1,margin);
101 clientArea.setColumnWidth(4,3*margin);
102 clientArea.setColumnWidth(7,margin);
103 clientArea.setRowHeight(1, margin);
104 clientArea.setRowHeight(6, margin);
105 resize();
106 refresh();
107 }
108
109 StatisticsWindow::~StatisticsWindow() {
110 LOGSECTION("StatisticsWindow::~StatisticsWindow");
111 IPaintHandler::stopHandlingEventsFor(&clientArea);
112 LOGS("Handler detached") LCV((int) this);
113 int i;
114 for (i = 0; i < nLines; i++) {
115 LOGS("Delete nameDemon") LCV((int) this);
116 delete nameDemon[i];
117 delete line[i].name;
118 LOGS("Delete valueDemon") LCV((int) this);
119 delete valueDemon[i];
120 delete line[i].value;
121 LOGS("Demons deleted") LCV(i);
122 }
123 sconDestructorCalls++;
124 }
125
126 StatisticsWindow::StatisticsWindow()
127 : AgFrame(IFrameWindow::dialogBorder
128 | dialogBackground
129 | IFrameWindow::systemMenu)
130 , clientArea(nextChildId(), this, this, IRectangle(),
131 IMultiCellCanvas::classDefaultStyle | IWindow::clipChildren)
132 , dataColorChange(this, onColorChange)
133 , fontChange(this, onFontChange)
134 , helpDemon(&clientArea, "Statistical Summary")
135 {
136 LOGSECTION("StatisticsWindow::StatisticsWindow");
137
138 IPaintHandler::handleEventsFor(&clientArea);
139 setClient(&clientArea);
140 char buf[1000];
141 sprintf(buf, "AnaGram : %s", simple_file_name.pointer());
142 windowTitle.setObjectText(buf);
143 windowTitle.setViewText("Statistical Summary");
144 registerTitle("Statistical Summary");
145 syntaxDependent = 1;
146 helpCursorSupported = 1;
147 dataColorChange.attach(&ColorSpec::data);
148 fontChange.attach(&FontSpec::dataTable);
149
150 setBackgroundColor(ColorSpec::data.bg());
151
152 IFont f = FontSpec::dataTable;
153 int margin = f.avgCharWidth();
154 int i;
155 for (i = 0; i < nLines; i++) {
156 line[i].name = statisticsField(&clientArea);
157 line[i].name->setAlignment(IStaticText::centerLeft);
158 line[i].name->setText(parameter[i].name);
159
160 line[i].value = statisticsField(&clientArea);
161 line[i].value->setAlignment(IStaticText::centerRight);
162 char buf[100];
163 sprintf(buf, "%d", *parameter[i].value);
164 line[i].value->setText(buf);
165 nameDemon[i] = new HelpDemon(line[i].name, "Statistical Summary");
166 valueDemon[i] = new HelpDemon(line[i].value, "Statistical Summary");
167 }
168 int j;
169 for (i = 0, j = 2; i < nLines/2; i++, j++) {
170 clientArea.addToCell(line[i].name, 2,j);
171 clientArea.addToCell(line[i].value,3,j);
172 }
173 for (j = 2; i < nLines; i++, j++) {
174 clientArea.addToCell(line[i].name, 5,j);
175 clientArea.addToCell(line[i].value,6,j);
176 }
177 clientArea.setColumnWidth(1,margin);
178 clientArea.setColumnWidth(4,3*margin);
179 clientArea.setColumnWidth(7,margin);
180 clientArea.setRowHeight(1, margin);
181 clientArea.setRowHeight(6, margin);
182 resize();
183 sconConstructorCalls++;
184 }
185
186 int StatisticsWindow::updateDisplay() {
187 LOGSECTION("StatisticsWindow::updateDisplay");
188 nparts = part_dict->nsx - 1;
189 errorCount = errorList.size();
190 int changeFlag = 0;
191 int i;
192 for (i = 0; i < nLines; i++) {
193 char buf[100];
194 sprintf(buf, "%d", *parameter[i].value);
195 if (line[i].value->text() == buf) {
196 continue;
197 }
198 LOGSECTION("Update value");
199 IString oldText = line[i].value->text();
200 line[i].value->setText(buf);
201 changeFlag = 1;
202 }
203 return changeFlag;
204 }
205