package syn3d.ui;
import simtools.data.DataInfo;
import simtools.data.DataSource;
import simtools.ui.SourceTree;
import syn3d.data.PropertyData;
import syn3d.data.SceneGraphDoubleData;
import syn3d.data.SceneGraphFloatData;
/**
* Special kind of table dedicated to manage boolean attributes (ex visibility...)
* @author ogor
*/
public class PropertyBooleanTableModel extends SceneGraphDataTableModel{
public PropertyBooleanTableModel(SourceTree sourceTree, PropertyData dcopy){
super(sourceTree,dcopy);
}
/* (non-Javadoc)
* @see jsynoptic3d.ui.SceneGraphDataUI#getName(int)
*/
public String getName(int index) {
return ((PropertyData)dataCopy).getName(index);
}
public Class getColumnClass(int columnIndex){
if ((columnIndex==1)||(columnIndex==2)) {
return Boolean.class;
}
return super.getColumnClass(columnIndex);
}
public Object getValueAt(int rowIndex, int columnIndex) {
switch(columnIndex){
case 0:
return getName(rowIndex);
case 1:
return getBooleanValue(rowIndex);
case 2:
return Boolean.valueOf(dataCopy.getDataSource(rowIndex)!=null);
case 3:
DataSource ds=dataCopy.getDataSource(rowIndex);
if(ds==null){
return "";
}
return DataInfo.getLabel(ds);
default:
throw new IllegalArgumentException();
}
}
/**
* A default implementation to handle SceneGraphFloatData
* @param index=rowIndex
* @param aValue=object displayed in the table
*/
public void setValue(int index, Object aValue){
if(dataCopy instanceof SceneGraphFloatData){
SceneGraphFloatData df=(SceneGraphFloatData)dataCopy;
df.setValue(index, ((aValue.equals(Boolean.TRUE))? (float)1.0 : (float)0.0));
}
else if(dataCopy instanceof SceneGraphDoubleData){
SceneGraphDoubleData dd =(SceneGraphDoubleData)dataCopy;
dd.setValue(index, ((aValue.equals(Boolean.TRUE))? (double)1.0 : (double)0.0));
}
}
/**
* A default implementation to handle SceneGraphFloatData
* @param index=rowIndex
* @return object to be displayed in the table
*/
public Object getBooleanValue(int index){
if(dataCopy instanceof SceneGraphFloatData){
SceneGraphFloatData df=(SceneGraphFloatData)dataCopy;
return (df.getValue(index)==0)? Boolean.FALSE : Boolean.TRUE;
}
else if(dataCopy instanceof SceneGraphDoubleData){
SceneGraphDoubleData dd =(SceneGraphDoubleData)dataCopy;
return (dd.getValue(index)==0)? Boolean.FALSE : Boolean.TRUE;
}
return null;
}
}