use of edu.cmu.tetrad.data.Variable in project tetrad by cmu-phil.
the class DataCellRenderer method checkValueAt.
/**
* @return true iff the given token is a legitimate value for the cell at
* (row, col) in the table.
*/
public boolean checkValueAt(String token, int col) {
if (col < getNumLeadingCols()) {
throw new IllegalArgumentException();
}
DataSet dataSet = getDataSet();
int dataCol = col - getNumLeadingCols();
if (dataCol < dataSet.getNumColumns()) {
Node variable = dataSet.getVariable(dataCol);
return ((Variable) variable).checkValue(token);
} else {
return true;
}
}
use of edu.cmu.tetrad.data.Variable in project tetrad by cmu-phil.
the class DataCellRenderer method clearSelected.
public void clearSelected() {
TabularDataTable model = (TabularDataTable) getModel();
DataSet dataSet = model.getDataSet();
if (!getRowSelectionAllowed()) {
int[] selectedCols = getSelectedColumns();
TableCellEditor editor = getCellEditor();
if (editor != null) {
editor.stopCellEditing();
}
for (int i = selectedCols.length - 1; i >= 0; i--) {
if (selectedCols[i] < getNumLeadingCols()) {
continue;
}
int dataCol = selectedCols[i] - getNumLeadingCols();
if (dataCol >= dataSet.getNumColumns()) {
continue;
}
Node variable = dataSet.getVariable(dataCol);
Object missingValue = ((Variable) variable).getMissingValueMarker();
for (int j = 0; j < dataSet.getNumRows(); j++) {
dataSet.setObject(j, dataCol, missingValue);
}
}
} else if (!getColumnSelectionAllowed()) {
int[] selectedRows = getSelectedRows();
TableCellEditor editor = getCellEditor();
if (editor != null) {
editor.stopCellEditing();
}
for (int i = getColumnCount() - 1; i >= 0; i--) {
if (i < getNumLeadingCols()) {
continue;
}
String colName = (String) (getValueAt(1, i));
if (colName == null) {
continue;
}
int dataCol = i - getNumLeadingCols();
Node variable = dataSet.getVariable(dataCol);
Object missingValue = ((Variable) variable).getMissingValueMarker();
for (int j = selectedRows.length - 1; j >= 0; j--) {
if (selectedRows[j] < 2) {
continue;
}
if (selectedRows[j] > dataSet.getNumRows() + 1) {
continue;
}
dataSet.setObject(selectedRows[j] - 2, dataCol, missingValue);
}
}
} else {
int[] selectedRows = getSelectedRows();
int[] selectedCols = getSelectedColumns();
TableCellEditor editor = getCellEditor();
if (editor != null) {
editor.stopCellEditing();
}
for (int i = selectedCols.length - 1; i >= 0; i--) {
if (selectedCols[i] < getNumLeadingCols()) {
continue;
}
int dataCol = selectedCols[i] - getNumLeadingCols();
if (dataCol >= dataSet.getNumColumns()) {
continue;
}
String colName = (String) (getValueAt(1, selectedCols[i]));
if (colName == null) {
continue;
}
Node variable = dataSet.getVariable(dataCol);
Object missingValue = ((Variable) variable).getMissingValueMarker();
for (int j = selectedRows.length - 1; j >= 0; j--) {
if (selectedRows[j] < 2) {
continue;
}
if (selectedRows[j] > dataSet.getNumRows() + 1) {
continue;
}
dataSet.setObject(selectedRows[j] - 2, dataCol, missingValue);
}
}
}
firePropertyChange("modelChanged", null, null);
model.fireTableDataChanged();
}
use of edu.cmu.tetrad.data.Variable in project tetrad by cmu-phil.
the class TabularDataTable method getValueAt.
/**
* @return the value at the given (row, col) coordinates of the table as an
* Object. If the variable for the col is a DiscreteVariable, the String
* value (as opposed to the integer index value) is extracted and returned.
* If the coordinates are out of range of the wrapped table model, 'null' is
* returned. Otherwise, the value stored in the wrapped table model at the
* given coordinates is returned.
*/
@Override
public Object getValueAt(int row, int col) {
int columnIndex = col - getNumLeadingCols();
int rowIndex = row - 2;
// else
if (col >= getNumLeadingCols() && col < dataSet.getNumColumns() + getNumLeadingCols()) {
Node variable = dataSet.getVariable(columnIndex);
if (row == 0) {
boolean discrete = variable instanceof DiscreteVariable;
return "C" + Integer.toString(columnIndex + 1) + (discrete ? "-T" : "");
} else if (row == 1) {
return dataSet.getVariable(columnIndex).getName();
} else if (rowIndex >= dataSet.getNumRows()) {
return null;
} else {
if (variable instanceof DiscreteVariable) {
((DiscreteVariable) variable).setCategoryNamesDisplayed(isCategoryNamesShown());
}
Object value = dataSet.getObject(rowIndex, columnIndex);
if (((Variable) variable).isMissingValue(value)) {
return "*";
} else {
return value;
}
}
} else if (col >= dataSet.getNumColumns() + getNumLeadingCols()) {
if (row == 0) {
return "C" + Integer.toString(columnIndex + 1);
}
}
return null;
}
use of edu.cmu.tetrad.data.Variable in project tetrad by cmu-phil.
the class TabularDataTable method isEmpty.
private boolean isEmpty(DataSet dataSet, int column) {
Node variable = dataSet.getVariable(column);
Object missingValue = ((Variable) variable).getMissingValueMarker();
for (int i = 0; i < dataSet.getNumRows(); i++) {
if (!(dataSet.getObject(i, column).equals(missingValue))) {
return false;
}
}
return true;
}
Aggregations