Pen.java



/** 線を描く時の情報を記憶する Pen */
import java.awt.*;
public class Pen {

 /** 線の色 */
    private Color color;

 /** 線の色にアクセスするメソッド */
    public Color getColor() {
        return color;
    }   
    public void setColor( Color color ) {
        this.color = color;
    }   

 /** 線の太さ、線の端の形状 */
    private BasicStroke stroke;
    public static final int ROUND=0;
    public static final int SQUARE=1;
    private int type;

/** 線の太さ、線の端の形状にアクセスするメソッド */
    public BasicStroke getBasicStroke() {
        return stroke;
    }   
    public void setBasicStroke( BasicStroke stroke ) {
        this.stroke = stroke;
    }   
    public float getLineWidth() {
        return stroke.getLineWidth();
    }   
    public void setLineWidth( float width ) {
        int cap = stroke.getEndCap();
        int join = stroke.getLineJoin();
        stroke = new BasicStroke( width, cap, join );
    }
    public int getLineType() {
        return type;
    }
    public void setLineType( int type ) {
        this.type = type;
        float width = stroke.getLineWidth();
        if( type == ROUND )
            stroke = new BasicStroke( width,
                         BasicStroke.CAP_ROUND,
                         BasicStroke.JOIN_ROUND );
        else
            stroke = new BasicStroke( width,
                         BasicStroke.CAP_SQUARE,
                         BasicStroke.JOIN_MITER );
    }

 /** コンストラクタ */
    public Pen() {
        color = Color.black;
        type = ROUND;
        stroke = new BasicStroke( 1.0f,
                     BasicStroke.CAP_ROUND,
                     BasicStroke.JOIN_ROUND );
    }
}