/*  Copyright (c) 2000 by Oracle Corporation. All Rights Reserved. */

package oracle.portal.provider.v2.render;

import java.io.PrintWriter;
import java.io.IOException;
import java.util.ResourceBundle;


import oracle.portal.provider.v2.resource.ProviderBundle;
import oracle.portal.utils.v2.ParameterMap;
import oracle.portal.utils.v2.SimpleParameterMap;
import oracle.webdb.utils.SimpleStringBuffer;

/**
 *  A ContainerRenderer306 is a utility class that renders the container
 *  for a portlet in the style of Oracle Portal v 3.0.6
 * 
 */
public class ContainerRenderer306 extends DefaultContainerRenderer
{
    /**
     *  Utility method for rendering the Design forms.  This method should be
     *  used in conjunction with renderDessignFormFooter() to work correctly.
     *  This routine emits the proper html FORM tag, appropriate hidden fields,
     *  the standard look/feel for the Form container, and the appropriate form
     *  buttons (based on the rendermode).
     *
     *  @param request the portlet render request.
     *  @param writer the response writer used to output the customize form header.
     *  @param formName the name used in the <FORM> tag's NAME attribute.  This must
     *  be none null so appropriate javascript can be generated to set the
     *  <i>actionParam</i> value.
     *  @param title the to display in the header (titlebar)
     *  @param actionParam the name of the hidden field that will hold the value
     *  that indicates which button was clicked.  The value is 'OK' if the OK button
     *  was clicked.  The value is 'APPLY' if the APPLY button is clicked
     *  @param helpURL  a URL to this customize form's help screen.  If null the help link
     *  is not displayed.
     */
    protected void renderDesignFormBodyBegin(PortletRenderRequest request,
                                             PrintWriter out,
                                             String formName,
                                             String title,
                                             String actionParam,
                                             String helpURL)
        throws IOException
    {
        ResourceBundle res = request.getProviderResource();

        // start container
        out.println("<CENTER>");
        out.println("<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH =\"90%\">");

        // Put Javascript to set button value
        // Needed so developers can set display value in appropriate language
        out.println("<SCRIPT LANGUAGE=\"JavaScript1.1\">");
        out.println("<!-- Comment out script for old browsers");
        out.println("function doSubmit(action) {");

        out.print("   document.");
        out.print(formName);
        out.print(".");
        out.print(actionParam);
        out.println(".value=action");

        out.print("   document.");
        out.print(formName);
        out.println(".submit()");
        
        out.println("}");
        out.println("//-->");
        out.println("</SCRIPT>");

        // draw title
        out.println("<TR><TD>");
        out.println("<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">");
        out.println("<TR>");
        out.println("<TD VALIGN=\"TOP\"><IMG SRC=\"/images/uiwizrul.gif\"></TD>");

        if (helpURL != null)
        {
            out.print("<TD WIDTH=\"90%\" BGCOLOR=\"#000066\" ROWSPAN=\"2\">");
            out.print("<FONT COLOR=\"#E0E0E0\" FACE=\"arial,helvetica\" ");
            out.print("SIZE=\"-1\"><B>");
            out.print(title);
            out.println("</B></FONT></TD>");

            out.print("<TD WIDTH=\"8%\" VALIGN=\"MIDDLE\" ALIGN=\"RIGHT\" ");
            out.print("BGCOLOR=\"#000066\" ROWSPAN=\"2\"> ");
            out.print("<A HREF=\"javascript:show_context_help('");
            out.print(helpURL);
            out.print("')\"><IMG SRC=\"/images/helps.gif\" ALT=\"Help\" ");
            out.println("BORDER=\"0\"></A></TD>");
        }
        else
        {
            out.print("<TD WIDTH=\"98%\" BGCOLOR=\"#000066\" ROWSPAN=\"2\">");
            out.print("<FONT COLOR=\"#E0E0E0\" FACE=\"arial,helvetica\" ");
            out.print("SIZE=\"-1\"><B>");
            out.print(title);
            out.println("</B></FONT></TD>");
        }

        out.println("<TD VALIGN=\"TOP\"><IMG SRC=\"/images/uiwizrur.gif\"></TD>");
        out.println("</TR>");
        out.println("<TR>");
        out.println("<TD BGCOLOR=\"#000066\"><IMG SRC=\"/images/red.gif\"></TD>");
        out.println("<TD BGCOLOR=\"#000066\"><IMG SRC=\"/images/red.gif\"></TD>");
        out.println("</TR>");
        out.println("</TABLE>");
        out.println("</TR></TD>");

        // draw header
        out.println("<TR><TD>");
        out.println("<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">");
        out.println("<TR>");
        out.println("<TD ROWSPAN=\"2\" VALIGN=\"TOP\"><IMG SRC=\"/images/compedit.gif\" VALIGN=\"TOP\" BORDER=\"0\"></TD>");
        out.println("<TD ALIGN=\"RIGHT\" VALIGN=\"TOP\">");
        out.println("<TABLE  BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"4\">");
        out.println("<TR>");

        // draw buttons
        if (request.getMode() == PortletRenderer.MODE_EDIT || request.getMode() == PortletRenderer.MODE_EDIT_DEFAULTS) {
            out.print("<TD BGCOLOR=\"#999999\"><INPUT TYPE=\"button\" ");
            out.print("NAME=\"p_request\" VALUE=\"");
            out.print(res.getString(ProviderBundle.APPLY_LABEL));
            out.println("\" onClick=\"javascript:doSubmit('APPLY')\"></TD>");

            out.print("<TD BGCOLOR=\"#999999\"><INPUT TYPE=\"button\" ");
            out.print("NAME=\"p_request\" VALUE=\"");
            out.print(res.getString(ProviderBundle.OK_LABEL));
            out.println("\" onClick=\"javascript:doSubmit('OK')\"></TD>");

            out.print("<TD BGCOLOR=\"#999999\"><INPUT TYPE=\"button\" ");
            out.print("NAME=\"p_request\" VALUE=\"");
            out.print(res.getString(ProviderBundle.CANCEL_LABEL));
            out.print("\" onClick=\"javascript:window.location='");
            out.print(request.getRenderContext().getBackURL());
            out.println("'\"></TD>");
        }
        else
        {
            out.print("<TD BGCOLOR=\"#999999\"><INPUT TYPE=\"button\" ");
            out.print("NAME=\"p_request\" VALUE=\"");
            out.print(res.getString(ProviderBundle.CLOSE_LABEL));
            out.print("\" onClick=\"javascript:window.location='");
            out.print(request.getRenderContext().getBackURL());
            out.println("'\"></TD>");
        }

        out.println("</TR>");
        out.println("</TABLE>");
        out.println("</TD>");
        out.println("</TR>");
        out.println("</TABLE>");
        out.println("</TD></TR>");

        // end container
        out.println("</TABLE>");
        out.println("</CENTER>");

        // start Table for design form/display
        out.println("<CENTER>");
        out.println("<TABLE  WIDTH=\"90%\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">");
        out.println("<TR><TD><BLOCKQUOTE><BLOCKQUOTE>");
        out.println("<TABLE>");
    }

    /**
     *  Utility method for completing the rendering of the Design form.
     *  This method should be
     *  used in conjunction with renderDesignFormHeader() to work correctly.
     *  This routine emits the proper html tags to close the FORM including
     *  the standard look/feel for the Form container.
     *
     *  @param request the portlet render request.
     *  @param writer the response writer used to output the customize form header.
     */
    protected void renderDesignFormBodyEnd(PortletRenderRequest request,
                                           PrintWriter out)
        throws IOException
    {
        // complete the form table
        out.println("</TABLE>");
        out.println("</BLOCKQUOTE></BLOCKQUOTE></TD></TR>");
        out.println("</TABLE>");
        out.println("</CENTER>");

        // now write the footer
        out.println("<CENTER>");
        out.println("<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"90%\">");
        out.println("<TR>");
        out.println("<TD><IMG src=\"/images/pobtrans.gif\" width=\"1\" height=\"8\"></TD>");
        out.println("</TR>");
        out.println("<TR>");
        out.println("<TD>");

        // 306 style "burger bun" begin
        out.println("<TABLE  BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">");
        out.println("<TR>");
        out.println("<TD><IMG SRC=\"/images/uiwizrll.gif\"></TD>");
        out.println("<TD WIDTH=\"98%\" BGCOLOR=\"#000066\"><IMG SRC=\"/images/red.gif\"></TD>");
        out.println("<TD><IMG SRC=\"/images/uiwizrlr.gif\"></TD>");
        // 306 style "burger bun" end
        
        out.println("</TR>");
        out.println("</TABLE>");
        out.println("</TD>");
        out.println("</TR>");
        out.println("</TABLE>");
        out.println("</CENTER>");
    }
}


