/*
 * Copyright (c) 2004, 2005, ADAPT project partners (IST-2001-37126).
 * 
 * ADAPTLookAndFeel.java
 */

package org.eu.adapt.demonstrator.web;

import java.io.IOException;
import java.io.PrintWriter;

public class ADAPTLookAndFeel
{
    private static final String BODY_STYLE = "style=\"color: #388b23; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: bold\"";

    public static void generatePageHeader(String rootPath, PrintWriter writer)
        throws IOException
    {
        generatePageHeader(rootPath, -1, writer);
    }

    public static void generatePageHeader(String rootPath, int reloadDelay, PrintWriter writer)
        throws IOException
    {
        writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">");
        writer.println();
        writer.println("<HTML>");
        writer.println("<HEAD>");
        writer.println("<TITLE>ADAPT Demonstrator</TITLE>");
        if (reloadDelay >= 0)
            writer.println("<META http-equiv=\"refresh\" content=\"" + reloadDelay + "\">");
        writer.println("</HEAD>");
        writer.println("<BODY " + BODY_STYLE + ">");
        writer.println("<TABLE width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
        writer.println("<TR>");
        writer.println("<TD width=\"50%\">&nbsp;</TD>");        
        writer.println("<TD width=\"870\">");
        writer.println("<IMG src=\"" + rootPath + "/ADAPT_header.jpg\">");
    }

    public static void generatePageFooter(PrintWriter writer)
        throws IOException
    {
        writer.println("</TD>");        
        writer.println("<TD width=\"50%\">&nbsp;</TD>");        
        writer.println("</TR>");
        writer.println("</TABLE>");
        writer.println("</BODY>");
        writer.println("</HTML>");
    }

    private static final String TABLE_BACKGROUND_STYLE = "style=\"background-color: #388b23\"";
    private static final String TABLE_HEADER_BOX_STYLE = "style=\"background-color: #388b23\"";
    private static final String TABLE_HEADER_TEXT_STYLE = "style=\"color: white; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: bold\"";
    private static final String TABLE_HEADER_TEXTLINK_STYLE = "style=\"color: white; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: bold; text-decoration: underline\"";
    private static final String TABLE_ENTRY_BOX_STYLE = "style=\"background-color: white\"";
    private static final String TABLE_ENTRY_TEXT_STYLE = "style=\"color: #388b23; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: bold\"";
    private static final String TABLE_ENTRY_TEXTLINK_STYLE = "style=\"color: #388b23; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: bold; text-decoration: underline\"";

    public static void generateTableHeader(String title, String ref, PrintWriter writer)
        throws IOException
    {
        writer.println("<TABLE width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"4\" " + TABLE_BACKGROUND_STYLE + ">");
        if (ref != null)
            writer.println("<TR><TD colspan=\"4\" " + TABLE_HEADER_BOX_STYLE + " align=\"center\"><A " + TABLE_HEADER_TEXTLINK_STYLE + " href=\"" + ref + "\">" + title + "</A></TD></TR>");
        else
            writer.println("<TR><TD colspan=\"4\" " + TABLE_HEADER_BOX_STYLE + " align=\"center\"><DIV " + TABLE_HEADER_TEXT_STYLE + ">" + title + "</DIV></TD></TR>");        
    }

    public static void generateTableSubheader(String title, String ref, PrintWriter writer)
        throws IOException
    {
        if (ref != null)
            writer.println("<TR><TD colspan=\"4\" " + TABLE_HEADER_BOX_STYLE + " align=\"center\"><A " + TABLE_HEADER_TEXTLINK_STYLE + " href=\"" + ref + "\">" + title + "</A></TD></TR>");
        else
            writer.println("<TR><TD colspan=\"4\" " + TABLE_HEADER_BOX_STYLE + " align=\"center\"><DIV " + TABLE_HEADER_TEXT_STYLE + ">" + title + "</DIV></TD></TR>");        
    }

