import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* IgoTextPanel クラスは、テキスト描画の碁盤を提供します。
* @author Jiro Suzuki
*/
public class IgoTextPanel extends IgoPanel{
private static final int FONTSIZE=31;
private static final int BANSIZEX=630;
private static final int BANSIZEY=615;
private static final int BOX=32;
private static final int ROSU=19;
private static final Font CONSTFONT=new Font("Serif",Font.PLAIN,FONTSIZE);
private static final Color CONSTCOLOR=new Color(255,255,255);
private IgoModel controller;
private IntBoard intBoard;
private TextBoard textBoard;
private char[][] currentBoard;
private Image image;
private Graphics g_image;
private boolean isPutable;
/**
* 石が置かれていない碁盤のインスタンスを生成します。
*/
IgoTextPanel(){
intBoard=new IntBoard();
textBoard=new TextBoard();
isPutable=false;
setOpaque(true);
addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent me){
if(isPutable){
boolean isOnBoardRow=false;
boolean isOnBoardCol=false;
int x=me.getX();
int y=me.getY();
int minX,minY,row,col;
for(row=0;row<ROSU;row++){
minY=row*BOX+11;
if(y>=minY && y<minY+BOX){
isOnBoardRow=true;
break;
}
}
for(col=0;col<ROSU;col++){
minX=col*BOX+11;
if(x>=minX && x<minX+BOX){
isOnBoardCol=true;
break;
}
}
if(isOnBoardRow && isOnBoardCol){
controller.putStone(row,col);
}
}
}
});
}
/**
* テキスト描画の碁盤を描画します。
* @param g 保護対象の Graphics オブジェクト
*/
public void paintComponent(Graphics g){
super.paintComponent(g);
currentBoard=textBoard.getTextBoard(intBoard);
image=createImage(BANSIZEX,BANSIZEY);
g_image=image.getGraphics();
g_image.setColor(CONSTCOLOR);
g_image.fillRect(0,0,BANSIZEX,BANSIZEY);
g_image.setColor(Color.black);
g_image.setFont(CONSTFONT);
String line=new String("");
for(int i=0;i<19;i++){
line=new String(currentBoard[i]);
g_image.drawString(line,20,i*FONTSIZE+40);
}
g.drawImage(image,0,0,this);
}
/**
* テキスト描画の碁盤を更新します。
* @param intBoard 碁盤に見立てた行列に、石の色を配置した碁盤データ
*/
public void update(IntBoard intBoard){
this.intBoard=intBoard;
repaint();
}
/**
* コントローラーを設定します。
* @param controller コントローラー
*/
public void setIgoGameController(IgoModel controller){
this.controller=controller;
isPutable=true;
}
}