/*
 * COPYRIGHT (c) 1998-1999 Jan-Henrik Haukeland, http://www.tildeslash.com/
 */

package ts.biff;

import java.awt.event.*;
import java.beans.*;
import java.util.Vector;
import java.awt.Component;

import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;

import ts.ui.TsTable;

/**
 * A JTable for viewing mail messages
 * 
 * @author  Jan-Henrik Haukeland
 * @version $Id: View.java,v 1.7 2001/08/13 12:48:28 hauk Exp $
 */
public class View extends TsTable
{

  public View()
  {
    super();
    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    setEditable(false);
    setCellSelectionEnabled(false);
    setColumnSelectionAllowed(false);
    setRowSelectionAllowed(true);
  }


  public void terminate() {
    myTableModel= null;
    myCellMask= null;
    myCallBack= null;
  }


  /**
   * Returns an int array with columns widths
   * @return an int array with current column widths
   */
  public int[] getColumnWidths() 
  {
    TableColumn column;
    int columns= getColumnCount();
    int[] i= new int[columns];
    
    for ( int j = 0; j < columns; j++ ) {
      column = getColumnModel().getColumn(j);
      i[j]= column.getPreferredWidth();
    }
    
    return i;
  }



  /**
   * Set prefered table columns widths. 
   * @param w an array with prefered column widths
   */
  public void setColumnWidths(int[] w) 
  {
    if ( w == null || w.length == 0 ) 
	return;

    TableColumn column;
    int columns= getColumnCount();
    int wl= w.length;

    for ( int i= 0; i < columns; i++ ) {
      if ( i > wl ) break;
      try {
	column = getColumnModel().getColumn(i);
	column.setPreferredWidth(w[i]);
      }	catch (Exception e) { 
	return; 
      }
    }
  }


}











