import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * GameInfoDialog クラスは、対局情報を表示するダイアログを提供します。 * @author Jiro Suzuki */ public class GameInfoDialog extends JDialog{ private static final Font FONT_MSG=new Font("MS UI Gothic",Font.PLAIN,16); private IgoModel controller; private JPanel jpInfo1; private JLabel jlInfoPB; private JLabel jlInfoPW; private JLabel jlInfoPBrank; private JLabel jlInfoPWrank; private JLabel jlInfoEvent; private JLabel jlInfoGameName; private JLabel jlInfoDate; private JLabel jlInfoKomi; private JLabel jlInfoResult; private JTextField jtfInfoPB; private JTextField jtfInfoPW; private JTextField jtfInfoPBrank; private JTextField jtfInfoPWrank; private JTextField jtfInfoEvent; private JTextField jtfInfoGameName; private JTextField jtfInfoDate; private JTextField jtfInfoKomi; private JTextField jtfInfoResult; private JButton bt_infoUpdate; private JButton bt_infoCancel; /** * パラメータに設定された内容で、インスタンスを生成します。 * @param owner 所有者 * @param title ダイアログのタイトル * @param modal モーダルにするかどうかの真偽値 * @param controller コントローラー */ public GameInfoDialog(Frame owner,String title,boolean modal,IgoModel controller){ super(owner,title,modal); this.controller=controller; jlInfoPB=new JLabel("黒番",SwingConstants.CENTER); jlInfoPW=new JLabel("白番",SwingConstants.CENTER); jlInfoPBrank=new JLabel("段位",SwingConstants.CENTER); jlInfoPWrank=new JLabel("段位",SwingConstants.CENTER); jlInfoEvent=new JLabel("大会名",SwingConstants.CENTER); jlInfoGameName=new JLabel("対局名",SwingConstants.CENTER); jlInfoDate=new JLabel("対局日",SwingConstants.CENTER); jlInfoKomi=new JLabel("コミ",SwingConstants.CENTER); jlInfoResult=new JLabel("結果",SwingConstants.CENTER); jtfInfoPB=new JTextField(); jtfInfoPW=new JTextField(); jtfInfoPBrank=new JTextField(); jtfInfoPWrank=new JTextField(); jtfInfoEvent=new JTextField(); jtfInfoGameName=new JTextField(); jtfInfoDate=new JTextField(); jtfInfoKomi=new JTextField(); jtfInfoResult=new JTextField(); bt_infoUpdate=new JButton("更新"); bt_infoCancel=new JButton("キャンセル"); jlInfoPB.setFont(FONT_MSG); jlInfoPW.setFont(FONT_MSG); jlInfoPBrank.setFont(FONT_MSG); jlInfoPWrank.setFont(FONT_MSG); jlInfoEvent.setFont(FONT_MSG); jlInfoGameName.setFont(FONT_MSG); jlInfoDate.setFont(FONT_MSG); jlInfoKomi.setFont(FONT_MSG); jlInfoResult.setFont(FONT_MSG); jtfInfoPB.setFont(FONT_MSG); jtfInfoPW.setFont(FONT_MSG); jtfInfoPBrank.setFont(FONT_MSG); jtfInfoPWrank.setFont(FONT_MSG); jtfInfoEvent.setFont(FONT_MSG); jtfInfoGameName.setFont(FONT_MSG); jtfInfoDate.setFont(FONT_MSG); jtfInfoKomi.setFont(FONT_MSG); jtfInfoResult.setFont(FONT_MSG); bt_infoUpdate.setFont(FONT_MSG); bt_infoCancel.setFont(FONT_MSG); jlInfoPB.setBounds(5,5,60,30); jlInfoPW.setBounds(5,40,60,30); jlInfoPBrank.setBounds(275,5,40,30); jlInfoPWrank.setBounds(275,40,40,30); jlInfoEvent.setBounds(5,75,60,30); jlInfoGameName.setBounds(5,110,60,30); jlInfoDate.setBounds(5,145,60,30); jlInfoKomi.setBounds(5,180,60,30); jlInfoResult.setBounds(5,215,60,30); jtfInfoPB.setBounds(70,5,200,30); jtfInfoPW.setBounds(70,40,200,30); jtfInfoPBrank.setBounds(320,5,145,30); jtfInfoPWrank.setBounds(320,40,145,30); jtfInfoEvent.setBounds(70,75,400,30); jtfInfoGameName.setBounds(70,110,400,30); jtfInfoDate.setBounds(70,145,200,30); jtfInfoKomi.setBounds(70,180,200,30); jtfInfoResult.setBounds(70,215,400,30); bt_infoUpdate.setBounds(145,250,100,30); bt_infoCancel.setBounds(255,250,100,30); bt_infoCancel.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e){ setVisible(false); } }); bt_infoUpdate.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e){ updateInfo(); } }); jpInfo1=new JPanel(); jpInfo1.setSize(500,300); jpInfo1.setLocation(0,0); jpInfo1.setLayout(null); jpInfo1.add(jlInfoPB); jpInfo1.add(jtfInfoPB); jpInfo1.add(jlInfoPBrank); jpInfo1.add(jtfInfoPBrank); jpInfo1.add(jlInfoPW); jpInfo1.add(jtfInfoPW); jpInfo1.add(jlInfoPWrank); jpInfo1.add(jtfInfoPWrank); jpInfo1.add(jlInfoEvent); jpInfo1.add(jtfInfoEvent); jpInfo1.add(jlInfoGameName); jpInfo1.add(jtfInfoGameName); jpInfo1.add(jlInfoDate); jpInfo1.add(jtfInfoDate); jpInfo1.add(jlInfoKomi); jpInfo1.add(jtfInfoKomi); jpInfo1.add(jlInfoResult); jpInfo1.add(jtfInfoResult); jpInfo1.add(bt_infoUpdate); jpInfo1.add(bt_infoCancel); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); getContentPane().setLayout(null); getContentPane().add(jpInfo1); setBounds(350,200,500,340); setVisible(false); } /** * ダイアログを表示します。 * @param gameInfo 対局情報 */ public void showDialog(GameInformation gameInfo){ jtfInfoPB.setText(gameInfo.getBlackPlayer()); jtfInfoPW.setText(gameInfo.getWhitePlayer()); jtfInfoPBrank.setText(gameInfo.getBlackRank()); jtfInfoPWrank.setText(gameInfo.getWhiteRank()); jtfInfoEvent.setText(gameInfo.getEvent()); jtfInfoGameName.setText(gameInfo.getGameName()); jtfInfoDate.setText(gameInfo.getDate()); jtfInfoKomi.setText(gameInfo.getKomi()); jtfInfoResult.setText(gameInfo.getResult()); setVisible(true); } private void updateInfo(){ GameInformation gameInfo=new GameInformation(); gameInfo.setBlackPlayer(jtfInfoPB.getText()); gameInfo.setWhitePlayer(jtfInfoPW.getText()); gameInfo.setBlackRank(jtfInfoPBrank.getText()); gameInfo.setWhiteRank(jtfInfoPWrank.getText()); gameInfo.setEvent(jtfInfoEvent.getText()); gameInfo.setGameName(jtfInfoGameName.getText()); gameInfo.setDate(jtfInfoDate.getText()); gameInfo.setKomi(jtfInfoKomi.getText()); gameInfo.setResult(jtfInfoResult.getText()); controller.updateGameInfo(gameInfo); setVisible(false); } }