package com.sun.solarisinstall.panels;

import java.awt.*;
import java.util.*;
import com.sun.wizards.core.*;
import com.sun.wizards.awt.*;
import com.sun.solarisinstall.*;

/*
 *  This panel prompts user to insert a CD. 
 */
public class InsertCDPanel extends WizardLeaf 
{
  private transient Panel mainPanel = null;
  private transient Panel textPanel = null;
  private transient FlowLabel CDprompt = null;
  private transient FlowLabel OKprompt = null;
  private String nextLabel = null;

  public InsertCDPanel()
  {
  }

  public InsertCDPanel(WizardState wizardState, String name)
  {
    super(wizardState, name);
  }
    
  public InsertCDPanel(String name,Route route,WizardTreeManager wizardManager) 
  {
    super(name, route, wizardManager);
  }

  /**
   * This method creates the user interface.
   */
  public void createUI()
  {
    super.createUI();
    setLayout(new BorderLayout());

    WizardTreeManager wizardManager = getTreeManager();

    /*
     * Add the header.
     */
    String heading =  MsgCat.getString("com.sun.solarisinstall.SolarisInstall", 
                SolarisInstallResources.MSG_HDR_INSERTCD); 
    add(new HeaderPanel(heading, null, 38), "North");
   
    add(mainPanel = new Panel(new BorderLayout()));

    textPanel = new Panel(new VerticalLayout());
    mainPanel.add(textPanel, "Center");
   
    /*
     * Eject the CD if there is one. This is the only place the CD
     * is ejected in this class, which means other classes must eject
     * the cd if there is a mount failure, etc.
     */
    Route objectRoute = getRoute().getChildServerRoute("profileObject");
    wizardManager.callServerObjectMethod(
                         objectRoute.copy(),
                         "EjectCD",
                         null, null);

  }


  public void beginDisplay()
  {
    super.beginDisplay();
    WizardTreeManager wizardManager = getTreeManager();
    nextLabel = wizardManager.setButtonLabel("next",
                      MsgCat.getString("com.sun.solarisinstall.SolarisInstall", 
                      SolarisInstallResources.MSG_OK_SPACES));


    if (CDprompt != null) textPanel.remove(CDprompt);

    String CDtext =  MsgCat.getString("com.sun.solarisinstall.SolarisInstall", 
                SolarisInstallResources.MSG_PLEASE_INSERTCD); 

    CDprompt = new FlowLabel(CDtext);

    textPanel.add(CDprompt, "10");

    CDtext =  MsgCat.getString("com.sun.solarisinstall.SolarisInstall", 
                SolarisInstallResources.MSG_CLICK_OK ); 

    OKprompt = new FlowLabel(CDtext);
    textPanel.add(OKprompt, "30");


    /*
     * Change the label of the next button.
     */
    wizardManager.setButtonLabel( "next",
                MsgCat.getString("com.sun.solarisinstall.SolarisInstall",
                SolarisInstallResources.MSG_OK_SPACES));


   }

   public void consoleInteraction()
   {
      String CDtext =  
	MsgCat.getString("com.sun.solarisinstall.SolarisInstall", 
        SolarisInstallResources.MSG_PLEASE_INSERTCD); 

      TTYDisplay.showText( CDtext );
      TTYDisplay.queryValue(
	    MsgCat.getString(
	       "com.sun.solarisinstall.SolarisInstall", 
	       SolarisInstallResources.MSG_CLI_INSERT_CD),"");
   }

   public int getButtonMask()
   {
     return(BACK_BUTTON | NEXT_BUTTON | EXIT_BUTTON);
   }
    

  /**
   * Returns true if this panel is finished displaying.
   * This method can be used to verify user input.
   *
   * @return    true if the display of this panel is
   *            complete; false otherwise.
   */
  public boolean isDisplayComplete()
  {
    WizardTreeManager wizardManager = getTreeManager();
    wizardManager.setButtonLabel("next", nextLabel);
    return(true);
  }


  public void abortDisplay()
  {
    WizardTreeManager wizardManager = getTreeManager();

    wizardManager.setButtonLabel("next", nextLabel);
  }


  public Panel gettextPanel()
  {
    return(textPanel);
  }


  public FlowLabel getCDprompt()
  {
    return(CDprompt);
  }

  public void setCDprompt(FlowLabel flow)
  {
    CDprompt = flow;
  }

  public FlowLabel getOKprompt()
  {
    return(OKprompt);
  }

  public void setOKprompt(FlowLabel flow)
  {
    OKprompt = flow;
  }

   
   public void addRuntimeResources(Vector resourceVector)
   {
     super.addRuntimeResources(resourceVector);
     resourceVector.addElement(new String[] {null, "com.sun.solarisinstall.panels.InsertCDPanel"});
   }
}
