import javax.swing.*;
import java.awt.*;
import java.util.*;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:
 * @author
 * @version 1.0
 */

public class GUI extends JFrame{
  BorderLayout borderLayout1 = new BorderLayout();
  JScrollPane jScrollPane1 = new JScrollPane();
  Vector columnHead = new Vector();
  JTable actionTable;
  Object table[][] = new Object[10][4];


  public GUI(Vector services)
  {
    try {
      jbInit(services);
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  private void jbInit(Vector services) throws Exception
  {
    createTable(services);
    this.getContentPane().setLayout(borderLayout1);
    columnHead.add("Service Name");
    columnHead.add("Host");
    columnHead.add("Port");
    columnHead.add("Monitored");

    actionTable = new JTable(table,columnHead.toArray());
    this.setTitle("Available Services");
    this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    jScrollPane1.getViewport().add(actionTable, null);
  }

  public GUI()
  {
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
  private void jbInit() throws Exception
  {
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  }

  public void createTable(Vector services)
  {
    StringTokenizer linha;
    for (int j=0; j< 10; j++)
    {
      table[j][0] = null;
      table[j][1] = null;
      table[j][2] = null;
      table[j][3] = null;

    }
    
    for(int i=0; i<services.size(); i++)
    {
      if ( services.elementAt(i) != null )
      {
        linha = new StringTokenizer((String)services.elementAt(i),"|");
        table[i][0] = linha.nextToken();
        table[i][1] = linha.nextToken();
        table[i][2] = linha.nextToken();
        table[i][3] = linha.nextToken();
      }
    }
  }
  
  public void refresh(Vector service)
  {
    createTable(service);
    
    for (int i=0; i<service.size(); i++)
      System.out.println(service.elementAt(i));
    System.out.println("-------------------------------------------------------------------");     
    
    actionTable = new JTable(table,columnHead.toArray());
    jScrollPane1.getViewport().add(actionTable, null);
  }
}