import java.io.*;
import java.text.*;
/**
* HTMLPrinter class creates html documents
*
**/
class HTMLPrinter {
FileWriter file;
PrintWriter pWriter;
DecimalFormat currencyFormat = new DecimalFormat("$ #,###,##0.00");
/**
*
* Create and initializes an HTML file.
* @param filename name of the file to be created
* @param Title title of the html document
* @throws IOException Input/output exception errors
*/
HTMLPrinter(String filename,String title) throws IOException {
file = new FileWriter(filename);
pWriter = new PrintWriter(file);
pWriter.println("
"+title+"");
pWriter.println("");
}
/**
*
* This method first writes out the closing HTML tags then closes
* the file
* @param none
* @return none
*
*/
void close(){
pWriter.println("");
pWriter.close();
}
/**
*
* Output text using the current text settings
* @param text characters to be output
* @return none
*/
void print(String text) {
pWriter.println(text);
}
/**
*
* Output bold text
* @param text characters to be output
* @return none
*/
void printBold(String text) {
pWriter.println(""+text+"");
}
/**
*
* Output Header text
* @param text characters to be output
* @param size integer 1-6, 1 being the largest header
* @return none
*/
void printHeading(String text, int size) {
pWriter.println(""+text+"");
}
/**
* Output underlined text
* @param text characters to be output
* @return none
*
*/
void printUnderLine(String text) {
pWriter.println(""+text+"");
}
/**
* Output a line break
* @param none
* @return none
*/
void lineBreak() {
pWriter.println("
");
}
/**
* Output a line break
* @param none
* @return none
*/
void println() {
pWriter.println("
");
}
/**
* Output a paragraph break
* @param none
* @return none
*/
void paragraph() {
pWriter.println("");
}
/**
*
* Output a table of text values
*
* @param textTable array of character strings
* @return none
*/
void print(String[] textTable, int border)
{
int i;
pWriter.println("
");
for(i = 0; i< textTable.length; i++)
pWriter.println(""+textTable[i]+" |
");
pWriter.println("
");
}
/**
*
* Output a two dimensional table of text values
*
* @param textTable array of character strings
* @return none
*/
void print(String[][] textTable, int border)
{
int row,col;
pWriter.println("");
for(row = 0; row < textTable.length; row++)
{
pWriter.println("");
for(col = 0; col < textTable[row].length; col++)
pWriter.println(""+textTable[row][col]+" | ");
pWriter.println("
");
}
pWriter.println("
");
}
/**
*
* Start Centering output. All output will be centered until
* a call to stopCentering is made
* @param none
* @return none
*/
void startCentering() {
pWriter.println("");
}
/**
*
* StopCentering output. Centering is turned off until the next
* call to startCentering
* @param none
* @return none
*/
void stopCentering() {
pWriter.println("");
}
/**
*
* This command is used to signify the begining of a table.
* After calling the start table command the program can then call
* startRow, endRow, printCell, etc.
*
* Example: outut a 2 by 2 table
*
* html.startTable(1); // border size of 1
* html.startRow();
* html.printCell("Cell Row 1, Col 1");
* html.printCell("Cell Row 1, Col 2");
* html.endRow();
* html.startRow();
* html.printCell("Cell Row 2, Col 1");
* html.printCell("Cell Row 2, Col 2");
* html.endRow();
* html.endTable();
*
* @param border border width in pixels, =0 for no border
* @return none
*/
void startTable(int border) {
pWriter.println("");
}
/**
*
* This command is used to signify the end of a table.
*
* @param none
* @return none
*/
void endTable() {
pWriter.println("
");
}
/**
*
* This command is used to signify the start of a new row.
*
* @param none
* @return none
*/
void startRow() {
pWriter.println("");
}
/**
*
* This command is used to signify the end of a row.
*
* @param none
* @return none
*/
void endRow() {
pWriter.println("
");
}/**
*
* This command is used to output text to a cell.
*
* @param text text string
* @return none
*/
void printCell(String text) {
pWriter.println(""+text+" | ");
}
/**
*
* This command is used to output double to a cell.
* No formatting is done.
*
* @param num double value to be output
* @return none
*/
void printCell(double num) {
pWriter.println(""+num+" | ");
}
/**
*
* This command is used to output an integer to a cell.
* No formatting is done.
*
* @param num integer to be output
* @return none
*/
void printCell(int num) {
pWriter.println(""+num+" | ");
}
/**
*
* This command is used to output an long to a cell.
* No formatting is done.
*
* @param num long to be output
* @return none
*/
void printCell(long num) {
pWriter.println(""+num+" | ");
}
/**
*
* This command is used to output a float to a cell.
* No formatting is done.
*
* @param num float to be output
* @return none
*/
void printCell(float num) {
pWriter.println(""+num+" | ");
}
/**
*
* This command is used to output a double to a cell.
* The double value is formatted as currency.
*
* @param num double to be output
* @return none
*/
void printCurrencyCell(double num) {
pWriter.println(""+currencyFormat.format(num)+" | ");
}
/**
*
* This command is used to output a float to a cell.
* The float value is formatted as currency.
*
* @param num float to be output
* @return none
*/
void printCurrencyCell(float num) {
pWriter.println(""+currencyFormat.format(num)+" | ");
}
/**
*
* This command is used to output text to a cell.
* Formatted as a header (bold) cell.
*
* @param text text string
* @return none
*/
void printBoldCell(String text) {
pWriter.println(""+text+" | ");
}
/**
*
* This command is used to output double to a cell.
* Formatted as a header (bold) cell.
*
* @param num double value to be output
* @return none
*/
void printBoldCell(double num) {
pWriter.println(""+num+" | ");
}
/**
*
* This command is used to output an integer to a cell.
* Formatted as a header (bold) cell.
*
* @param num integer to be output
* @return none
*/
void printBoldCell(int num) {
pWriter.println(""+num+" | ");
}
/**
*
* This command is used to output an long to a cell.
* Formatted as a header (bold) cell.
*
* @param num long to be output
* @return none
*/
void printBoldCell(long num) {
pWriter.println(""+num+" | ");
}
/**
*
* This command is used to output a float to a cell.
* Formatted as a header (bold) cell.
*
* @param num float to be output
* @return none
*/
void printBoldCell(float num) {
pWriter.println(""+num+" | ");
}
/**
*
* This command is used to output a double to a cell.
* The double value is formatted as currency.
* Formatted as a header (bold) cell.
*
* @param num double to be output
* @return none
*/
void printBoldCurrencyCell(double num) {
pWriter.println(""+currencyFormat.format(num)+" | ");
}
/**
*
* This command is used to output a float to a cell.
* The float value is formatted as currency.
* Formatted as a header (bold) cell.
*
* @param num float to be output
* @return none
*/
void printBoldCurrencyCell(float num) {
pWriter.println(""+currencyFormat.format(num)+" | ");
}
}