UI: fixed error and improved stability on lobby's table selection/click;
- /*
- * TablesPanel.java
- *
- * Created on 15-Dec-2009, 10:54:01 PM
- */
package mage.client.table;
import mage.cards.decks.importer.DeckImporterUtil;
openTableAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
- int modelRow = Integer.valueOf(e.getActionCommand());
+ // tableUUID;gameUUID
+ String searchID = e.getActionCommand();
+ int modelRow = tableModel.findRowByTableAndGameInfo(searchID);
+ if (modelRow == -1) {
+ return;
+ }
UUID tableId = (UUID) tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 3);
UUID gameId = (UUID) tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 2);
String action = (String) tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN);
closedTableAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
- int modelRow = Integer.valueOf(e.getActionCommand());
+ // tableUUID;gameUUID
+ String searchID = e.getActionCommand();
+ int modelRow = tableModel.findRowByTableAndGameInfo(searchID);
+ if (modelRow == -1) {
+ return;
+ }
String action = (String) matchesModel.getValueAt(modelRow, MatchesTableModel.COLUMN_ACTION);
switch (action) {
case "Replay":
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
- if (e.getClickCount() == 2) {
- int selRow = table.getSelectedRow();
- if (selRow != -1) {
- int dataRow = table.convertRowIndexToModel(selRow);
- if (dataRow != -1) {
- action.actionPerformed(new ActionEvent(e.getSource(), e.getID(), "" + dataRow));
- }
- }
+ int row = table.getSelectedRow();
+ if (e.getClickCount() == 2 && row != -1) {
+ action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, tableModel.findTableAndGameInfoByRow(row)));
}
}
});
@@ -1393,6 +1393,28 @@ class TableTableModel extends AbstractTableModel {
this.fireTableDataChanged();
}
+ public String getTableAndGameInfo(int row) {
+ return this.tables[row].getTableId().toString() + ";" + (!tables[row].getGames().isEmpty() ? tables[row].getGames().get(0) : null).toString();
+ }
+
+ public String findTableAndGameInfoByRow(int row) {
+ if (row >= 0 && this.tables.length < row) {
+ return getTableAndGameInfo(row);
+ } else {
+ return null;
+ }
+ }
+
+ public int findRowByTableAndGameInfo(String tableAndGame) {
+ for (int i = 0; i < this.tables.length; i++) {
+ String rowID = this.tables[i].getTableId().toString() + ";" + (!tables[i].getGames().isEmpty() ? tables[i].getGames().get(0) : null).toString();
+ if (tableAndGame.equals(rowID)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
public String getSkillLevelAsCode(SkillLevel skill, boolean asRegExp) {
String res;
switch (skill) {
