mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
Fixed broken tables selection in lobby
This commit is contained in:
parent
66aab73cfa
commit
253c580639
6 changed files with 539 additions and 478 deletions
|
@ -0,0 +1,145 @@
|
|||
package mage.client.table;
|
||||
|
||||
import mage.remote.MageRemoteException;
|
||||
import mage.view.MatchView;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MatchesTableModel extends AbstractTableModel {
|
||||
|
||||
private final String[] columnNames = new String[]{"Deck Type", "Players", "Game Type", "Rating", "Result", "Duration", "Start Time", "End Time", "Action"};
|
||||
public static final int COLUMN_DURATION = 5;
|
||||
public static final int COLUMN_START = 6;
|
||||
public static final int COLUMN_END = 7;
|
||||
public static final int COLUMN_ACTION = 8; // column the action is located (starting with 0)
|
||||
|
||||
private MatchView[] matches = new MatchView[0];
|
||||
|
||||
public void loadData(Collection<MatchView> matches) throws MageRemoteException {
|
||||
this.matches = matches.toArray(new MatchView[0]);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
MatchesTableModel() {
|
||||
}
|
||||
|
||||
|
||||
public String getTableAndGameInfo(int row) {
|
||||
return this.matches[row].getTableId().toString() + ";" + (!matches[row].getGames().isEmpty() ? matches[row].getGames().get(0).toString() : "null");
|
||||
}
|
||||
|
||||
public String findTableAndGameInfoByRow(int row) {
|
||||
if (row >= 0 && row < this.matches.length) {
|
||||
return getTableAndGameInfo(row);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int findRowByTableAndGameInfo(String tableAndGame) {
|
||||
for (int i = 0; i < this.matches.length; i++) {
|
||||
String rowID = this.matches[i].getTableId().toString() + ";" + (!this.matches[i].getGames().isEmpty() ? this.matches[i].getGames().get(0).toString() : "null");
|
||||
if (tableAndGame.equals(rowID)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return matches.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int arg0, int arg1) {
|
||||
switch (arg1) {
|
||||
case 0:
|
||||
return matches[arg0].getDeckType();
|
||||
case 1:
|
||||
return matches[arg0].getPlayers();
|
||||
case 2:
|
||||
return matches[arg0].getGameType();
|
||||
case 3:
|
||||
return matches[arg0].isRated() ? TablesTableModel.RATED_VALUE_YES : TablesTableModel.RATED_VALUE_NO;
|
||||
case 4:
|
||||
return matches[arg0].getResult();
|
||||
case 5:
|
||||
if (matches[arg0].getEndTime() != null) {
|
||||
return matches[arg0].getEndTime().getTime() - matches[arg0].getStartTime().getTime() + new Date().getTime();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
case 6:
|
||||
return matches[arg0].getStartTime();
|
||||
case 7:
|
||||
return matches[arg0].getEndTime();
|
||||
case 8:
|
||||
if (matches[arg0].isTournament()) {
|
||||
return "Show";
|
||||
} else if (matches[arg0].isReplayAvailable()) {
|
||||
return "Replay";
|
||||
} else {
|
||||
return "None";
|
||||
}
|
||||
case 9:
|
||||
return matches[arg0].getGames();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public java.util.List<UUID> getListofGames(int row) {
|
||||
return matches[row].getGames();
|
||||
}
|
||||
|
||||
public boolean isTournament(int row) {
|
||||
return matches[row].isTournament();
|
||||
}
|
||||
|
||||
public UUID getMatchId(int row) {
|
||||
return matches[row].getMatchId();
|
||||
}
|
||||
|
||||
public UUID getTableId(int row) {
|
||||
return matches[row].getTableId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int columnIndex) {
|
||||
String colName = "";
|
||||
|
||||
if (columnIndex <= getColumnCount()) {
|
||||
colName = columnNames[columnIndex];
|
||||
}
|
||||
|
||||
return colName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case COLUMN_DURATION:
|
||||
return Long.class;
|
||||
case COLUMN_START:
|
||||
return Date.class;
|
||||
case COLUMN_END:
|
||||
return Date.class;
|
||||
default:
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return columnIndex == COLUMN_ACTION;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +1,21 @@
|
|||
package mage.client.table;
|
||||
|
||||
package mage.client.util;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
|
||||
import java.awt.Component;
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import javax.swing.AbstractCellEditor;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ButtonColumn extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener, MouseListener {
|
||||
public class TablesButtonColumn extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener, MouseListener {
|
||||
|
||||
private final JTable table;
|
||||
private final Action action;
|
||||
|
@ -28,7 +24,7 @@ public class ButtonColumn extends AbstractCellEditor implements TableCellRendere
|
|||
private String text;
|
||||
private boolean isButtonColumnEditor;
|
||||
|
||||
public ButtonColumn(JTable table, Action action, int column) {
|
||||
public TablesButtonColumn(JTable table, Action action, int column) {
|
||||
super();
|
||||
this.table = table;
|
||||
this.action = action;
|
||||
|
@ -88,7 +84,7 @@ public class ButtonColumn extends AbstractCellEditor implements TableCellRendere
|
|||
if (table.getRowCount() > 0 && table.getRowCount() >= table.getEditingRow() && table.getEditingRow() >= 0) {
|
||||
int row = table.convertRowIndexToModel(table.getEditingRow());
|
||||
fireEditingStopped();
|
||||
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, String.valueOf(row));
|
||||
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, TablesUtil.getSearchIdFromTable(table, row));
|
||||
action.actionPerformed(event);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,10 @@ import mage.client.SessionHandler;
|
|||
import mage.client.chat.ChatPanelBasic;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.dialog.*;
|
||||
import mage.client.util.*;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.IgnoreList;
|
||||
import mage.client.util.MageTableRowSorter;
|
||||
import mage.client.util.URLHandler;
|
||||
import mage.client.util.gui.GuiDisplayUtil;
|
||||
import mage.client.util.gui.TableUtil;
|
||||
import mage.constants.*;
|
||||
|
@ -25,7 +28,6 @@ import org.ocpsoft.prettytime.units.JustNow;
|
|||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import java.awt.*;
|
||||
|
@ -52,7 +54,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
private static final Logger LOGGER = Logger.getLogger(TablesPanel.class);
|
||||
private static final int[] DEFAULT_COLUMNS_WIDTH = {35, 150, 120, 180, 80, 120, 80, 60, 40, 40, 60};
|
||||
|
||||
private final TableTableModel tableModel;
|
||||
private final TablesTableModel tableModel;
|
||||
private final MatchesTableModel matchesModel;
|
||||
private UUID roomId;
|
||||
private UpdateTablesTask updateTablesTask;
|
||||
|
@ -67,8 +69,8 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
private final MageTableRowSorter activeTablesSorter;
|
||||
private final MageTableRowSorter completedTablesSorter;
|
||||
|
||||
private final ButtonColumn actionButton1;
|
||||
private final ButtonColumn actionButton2;
|
||||
private final TablesButtonColumn actionButton1;
|
||||
private final TablesButtonColumn actionButton2;
|
||||
|
||||
final JToggleButton[] filterButtons;
|
||||
|
||||
|
@ -161,7 +163,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
*/
|
||||
public TablesPanel() {
|
||||
|
||||
tableModel = new TableTableModel();
|
||||
tableModel = new TablesTableModel();
|
||||
matchesModel = new MatchesTableModel();
|
||||
gameChooser = new GameChooser();
|
||||
|
||||
|
@ -179,12 +181,12 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
tableTables.setRowSorter(activeTablesSorter);
|
||||
|
||||
// time ago
|
||||
tableTables.getColumnModel().getColumn(TableTableModel.COLUMN_CREATED).setCellRenderer(timeAgoCellRenderer);
|
||||
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_CREATED).setCellRenderer(timeAgoCellRenderer);
|
||||
// skill level
|
||||
tableTables.getColumnModel().getColumn(TableTableModel.COLUMN_SKILL).setCellRenderer(skillCellRenderer);
|
||||
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_SKILL).setCellRenderer(skillCellRenderer);
|
||||
|
||||
/* date sorter (not need, default is good - see getColumnClass)
|
||||
activeTablesSorter.setComparator(TableTableModel.COLUMN_CREATED, new Comparator<Date>() {
|
||||
activeTablesSorter.setComparator(TablesTableModel.COLUMN_CREATED, new Comparator<Date>() {
|
||||
@Override
|
||||
public int compare(Date v1, Date v2) {
|
||||
return v1.compareTo(v2);
|
||||
|
@ -194,7 +196,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
|
||||
// default sort by created date (last games from above)
|
||||
ArrayList list = new ArrayList();
|
||||
list.add(new RowSorter.SortKey(TableTableModel.COLUMN_CREATED, SortOrder.DESCENDING));
|
||||
list.add(new RowSorter.SortKey(TablesTableModel.COLUMN_CREATED, SortOrder.DESCENDING));
|
||||
activeTablesSorter.setSortKeys(list);
|
||||
|
||||
TableUtil.setColumnWidthAndOrder(tableTables, DEFAULT_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_ORDER);
|
||||
|
@ -239,19 +241,18 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
openTableAction = new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// tableUUID;gameUUID
|
||||
String searchID = e.getActionCommand();
|
||||
int modelRow = tableModel.findRowByTableAndGameInfo(searchID);
|
||||
int modelRow = TablesUtil.findTableRowFromSearchId(tableModel, 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);
|
||||
String deckType = (String) tableModel.getValueAt(modelRow, TableTableModel.COLUMN_DECK_TYPE);
|
||||
boolean isTournament = (Boolean) tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 1);
|
||||
String owner = (String) tableModel.getValueAt(modelRow, TableTableModel.COLUMN_OWNER);
|
||||
String pwdColumn = (String) tableModel.getValueAt(modelRow, TableTableModel.COLUMN_PASSWORD);
|
||||
UUID tableId = (UUID) tableModel.getValueAt(modelRow, TablesTableModel.ACTION_COLUMN + 3);
|
||||
UUID gameId = (UUID) tableModel.getValueAt(modelRow, TablesTableModel.ACTION_COLUMN + 2);
|
||||
String action = (String) tableModel.getValueAt(modelRow, TablesTableModel.ACTION_COLUMN);
|
||||
String deckType = (String) tableModel.getValueAt(modelRow, TablesTableModel.COLUMN_DECK_TYPE);
|
||||
boolean isTournament = (Boolean) tableModel.getValueAt(modelRow, TablesTableModel.ACTION_COLUMN + 1);
|
||||
String owner = (String) tableModel.getValueAt(modelRow, TablesTableModel.COLUMN_OWNER);
|
||||
String pwdColumn = (String) tableModel.getValueAt(modelRow, TablesTableModel.COLUMN_PASSWORD);
|
||||
switch (action) {
|
||||
case "Join":
|
||||
if (owner.equals(SessionHandler.getUserName()) || owner.startsWith(SessionHandler.getUserName() + ',')) {
|
||||
|
@ -278,7 +279,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
if (isTournament) {
|
||||
LOGGER.info("Joining tournament " + tableId);
|
||||
if (deckType.startsWith("Limited")) {
|
||||
if (TableTableModel.PASSWORD_VALUE_YES.equals(pwdColumn)) {
|
||||
if (TablesTableModel.PASSWORD_VALUE_YES.equals(pwdColumn)) {
|
||||
joinTableDialog.showDialog(roomId, tableId, true, deckType.startsWith("Limited"));
|
||||
} else {
|
||||
SessionHandler.joinTournamentTable(roomId, tableId, SessionHandler.getUserName(), PlayerType.HUMAN, 1, null, "");
|
||||
|
@ -321,9 +322,8 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
closedTableAction = new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// tableUUID;gameUUID
|
||||
String searchID = e.getActionCommand();
|
||||
int modelRow = tableModel.findRowByTableAndGameInfo(searchID);
|
||||
int modelRow = TablesUtil.findTableRowFromSearchId(matchesModel, searchID);
|
||||
if (modelRow == -1) {
|
||||
return;
|
||||
}
|
||||
|
@ -351,8 +351,8 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
};
|
||||
|
||||
// !!!! adds action buttons to the table panel (don't delete this)
|
||||
actionButton1 = new ButtonColumn(tableTables, openTableAction, tableTables.convertColumnIndexToView(TableTableModel.ACTION_COLUMN));
|
||||
actionButton2 = new ButtonColumn(tableCompleted, closedTableAction, tableCompleted.convertColumnIndexToView(MatchesTableModel.COLUMN_ACTION));
|
||||
actionButton1 = new TablesButtonColumn(tableTables, openTableAction, tableTables.convertColumnIndexToView(TablesTableModel.ACTION_COLUMN));
|
||||
actionButton2 = new TablesButtonColumn(tableCompleted, closedTableAction, tableCompleted.convertColumnIndexToView(MatchesTableModel.COLUMN_ACTION));
|
||||
// !!!!
|
||||
addTableDoubleClickListener(tableTables, openTableAction);
|
||||
addTableDoubleClickListener(tableCompleted, closedTableAction);
|
||||
|
@ -364,7 +364,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
public void mouseClicked(MouseEvent e) {
|
||||
int row = table.getSelectedRow();
|
||||
if (e.getClickCount() == 2 && row != -1) {
|
||||
action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, tableModel.findTableAndGameInfoByRow(row)));
|
||||
action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, TablesUtil.getSearchIdFromTable(table, row)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -608,87 +608,87 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
// state
|
||||
java.util.List<RowFilter<Object, Object>> stateFilterList = new ArrayList<>();
|
||||
if (btnStateWaiting.isSelected()) {
|
||||
stateFilterList.add(RowFilter.regexFilter("Waiting", TableTableModel.COLUMN_STATUS));
|
||||
stateFilterList.add(RowFilter.regexFilter("Waiting", TablesTableModel.COLUMN_STATUS));
|
||||
}
|
||||
if (btnStateActive.isSelected()) {
|
||||
stateFilterList.add(RowFilter.regexFilter("Dueling|Constructing|Drafting|Sideboard", TableTableModel.COLUMN_STATUS));
|
||||
stateFilterList.add(RowFilter.regexFilter("Dueling|Constructing|Drafting|Sideboard", TablesTableModel.COLUMN_STATUS));
|
||||
}
|
||||
|
||||
// type
|
||||
java.util.List<RowFilter<Object, Object>> typeFilterList = new ArrayList<>();
|
||||
if (btnTypeMatch.isSelected()) {
|
||||
typeFilterList.add(RowFilter.regexFilter("Two|Commander|Free|Tiny|Momir", TableTableModel.COLUMN_GAME_TYPE));
|
||||
typeFilterList.add(RowFilter.regexFilter("Two|Commander|Free|Tiny|Momir", TablesTableModel.COLUMN_GAME_TYPE));
|
||||
}
|
||||
if (btnTypeTourneyConstructed.isSelected()) {
|
||||
typeFilterList.add(RowFilter.regexFilter("Constructed", TableTableModel.COLUMN_GAME_TYPE));
|
||||
typeFilterList.add(RowFilter.regexFilter("Constructed", TablesTableModel.COLUMN_GAME_TYPE));
|
||||
}
|
||||
if (btnTypeTourneyLimited.isSelected()) {
|
||||
typeFilterList.add(RowFilter.regexFilter("Booster|Sealed", TableTableModel.COLUMN_GAME_TYPE));
|
||||
typeFilterList.add(RowFilter.regexFilter("Booster|Sealed", TablesTableModel.COLUMN_GAME_TYPE));
|
||||
}
|
||||
|
||||
// format
|
||||
java.util.List<RowFilter<Object, Object>> formatFilterList = new ArrayList<>();
|
||||
if (btnFormatBlock.isSelected()) {
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed.*Block", TableTableModel.COLUMN_DECK_TYPE));
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed.*Block", TablesTableModel.COLUMN_DECK_TYPE));
|
||||
}
|
||||
if (btnFormatStandard.isSelected()) {
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed - Standard", TableTableModel.COLUMN_DECK_TYPE));
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed - Standard", TablesTableModel.COLUMN_DECK_TYPE));
|
||||
}
|
||||
if (btnFormatModern.isSelected()) {
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed - Modern", TableTableModel.COLUMN_DECK_TYPE));
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed - Modern", TablesTableModel.COLUMN_DECK_TYPE));
|
||||
}
|
||||
if (btnFormatLegacy.isSelected()) {
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed - Legacy", TableTableModel.COLUMN_DECK_TYPE));
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed - Legacy", TablesTableModel.COLUMN_DECK_TYPE));
|
||||
}
|
||||
if (btnFormatVintage.isSelected()) {
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed - Vintage", TableTableModel.COLUMN_DECK_TYPE));
|
||||
formatFilterList.add(RowFilter.regexFilter("^Constructed - Vintage", TablesTableModel.COLUMN_DECK_TYPE));
|
||||
}
|
||||
if (btnFormatCommander.isSelected()) {
|
||||
formatFilterList.add(RowFilter.regexFilter("^Commander|^Duel Commander|^Penny Dreadful Commander|^Freeform Commander|^MTGO 1v1 Commander|^Duel Brawl|^Brawl", TableTableModel.COLUMN_DECK_TYPE));
|
||||
formatFilterList.add(RowFilter.regexFilter("^Commander|^Duel Commander|^Penny Dreadful Commander|^Freeform Commander|^MTGO 1v1 Commander|^Duel Brawl|^Brawl", TablesTableModel.COLUMN_DECK_TYPE));
|
||||
}
|
||||
if (btnFormatTinyLeader.isSelected()) {
|
||||
formatFilterList.add(RowFilter.regexFilter("^Tiny", TableTableModel.COLUMN_DECK_TYPE));
|
||||
formatFilterList.add(RowFilter.regexFilter("^Tiny", TablesTableModel.COLUMN_DECK_TYPE));
|
||||
}
|
||||
if (btnFormatLimited.isSelected()) {
|
||||
formatFilterList.add(RowFilter.regexFilter("^Limited", TableTableModel.COLUMN_DECK_TYPE));
|
||||
formatFilterList.add(RowFilter.regexFilter("^Limited", TablesTableModel.COLUMN_DECK_TYPE));
|
||||
}
|
||||
if (btnFormatOther.isSelected()) {
|
||||
formatFilterList.add(RowFilter.regexFilter("^Momir Basic|^Constructed - Pauper|^Constructed - Frontier|^Constructed - Extended|^Constructed - Eternal|^Constructed - Historical|^Constructed - Super|^Constructed - Freeform|^Australian Highlander|^Canadian Highlander|^Constructed - Old", TableTableModel.COLUMN_DECK_TYPE));
|
||||
formatFilterList.add(RowFilter.regexFilter("^Momir Basic|^Constructed - Pauper|^Constructed - Frontier|^Constructed - Extended|^Constructed - Eternal|^Constructed - Historical|^Constructed - Super|^Constructed - Freeform|^Australian Highlander|^Canadian Highlander|^Constructed - Old", TablesTableModel.COLUMN_DECK_TYPE));
|
||||
}
|
||||
|
||||
// skill
|
||||
java.util.List<RowFilter<Object, Object>> skillFilterList = new ArrayList<>();
|
||||
if (btnSkillBeginner.isSelected()) {
|
||||
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.BEGINNER, true), TableTableModel.COLUMN_SKILL));
|
||||
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.BEGINNER, true), TablesTableModel.COLUMN_SKILL));
|
||||
}
|
||||
if (btnSkillCasual.isSelected()) {
|
||||
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.CASUAL, true), TableTableModel.COLUMN_SKILL));
|
||||
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.CASUAL, true), TablesTableModel.COLUMN_SKILL));
|
||||
}
|
||||
if (btnSkillSerious.isSelected()) {
|
||||
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.SERIOUS, true), TableTableModel.COLUMN_SKILL));
|
||||
skillFilterList.add(RowFilter.regexFilter(this.tableModel.getSkillLevelAsCode(SkillLevel.SERIOUS, true), TablesTableModel.COLUMN_SKILL));
|
||||
}
|
||||
|
||||
String ratedMark = TableTableModel.RATED_VALUE_YES;
|
||||
String ratedMark = TablesTableModel.RATED_VALUE_YES;
|
||||
java.util.List<RowFilter<Object, Object>> ratingFilterList = new ArrayList<>();
|
||||
if (btnRated.isSelected()) {
|
||||
// yes word
|
||||
ratingFilterList.add(RowFilter.regexFilter("^" + ratedMark, TableTableModel.COLUMN_RATING));
|
||||
ratingFilterList.add(RowFilter.regexFilter("^" + ratedMark, TablesTableModel.COLUMN_RATING));
|
||||
}
|
||||
if (btnUnrated.isSelected()) {
|
||||
// not yes word, see https://stackoverflow.com/a/406408/1276632
|
||||
ratingFilterList.add(RowFilter.regexFilter("^((?!" + ratedMark + ").)*$", TableTableModel.COLUMN_RATING));
|
||||
ratingFilterList.add(RowFilter.regexFilter("^((?!" + ratedMark + ").)*$", TablesTableModel.COLUMN_RATING));
|
||||
}
|
||||
|
||||
// Password
|
||||
String passwordMark = TableTableModel.PASSWORD_VALUE_YES;
|
||||
String passwordMark = TablesTableModel.PASSWORD_VALUE_YES;
|
||||
java.util.List<RowFilter<Object, Object>> passwordFilterList = new ArrayList<>();
|
||||
if (btnPassword.isSelected()) {
|
||||
// yes
|
||||
passwordFilterList.add(RowFilter.regexFilter("^" + passwordMark, TableTableModel.COLUMN_PASSWORD));
|
||||
passwordFilterList.add(RowFilter.regexFilter("^" + passwordMark, TablesTableModel.COLUMN_PASSWORD));
|
||||
}
|
||||
if (btnOpen.isSelected()) {
|
||||
// no
|
||||
passwordFilterList.add(RowFilter.regexFilter("^((?!" + passwordMark + ").)*$", TableTableModel.COLUMN_PASSWORD));
|
||||
passwordFilterList.add(RowFilter.regexFilter("^((?!" + passwordMark + ").)*$", TablesTableModel.COLUMN_PASSWORD));
|
||||
}
|
||||
|
||||
// Hide games of ignored players
|
||||
|
@ -699,7 +699,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
ignoreListFilterList.add(new RowFilter<Object, Object>() {
|
||||
@Override
|
||||
public boolean include(Entry<? extends Object, ? extends Object> entry) {
|
||||
final String owner = entry.getStringValue(TableTableModel.COLUMN_OWNER);
|
||||
final String owner = entry.getStringValue(TablesTableModel.COLUMN_OWNER);
|
||||
return !ignoreListCopy.contains(owner);
|
||||
}
|
||||
});
|
||||
|
@ -708,7 +708,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
if (stateFilterList.isEmpty() || typeFilterList.isEmpty() || formatFilterList.isEmpty()
|
||||
|| skillFilterList.isEmpty() || ratingFilterList.isEmpty()
|
||||
|| passwordFilterList.isEmpty()) { // no selection
|
||||
activeTablesSorter.setRowFilter(RowFilter.regexFilter("Nothing", TableTableModel.COLUMN_SKILL));
|
||||
activeTablesSorter.setRowFilter(RowFilter.regexFilter("Nothing", TablesTableModel.COLUMN_SKILL));
|
||||
} else {
|
||||
java.util.List<RowFilter<Object, Object>> filterList = new ArrayList<>();
|
||||
|
||||
|
@ -1357,201 +1357,6 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
|
||||
}
|
||||
|
||||
class TableTableModel extends AbstractTableModel {
|
||||
|
||||
final ImageIcon tourneyIcon = new javax.swing.ImageIcon(getClass().getResource("/tables/tourney_icon.png"));
|
||||
final ImageIcon matchIcon = new javax.swing.ImageIcon(getClass().getResource("/tables/match_icon.png"));
|
||||
|
||||
public static final int COLUMN_ICON = 0;
|
||||
public static final int COLUMN_DECK_TYPE = 1; // column the deck type is located (starting with 0) Start string is used to check for Limited
|
||||
public static final int COLUMN_OWNER = 2;
|
||||
public static final int COLUMN_GAME_TYPE = 3;
|
||||
public static final int COLUMN_INFO = 4;
|
||||
public static final int COLUMN_STATUS = 5;
|
||||
public static final int COLUMN_PASSWORD = 6;
|
||||
public static final int COLUMN_CREATED = 7;
|
||||
public static final int COLUMN_SKILL = 8;
|
||||
public static final int COLUMN_RATING = 9;
|
||||
public static final int COLUMN_QUIT_RATIO = 10;
|
||||
public static final int COLUMN_MINIMUM_RATING = 11;
|
||||
public static final int ACTION_COLUMN = 12; // column the action is located (starting with 0)
|
||||
|
||||
public static final String RATED_VALUE_YES = "YES";
|
||||
public static final String RATED_VALUE_NO = "";
|
||||
|
||||
public static final String PASSWORD_VALUE_YES = "YES";
|
||||
|
||||
private final String[] columnNames = new String[]{"M/T", "Deck Type", "Owner / Players", "Game Type", "Info", "Status", "Password", "Created / Started", "Skill Level", "Rated", "Quit %", "Min Rating", "Action"};
|
||||
|
||||
private TableView[] tables = new TableView[0];
|
||||
|
||||
TableTableModel() {
|
||||
}
|
||||
|
||||
public void loadData(Collection<TableView> tables) throws MageRemoteException {
|
||||
this.tables = tables.toArray(new TableView[0]);
|
||||
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) {
|
||||
case BEGINNER:
|
||||
res = "*";
|
||||
break;
|
||||
case CASUAL:
|
||||
res = "**";
|
||||
break;
|
||||
case SERIOUS:
|
||||
res = "***";
|
||||
break;
|
||||
default:
|
||||
res = "";
|
||||
break;
|
||||
}
|
||||
|
||||
// regexp format for search table rows
|
||||
if (asRegExp) {
|
||||
res = String.format("^%s$", res.replace("*", "\\*"));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return tables.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int arg0, int arg1) {
|
||||
switch (arg1) {
|
||||
case 0:
|
||||
return tables[arg0].isTournament() ? tourneyIcon : matchIcon;
|
||||
case 1:
|
||||
return tables[arg0].getDeckType();
|
||||
case 2:
|
||||
return tables[arg0].getControllerName();
|
||||
case 3:
|
||||
return tables[arg0].getGameType();
|
||||
case 4:
|
||||
return tables[arg0].getAdditionalInfo();
|
||||
case 5:
|
||||
return tables[arg0].getTableStateText();
|
||||
case 6:
|
||||
return tables[arg0].isPassworded() ? PASSWORD_VALUE_YES : "";
|
||||
case 7:
|
||||
return tables[arg0].getCreateTime(); // use cell render, not format here
|
||||
case 8:
|
||||
return this.getSkillLevelAsCode(tables[arg0].getSkillLevel(), false);
|
||||
case 9:
|
||||
return tables[arg0].isRated() ? RATED_VALUE_YES : RATED_VALUE_NO;
|
||||
case 10:
|
||||
return tables[arg0].getQuitRatio();
|
||||
case 11:
|
||||
return tables[arg0].getMinimumRating();
|
||||
case 12:
|
||||
switch (tables[arg0].getTableState()) {
|
||||
|
||||
case WAITING:
|
||||
String owner = tables[arg0].getControllerName();
|
||||
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
|
||||
return "";
|
||||
}
|
||||
return "Join";
|
||||
case CONSTRUCTING:
|
||||
case DRAFTING:
|
||||
if (tables[arg0].isTournament()) {
|
||||
return "Show";
|
||||
}
|
||||
case DUELING:
|
||||
if (tables[arg0].isTournament()) {
|
||||
return "Show";
|
||||
} else {
|
||||
owner = tables[arg0].getControllerName();
|
||||
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
|
||||
return "";
|
||||
}
|
||||
if (tables[arg0].getSpectatorsAllowed()) {
|
||||
return "Watch";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
case 13:
|
||||
return tables[arg0].isTournament();
|
||||
case 14:
|
||||
if (!tables[arg0].getGames().isEmpty()) {
|
||||
return tables[arg0].getGames().get(0);
|
||||
}
|
||||
return null;
|
||||
case 15:
|
||||
return tables[arg0].getTableId();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int columnIndex) {
|
||||
String colName = "";
|
||||
|
||||
if (columnIndex <= getColumnCount()) {
|
||||
colName = columnNames[columnIndex];
|
||||
}
|
||||
|
||||
return colName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case COLUMN_ICON:
|
||||
return Icon.class;
|
||||
case COLUMN_SKILL:
|
||||
return SkillLevel.class;
|
||||
case COLUMN_CREATED:
|
||||
return Date.class;
|
||||
default:
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return columnIndex == ACTION_COLUMN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
||||
|
||||
private final UUID roomId;
|
||||
|
@ -1640,119 +1445,6 @@ class UpdatePlayersTask extends SwingWorker<Void, Collection<RoomUsersView>> {
|
|||
|
||||
}
|
||||
|
||||
class MatchesTableModel extends AbstractTableModel {
|
||||
|
||||
private final String[] columnNames = new String[]{"Deck Type", "Players", "Game Type", "Rating", "Result", "Duration", "Start Time", "End Time", "Action"};
|
||||
public static final int COLUMN_DURATION = 5;
|
||||
public static final int COLUMN_START = 6;
|
||||
public static final int COLUMN_END = 7;
|
||||
public static final int COLUMN_ACTION = 8; // column the action is located (starting with 0)
|
||||
|
||||
private MatchView[] matches = new MatchView[0];
|
||||
|
||||
public void loadData(Collection<MatchView> matches) throws MageRemoteException {
|
||||
this.matches = matches.toArray(new MatchView[0]);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
MatchesTableModel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return matches.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int arg0, int arg1) {
|
||||
switch (arg1) {
|
||||
case 0:
|
||||
return matches[arg0].getDeckType();
|
||||
case 1:
|
||||
return matches[arg0].getPlayers();
|
||||
case 2:
|
||||
return matches[arg0].getGameType();
|
||||
case 3:
|
||||
return matches[arg0].isRated() ? TableTableModel.RATED_VALUE_YES : TableTableModel.RATED_VALUE_NO;
|
||||
case 4:
|
||||
return matches[arg0].getResult();
|
||||
case 5:
|
||||
if (matches[arg0].getEndTime() != null) {
|
||||
return matches[arg0].getEndTime().getTime() - matches[arg0].getStartTime().getTime() + new Date().getTime();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
case 6:
|
||||
return matches[arg0].getStartTime();
|
||||
case 7:
|
||||
return matches[arg0].getEndTime();
|
||||
case 8:
|
||||
if (matches[arg0].isTournament()) {
|
||||
return "Show";
|
||||
} else if (matches[arg0].isReplayAvailable()) {
|
||||
return "Replay";
|
||||
} else {
|
||||
return "None";
|
||||
}
|
||||
case 9:
|
||||
return matches[arg0].getGames();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public java.util.List<UUID> getListofGames(int row) {
|
||||
return matches[row].getGames();
|
||||
}
|
||||
|
||||
public boolean isTournament(int row) {
|
||||
return matches[row].isTournament();
|
||||
}
|
||||
|
||||
public UUID getMatchId(int row) {
|
||||
return matches[row].getMatchId();
|
||||
}
|
||||
|
||||
public UUID getTableId(int row) {
|
||||
return matches[row].getTableId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int columnIndex) {
|
||||
String colName = "";
|
||||
|
||||
if (columnIndex <= getColumnCount()) {
|
||||
colName = columnNames[columnIndex];
|
||||
}
|
||||
|
||||
return colName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case COLUMN_DURATION:
|
||||
return Long.class;
|
||||
case COLUMN_START:
|
||||
return Date.class;
|
||||
case COLUMN_END:
|
||||
return Date.class;
|
||||
default:
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return columnIndex == COLUMN_ACTION;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
|
||||
|
||||
private final UUID roomId;
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
package mage.client.table;
|
||||
|
||||
import mage.client.SessionHandler;
|
||||
import mage.constants.SkillLevel;
|
||||
import mage.remote.MageRemoteException;
|
||||
import mage.view.TableView;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
public class TablesTableModel extends AbstractTableModel {
|
||||
|
||||
final ImageIcon tourneyIcon = new ImageIcon(getClass().getResource("/tables/tourney_icon.png"));
|
||||
final ImageIcon matchIcon = new ImageIcon(getClass().getResource("/tables/match_icon.png"));
|
||||
|
||||
public static final int COLUMN_ICON = 0;
|
||||
public static final int COLUMN_DECK_TYPE = 1; // column the deck type is located (starting with 0) Start string is used to check for Limited
|
||||
public static final int COLUMN_OWNER = 2;
|
||||
public static final int COLUMN_GAME_TYPE = 3;
|
||||
public static final int COLUMN_INFO = 4;
|
||||
public static final int COLUMN_STATUS = 5;
|
||||
public static final int COLUMN_PASSWORD = 6;
|
||||
public static final int COLUMN_CREATED = 7;
|
||||
public static final int COLUMN_SKILL = 8;
|
||||
public static final int COLUMN_RATING = 9;
|
||||
public static final int COLUMN_QUIT_RATIO = 10;
|
||||
public static final int COLUMN_MINIMUM_RATING = 11;
|
||||
public static final int ACTION_COLUMN = 12; // column the action is located (starting with 0)
|
||||
|
||||
public static final String RATED_VALUE_YES = "YES";
|
||||
public static final String RATED_VALUE_NO = "";
|
||||
|
||||
public static final String PASSWORD_VALUE_YES = "YES";
|
||||
|
||||
private final String[] columnNames = new String[]{"M/T", "Deck Type", "Owner / Players", "Game Type", "Info", "Status", "Password", "Created / Started", "Skill Level", "Rated", "Quit %", "Min Rating", "Action"};
|
||||
|
||||
private TableView[] tables = new TableView[0];
|
||||
|
||||
TablesTableModel() {
|
||||
}
|
||||
|
||||
public void loadData(Collection<TableView> tables) throws MageRemoteException {
|
||||
this.tables = tables.toArray(new TableView[0]);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
public String getTableAndGameInfo(int row) {
|
||||
return this.tables[row].getTableId().toString() + ";" + (!tables[row].getGames().isEmpty() ? tables[row].getGames().get(0).toString() : "null");
|
||||
}
|
||||
|
||||
public String findTableAndGameInfoByRow(int row) {
|
||||
if (row >= 0 && row < this.tables.length) {
|
||||
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() + ";" + (!this.tables[i].getGames().isEmpty() ? this.tables[i].getGames().get(0).toString() : "null");
|
||||
if (tableAndGame.equals(rowID)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public String getSkillLevelAsCode(SkillLevel skill, boolean asRegExp) {
|
||||
String res;
|
||||
switch (skill) {
|
||||
case BEGINNER:
|
||||
res = "*";
|
||||
break;
|
||||
case CASUAL:
|
||||
res = "**";
|
||||
break;
|
||||
case SERIOUS:
|
||||
res = "***";
|
||||
break;
|
||||
default:
|
||||
res = "";
|
||||
break;
|
||||
}
|
||||
|
||||
// regexp format for search table rows
|
||||
if (asRegExp) {
|
||||
res = String.format("^%s$", res.replace("*", "\\*"));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return tables.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int arg0, int arg1) {
|
||||
switch (arg1) {
|
||||
case 0:
|
||||
return tables[arg0].isTournament() ? tourneyIcon : matchIcon;
|
||||
case 1:
|
||||
return tables[arg0].getDeckType();
|
||||
case 2:
|
||||
return tables[arg0].getControllerName();
|
||||
case 3:
|
||||
return tables[arg0].getGameType();
|
||||
case 4:
|
||||
return tables[arg0].getAdditionalInfo();
|
||||
case 5:
|
||||
return tables[arg0].getTableStateText();
|
||||
case 6:
|
||||
return tables[arg0].isPassworded() ? PASSWORD_VALUE_YES : "";
|
||||
case 7:
|
||||
return tables[arg0].getCreateTime(); // use cell render, not format here
|
||||
case 8:
|
||||
return this.getSkillLevelAsCode(tables[arg0].getSkillLevel(), false);
|
||||
case 9:
|
||||
return tables[arg0].isRated() ? RATED_VALUE_YES : RATED_VALUE_NO;
|
||||
case 10:
|
||||
return tables[arg0].getQuitRatio();
|
||||
case 11:
|
||||
return tables[arg0].getMinimumRating();
|
||||
case 12:
|
||||
switch (tables[arg0].getTableState()) {
|
||||
|
||||
case WAITING:
|
||||
String owner = tables[arg0].getControllerName();
|
||||
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
|
||||
return "";
|
||||
}
|
||||
return "Join";
|
||||
case CONSTRUCTING:
|
||||
case DRAFTING:
|
||||
if (tables[arg0].isTournament()) {
|
||||
return "Show";
|
||||
}
|
||||
case DUELING:
|
||||
if (tables[arg0].isTournament()) {
|
||||
return "Show";
|
||||
} else {
|
||||
owner = tables[arg0].getControllerName();
|
||||
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
|
||||
return "";
|
||||
}
|
||||
if (tables[arg0].getSpectatorsAllowed()) {
|
||||
return "Watch";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
case 13:
|
||||
return tables[arg0].isTournament();
|
||||
case 14:
|
||||
if (!tables[arg0].getGames().isEmpty()) {
|
||||
return tables[arg0].getGames().get(0);
|
||||
}
|
||||
return null;
|
||||
case 15:
|
||||
return tables[arg0].getTableId();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int columnIndex) {
|
||||
String colName = "";
|
||||
|
||||
if (columnIndex <= getColumnCount()) {
|
||||
colName = columnNames[columnIndex];
|
||||
}
|
||||
|
||||
return colName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case COLUMN_ICON:
|
||||
return Icon.class;
|
||||
case COLUMN_SKILL:
|
||||
return SkillLevel.class;
|
||||
case COLUMN_CREATED:
|
||||
return Date.class;
|
||||
default:
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return columnIndex == ACTION_COLUMN;
|
||||
}
|
||||
|
||||
}
|
40
Mage.Client/src/main/java/mage/client/table/TablesUtil.java
Normal file
40
Mage.Client/src/main/java/mage/client/table/TablesUtil.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package mage.client.table;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class TablesUtil {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(TablesUtil.class);
|
||||
|
||||
public static String getSearchIdFromTable(JTable table, int row) {
|
||||
// tableUUID;gameUUID
|
||||
String searchId = null;
|
||||
if (table.getModel() instanceof TablesTableModel) {
|
||||
searchId = ((TablesTableModel) table.getModel()).findTableAndGameInfoByRow(row);
|
||||
} else if (table.getModel() instanceof MatchesTableModel) {
|
||||
searchId = ((MatchesTableModel) table.getModel()).findTableAndGameInfoByRow(row);
|
||||
} else {
|
||||
logger.error("Not supported tables model " + table.getModel().getClass().toString());
|
||||
}
|
||||
return searchId;
|
||||
}
|
||||
|
||||
public static int findTableRowFromSearchId(Object tableModel, String searchId) {
|
||||
// tableUUID;gameUUID
|
||||
int row = -1;
|
||||
if (tableModel instanceof TablesTableModel) {
|
||||
row = ((TablesTableModel) tableModel).findRowByTableAndGameInfo(searchId);
|
||||
} else if (tableModel instanceof MatchesTableModel) {
|
||||
row = ((MatchesTableModel) tableModel).findRowByTableAndGameInfo(searchId);
|
||||
} else {
|
||||
logger.error("Not supported tables model " + tableModel.getClass().toString());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +1,21 @@
|
|||
|
||||
|
||||
/*
|
||||
* TournamentPanel.java
|
||||
*
|
||||
* Created on 20-Jan-2011, 9:18:30 PM
|
||||
*/
|
||||
package mage.client.tournament;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Rectangle;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.SessionHandler;
|
||||
import mage.client.chat.ChatPanelBasic;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.table.TablesButtonColumn;
|
||||
import mage.client.util.Format;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.gui.TableUtil;
|
||||
import mage.client.util.gui.countryBox.CountryCellRenderer;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.view.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -19,34 +25,10 @@ import java.util.UUID;
|
|||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.SessionHandler;
|
||||
import mage.client.chat.ChatPanelBasic;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_MATCH_COLUMNS_ORDER;
|
||||
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_MATCH_COLUMNS_WIDTH;
|
||||
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_PLAYER_COLUMNS_ORDER;
|
||||
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_PLAYER_COLUMNS_WIDTH;
|
||||
import mage.client.util.ButtonColumn;
|
||||
import mage.client.util.Format;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.gui.TableUtil;
|
||||
import mage.client.util.gui.countryBox.CountryCellRenderer;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.view.RoundView;
|
||||
import mage.view.TournamentGameView;
|
||||
import mage.view.TournamentPlayerView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserRequestMessage;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import static mage.client.dialog.PreferencesDialog.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentPanel extends javax.swing.JPanel {
|
||||
|
@ -64,7 +46,7 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
private UpdateTournamentTask updateTask;
|
||||
private final DateFormat df;
|
||||
|
||||
private final ButtonColumn actionButtonColumn1;
|
||||
private final TablesButtonColumn actionButtonColumn1;
|
||||
|
||||
/**
|
||||
* Creates new form TournamentPanel
|
||||
|
@ -111,7 +93,7 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
};
|
||||
|
||||
// action button, don't delete this
|
||||
actionButtonColumn1 = new ButtonColumn(tableMatches, action, tableMatches.convertColumnIndexToView(TournamentMatchesTableModel.ACTION_COLUMN));
|
||||
actionButtonColumn1 = new TablesButtonColumn(tableMatches, action, tableMatches.convertColumnIndexToView(TournamentMatchesTableModel.ACTION_COLUMN));
|
||||
setGUISize();
|
||||
|
||||
}
|
||||
|
@ -390,67 +372,67 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
javax.swing.GroupLayout actionPanelLayout = new javax.swing.GroupLayout(actionPanel);
|
||||
actionPanel.setLayout(actionPanelLayout);
|
||||
actionPanelLayout.setHorizontalGroup(
|
||||
actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(lblName)
|
||||
.addComponent(lblState)
|
||||
.addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
|
||||
.addComponent(txtTournamentState))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(lblType)
|
||||
.addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblStartTime))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblEndTime)
|
||||
.addComponent(txtEndTime))))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, Short.MAX_VALUE)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(btnQuitTournament, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btnCloseWindow, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(lblName)
|
||||
.addComponent(lblState)
|
||||
.addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
|
||||
.addComponent(txtTournamentState))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(lblType)
|
||||
.addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblStartTime))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblEndTime)
|
||||
.addComponent(txtEndTime))))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, Short.MAX_VALUE)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(btnQuitTournament, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btnCloseWindow, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
actionPanelLayout.setVerticalGroup(
|
||||
actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addGap(7, 7, 7)
|
||||
.addComponent(lblName))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, actionPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(lblType)))
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(btnQuitTournament))
|
||||
.addGap(13, 13, 13)
|
||||
.addComponent(btnCloseWindow))
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addGap(6, 6, 6)
|
||||
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblState)
|
||||
.addComponent(lblStartTime)
|
||||
.addComponent(lblEndTime))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addComponent(txtTournamentState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(txtStartTime)
|
||||
.addComponent(txtEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
|
||||
.addContainerGap())
|
||||
actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addGap(7, 7, 7)
|
||||
.addComponent(lblName))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, actionPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(lblType)))
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(btnQuitTournament))
|
||||
.addGap(13, 13, 13)
|
||||
.addComponent(btnCloseWindow))
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addGap(6, 6, 6)
|
||||
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblState)
|
||||
.addComponent(lblStartTime)
|
||||
.addComponent(lblEndTime))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(actionPanelLayout.createSequentialGroup()
|
||||
.addComponent(txtTournamentState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(txtStartTime)
|
||||
.addComponent(txtEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
jSplitPane2.setResizeWeight(1.0);
|
||||
|
@ -481,17 +463,17 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(actionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jSplitPane2, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(actionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jSplitPane2, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
|
Loading…
Reference in a new issue