From 30803c7fae5f7997d09f599deef36b568b74b548 Mon Sep 17 00:00:00 2001 From: lodici Date: Fri, 24 Feb 2017 03:17:08 +0000 Subject: [PATCH] update content and style of the Result column in DeckGamesJTable. --- src/magic/ui/deck/games/DeckGame.java | 12 +++++- src/magic/ui/deck/games/DeckGamesJTable.java | 18 ++++---- .../ui/deck/games/DeckGamesTableModel.java | 24 +++++------ .../ui/deck/games/ResultCellRenderer.java | 42 +++++++++++++++++++ 4 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 src/magic/ui/deck/games/ResultCellRenderer.java diff --git a/src/magic/ui/deck/games/DeckGame.java b/src/magic/ui/deck/games/DeckGame.java index 47aad66862..cbc24499b4 100644 --- a/src/magic/ui/deck/games/DeckGame.java +++ b/src/magic/ui/deck/games/DeckGame.java @@ -121,11 +121,15 @@ class DeckGame { : new DeckInfo(gameInfo.player1DeckName, gameInfo.player1DeckColor); } - String getResultInfo() { + boolean isWinner() { int playerNum = gameInfo.player1DeckName.equals(deck.getName()) ? 1 : 2; int winningPlayer = Integer.parseInt(gameInfo.winningPlayerProfile); + return winningPlayer == playerNum; + } + + String getResultInfo() { return String.format("%s %d %s", - winningPlayer == playerNum ? MText.get(_S4) : MText.get(_S5), + isWinner() ? MText.get(_S4) : MText.get(_S5), gameInfo.turns, gameInfo.isConceded ? "(" + MText.get(_S6) + ")" : "" ).trim(); @@ -135,4 +139,8 @@ class DeckGame { return MText.get(_S3, gameInfo.startLife, gameInfo.startHandSize); } + int getTurns() { + return gameInfo.turns; + } + } diff --git a/src/magic/ui/deck/games/DeckGamesJTable.java b/src/magic/ui/deck/games/DeckGamesJTable.java index 81b6fd3b14..2cf23941dd 100644 --- a/src/magic/ui/deck/games/DeckGamesJTable.java +++ b/src/magic/ui/deck/games/DeckGamesJTable.java @@ -45,19 +45,21 @@ class DeckGamesJTable extends JTable { } private void setColumnRenderers() { - getColumnModel().getColumn(0).setCellRenderer(new GameCellRenderer()); - getColumnModel().getColumn(1).setCellRenderer(new PlayerCellRenderer()); + getColumnModel().getColumn(0).setCellRenderer(new ResultCellRenderer()); + getColumnModel().getColumn(1).setCellRenderer(new GameCellRenderer()); getColumnModel().getColumn(2).setCellRenderer(new PlayerCellRenderer()); - getColumnModel().getColumn(3).setCellRenderer(new DeckCellRenderer()); + getColumnModel().getColumn(3).setCellRenderer(new PlayerCellRenderer()); + getColumnModel().getColumn(4).setCellRenderer(new DeckCellRenderer()); } private void setDefaultColumnProperties() { final TableColumnModel cm = getColumnModel(); // set initial column widths. - for (int i = 0; i < cm.getColumnCount(); i++) { - cm.getColumn(i).setMinWidth(130); - cm.getColumn(i).setPreferredWidth(130); - } + cm.getColumn(0).setMinWidth(30); + cm.getColumn(1).setMinWidth(130); + cm.getColumn(2).setMinWidth(170); + cm.getColumn(3).setMinWidth(170); + cm.getColumn(4).setMinWidth(180); final JTableHeader header = getTableHeader(); header.setReorderingAllowed(true); final DefaultTableCellRenderer renderer = @@ -87,7 +89,7 @@ class DeckGamesJTable extends JTable { @Override public void setModel(TableModel dataModel) { super.setModel(dataModel); - setColumnRenderers(); + setColumnRenderers(); if (tca != null) { tca.adjustColumns(); } diff --git a/src/magic/ui/deck/games/DeckGamesTableModel.java b/src/magic/ui/deck/games/DeckGamesTableModel.java index e333269a50..c9ed7e092e 100644 --- a/src/magic/ui/deck/games/DeckGamesTableModel.java +++ b/src/magic/ui/deck/games/DeckGamesTableModel.java @@ -19,7 +19,6 @@ class DeckGamesTableModel extends AbstractTableModel { private static final String _S3 = "Player"; private static final String _S4 = "Opponent"; private static final String _S5 = "Opponent deck"; - private static final String _S6 = "Result"; private static final int PAGE_SIZE = 8; @@ -63,11 +62,11 @@ class DeckGamesTableModel extends AbstractTableModel { @Override public String getColumnName(int columnIndex) { switch (columnIndex) { - case 0: return MText.get(_S1); - case 1: return MText.get(_S3); - case 2: return MText.get(_S4); - case 3: return MText.get(_S5); - case 4: return MText.get(_S6); + case 0: return ""; + case 1: return MText.get(_S1); + case 2: return MText.get(_S3); + case 3: return MText.get(_S4); + case 4: return MText.get(_S5); default: return "???"; } } @@ -76,9 +75,10 @@ class DeckGamesTableModel extends AbstractTableModel { public Class getColumnClass(int col) { switch (col) { case 0: return DeckGame.class; - case 1: return PlayerInfo.class; + case 1: return DeckGame.class; case 2: return PlayerInfo.class; - case 3: return DeckInfo.class; + case 3: return PlayerInfo.class; + case 4: return DeckInfo.class; default: return String.class; } } @@ -93,10 +93,10 @@ class DeckGamesTableModel extends AbstractTableModel { DeckGame stats = gameStats.get(row); switch (col) { case 0: return stats; - case 1: return stats.getDeckPlayerInfo(); - case 2: return stats.getOpponentInfo(); - case 3: return stats.getOpponentDeckInfo(); - case 4: return stats.getResultInfo(); + case 1: return stats; + case 2: return stats.getDeckPlayerInfo(); + case 3: return stats.getOpponentInfo(); + case 4: return stats.getOpponentDeckInfo(); default: return "???"; } } diff --git a/src/magic/ui/deck/games/ResultCellRenderer.java b/src/magic/ui/deck/games/ResultCellRenderer.java new file mode 100644 index 0000000000..7429a834dc --- /dev/null +++ b/src/magic/ui/deck/games/ResultCellRenderer.java @@ -0,0 +1,42 @@ +package magic.ui.deck.games; + +import java.awt.Component; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.table.DefaultTableCellRenderer; +import magic.data.MagicIcon; +import magic.ui.FontsAndBorders; +import magic.ui.MagicImages; +import net.miginfocom.swing.MigLayout; + +@SuppressWarnings("serial") +class ResultCellRenderer extends DefaultTableCellRenderer { + + private static final ImageIcon WON_ICON = MagicImages.getIcon(MagicIcon.LEGAL); + private static final ImageIcon LOST_ICON = MagicImages.getIcon(MagicIcon.BANNED); + private static final MigLayout layout = new MigLayout( + "flowy, insets 0, gap 0", "[fill, grow, center]", "7[][]" + ); + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + + DeckGame info = (DeckGame) value; + + JLabel iconLabel = new JLabel(info.isWinner() ? WON_ICON : LOST_ICON); + iconLabel.setHorizontalAlignment(SwingConstants.CENTER); + + JLabel turnLabel = new JLabel(String.valueOf(info.getTurns())); + turnLabel.setHorizontalAlignment(SwingConstants.CENTER); + turnLabel.setFont(FontsAndBorders.FONT0); + + JPanel panel = new JPanel(layout); + panel.add(iconLabel); + panel.add(turnLabel); + + return panel; + } +}