diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java index 81e068edd4..e2e9a95249 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -56,7 +56,7 @@ import static mage.client.dialog.PreferencesDialog.*; 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 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 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 */ @@ -189,6 +199,8 @@ public class TablesPanel extends javax.swing.JPanel { tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_CREATED).setCellRenderer(timeAgoCellRenderer); // skill level 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) activeTablesSorter.setComparator(TablesTableModel.COLUMN_CREATED, new Comparator() { diff --git a/Mage.Client/src/main/java/mage/client/table/TablesTableModel.java b/Mage.Client/src/main/java/mage/client/table/TablesTableModel.java index fd9b482f68..1348887d81 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesTableModel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesTableModel.java @@ -28,24 +28,26 @@ public class TablesTableModel extends AbstractTableModel { 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 int COLUMN_NAME = 2; + public static final int COLUMN_SEATS = 3; + public static final int COLUMN_OWNER = 4; + public static final int COLUMN_GAME_TYPE = 5; + public static final int COLUMN_INFO = 6; + public static final int COLUMN_STATUS = 7; + public static final int COLUMN_PASSWORD = 8; + public static final int COLUMN_CREATED = 9; + public static final int COLUMN_SKILL = 10; + public static final int COLUMN_RATING = 11; + 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_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 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]; @@ -115,55 +117,59 @@ public class TablesTableModel extends AbstractTableModel { } @Override - public Object getValueAt(int arg0, int arg1) { - switch (arg1) { + public Object getValueAt(int rowIndex, int columnIndex) { + switch (columnIndex) { case 0: - return tables[arg0].isTournament() ? tourneyIcon : matchIcon; + return tables[rowIndex].isTournament() ? tourneyIcon : matchIcon; case 1: - return tables[arg0].getDeckType(); + return tables[rowIndex].getDeckType(); case 2: - return tables[arg0].getControllerName(); + return tables[rowIndex].getTableName(); case 3: - return tables[arg0].getGameType(); + return tables[rowIndex].getSeatsInfo(); case 4: - return tables[arg0].getAdditionalInfo(); + return tables[rowIndex].getControllerName(); case 5: - return tables[arg0].getTableStateText(); + return tables[rowIndex].getGameType(); case 6: - return tables[arg0].isPassworded() ? PASSWORD_VALUE_YES : ""; + return tables[rowIndex].getAdditionalInfo(); case 7: - return tables[arg0].getCreateTime(); // use cell render, not format here + return tables[rowIndex].getTableStateText(); case 8: - return this.getSkillLevelAsCode(tables[arg0].getSkillLevel(), false); + return tables[rowIndex].isPassworded() ? PASSWORD_VALUE_YES : ""; case 9: - return tables[arg0].isRated() ? RATED_VALUE_YES : RATED_VALUE_NO; + return tables[rowIndex].getCreateTime(); // use cell render, not format here case 10: - return tables[arg0].getQuitRatio(); + return this.getSkillLevelAsCode(tables[rowIndex].getSkillLevel(), false); case 11: - return tables[arg0].getMinimumRating(); + return tables[rowIndex].isRated() ? RATED_VALUE_YES : RATED_VALUE_NO; case 12: - switch (tables[arg0].getTableState()) { + return tables[rowIndex].getQuitRatio(); + case 13: + return tables[rowIndex].getMinimumRating(); + case 14: + switch (tables[rowIndex].getTableState()) { case WAITING: - String owner = tables[arg0].getControllerName(); + String owner = tables[rowIndex].getControllerName(); if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) { return ""; } return "Join"; case CONSTRUCTING: case DRAFTING: - if (tables[arg0].isTournament()) { + if (tables[rowIndex].isTournament()) { return "Show"; } case DUELING: - if (tables[arg0].isTournament()) { + if (tables[rowIndex].isTournament()) { return "Show"; } else { - owner = tables[arg0].getControllerName(); + owner = tables[rowIndex].getControllerName(); if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) { return ""; } - if (tables[arg0].getSpectatorsAllowed()) { + if (tables[rowIndex].getSpectatorsAllowed()) { return "Watch"; } return ""; @@ -171,15 +177,15 @@ public class TablesTableModel extends AbstractTableModel { default: return ""; } - case 13: - return tables[arg0].isTournament(); - case 14: - if (!tables[arg0].getGames().isEmpty()) { - return tables[arg0].getGames().get(0); + case 15: + return tables[rowIndex].isTournament(); + case 16: + if (!tables[rowIndex].getGames().isEmpty()) { + return tables[rowIndex].getGames().get(0); } return null; - case 15: - return tables[arg0].getTableId(); + case 17: + return tables[rowIndex].getTableId(); } return ""; } diff --git a/Mage.Common/src/main/java/mage/view/TableView.java b/Mage.Common/src/main/java/mage/view/TableView.java index 948c7717bf..efd42d3239 100644 --- a/Mage.Common/src/main/java/mage/view/TableView.java +++ b/Mage.Common/src/main/java/mage/view/TableView.java @@ -1,11 +1,5 @@ - 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.TableState; import mage.game.Game; @@ -15,6 +9,12 @@ import mage.game.draft.Draft; import mage.game.match.MatchPlayer; 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 */ @@ -32,6 +32,7 @@ public class TableView implements Serializable { private TableState tableState; private final SkillLevel skillLevel; private final String tableStateText; + private final String seatsInfo; private boolean isTournament; private List seats = new ArrayList<>(); private List games = new ArrayList<>(); @@ -46,10 +47,6 @@ public class TableView implements Serializable { this.tableId = table.getId(); this.gameType = table.getGameType(); this.tableName = table.getName(); - String tableNameInfo = null; - if (tableName != null && !tableName.isEmpty()) { - tableNameInfo = " [" + table.getName() + ']'; - } this.controllerName = table.getControllerName(); this.tableState = table.getState(); if (table.getState() == TableState.WAITING @@ -69,8 +66,9 @@ public class TableView implements Serializable { } if (!table.isTournament()) { // MATCH + seatsInfo = "" + table.getMatch().getPlayers().size() + '/' + table.getSeats().length; 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 { tableStateText = table.getState().toString(); } @@ -94,7 +92,7 @@ public class TableView implements Serializable { sbScore.append(" Draws: ").append(table.getMatch().getDraws()); } this.controllerName += sb.toString(); - this.deckType = table.getDeckType() + (tableNameInfo != null ? tableNameInfo : ""); + this.deckType = table.getDeckType(); StringBuilder addInfo = new StringBuilder(); if (table.getMatch().getGames().isEmpty()) { addInfo.append("Wins:").append(table.getMatch().getWinsNeeded()); @@ -129,10 +127,11 @@ public class TableView implements Serializable { } } this.controllerName += sb1.toString(); + this.seatsInfo = "" + table.getTournament().getPlayers().size() + "/" + table.getNumberOfSeats(); StringBuilder infoText = new StringBuilder(); StringBuilder stateText = new StringBuilder(table.getState().toString()); 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()) { case WAITING: 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.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.quitRatio = Integer.toString(table.getTournament().getOptions().getQuitRatio()); this.minimumRating = Integer.toString(table.getTournament().getOptions().getMinimumRating()); @@ -180,11 +179,11 @@ public class TableView implements Serializable { public String getControllerName() { return controllerName; } - + public boolean getSpectatorsAllowed() { return spectatorsAllowed; } - + public String getGameType() { return gameType; @@ -210,6 +209,10 @@ public class TableView implements Serializable { return games; } + public String getSeatsInfo() { + return seatsInfo; + } + public boolean isTournament() { return this.isTournament; } @@ -226,9 +229,13 @@ public class TableView implements Serializable { 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() { return limited;