/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2005, by :
* Corporate:
* EADS Astrium SAS
* EADS CRC
* Individual:
* Claude Cazenave
*
* $Id: TableModelObjectInfo.java,v 1.1 2006/11/06 14:46:03 booba_skaya Exp $
*
*/
package simtools.ui;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javax.swing.table.DefaultTableModel;
import simtools.ui.JDialogObjectInfo.Info;
/**
* Class TableModelObjectInfo
* The table model for the JDialogObjectInfos.
*/
public class TableModelObjectInfo extends DefaultTableModel {
/**(<b>long</b>) serialVersionUID.*/
private static final long serialVersionUID = 4768777821796967246L;
/**(<b>int</b>) COLUMN_COUNT: The number of column.*/
private static final int COLUMN_COUNT = 2;
/**(<b>int</b>) COLUMN_COUNT: The number of column.*/
private static final String[] DEFAULT_COLUMN_NAMES = new String[]{"Name", "Value"};
/**(<b>int</b>) COLUMN_COUNT: The key to column names.*/
private static final String[] KEY_COLUMN_NAMES = new String[]{"objectInfoColumn0", "objectInfoColumn1"};
/**(<b>int</b>) NAME_COLUMN: the column index for the name.*/
protected static final int NAME_COLUMN = 0;
/**(<b>int</b>) VALUE_COLUMN: the column index for the value.*/
protected static final int VALUE_COLUMN = 1;
/**(<b>ArrayList</b>) infos: the info that are displayed in this table.*/
private ArrayList infos;
/**(<b>ResourceBundle</b>) resources: The resources.*/
private ResourceBundle resources;
/**
* Contructor TableModelObjectInfo
* <br><b>Summary:</b><br>
* The constructor of the class TableModelObjectInfo.
* @param infos The infos to be displayed in this table.
*/
public TableModelObjectInfo(ArrayList infos, ResourceBundle resources){
this.infos = infos;
this.resources = resources;
}
/* (non-Javadoc)
* @see javax.swing.table.DefaultTableModel#getColumnCount()
*/
public int getColumnCount() {
//There is 2 columns.
//A property name, and its value.
return COLUMN_COUNT;
}
/* (non-Javadoc)
* @see javax.swing.table.DefaultTableModel#getColumnName(int)
*/
public String getColumnName(int column) {
//The result of the method
String result = null;
if(resources != null){
result = (String) resources.getObject(KEY_COLUMN_NAMES[column]);
}
//if failed to found the value, take default one.
if(result == null){
result = DEFAULT_COLUMN_NAMES[column];
}
//return the result
return result;
}
/* (non-Javadoc)
* @see javax.swing.table.DefaultTableModel#getRowCount()
*/
public int getRowCount() {
int result = 0;
if(infos != null){
result = infos.size();
}
return result;
}
/* (non-Javadoc)
* @see javax.swing.table.DefaultTableModel#getValueAt(int, int)
*/
public Object getValueAt(int row, int column) {
//the result of the method.
Object result = null;
//retrieve the requested info.
Info info = (Info) infos.get(row);
//On column 0, return the name.
switch (column) {
case NAME_COLUMN:
result = info.name;
break;
case VALUE_COLUMN:
result = info.value;
break;
}
//return the result
return result;
}
/* (non-Javadoc)
* @see javax.swing.table.DefaultTableModel#isCellEditable(int, int)
*/
public boolean isCellEditable(int row, int column) {
//This table is not editable
return false;
}
}