FileDocCategorySizeDatePackage
GenericTableInfo.javaAPI DocGlassfish v2 API6156Fri May 04 22:34:56 BST 2007com.sun.enterprise.tools.common.ui

GenericTableInfo

public class GenericTableInfo extends Object
author
bnevins
version

Fields Summary
private int
numCols
private int
numRows
private String[]
data
private String[]
columnNames
private boolean[]
isEditable
Constructors Summary
public GenericTableInfo(int nc)

		numCols = nc;
		Reporter.assertIt(nc > 0); //NOI18N
		
		columnNames = new String[numCols];
		isEditable  = new boolean[numCols];
		
		for(int i = 0; i < numCols; i++)
		{
			columnNames[i] = "Column " + i;//NOI18N	// just to have a default...
			isEditable[i] = true;	// by default -- all cells are editable...
		}
	
public GenericTableInfo(int nr, int nc)

		numCols = nc;
		numRows = nr;
		// no columns -- bad!  no rows -- OK!
		Reporter.assertIt(nc > 0); //NOI18N
		Reporter.assertIt(nr >= 0); //NOI18N
		
		data = new String[numCols][numRows];
		columnNames = new String[numCols];
		isEditable  = new boolean[numCols];
		
		for(int i = 0; i < numCols; i++)
		{
			columnNames[i] = "Column " + i;//NOI18N	// just to have a default...
			isEditable[i] = true;	// by default -- all cells are editable...
		}
	
Methods Summary
private voidcheckColumnNumber(int col)

		if(col < 0 || col >= numCols)
			throw new  IllegalArgumentException("column number must be between 0 and " + (numCols - 1) + " -- attempted to use non-existant column # " + col);//NOI18N
	
private voidcheckRowNumber(int row)

		if(row < 0 || row >= numRows)
			throw new  IllegalArgumentException("Row number must be between 0 and " + (numRows - 1) + " -- attempted to use non-existant row # " + row);//NOI18N
	
public intgetColumnCount()

		return numCols;
	
public java.lang.StringgetColumnName(int col)

		checkColumnNumber(col);
		return columnNames[col];
	
public intgetRowCount()

		return numRows;
	
public java.lang.StringgetString(int row, int col)

		checkColumnNumber(col);
		checkRowNumber(row);
		//System.out.println("getString[col=" + col + "][r=" + row + "]: " + data[col][row]);//NOI18N
		return data[col][row];
	
public booleanisColumnEditable(int c)

 
	///	System.out.println("isColEditable for Column " + c + " --- " + isEditable[c]);//NOI18N
		checkColumnNumber(c);
		return isEditable[c];
	
public static voidmain(java.lang.String[] args)

	
	/////////////////////////////////////////////////

	    
	
		GenericTableInfo gti = new GenericTableInfo(2, 3);
		gti.setColumnName(0, "Col 0 here!");//NOI18N		
		gti.setColumnName(1, "Col 1 here!");//NOI18N
		
		for(int r = 0; r < 2; r++)
		{
			for(int c = 0; c < 3; c++)
			{
				gti.setString(r, c, "c" + c + "r" + r);//NOI18N
			}
		}
		System.out.println("" + gti);//NOI18N
	
public voidsetColumnName(int col, java.lang.String name)

		checkColumnNumber(col);
		columnNames[col] = name;
	
public voidsetColumnReadOnly(int c)

 
		checkColumnNumber(c);
		isEditable[c] = false;
	
public voidsetString(int row, int col, java.lang.String name)

		checkColumnNumber(col);
		checkRowNumber(row);
		
		data[col][row] = name;
	
public java.lang.StringtoString()

		String s = "";//NOI18N
		
		for(int c = 0; c < numCols; c++)
		{
			s += "Column Name " + c + ":  " + columnNames[c] + "\n";//NOI18N
		}
		
		for(int r = 0; r < numRows; r++)
		{
			for(int c = 0; c < numCols; c++)
			{
				s += "row " + r + ", col " + c + ":  " + data[c][r] + "\n";//NOI18N
			}
		}
		return s;