    public static void generateTableSubheader(String title1, String ref1, String title2, String ref2, PrintWriter writer)
        throws IOException
    {
        writer.println("<TR>");
        if (ref1 != null)
            writer.println("<TD colspan=\"2\" " + TABLE_HEADER_BOX_STYLE + " align=\"center\"><A " + TABLE_HEADER_TEXTLINK_STYLE + " href=\"" + ref1 + "\">" + title1 + "</A></TD>");
        else
            writer.println("<TD colspan=\"2\" " + TABLE_HEADER_BOX_STYLE + " align=\"center\"><DIV " + TABLE_HEADER_TEXT_STYLE + ">" + title1 + "</DIV></TD>");        
        if (ref2 != null)
            writer.println("<TD colspan=\"2\" " + TABLE_HEADER_BOX_STYLE + " align=\"center\"><A " + TABLE_HEADER_TEXTLINK_STYLE + " href=\"" + ref2 + "\">" + title2 + "</A></TD>");
        else
            writer.println("<TD colspan=\"2\" " + TABLE_HEADER_BOX_STYLE + " align=\"center\"><DIV " + TABLE_HEADER_TEXT_STYLE + ">" + title2 + "</DIV></TD>");        
        writer.println("</TR>");
    }

    public static void generateTableEntry(String text, String ref, PrintWriter writer)
        throws IOException
    {
        if (ref != null)
            writer.println("<TR><TD colspan=\"4\" " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref + "\">" + text + "</A></TD></TR>");
        else
            writer.println("<TR><TD colspan=\"4\" " + TABLE_ENTRY_BOX_STYLE + "><DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text + "</DIV></TD></TR>");        
    }

    public static void generateTableEntry(String text1, String ref1, String text2, String ref2, PrintWriter writer)
        throws IOException
    {
        writer.println("<TR>");
        if (ref1 != null)
            writer.println("<TD colspan=\"2\" " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref1 + "\">" + text1 + "</A></TD>");
        else
            writer.println("<TD colspan=\"2\" " + TABLE_ENTRY_BOX_STYLE + "<DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text1 + "</DIV></TD>");        
        if (ref2 != null)
            writer.println("<TD colspan=\"2\" " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref2 + "\">" + text2 + "</A></TD>");
        else
            writer.println("<TD colspan=\"2\" " + TABLE_ENTRY_BOX_STYLE + "><DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text2 + "</DIV></TD>");        
        writer.println("</TR>");
    }

    public static void generateTableEntry(String text1, String ref1, String text2, String ref2, String text3, String ref3, PrintWriter writer)
        throws IOException
    {
        writer.println("<TR>");
        if (ref1 != null)
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref1 + "\">" + text1 + "</A></TD>");
        else
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text1 + "</DIV></TD>");        
        if (ref2 != null)
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref2 + "\">" + text2 + "</A></TD>");
        else
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text2 + "</DIV></TD>");        
        if (ref3 != null)
            writer.println("<TD colspan=\"2\" " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref3 + "\">" + text3 + "</A></TD>");
        else
            writer.println("<TD colspan=\"2\" " + TABLE_ENTRY_BOX_STYLE + "><DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text3 + "</DIV></TD>");        
        writer.println("</TR>");
    }

    public static void generateTableEntry(String text1, String ref1, String text2, String ref2, String text3, String ref3, String text4, String ref4, PrintWriter writer)
        throws IOException
    {
        writer.println("<TR>");
        if (ref1 != null)
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref1 + "\">" + text1 + "</A></TD>");
        else
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text1 + "</DIV></TD>");        
        if (ref2 != null)
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref2 + "\">" + text2 + "</A></TD>");
        else
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text2 + "</DIV></TD>");        
        if (ref3 != null)
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref3 + "\">" + text3 + "</A></TD>");
        else
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text3 + "</DIV></TD>");        
        if (ref4 != null)
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><A " + TABLE_ENTRY_TEXTLINK_STYLE + " href=\"" + ref4 + "\">" + text4 + "</A></TD>");
        else
            writer.println("<TD " + TABLE_ENTRY_BOX_STYLE + "><DIV " + TABLE_ENTRY_TEXT_STYLE + ">" + text4 + "</DIV></TD>");        
        writer.println("</TR>");
    }

    public static void generateTableFooter(PrintWriter writer)
        throws IOException
    {
        writer.println("</TABLE>");
        writer.println("<BR>");
    }
}