* UI: added game name and seats number columns to tables list;

This commit is contained in:
Oleg Agafonov 2019-01-22 18:32:27 +04:00
parent 12b8c12d74
commit cfff0f8116
3 changed files with 83 additions and 58 deletions

View file

@ -56,7 +56,7 @@ import static mage.client.dialog.PreferencesDialog.*;
public class TablesPanel extends javax.swing.JPanel { public class TablesPanel extends javax.swing.JPanel {
private static final Logger LOGGER = Logger.getLogger(TablesPanel.class); 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 static final int[] DEFAULT_COLUMNS_WIDTH = {35, 150, 100, 50, 120, 180, 80, 120, 80, 60, 40, 40, 60};
private final TablesTableModel tableModel; private final TablesTableModel tableModel;
private final MatchesTableModel matchesModel; private final MatchesTableModel matchesModel;
@ -163,6 +163,16 @@ public class TablesPanel extends javax.swing.JPanel {
} }
}; };
// center text render
TableCellRenderer centerCellRenderer = new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
label.setHorizontalAlignment(JLabel.CENTER);
return label;
}
};
/** /**
* Creates new form TablesPanel * Creates new form TablesPanel
*/ */
@ -189,6 +199,8 @@ public class TablesPanel extends javax.swing.JPanel {
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_CREATED).setCellRenderer(timeAgoCellRenderer); tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_CREATED).setCellRenderer(timeAgoCellRenderer);
// skill level // skill level
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_SKILL).setCellRenderer(skillCellRenderer); tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_SKILL).setCellRenderer(skillCellRenderer);
// seats
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_SEATS).setCellRenderer(centerCellRenderer);
/* date sorter (not need, default is good - see getColumnClass) /* date sorter (not need, default is good - see getColumnClass)
activeTablesSorter.setComparator(TablesTableModel.COLUMN_CREATED, new Comparator<Date>() { activeTablesSorter.setComparator(TablesTableModel.COLUMN_CREATED, new Comparator<Date>() {

View file

@ -28,24 +28,26 @@ public class TablesTableModel extends AbstractTableModel {
public static final int COLUMN_ICON = 0; 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_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_NAME = 2;
public static final int COLUMN_GAME_TYPE = 3; public static final int COLUMN_SEATS = 3;
public static final int COLUMN_INFO = 4; public static final int COLUMN_OWNER = 4;
public static final int COLUMN_STATUS = 5; public static final int COLUMN_GAME_TYPE = 5;
public static final int COLUMN_PASSWORD = 6; public static final int COLUMN_INFO = 6;
public static final int COLUMN_CREATED = 7; public static final int COLUMN_STATUS = 7;
public static final int COLUMN_SKILL = 8; public static final int COLUMN_PASSWORD = 8;
public static final int COLUMN_RATING = 9; public static final int COLUMN_CREATED = 9;
public static final int COLUMN_QUIT_RATIO = 10; public static final int COLUMN_SKILL = 10;
public static final int COLUMN_MINIMUM_RATING = 11; public static final int COLUMN_RATING = 11;
public static final int ACTION_COLUMN = 12; // column the action is located (starting with 0) public static final int COLUMN_QUIT_RATIO = 12;
public static final int COLUMN_MINIMUM_RATING = 13;
public static final int ACTION_COLUMN = 14; // column the action is located (starting with 0)
public static final String RATED_VALUE_YES = "YES"; public static final String RATED_VALUE_YES = "YES";
public static final String RATED_VALUE_NO = ""; public static final String RATED_VALUE_NO = "";
public static final String PASSWORD_VALUE_YES = "YES"; 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 final String[] columnNames = new String[]{"M/T", "Deck Type", "Name", "Seats", "Owner / Players", "Game Type", "Info", "Status", "Password", "Created / Started", "Skill Level", "Rated", "Quit %", "Min Rating", "Action"};
private TableView[] tables = new TableView[0]; private TableView[] tables = new TableView[0];
@ -115,55 +117,59 @@ public class TablesTableModel extends AbstractTableModel {
} }
@Override @Override
public Object getValueAt(int arg0, int arg1) { public Object getValueAt(int rowIndex, int columnIndex) {
switch (arg1) { switch (columnIndex) {
case 0: case 0:
return tables[arg0].isTournament() ? tourneyIcon : matchIcon; return tables[rowIndex].isTournament() ? tourneyIcon : matchIcon;
case 1: case 1:
return tables[arg0].getDeckType(); return tables[rowIndex].getDeckType();
case 2: case 2:
return tables[arg0].getControllerName(); return tables[rowIndex].getTableName();
case 3: case 3:
return tables[arg0].getGameType(); return tables[rowIndex].getSeatsInfo();
case 4: case 4:
return tables[arg0].getAdditionalInfo(); return tables[rowIndex].getControllerName();
case 5: case 5:
return tables[arg0].getTableStateText(); return tables[rowIndex].getGameType();
case 6: case 6:
return tables[arg0].isPassworded() ? PASSWORD_VALUE_YES : ""; return tables[rowIndex].getAdditionalInfo();
case 7: case 7:
return tables[arg0].getCreateTime(); // use cell render, not format here return tables[rowIndex].getTableStateText();
case 8: case 8:
return this.getSkillLevelAsCode(tables[arg0].getSkillLevel(), false); return tables[rowIndex].isPassworded() ? PASSWORD_VALUE_YES : "";
case 9: case 9:
return tables[arg0].isRated() ? RATED_VALUE_YES : RATED_VALUE_NO; return tables[rowIndex].getCreateTime(); // use cell render, not format here
case 10: case 10:
return tables[arg0].getQuitRatio(); return this.getSkillLevelAsCode(tables[rowIndex].getSkillLevel(), false);
case 11: case 11:
return tables[arg0].getMinimumRating(); return tables[rowIndex].isRated() ? RATED_VALUE_YES : RATED_VALUE_NO;
case 12: case 12:
switch (tables[arg0].getTableState()) { return tables[rowIndex].getQuitRatio();
case 13:
return tables[rowIndex].getMinimumRating();
case 14:
switch (tables[rowIndex].getTableState()) {
case WAITING: case WAITING:
String owner = tables[arg0].getControllerName(); String owner = tables[rowIndex].getControllerName();
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) { if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
return ""; return "";
} }
return "Join"; return "Join";
case CONSTRUCTING: case CONSTRUCTING:
case DRAFTING: case DRAFTING:
if (tables[arg0].isTournament()) { if (tables[rowIndex].isTournament()) {
return "Show"; return "Show";
} }
case DUELING: case DUELING:
if (tables[arg0].isTournament()) { if (tables[rowIndex].isTournament()) {
return "Show"; return "Show";
} else { } else {
owner = tables[arg0].getControllerName(); owner = tables[rowIndex].getControllerName();
if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) { if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) {
return ""; return "";
} }
if (tables[arg0].getSpectatorsAllowed()) { if (tables[rowIndex].getSpectatorsAllowed()) {
return "Watch"; return "Watch";
} }
return ""; return "";
@ -171,15 +177,15 @@ public class TablesTableModel extends AbstractTableModel {
default: default:
return ""; return "";
} }
case 13: case 15:
return tables[arg0].isTournament(); return tables[rowIndex].isTournament();
case 14: case 16:
if (!tables[arg0].getGames().isEmpty()) { if (!tables[rowIndex].getGames().isEmpty()) {
return tables[arg0].getGames().get(0); return tables[rowIndex].getGames().get(0);
} }
return null; return null;
case 15: case 17:
return tables[arg0].getTableId(); return tables[rowIndex].getTableId();
} }
return ""; return "";
} }

View file

@ -1,11 +1,5 @@
package mage.view; package mage.view;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import mage.constants.SkillLevel; import mage.constants.SkillLevel;
import mage.constants.TableState; import mage.constants.TableState;
import mage.game.Game; import mage.game.Game;
@ -15,6 +9,12 @@ import mage.game.draft.Draft;
import mage.game.match.MatchPlayer; import mage.game.match.MatchPlayer;
import mage.game.tournament.TournamentPlayer; import mage.game.tournament.TournamentPlayer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -32,6 +32,7 @@ public class TableView implements Serializable {
private TableState tableState; private TableState tableState;
private final SkillLevel skillLevel; private final SkillLevel skillLevel;
private final String tableStateText; private final String tableStateText;
private final String seatsInfo;
private boolean isTournament; private boolean isTournament;
private List<SeatView> seats = new ArrayList<>(); private List<SeatView> seats = new ArrayList<>();
private List<UUID> games = new ArrayList<>(); private List<UUID> games = new ArrayList<>();
@ -46,10 +47,6 @@ public class TableView implements Serializable {
this.tableId = table.getId(); this.tableId = table.getId();
this.gameType = table.getGameType(); this.gameType = table.getGameType();
this.tableName = table.getName(); this.tableName = table.getName();
String tableNameInfo = null;
if (tableName != null && !tableName.isEmpty()) {
tableNameInfo = " [" + table.getName() + ']';
}
this.controllerName = table.getControllerName(); this.controllerName = table.getControllerName();
this.tableState = table.getState(); this.tableState = table.getState();
if (table.getState() == TableState.WAITING if (table.getState() == TableState.WAITING
@ -69,8 +66,9 @@ public class TableView implements Serializable {
} }
if (!table.isTournament()) { if (!table.isTournament()) {
// MATCH // MATCH
seatsInfo = "" + table.getMatch().getPlayers().size() + '/' + table.getSeats().length;
if (table.getState() == TableState.WAITING || table.getState() == TableState.READY_TO_START) { if (table.getState() == TableState.WAITING || table.getState() == TableState.READY_TO_START) {
tableStateText = table.getState().toString() + " (" + table.getMatch().getPlayers().size() + '/' + table.getSeats().length + ')'; tableStateText = table.getState().toString() + " (" + seatsInfo + ')';
} else { } else {
tableStateText = table.getState().toString(); tableStateText = table.getState().toString();
} }
@ -94,7 +92,7 @@ public class TableView implements Serializable {
sbScore.append(" Draws: ").append(table.getMatch().getDraws()); sbScore.append(" Draws: ").append(table.getMatch().getDraws());
} }
this.controllerName += sb.toString(); this.controllerName += sb.toString();
this.deckType = table.getDeckType() + (tableNameInfo != null ? tableNameInfo : ""); this.deckType = table.getDeckType();
StringBuilder addInfo = new StringBuilder(); StringBuilder addInfo = new StringBuilder();
if (table.getMatch().getGames().isEmpty()) { if (table.getMatch().getGames().isEmpty()) {
addInfo.append("Wins:").append(table.getMatch().getWinsNeeded()); addInfo.append("Wins:").append(table.getMatch().getWinsNeeded());
@ -129,10 +127,11 @@ public class TableView implements Serializable {
} }
} }
this.controllerName += sb1.toString(); this.controllerName += sb1.toString();
this.seatsInfo = "" + table.getTournament().getPlayers().size() + "/" + table.getNumberOfSeats();
StringBuilder infoText = new StringBuilder(); StringBuilder infoText = new StringBuilder();
StringBuilder stateText = new StringBuilder(table.getState().toString()); StringBuilder stateText = new StringBuilder(table.getState().toString());
infoText.append("Wins:").append(table.getTournament().getOptions().getMatchOptions().getWinsNeeded()); infoText.append("Wins:").append(table.getTournament().getOptions().getMatchOptions().getWinsNeeded());
infoText.append(" Seats: ").append(table.getTournament().getPlayers().size()).append('/').append(table.getNumberOfSeats()); infoText.append(" Seats: ").append(this.seatsInfo);
switch (table.getState()) { switch (table.getState()) {
case WAITING: case WAITING:
stateText.append(" (").append(table.getTournament().getPlayers().size()).append('/').append(table.getNumberOfSeats()).append(')'); stateText.append(" (").append(table.getTournament().getPlayers().size()).append('/').append(table.getNumberOfSeats()).append(')');
@ -158,7 +157,7 @@ public class TableView implements Serializable {
} }
this.additionalInfo = infoText.toString(); this.additionalInfo = infoText.toString();
this.tableStateText = stateText.toString(); this.tableStateText = stateText.toString();
this.deckType = table.getDeckType() + ' ' + table.getTournament().getBoosterInfo() + (tableNameInfo != null ? tableNameInfo : ""); this.deckType = table.getDeckType() + ' ' + table.getTournament().getBoosterInfo();
this.skillLevel = table.getTournament().getOptions().getMatchOptions().getSkillLevel(); this.skillLevel = table.getTournament().getOptions().getMatchOptions().getSkillLevel();
this.quitRatio = Integer.toString(table.getTournament().getOptions().getQuitRatio()); this.quitRatio = Integer.toString(table.getTournament().getOptions().getQuitRatio());
this.minimumRating = Integer.toString(table.getTournament().getOptions().getMinimumRating()); this.minimumRating = Integer.toString(table.getTournament().getOptions().getMinimumRating());
@ -210,6 +209,10 @@ public class TableView implements Serializable {
return games; return games;
} }
public String getSeatsInfo() {
return seatsInfo;
}
public boolean isTournament() { public boolean isTournament() {
return this.isTournament; return this.isTournament;
} }
@ -226,9 +229,13 @@ public class TableView implements Serializable {
return skillLevel; return skillLevel;
} }
public String getQuitRatio() { return quitRatio; } public String getQuitRatio() {
return quitRatio;
}
public String getMinimumRating() { return minimumRating; } public String getMinimumRating() {
return minimumRating;
}
public boolean isLimited() { public boolean isLimited() {
return limited; return limited;