dnl.utils.text.table.GuavaTableModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of j-text-utils Show documentation
Show all versions of j-text-utils Show documentation
Gives text representations of common data views such as tree and table.
The newest version!
package dnl.utils.text.table;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.swing.table.AbstractTableModel;
import com.google.common.collect.Lists;
import com.google.common.collect.Table;
/**
*
* @author Daniel Orr
*
*/
public class GuavaTableModel extends AbstractTableModel {
private Table guavaTable;
private List columnNames;
private int rowCount;
public GuavaTableModel(Table guavaTable) {
this.guavaTable = guavaTable;
this.columnNames = Lists.newArrayList(guavaTable.columnKeySet());
Collections.sort(this.columnNames);
Set rowIndexes = this.guavaTable.rowKeySet();
this.rowCount = Collections.max(rowIndexes)+1;
}
@Override
public String getColumnName(int column) {
return columnNames.get(column);
}
@Override
public int getRowCount() {
return rowCount;
}
@Override
public int getColumnCount() {
return columnNames.size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return guavaTable.get(rowIndex, columnNames.get(columnIndex));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy