Methods Summary |
---|
public void | addMouseListener(javax.swing.JTable table)
table.getTableHeader().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
// check for double click
if (event.getClickCount() < 2) {
return;
}
// find column of click and
int tableColumn = table.columnAtPoint(event.getPoint());
// translate to table model index and sort
int modelColumn = table.convertColumnIndexToModel(tableColumn);
sort(modelColumn);
}
});
|
public int | getSortedColumnNumber()
return sortColumn;
|
public java.lang.String | getSortedDirection(int columnNumber)
if (getSortedColumnNumber() < 0) {
return NONE;
}
return _sortDirection;
|
public java.lang.Object | getValueAt(int r, int c)
if ((rows.size() > 0) && (r < rows.size())) {
return model.getValueAt(((Row) rows.get(r)).index, c);
}
return null;
|
public boolean | isCellEditable(int r, int c)
if ((rows.size() > 0) && (r < rows.size())) {
return model.isCellEditable(((Row) rows.get(r)).index, c);
}
return false;
|
protected void | refresh()
rows.clear();
for (int i = 0; i < model.getRowCount(); i++) {
rows.add(new Row(i));
}
if (dirty && (sortColumn > -1)) {
sort(sortColumn);
}
|
public void | removeRow(int rowNum)
int mappedRow = ((Row) rows.get(rowNum)).index;
super.removeRow(mappedRow);
|
public void | setModel(javax.swing.table.TableModel tm)
super.setModel(tm);
rows.ensureCapacity(model.getRowCount());
model.addTableModelListener(this);
sortColumn = -1;
dirty = true;
refresh();
|
public void | setValueAt(java.lang.Object aValue, int r, int c)
if ((rows.size() > 0) && (r < rows.size())) {
model.setValueAt(aValue, ((Row) rows.get(r)).index, c);
}
|
public void | sort(int columnNumber, java.lang.String direction)
_sortDirection = ASC;
dirty = true;
sort(columnNumber);
if (DESC.equals(direction)) {
sort(columnNumber);
_sortDirection = DESC;
}
|
protected void | sort(int c)
boolean sorted = (sortColumn == c);
sortColumn = c;
if (dirty || !sorted) {
Collections.sort(rows);
dirty = false;
} else {
Collections.reverse(rows);
}
fireTableDataChanged();
|
public void | tableChanged(javax.swing.event.TableModelEvent e)Implements the TableModelListener interface to receive
notifications of * changes to the table model. SortFilterModel needs
to receive events for adding and removing rows.
dirty = true;
refresh();
fireTableChanged(e);
|