update content and style of the Result column in DeckGamesJTable.

master
lodici 2017-02-24 03:17:08 +00:00
parent db80ef14ee
commit 30803c7fae
4 changed files with 74 additions and 22 deletions

View File

@ -121,11 +121,15 @@ class DeckGame {
: new DeckInfo(gameInfo.player1DeckName, gameInfo.player1DeckColor); : new DeckInfo(gameInfo.player1DeckName, gameInfo.player1DeckColor);
} }
String getResultInfo() { boolean isWinner() {
int playerNum = gameInfo.player1DeckName.equals(deck.getName()) ? 1 : 2; int playerNum = gameInfo.player1DeckName.equals(deck.getName()) ? 1 : 2;
int winningPlayer = Integer.parseInt(gameInfo.winningPlayerProfile); int winningPlayer = Integer.parseInt(gameInfo.winningPlayerProfile);
return winningPlayer == playerNum;
}
String getResultInfo() {
return String.format("%s %d %s", return String.format("%s %d %s",
winningPlayer == playerNum ? MText.get(_S4) : MText.get(_S5), isWinner() ? MText.get(_S4) : MText.get(_S5),
gameInfo.turns, gameInfo.turns,
gameInfo.isConceded ? "(" + MText.get(_S6) + ")" : "" gameInfo.isConceded ? "(" + MText.get(_S6) + ")" : ""
).trim(); ).trim();
@ -135,4 +139,8 @@ class DeckGame {
return MText.get(_S3, gameInfo.startLife, gameInfo.startHandSize); return MText.get(_S3, gameInfo.startLife, gameInfo.startHandSize);
} }
int getTurns() {
return gameInfo.turns;
}
} }

View File

@ -45,19 +45,21 @@ class DeckGamesJTable extends JTable {
} }
private void setColumnRenderers() { private void setColumnRenderers() {
getColumnModel().getColumn(0).setCellRenderer(new GameCellRenderer()); getColumnModel().getColumn(0).setCellRenderer(new ResultCellRenderer());
getColumnModel().getColumn(1).setCellRenderer(new PlayerCellRenderer()); getColumnModel().getColumn(1).setCellRenderer(new GameCellRenderer());
getColumnModel().getColumn(2).setCellRenderer(new PlayerCellRenderer()); 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() { private void setDefaultColumnProperties() {
final TableColumnModel cm = getColumnModel(); final TableColumnModel cm = getColumnModel();
// set initial column widths. // set initial column widths.
for (int i = 0; i < cm.getColumnCount(); i++) { cm.getColumn(0).setMinWidth(30);
cm.getColumn(i).setMinWidth(130); cm.getColumn(1).setMinWidth(130);
cm.getColumn(i).setPreferredWidth(130); cm.getColumn(2).setMinWidth(170);
} cm.getColumn(3).setMinWidth(170);
cm.getColumn(4).setMinWidth(180);
final JTableHeader header = getTableHeader(); final JTableHeader header = getTableHeader();
header.setReorderingAllowed(true); header.setReorderingAllowed(true);
final DefaultTableCellRenderer renderer = final DefaultTableCellRenderer renderer =
@ -87,7 +89,7 @@ class DeckGamesJTable extends JTable {
@Override @Override
public void setModel(TableModel dataModel) { public void setModel(TableModel dataModel) {
super.setModel(dataModel); super.setModel(dataModel);
setColumnRenderers(); setColumnRenderers();
if (tca != null) { if (tca != null) {
tca.adjustColumns(); tca.adjustColumns();
} }

View File

@ -19,7 +19,6 @@ class DeckGamesTableModel extends AbstractTableModel {
private static final String _S3 = "Player"; private static final String _S3 = "Player";
private static final String _S4 = "Opponent"; private static final String _S4 = "Opponent";
private static final String _S5 = "Opponent deck"; private static final String _S5 = "Opponent deck";
private static final String _S6 = "Result";
private static final int PAGE_SIZE = 8; private static final int PAGE_SIZE = 8;
@ -63,11 +62,11 @@ class DeckGamesTableModel extends AbstractTableModel {
@Override @Override
public String getColumnName(int columnIndex) { public String getColumnName(int columnIndex) {
switch (columnIndex) { switch (columnIndex) {
case 0: return MText.get(_S1); case 0: return "";
case 1: return MText.get(_S3); case 1: return MText.get(_S1);
case 2: return MText.get(_S4); case 2: return MText.get(_S3);
case 3: return MText.get(_S5); case 3: return MText.get(_S4);
case 4: return MText.get(_S6); case 4: return MText.get(_S5);
default: return "???"; default: return "???";
} }
} }
@ -76,9 +75,10 @@ class DeckGamesTableModel extends AbstractTableModel {
public Class<?> getColumnClass(int col) { public Class<?> getColumnClass(int col) {
switch (col) { switch (col) {
case 0: return DeckGame.class; case 0: return DeckGame.class;
case 1: return PlayerInfo.class; case 1: return DeckGame.class;
case 2: return PlayerInfo.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; default: return String.class;
} }
} }
@ -93,10 +93,10 @@ class DeckGamesTableModel extends AbstractTableModel {
DeckGame stats = gameStats.get(row); DeckGame stats = gameStats.get(row);
switch (col) { switch (col) {
case 0: return stats; case 0: return stats;
case 1: return stats.getDeckPlayerInfo(); case 1: return stats;
case 2: return stats.getOpponentInfo(); case 2: return stats.getDeckPlayerInfo();
case 3: return stats.getOpponentDeckInfo(); case 3: return stats.getOpponentInfo();
case 4: return stats.getResultInfo(); case 4: return stats.getOpponentDeckInfo();
default: return "???"; default: return "???";
} }
} }

View File

@ -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;
}
}