package ipm.gerdc.baccarat.page;
import ipm.gerdc.baccarat.MainFrame;
import ipm.gerdc.baccarat.model.GameInfoBean;
import ipm.gerdc.baccarat.util.GameTools;
import ipm.gerdc.baccarat.util.GenReport;
import ipm.gerdc.baccarat.util.TextFactory;
import ipm.gerdc.baccarat.util.UIFactory;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
public class ReportPage extends InfoPage {
private static final long serialVersionUID = 1L;
private static String[] sHeader;
private static String[][] sBody;
private static JButton jbPlay, jbExport;
@Override
public JPanel buildBodyPanel() throws Exception {
JPanel r1 = UIFactory.makeJPanel("CENTER");
r1.add(UIFactory.makeJLabel(TextFactory.textList.get("Report"), 38));
JPanel r2 = UIFactory.makeJPanel("CENTER");
r2.add(jbPlay);
r2.add(jbExport);
JPanel pnlTop = new JPanel();
pnlTop.setLayout(new GridLayout(2, 0));
pnlTop.add(r1);
pnlTop.add(r2);
JTable jtReport = new JTable(sBody, sHeader);
DefaultTableCellRenderer renderC = new DefaultTableCellRenderer();
renderC.setHorizontalAlignment(JLabel.CENTER);
DefaultTableCellRenderer renderR = new DefaultTableCellRenderer();
renderR.setHorizontalAlignment(JLabel.RIGHT);
jtReport.getColumnModel().getColumn(1).setCellRenderer(renderC);
jtReport.getColumnModel().getColumn(2).setCellRenderer(renderC);
jtReport.getColumnModel().getColumn(4).setCellRenderer(renderR);
jtReport.getColumnModel().getColumn(5).setCellRenderer(renderR);
jtReport.getColumnModel().getColumn(6).setCellRenderer(renderR);
jtReport.getColumnModel().getColumn(7).setCellRenderer(renderR);
jtReport.getColumnModel().getColumn(8).setCellRenderer(renderR);
jtReport.getColumnModel().getColumn(9).setCellRenderer(renderR);
jtReport.setEnabled(false);
JScrollPane jsp = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jsp.getViewport().add(jtReport);
jsp.setPreferredSize(parent.getSreen());
JPanel pnlMain = UIFactory.makeJPanel("CENTER");
pnlMain.setLayout(new BorderLayout());
pnlMain.add(pnlTop, BorderLayout.NORTH);
pnlMain.add(jsp, BorderLayout.CENTER);
return pnlMain;
}
@Override
public void initValue() throws Exception {
jbPlay = UIFactory.makeJButton(TextFactory.textList.get("PlayBtn"), "play", this);
jbExport = UIFactory.makeJButton(TextFactory.textList.get("ExportBtn"), "export", this);
sHeader = new String[10];
sHeader[0] = TextFactory.textList.get("GameID");
sHeader[1] = TextFactory.textList.get("GameTime");
sHeader[2] = TextFactory.textList.get("Result");
sHeader[3] = TextFactory.textList.get("Winner");
sHeader[4] = TextFactory.textList.get("BoP");
sHeader[5] = TextFactory.textList.get("BoB");
sHeader[6] = TextFactory.textList.get("BoT");
sHeader[7] = TextFactory.textList.get("WagerAmt");
sHeader[8] = TextFactory.textList.get("PaybackAmt");
sHeader[9] = TextFactory.textList.get("Balance");
sBody = new String[parent.getGameList().size()][10];
for (int i = 0; i < parent.getGameList().size(); i++) {
GameInfoBean bean = parent.getGameList().get(i);
sBody[i][0] = bean.getGameID();
sBody[i][1] = bean.getGameTime();
sBody[i][2] = bean.getPlayerPoint() + "-" + bean.getBankerPoint();
sBody[i][3] = bean.getResultNum();
sBody[i][4] = GameTools.formatAmount(bean.getBetOnPlayer());
sBody[i][5] = GameTools.formatAmount(bean.getBetOnBanker());
sBody[i][6] = GameTools.formatAmount(bean.getBetOnTie());
sBody[i][7] = GameTools.formatAmount(bean.getBettingAmount());
sBody[i][8] = GameTools.formatAmount(bean.getReturnAmount());
sBody[i][9] = GameTools.formatAmount(bean.getBalance());
}
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() instanceof JButton) {
if (ae.getSource().equals(jbPlay)) {
parent.switchPage(MainFrame.Page_001);
} else if (ae.getSource().equals(jbExport)) {
GenReport.genReport(parent.getGameList());
parent.popup("S", TextFactory.textList.get("ExportMsg"));
}
}
}
}