package transfer.ui;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTable;
import javax.swing.table.TableModel;
import transfer.AbstractFileTransfer;
import transfer.ui.bar.AbstractBar;
public class TransferJTable extends JTable
{
private static final long serialVersionUID = 2286953050024799374L;
public TransferJTable(TableModel model)
{
super(model);
getColumnModel().getColumn(0).setMaxWidth(30);
getColumnModel().getColumn(2).setMaxWidth(200);
getColumnModel().getColumn(3).setMaxWidth(200);
getColumnModel().getColumn(4).setMaxWidth(100);
getColumnModel().getColumn(6).setMaxWidth(300);
setDefaultRenderer(AbstractBar.class, new ProgressBarRenderer());
addMouseListener(new DoubleClickListener());
}
private class DoubleClickListener extends MouseAdapter
{
public void mouseClicked(MouseEvent event)
{
if (!getSelectionModel().isSelectionEmpty())
{
if (event.getClickCount() == 2)
{
handleDoubleClick();
}
}
}
private void handleDoubleClick()
{
TransferTableEntry tableEntry = (TransferTableEntry) getValueAt(
getSelectedRow(), 1);
AbstractFileTransfer transfer = tableEntry.getTransfer();
if (transfer.isFinished())
{
// TODO: open file
}
else
{
transfer.forkToChat();
}
}
}
}