package com.sun.sysid.panels;

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

public class FindSpecifyPanel extends WizardLeaf
{
  CheckboxGroup cgroup;
  Checkbox cb[] = new Checkbox[2];

  static String nameServerString;
	private String[] names = null;
  Boolean findAServer;
  Panel mainPanel = new Panel(new VerticalLayout());
	
  public FindSpecifyPanel()
    {
    }
	
  public FindSpecifyPanel(WizardState wizardState, String name)
    {
      super(wizardState, name);
    }
	
  public FindSpecifyPanel(WizardState wizardState)
    {
      super(wizardState, "FindSpecify");
    }
	
  public FindSpecifyPanel(String name, Route route, 
			  WizardTreeManager wizardManager)
    {
      super(name, route, wizardManager);
    }
	
  public void createUI()
    {
      WizardTreeManager wizardManager = getTreeManager();
      super.createUI();
      HeaderPanel headerPanel = getHeaderPanel();
      String heading = MsgCat.getString("com.sun.sysid.Sysid", "Name Server");
      if (headerPanel != null)
	headerPanel.setText(heading);
		
      mainPanel.add(new FlowLabel(nameServerString = MsgCat.getString("com.sun.sysid.Sysid", 
						   "nameServerString")), "1");
      mainPanel.add(new FlowLabel(MsgCat.getString("com.sun.sysid.Sysid", 
						   "Name server:")), "2");	
      names = new String[] {MsgCat.getString("com.sun.sysid.Sysid", "Find one"),
			MsgCat.getString("com.sun.sysid.Sysid", "Specify one")};
      cgroup = new CheckboxGroup();
		
      findAServer = 
	(Boolean) wizardManager.callServerObjectMethod(getRoute(),
					"getData",
					new String[] { "java.lang.String.class" },
				        new Object[] { "findAServer"});
		
      cgroup = new CheckboxGroup();
  		
      for(int i=0; i<names.length; i++)
	{
	  Panel p = new Panel(new FlowLayout(FlowLayout.LEFT));
	  cb[i] = new Checkbox(names[i], cgroup, false);
	  p.add(cb[i]);
	  if (i == (findAServer.booleanValue()?0:1))
	    cb[i].setState(true);
	  mainPanel.add(p, Integer.toString(i+3));
	}
      add(mainPanel, "Center");
		
    }

      public void consoleInteraction()
      {
        String promptString = MsgCat.getString("com.sun.sysid.Sysid", 
                                                 "cli_nameServerPrompt");
          String textString = MsgCat.getString("com.sun.sysid.Sysid", 
                                               "cli_nameServerDesc");
         nameServerString = MsgCat.getString("com.sun.sysid.Sysid", 
                                              "cli_nameServerString");
 
         
 
         int ret = TTYDisplay.queryValue(promptString, textString, 
                                    names,
                                    (findAServer.booleanValue())?0:1, nameServerString);
	 if (ret == 0)
	 {
	    findAServer = new Boolean(true);
	 }
	 else
	 {
	    findAServer = new Boolean(false);
	 }
     }

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

  public boolean isDisplayComplete()
    {
      WizardTreeManager wizardManager = getTreeManager();
      if (wizardManager.hasGUI())
      {
	 findAServer = new Boolean(cb[0].getState());
      }
      wizardManager.callServerObjectMethod(getRoute(), "setData",
					   new String[] { "java.lang.String.class", 
							    "java.lang.Object.class" },
					   new Object[] { "findAServer", findAServer});
      if (findAServer.booleanValue())
	{
	  if (Def.DEBUG) System.out.println("Name Server Method = Find One");
	  wizardManager.callServerObjectMethod(getRoute(), "setData",
					  new String[] { "java.lang.String.class", 
						       	  "java.lang.Object.class" },
					  new Object[] {"skipFindSvr", 
							  new Boolean(true)});
	}
      else
	{
	  if (Def.DEBUG) System.out.println("Name Server Method = Specify One");
	  wizardManager.callServerObjectMethod(getRoute(), "setData",
					  new String[] { "java.lang.String.class", 
							  "java.lang.Object.class" },
					       new Object[] {"skipFindSvr", 
							       new Boolean(false)});
	}
      return(true);
    }
	

  public void addRuntimeResources(Vector resourceVector)
    {
      super.addRuntimeResources(resourceVector);
      resourceVector.addElement(new String[] {null, 
				"com.sun.sysid.panels.FindSpecifyPanel"});
      resourceVector.addElement(new String[] {null, 
				"com.sun.sysid.SysidResources"});
      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"});
    }
}
