ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/DBReporter/IscreamLayout.java
Revision: 1.29
Committed: Fri Feb 16 09:13:12 2001 UTC (24 years, 10 months ago) by pjm2
Branch: MAIN
CVS Tags: HEAD
Changes since 1.28: +2 -2 lines
State: FILE REMOVED
Log Message:
After the radical changes in the i-scream database design, some of these
classes had to be rewritten.  The new design also meant that it was
possible to generate multiple reports per machine per SQL select, so other
parts of the DBReporter were rewritten to take advantage of this
performance gain.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2
3
4
5 //---IMPORTS---
6
7 import java.io.*;
8
9 import java.util.*;
10
11 import java.awt.geom.*;
12
13
14
15 /**
16
17 * Provides common i-screamed SHTML layout themes for the historical reports.
18
19 *
20
21 * @author $Author: pjm2 $
22
23 * @version $Id: IscreamLayout.java,v 1.28 2001/01/11 19:03:04 pjm2 Exp $
24
25 */
26
27 public class IscreamLayout {
28
29
30
31 //---FINAL ATTRIBUTES---
32
33
34
35 /**
36
37 * The current CVS revision of this class
38
39 */
40
41 public final String REVISION = "$Revision: 1.28 $";
42
43
44
45 //---STATIC METHODS---
46
47
48
49 public static void printDocType(BufferedWriter bw) throws IOException{
50
51 bw.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
52
53 bw.newLine();
54
55 bw.newLine();
56
57 bw.flush();
58
59 }
60
61
62
63 public static void printHeader(BufferedWriter bw, String title, String metaDescription, String metaKeywords) throws IOException{
64
65 bw.write("<html>");
66
67 bw.write("<head>");
68
69 bw.write("<title>"+title+"</title>");
70
71 bw.write("<meta http-equiv=\"pragma\" content=\"no-cache\">");
72
73 bw.write("<meta http-equiv=\"cache-control\" content=\"no-cache\">");
74
75 bw.write("<meta name=\"description\" content=\""+metaDescription+"\">");
76
77 bw.write("<meta name=\"keywords\" content=\""+metaKeywords+"\">");
78
79 bw.write("<meta name=\"generator\" content=\"pjm2's DBReporterMain\">");
80
81 bw.write("</head>");
82
83 bw.write("<body bgcolor=\"#ffffff\" link=\"#0000ff\" alink=\"#3333cc\" vlink=\"#3333cc\" text=\"#000066\">");
84
85 bw.write("<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" align=\"center\">");
86
87 bw.write(" <tr>");
88
89 bw.write(" <td valign=\"top\">");
90
91 bw.write("");
92
93 bw.newLine();
94
95 bw.flush();
96
97 }
98
99
100
101 public static void printLeftMenu(BufferedWriter bw) throws IOException{
102
103 bw.newLine();
104
105 bw.write("<!--#include virtual=\"../left.inc\" -->");
106
107 bw.newLine();
108
109 bw.flush();
110
111 }
112
113
114
115 public static void printTitle(BufferedWriter bw, String title) throws IOException{
116
117 bw.newLine();
118
119 bw.write("<!--#include virtual=\"../title.inc\" -->");
120
121 bw.newLine();
122
123 bw.newLine();
124
125 bw.write("<h3>"+title+"</h3>");
126
127 bw.newLine();
128
129 bw.flush();
130
131 }
132
133
134
135 public static void printAllMachines(BufferedWriter bw, LinkedList list) throws IOException{
136
137 bw.write("<table border=\"0\" align=\"center\">");
138
139
140
141 Iterator it = list.iterator();
142
143 while (it.hasNext()){
144
145 ReportPage rp = (ReportPage)it.next();
146
147 bw.write("<tr><td><font size=\"4\"><a href=\"../"+rp.getWhen()+rp.getMachineName()+"."+rp.getReport()+".shtml\">"+rp.getWhen()+rp.getMachineName()+"</a></font></td></tr>");
148
149 }
150
151
152
153 bw.write("</table>");
154
155 bw.flush();
156
157 }
158
159
160
161 public static void printMachinesByTime(BufferedWriter bw, LinkedList list, String when) throws IOException{
162
163 bw.write("<table border=\"0\" align=\"center\">");
164
165
166
167 Iterator it = list.iterator();
168
169 while (it.hasNext()){
170
171 ReportPage rp = (ReportPage)it.next();
172
173 if (rp.getWhen().equals(when)){
174
175 bw.write("<tr><td><font size=\"4\"><a href=\"../"+rp.getWhen()+rp.getMachineName()+"."+rp.getReport()+".shtml\">"+rp.getMachineName()+"</a></font></td></tr>");
176
177 }
178
179 }
180
181
182
183 bw.write("</table>");
184
185 bw.flush();
186
187 }
188
189
190
191 public static void printTimesByMachine(BufferedWriter bw, LinkedList list, String machine_name) throws IOException{
192
193 bw.write("<table border=\"0\" align=\"center\">");
194
195
196
197 Iterator it = list.iterator();
198
199 while (it.hasNext()){
200
201 ReportPage rp = (ReportPage)it.next();
202
203 if (rp.getMachineName().equals(machine_name)){
204
205 bw.write("<tr><td><font size=\"4\"><a href=\"../"+rp.getWhen()+rp.getMachineName()+"."+rp.getReport()+".shtml\">"+rp.getWhen()+"</a></font></td></tr>");
206
207 }
208
209 }
210
211
212
213 bw.write("</table>");
214
215 bw.flush();
216
217 }
218
219
220
221 public static void printGraph(BufferedWriter bw, String filename, int width, int height, int type, long startDate, long endDate) throws IOException{
222
223
224
225 String graphTitle = "Unknown time period";
226
227 String xAxisTitle = "Time";
228
229 String yAxisTitle = "Value";
230
231 String scaleRow = " <tr><td>&nbsp;</td><td align=\"left\">"+DateUtils.dateString(startDate)+"</td><td align=\"right\">"+DateUtils.dateString(endDate)+"</td></tr>";
232
233 int colspan = 2;
234
235
236
237 switch (type) {
238
239 case ReportPage.HOUR:
240
241 graphTitle = "Hourly report from "+DateUtils.dateString(startDate)+" to "+DateUtils.dateString(endDate);
242
243 scaleRow = " <tr><td>&nbsp;</td>";
244
245 for (long i = startDate; i < endDate; i+=DateUtils.secsPerHour/6){
246
247 scaleRow += "<td align=\"left\" width=\""+(100/colspan)+"%\"><font size=\"2\">&gt;"+DateUtils.timeString(i)+"</font></td>";
248
249 }
250
251 scaleRow += "</tr>";
252
253 colspan = 6;
254
255 break;
256
257 case ReportPage.DAY:
258
259 graphTitle = "24 hour report from "+DateUtils.dateString(startDate)+" to "+DateUtils.dateString(endDate);
260
261 scaleRow = " <tr><td>&nbsp;</td>";
262
263 for (int i = 0; i < 24; i++){
264
265 scaleRow += "<td align=\"center\" width=\""+(100/colspan)+"%\"><font size=\"2\">"+i+"</font></td>";
266
267 }
268
269 scaleRow += "</tr>";
270
271 colspan = 24;
272
273 break;
274
275 case ReportPage.WEEK:
276
277 graphTitle = "7 day report from "+DateUtils.shortDateString(startDate)+" to "+DateUtils.shortDateString(endDate);
278
279 colspan = 7;
280
281 scaleRow = " <tr><td>&nbsp;</td>";
282
283 for (long i = startDate; i < endDate; i+=DateUtils.secsPerDay){
284
285 scaleRow += "<td align=\"center\" width=\""+(100/colspan)+"%\">"+DateUtils.dayName(i)+"</td>";
286
287 }
288
289 scaleRow += "</tr>";
290
291 break;
292
293 case ReportPage.MONTH:
294
295 graphTitle = "30 day report from "+DateUtils.shortDateString(startDate)+" to "+DateUtils.shortDateString(endDate);
296
297 scaleRow = " <tr><td>&nbsp;</td><td align=\"left\">"+DateUtils.shortDateString(startDate)+"</td><td align=\"right\">"+DateUtils.shortDateString(endDate)+"</td></tr>";
298
299 colspan = 2;
300
301 break;
302
303 default:
304
305 // Do nothing, leave values as they are.
306
307 }
308
309
310
311 bw.write("<table border=\"0\">");
312
313 bw.write(" <tr><td>&nbsp;</td><td colspan=\""+colspan+"\"><b>"+graphTitle+"</b></td></tr>");
314
315 bw.write(" <tr><td valign=\"top\" align=\"right\">max</td><td colspan=\""+colspan+"\" rowspan=\"3\"><img src=\""+filename+"\" width=\""+width+"\" height=\""+height+"\"></td></tr><tr><td valign=\"middle\" align=\"right\">"+yAxisTitle+"</td></tr><tr><td valign=\"bottom\" align=\"right\">min</td></tr>");
316
317 bw.write(scaleRow);
318
319 bw.write("</table>");
320
321 bw.newLine();
322
323 bw.flush();
324
325 }
326
327
328
329 public static void printTable(BufferedWriter bw, PlotData pd) throws IOException{
330
331
332
333 bw.write("<table border=\"0\" align=\"center\">");
334
335
336
337 bw.write("<tr bgcolor=\"black\"><td><font color=\"white\">Date</font></td><td><font color=\"white\">Value</font></td></tr>");
338
339
340
341 // Alternating row colours.
342
343 String rowColour1 = "#ccccff";
344
345 String rowColour2 = "#ffffff";
346
347
348
349 String rowColour = rowColour1;
350
351
352
353 Iterator it = pd.iterator();
354
355 while (it.hasNext()){
356
357 Point2D p = (Point2D)it.next();
358
359 double x = p.getX();
360
361 double y = p.getY();
362
363
364
365 if (rowColour.equals(rowColour1)){
366
367 rowColour = rowColour2;
368
369 }
370
371 else {
372
373 rowColour = rowColour1;
374
375 }
376
377
378
379 bw.write("<tr bgcolor=\""+rowColour+"\"><td>"+x+"</td><td>"+y+"</td></tr>");
380
381 }
382
383
384
385 bw.write("</table>");
386
387 bw.flush();
388
389 }
390
391
392
393 public static void printBottom(BufferedWriter bw) throws IOException{
394
395 bw.newLine();
396
397 bw.write("<!--#include virtual=\"../bottom.inc\" -->");
398
399 bw.newLine();
400
401 bw.newLine();
402
403 bw.flush();
404
405 }
406
407
408
409
410
411
412
413 //---CONSTRUCTORS---
414
415
416
417
418
419 //---PUBLIC METHODS---
420
421
422
423 /**
424
425 * Overrides the {@link java.lang.Object#toString() Object.toString()}
426
427 * method to provide clean logging (every class should have this).
428
429 *
430
431 * @return the name of this class and its CVS revision
432
433 */
434
435 public String toString() {
436
437 return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
438
439 }
440
441
442
443 //---PRIVATE METHODS---
444
445
446
447 //---ACCESSOR/MUTATOR METHODS---
448
449
450
451 //---ATTRIBUTES---
452
453
454
455 //---STATIC ATTRIBUTES---
456
457
458
459 }
460