ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/DBReporter/IscreamLayout.java
Revision: 1.8
Committed: Sun Jan 7 13:49:54 2001 UTC (24 years, 11 months ago) by pjm2
Branch: MAIN
Changes since 1.7: +16 -0 lines
Log Message:
The x axis of each graph now includes a scale.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2
3 //---IMPORTS---
4 import java.io.*;
5 import java.util.*;
6 import java.awt.geom.*;
7
8 /**
9 * Provides common i-screamed SHTML layout themes for the historical reports.
10 *
11 * @author $Author: pjm2 $
12 * @version $Id: IscreamLayout.java,v 1.1 2000/12/11 16:34:16 pjm2 Exp $
13 */
14 public class IscreamLayout {
15
16 //---FINAL ATTRIBUTES---
17
18 /**
19 * The current CVS revision of this class
20 */
21 public final String REVISION = "$Revision: 1.1 $";
22
23 //---STATIC METHODS---
24
25 public static void printDocType(BufferedWriter bw) throws IOException{
26 bw.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
27 bw.newLine();
28 bw.newLine();
29 bw.flush();
30 }
31
32 public static void printHeader(BufferedWriter bw, String title, String metaDescription, String metaKeywords) throws IOException{
33 bw.write("<html>");
34 bw.write("<head>");
35 bw.write("<title>"+title+"</title>");
36 bw.write("<meta name=\"description\" content=\""+metaDescription+"\">");
37 bw.write("<meta name=\"keywords\" content=\""+metaKeywords+"\">");
38 bw.write("<meta name=\"generator\" content=\"pjm2's DBReporterMain\">");
39 bw.write("</head>");
40 bw.write("<body bgcolor=\"#ffffff\" link=\"#0000ff\" alink=\"#3333cc\" vlink=\"#3333cc\" text=\"#000066\">");
41 bw.write("<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">");
42 bw.write(" <tr>");
43 bw.write(" <td valign=\"top\">");
44 bw.write("");
45 bw.newLine();
46 bw.flush();
47 }
48
49 public static void printLeftMenu(BufferedWriter bw) throws IOException{
50 bw.newLine();
51 bw.write("<!--#include virtual=\"../left.inc\" -->");
52 bw.newLine();
53 bw.write("</td><td valign=\"top\">");
54 bw.newLine();
55 bw.flush();
56 }
57
58 public static void printTitle(BufferedWriter bw, String title) throws IOException{
59 bw.newLine();
60 bw.write("<!--#include virtual=\"../title.inc\" -->");
61 bw.newLine();
62 bw.newLine();
63 bw.write("<h3>"+title+"</h3>");
64 bw.newLine();
65 bw.flush();
66 }
67
68 public static void printGraph(BufferedWriter bw, String filename, int width, int height, int type, long startDate, long endDate) throws IOException{
69
70 String graphTitle = "Unknown time period";
71 String xAxisTitle = "Time";
72 String yAxisTitle = "Value";
73 String scaleRow = " <tr><td>&nbsp;</td><td align=\"left\">"+DateUtils.dateString(startDate)+"</td><td align=\"right\">"+DateUtils.dateString(endDate)+"</td></tr>";
74
75 switch (type) {
76 case ReportPage.HOUR:
77 graphTitle = "Hourly report from "+DateUtils.dateString(startDate)+" to "+DateUtils.dateString(endDate);
78 scaleRow = " <tr>";
79 for (long i = startDate; i < endDate; i+=DateUtils.secsPerHour/6){
80 scaleRow += "<td>"+DateUtils.timeString(i)+"</td>";
81 }
82 scaleRow += "</tr>";
83 break;
84 case ReportPage.DAY:
85 graphTitle = "24 hour report from "+DateUtils.dateString(startDate)+" to "+DateUtils.dateString(endDate);
86 scaleRow = " <tr>";
87 for (int i = 0; i < 24; i++){
88 scaleRow += "<td>"+i+"</td>";
89 }
90 scaleRow += "</tr>";
91 break;
92 case ReportPage.WEEK:
93 graphTitle = "7 day report from "+DateUtils.shortDateString(startDate)+" to "+DateUtils.shortDateString(endDate);
94 scaleRow = " <tr>";
95 for (long i = startDate; i < endDate; i+=DateUtils.secsPerDay){
96 scaleRow += "<td>"+i+"</td>";
97 }
98 scaleRow += "</tr>";
99 break;
100 case ReportPage.MONTH:
101 graphTitle = "30 day report from "+DateUtils.shortDateString(startDate)+" to "+DateUtils.shortDateString(endDate);
102 scaleRow = " <tr><td>&nbsp;</td><td align=\"left\">"+DateUtils.shortDateString(startDate)+"</td><td align=\"right\">"+DateUtils.shortDateString(endDate)+"</td></tr>";
103 break;
104 default:
105 // Do nothing, leave values as they are.
106 }
107
108 bw.write("<table border=\"0\">");
109 bw.write(" <tr><td>&nbsp;</td><td colspan=\"2\"><b>"+graphTitle+"</b></td></tr>");
110 bw.write(" <tr><td>"+yAxisTitle+"</td><td colspan=\"2\"><img src=\""+filename+"\" width=\""+width+"\" height=\""+height+"\"></td></tr>");
111 bw.write(scaleRow);
112 bw.write("</table>");
113 bw.newLine();
114 bw.flush();
115 }
116
117 public static void printTable(BufferedWriter bw, PlotData pd) throws IOException{
118
119 bw.write("<table border=\"0\" align=\"center\">");
120
121 bw.write("<tr bgcolor=\"black\"><td><font color=\"white\">Date</font></td><td><font color=\"white\">Value</font></td></tr>");
122
123 // Alternating row colours.
124 String rowColour1 = "#ccccff";
125 String rowColour2 = "#ffffff";
126
127 String rowColour = rowColour1;
128
129 Iterator it = pd.iterator();
130 while (it.hasNext()){
131 Point2D p = (Point2D)it.next();
132 double x = p.getX();
133 double y = p.getY();
134
135 if (rowColour.equals(rowColour1)){
136 rowColour = rowColour2;
137 }
138 else {
139 rowColour = rowColour1;
140 }
141
142 bw.write("<tr bgcolor=\""+rowColour+"\"><td>"+x+"</td><td>"+y+"</td></tr>");
143 }
144
145 bw.write("</table>");
146 bw.flush();
147 }
148
149 public static void printBottom(BufferedWriter bw) throws IOException{
150 bw.newLine();
151 bw.write("<!--#include virtual=\"../bottom.inc\" -->");
152 bw.newLine();
153 bw.newLine();
154 bw.flush();
155 }
156
157
158
159 //---CONSTRUCTORS---
160
161
162 //---PUBLIC METHODS---
163
164 /**
165 * Overrides the {@link java.lang.Object#toString() Object.toString()}
166 * method to provide clean logging (every class should have this).
167 *
168 * @return the name of this class and its CVS revision
169 */
170 public String toString() {
171 return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
172 }
173
174 //---PRIVATE METHODS---
175
176 //---ACCESSOR/MUTATOR METHODS---
177
178 //---ATTRIBUTES---
179
180 //---STATIC ATTRIBUTES---
181
182 }