package com.sun.sysid.panels;

import java.awt.*;
import java.util.*;
import com.sun.wizards.awt.*;
import com.sun.wizards.panels.*;
import com.sun.wizards.core.*;
import com.sun.sysid.core.*;

public class DomainNamePanel extends WizardLeaf
{
  
  static String domainNameString; 
  Panel mainPanel = new Panel(new VerticalLayout());
  TextField domainField;
  
  String domainName;
  
  public DomainNamePanel()
    {
    }
  
  public DomainNamePanel(WizardState wizardState, String name)
    {
      super(wizardState, name);
    }
  
  public DomainNamePanel(WizardState wizardState)
    {
      super(wizardState, "Domain Name");
    }
  
  public DomainNamePanel(String name, Route route, 
			 WizardTreeManager wizardManager)
    {
      super(name, route, wizardManager);
    }
  
  public void createUI()
    {
      WizardTreeManager wizardManager = getTreeManager();
      super.createUI();

      /*
       * Set the header text.
       */
      HeaderPanel headerPanel = getHeaderPanel();

      String heading = MsgCat.getString("com.sun.sysid.Sysid", "Domain Name");

      if(headerPanel != null) {
        headerPanel.setText(heading);
      }

      
      domainName = (String) wizardManager.callServerObjectMethod(getRoute(),
					"getData",
					new String[] { "java.lang.String.class" },
					new Object[] { "domainName" });
      domainField = new TextField(domainName, 32);
      mainPanel.add(new FlowLabel(domainNameString = MsgCat.getString("com.sun.sysid.Sysid",
					"domainNameString")), "1");
      mainPanel.add(new FlowLabel(),"2");
      mainPanel.add(new FlowLabel(),"3");
      mainPanel.add(new FlowLabel(),"4");
      mainPanel.add(new FlowLabel("<bold>" + 
				  MsgCat.getString("com.sun.sysid.Sysid", 
						   "Domain Name:")),"5");
      Panel p = new Panel(new FlowLayout(FlowLayout.LEFT));
      p.add(domainField);
      mainPanel.add(p,"6");
      add(mainPanel,"Center");
      domainField.requestFocus();
    }

  public void consoleInteraction()
     {
       TTYDisplay.showNewline();
       String promptString =  MsgCat.getString("com.sun.sysid.Sysid", 
                                               "cli_domainPromptString");
       domainNameString = MsgCat.getString("com.sun.sysid.Sysid", "cli_domainNameString");
       String result = TTYDisplay.queryValue(promptString, domainName, domainNameString);
       domainField.setText( result );
     }
 

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

  public void beginDisplay() 
    {
      super.beginDisplay();
      if (domainField != null)
	domainField.requestFocus();
    }
  public boolean isDisplayComplete()
    {
      WizardTreeManager wizardManager = getTreeManager();
      domainName = domainField.getText();
      wizardManager.callServerObjectMethod(getRoute(), "setData",
					   new String[] { "java.lang.String.class",
							    "java.lang.Object.class" },
					   new Object[] { "domainName", domainName });
      return(true);
    }
  
  public void addRuntimeResources(Vector resourceVector)
    {
      super.addRuntimeResources(resourceVector);
      resourceVector.addElement(new String[] {null, 
				"com.sun.sysid.panels.DomainNamePanel"});
      resourceVector.addElement(new String[] {null, 
				"com.sun.sysid.SysidResources"});
      resourceVector.addElement(new String[] {null, 
				"com.sun.sysid.core.PanelServices"});
      resourceVector.addElement(new String[] {null, 
				"com.sun.wizards.awt.InsetsPanel"});
      resourceVector.addElement(new String[] {null, 
				"com.sun.wizards.awt.FullWidthPanel"});
      resourceVector.addElement(new String[] {null, 
				"com.sun.wizards.awt.FlowLabel"});
      resourceVector.addElement(new String[] {null, 
				"com.sun.wizards.awt.VerticalLayout"});
      resourceVector.addElement(new String[] {null,
                        "com.sun.wizards.awt.Separator"});
    }
}
