| 1 |
pjm2 |
1.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 |
pjm2 |
1.27 |
* @version $Id: IscreamLayout.java,v 1.26 2001/01/08 09:54:48 pjm2 Exp $ |
| 13 |
pjm2 |
1.1 |
*/ |
| 14 |
|
|
public class IscreamLayout { |
| 15 |
|
|
|
| 16 |
|
|
//---FINAL ATTRIBUTES--- |
| 17 |
|
|
|
| 18 |
|
|
/** |
| 19 |
|
|
* The current CVS revision of this class |
| 20 |
|
|
*/ |
| 21 |
pjm2 |
1.27 |
public final String REVISION = "$Revision: 1.26 $"; |
| 22 |
pjm2 |
1.1 |
|
| 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 |
pjm2 |
1.14 |
bw.write("<meta http-equiv=\"pragma\" content=\"no-cache\">"); |
| 37 |
|
|
bw.write("<meta http-equiv=\"cache-control\" content=\"no-cache\">"); |
| 38 |
pjm2 |
1.1 |
bw.write("<meta name=\"description\" content=\""+metaDescription+"\">"); |
| 39 |
|
|
bw.write("<meta name=\"keywords\" content=\""+metaKeywords+"\">"); |
| 40 |
|
|
bw.write("<meta name=\"generator\" content=\"pjm2's DBReporterMain\">"); |
| 41 |
|
|
bw.write("</head>"); |
| 42 |
|
|
bw.write("<body bgcolor=\"#ffffff\" link=\"#0000ff\" alink=\"#3333cc\" vlink=\"#3333cc\" text=\"#000066\">"); |
| 43 |
pjm2 |
1.24 |
bw.write("<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" align=\"center\">"); |
| 44 |
pjm2 |
1.1 |
bw.write(" <tr>"); |
| 45 |
|
|
bw.write(" <td valign=\"top\">"); |
| 46 |
|
|
bw.write(""); |
| 47 |
|
|
bw.newLine(); |
| 48 |
|
|
bw.flush(); |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
|
|
public static void printLeftMenu(BufferedWriter bw) throws IOException{ |
| 52 |
|
|
bw.newLine(); |
| 53 |
pjm2 |
1.2 |
bw.write("<!--#include virtual=\"../left.inc\" -->"); |
| 54 |
pjm2 |
1.1 |
bw.newLine(); |
| 55 |
|
|
bw.flush(); |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
public static void printTitle(BufferedWriter bw, String title) throws IOException{ |
| 59 |
|
|
bw.newLine(); |
| 60 |
pjm2 |
1.2 |
bw.write("<!--#include virtual=\"../title.inc\" -->"); |
| 61 |
pjm2 |
1.1 |
bw.newLine(); |
| 62 |
|
|
bw.newLine(); |
| 63 |
|
|
bw.write("<h3>"+title+"</h3>"); |
| 64 |
|
|
bw.newLine(); |
| 65 |
|
|
bw.flush(); |
| 66 |
|
|
} |
| 67 |
|
|
|
| 68 |
pjm2 |
1.27 |
public static void printAllMachines(BufferedWriter bw, LinkedList list) throws IOException{ |
| 69 |
pjm2 |
1.20 |
bw.write("<table border=\"0\" align=\"center\">"); |
| 70 |
|
|
|
| 71 |
|
|
Iterator it = list.iterator(); |
| 72 |
|
|
while (it.hasNext()){ |
| 73 |
|
|
ReportPage rp = (ReportPage)it.next(); |
| 74 |
pjm2 |
1.27 |
bw.write("<tr><td><font size=\"4\"><a href=\"../"+rp.getWhen()+rp.getMachineName()+"."+rp.getReport()+".shtml\">"+rp.getWhen()+rp.getMachineName()+"</a></font></td></tr>"); |
| 75 |
pjm2 |
1.26 |
} |
| 76 |
|
|
|
| 77 |
|
|
bw.write("</table>"); |
| 78 |
|
|
bw.flush(); |
| 79 |
|
|
} |
| 80 |
|
|
|
| 81 |
|
|
public static void printMachinesByTime(BufferedWriter bw, LinkedList list, String when) throws IOException{ |
| 82 |
|
|
bw.write("<table border=\"0\" align=\"center\">"); |
| 83 |
|
|
|
| 84 |
|
|
Iterator it = list.iterator(); |
| 85 |
|
|
while (it.hasNext()){ |
| 86 |
|
|
ReportPage rp = (ReportPage)it.next(); |
| 87 |
|
|
if (rp.getWhen().equals(when)){ |
| 88 |
|
|
bw.write("<tr><td><font size=\"4\"><a href=\"../"+rp.getWhen()+rp.getMachineName()+"."+rp.getReport()+".shtml\">"+rp.getMachineName()+"</a></font></td></tr>"); |
| 89 |
|
|
} |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
|
|
bw.write("</table>"); |
| 93 |
|
|
bw.flush(); |
| 94 |
|
|
} |
| 95 |
|
|
|
| 96 |
|
|
public static void printTimesByMachine(BufferedWriter bw, LinkedList list, String machine_name) throws IOException{ |
| 97 |
|
|
bw.write("<table border=\"0\" align=\"center\">"); |
| 98 |
|
|
|
| 99 |
|
|
Iterator it = list.iterator(); |
| 100 |
|
|
while (it.hasNext()){ |
| 101 |
|
|
ReportPage rp = (ReportPage)it.next(); |
| 102 |
|
|
if (rp.getMachineName().equals(machine_name)){ |
| 103 |
|
|
bw.write("<tr><td><font size=\"4\"><a href=\"../"+rp.getWhen()+rp.getMachineName()+"."+rp.getReport()+".shtml\">"+rp.getWhen()+"</a></font></td></tr>"); |
| 104 |
|
|
} |
| 105 |
pjm2 |
1.20 |
} |
| 106 |
|
|
|
| 107 |
|
|
bw.write("</table>"); |
| 108 |
|
|
bw.flush(); |
| 109 |
|
|
} |
| 110 |
|
|
|
| 111 |
pjm2 |
1.3 |
public static void printGraph(BufferedWriter bw, String filename, int width, int height, int type, long startDate, long endDate) throws IOException{ |
| 112 |
|
|
|
| 113 |
|
|
String graphTitle = "Unknown time period"; |
| 114 |
|
|
String xAxisTitle = "Time"; |
| 115 |
|
|
String yAxisTitle = "Value"; |
| 116 |
pjm2 |
1.6 |
String scaleRow = " <tr><td> </td><td align=\"left\">"+DateUtils.dateString(startDate)+"</td><td align=\"right\">"+DateUtils.dateString(endDate)+"</td></tr>"; |
| 117 |
pjm2 |
1.9 |
int colspan = 2; |
| 118 |
pjm2 |
1.3 |
|
| 119 |
|
|
switch (type) { |
| 120 |
|
|
case ReportPage.HOUR: |
| 121 |
pjm2 |
1.6 |
graphTitle = "Hourly report from "+DateUtils.dateString(startDate)+" to "+DateUtils.dateString(endDate); |
| 122 |
pjm2 |
1.9 |
scaleRow = " <tr><td> </td>"; |
| 123 |
pjm2 |
1.8 |
for (long i = startDate; i < endDate; i+=DateUtils.secsPerHour/6){ |
| 124 |
pjm2 |
1.18 |
scaleRow += "<td align=\"left\" width=\""+(100/colspan)+"%\"><font size=\"2\">>"+DateUtils.timeString(i)+"</font></td>"; |
| 125 |
pjm2 |
1.8 |
} |
| 126 |
|
|
scaleRow += "</tr>"; |
| 127 |
pjm2 |
1.9 |
colspan = 6; |
| 128 |
pjm2 |
1.3 |
break; |
| 129 |
|
|
case ReportPage.DAY: |
| 130 |
pjm2 |
1.6 |
graphTitle = "24 hour report from "+DateUtils.dateString(startDate)+" to "+DateUtils.dateString(endDate); |
| 131 |
pjm2 |
1.9 |
scaleRow = " <tr><td> </td>"; |
| 132 |
pjm2 |
1.8 |
for (int i = 0; i < 24; i++){ |
| 133 |
pjm2 |
1.16 |
scaleRow += "<td align=\"center\" width=\""+(100/colspan)+"%\"><font size=\"2\">"+i+"</font></td>"; |
| 134 |
pjm2 |
1.8 |
} |
| 135 |
|
|
scaleRow += "</tr>"; |
| 136 |
pjm2 |
1.9 |
colspan = 24; |
| 137 |
pjm2 |
1.3 |
break; |
| 138 |
|
|
case ReportPage.WEEK: |
| 139 |
pjm2 |
1.7 |
graphTitle = "7 day report from "+DateUtils.shortDateString(startDate)+" to "+DateUtils.shortDateString(endDate); |
| 140 |
pjm2 |
1.16 |
colspan = 7; |
| 141 |
pjm2 |
1.9 |
scaleRow = " <tr><td> </td>"; |
| 142 |
pjm2 |
1.8 |
for (long i = startDate; i < endDate; i+=DateUtils.secsPerDay){ |
| 143 |
pjm2 |
1.16 |
scaleRow += "<td align=\"center\" width=\""+(100/colspan)+"%\">"+DateUtils.dayName(i)+"</td>"; |
| 144 |
pjm2 |
1.8 |
} |
| 145 |
|
|
scaleRow += "</tr>"; |
| 146 |
pjm2 |
1.3 |
break; |
| 147 |
|
|
case ReportPage.MONTH: |
| 148 |
pjm2 |
1.7 |
graphTitle = "30 day report from "+DateUtils.shortDateString(startDate)+" to "+DateUtils.shortDateString(endDate); |
| 149 |
pjm2 |
1.8 |
scaleRow = " <tr><td> </td><td align=\"left\">"+DateUtils.shortDateString(startDate)+"</td><td align=\"right\">"+DateUtils.shortDateString(endDate)+"</td></tr>"; |
| 150 |
pjm2 |
1.9 |
colspan = 2; |
| 151 |
pjm2 |
1.3 |
break; |
| 152 |
|
|
default: |
| 153 |
pjm2 |
1.6 |
// Do nothing, leave values as they are. |
| 154 |
pjm2 |
1.3 |
} |
| 155 |
|
|
|
| 156 |
pjm2 |
1.1 |
bw.write("<table border=\"0\">"); |
| 157 |
pjm2 |
1.9 |
bw.write(" <tr><td> </td><td colspan=\""+colspan+"\"><b>"+graphTitle+"</b></td></tr>"); |
| 158 |
pjm2 |
1.15 |
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>"); |
| 159 |
pjm2 |
1.3 |
bw.write(scaleRow); |
| 160 |
pjm2 |
1.1 |
bw.write("</table>"); |
| 161 |
|
|
bw.newLine(); |
| 162 |
|
|
bw.flush(); |
| 163 |
|
|
} |
| 164 |
|
|
|
| 165 |
|
|
public static void printTable(BufferedWriter bw, PlotData pd) throws IOException{ |
| 166 |
pjm2 |
1.4 |
|
| 167 |
pjm2 |
1.1 |
bw.write("<table border=\"0\" align=\"center\">"); |
| 168 |
|
|
|
| 169 |
|
|
bw.write("<tr bgcolor=\"black\"><td><font color=\"white\">Date</font></td><td><font color=\"white\">Value</font></td></tr>"); |
| 170 |
|
|
|
| 171 |
pjm2 |
1.4 |
// Alternating row colours. |
| 172 |
pjm2 |
1.1 |
String rowColour1 = "#ccccff"; |
| 173 |
|
|
String rowColour2 = "#ffffff"; |
| 174 |
|
|
|
| 175 |
|
|
String rowColour = rowColour1; |
| 176 |
|
|
|
| 177 |
|
|
Iterator it = pd.iterator(); |
| 178 |
|
|
while (it.hasNext()){ |
| 179 |
|
|
Point2D p = (Point2D)it.next(); |
| 180 |
|
|
double x = p.getX(); |
| 181 |
|
|
double y = p.getY(); |
| 182 |
|
|
|
| 183 |
|
|
if (rowColour.equals(rowColour1)){ |
| 184 |
|
|
rowColour = rowColour2; |
| 185 |
|
|
} |
| 186 |
|
|
else { |
| 187 |
|
|
rowColour = rowColour1; |
| 188 |
|
|
} |
| 189 |
|
|
|
| 190 |
|
|
bw.write("<tr bgcolor=\""+rowColour+"\"><td>"+x+"</td><td>"+y+"</td></tr>"); |
| 191 |
|
|
} |
| 192 |
|
|
|
| 193 |
|
|
bw.write("</table>"); |
| 194 |
|
|
bw.flush(); |
| 195 |
|
|
} |
| 196 |
|
|
|
| 197 |
|
|
public static void printBottom(BufferedWriter bw) throws IOException{ |
| 198 |
|
|
bw.newLine(); |
| 199 |
pjm2 |
1.2 |
bw.write("<!--#include virtual=\"../bottom.inc\" -->"); |
| 200 |
pjm2 |
1.1 |
bw.newLine(); |
| 201 |
|
|
bw.newLine(); |
| 202 |
|
|
bw.flush(); |
| 203 |
|
|
} |
| 204 |
|
|
|
| 205 |
|
|
|
| 206 |
|
|
|
| 207 |
|
|
//---CONSTRUCTORS--- |
| 208 |
|
|
|
| 209 |
|
|
|
| 210 |
|
|
//---PUBLIC METHODS--- |
| 211 |
|
|
|
| 212 |
|
|
/** |
| 213 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
| 214 |
|
|
* method to provide clean logging (every class should have this). |
| 215 |
|
|
* |
| 216 |
|
|
* @return the name of this class and its CVS revision |
| 217 |
|
|
*/ |
| 218 |
|
|
public String toString() { |
| 219 |
|
|
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
| 220 |
|
|
} |
| 221 |
|
|
|
| 222 |
|
|
//---PRIVATE METHODS--- |
| 223 |
|
|
|
| 224 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
| 225 |
|
|
|
| 226 |
|
|
//---ATTRIBUTES--- |
| 227 |
|
|
|
| 228 |
|
|
//---STATIC ATTRIBUTES--- |
| 229 |
|
|
|
| 230 |
|
|
} |