games = new TranslucentJTable(gamesModel,0.5f) {
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
if (c instanceof JComponent) {
JComponent jc = (JComponent) c;
Game game = (Game)gamesModel.getDataVector().get(row);
StringBuffer buffer = new StringBuffer();
buffer.append( "<html>" );
buffer.append("Description: ");
buffer.append( getLobbyGame(game.getType(),false).getGameDescription(game.getOptions()) );
buffer.append("<br>");
buffer.append("ID: ");
buffer.append(game.getId());
buffer.append("<br>");
buffer.append("WhosTurn: ");
buffer.append(game.getWhosTurn());
buffer.append("<br>");
buffer.append("Players: ");
buffer.append(game.getPlayers());
buffer.append("<br>");
// Iterator it = game.getPlayers().iterator();
// while (it.hasNext()) {
// buffer.append( ( (Player)it.next() ).getName() );
// buffer.append( "<br>" );
// }
jc.setToolTipText( buffer.toString() );
if (!(jc instanceof TranslucentJButton) && game.getWhosTurn()!=null && !"".equals(game.getWhosTurn()) && !game.getPlayers().contains(new Player(game.getWhosTurn(), 0))) {
jc.setBackground(Color.RED);
jc.setOpaque(true);
}
}
return c;
}
};
/*
{
public Component prepareRenderer(TableCellRenderer renderer,int row, int col) {
Component comp = super.prepareRenderer(renderer, row, col);
JComponent jcomp = (JComponent)comp;
if (comp == jcomp) {
jcomp.setToolTipText((String)getValueAt(row, col));
}
return comp;
}
};
*/
gamesModel.addTableModelListener(games);
games.getTableHeader().setReorderingAllowed(false);
games.getTableHeader().setOpaque(false);
games.getTableHeader().setDefaultRenderer(new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table,Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
if(c instanceof JLabel) {
//We get a better looking font if we do not use the default table font.
JLabel label = new JLabel(((JLabel)c).getText());
label.setOpaque(false);
label.setHorizontalAlignment(SwingConstants.CENTER);
if(column==table.getColumnCount()) {
label.setBorder(BorderFactory.createLineBorder(Color.BLACK ));
}
else {
label.setBorder(BorderFactory.createMatteBorder(1,0,1,1,Color.BLACK ));
}
return label;
}
return c;
}
});
games.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
//games.addColumn(new javax.swing.table.TableColumn(0, 32));
games.getColumnModel().getColumn(0).setMaxWidth(32);
games.getColumnModel().getColumn(2).setMaxWidth(50);
games.getColumnModel().getColumn(3).setMaxWidth(50);
games.getColumnModel().getColumn(4).setMaxWidth(50);
games.getColumnModel().getColumn(5).setMaxWidth(50);
games.getColumn("Action").setCellRenderer(new ButtonRenderer());
games.getColumn("Action").setCellEditor(new ButtonEditor());
String DELETE = "del";
int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
InputMap inputMap = games.getInputMap(condition);
ActionMap actionMap = games.getActionMap();
// DELETE is a String constant that for me was defined as "Delete"
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), DELETE);
actionMap.put(DELETE, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (playerType >= Player.PLAYER_MODERATOR) {
int[] selections = games.getSelectedRows();
Game[] gamesToRemove = new Game[selections.length];
int startedGameCount = 0;
for (int c = 0; c < selections.length; c++) {
Game game = gamesToRemove[c] = gamesModel.getGame(selections[c]);
if (game.getNumOfPlayers() == game.getMaxPlayers()) {
startedGameCount++;
}
}
if (startedGameCount > 0) {
int result = JOptionPane.showConfirmDialog(LobbyClientGUI.this,