
--- CanvasPanel.java Mon Jun 01 05:12:13 2009
+++ CanvasPanel.java Sat Jun 13 02:32:23 2009
@@ -97,4 +97,12 @@
((Graphics2D) g).drawImage(img, 0, 0, this);
}
}
+
+ // --------------------------------------------------
+ // マウスの座標があるキャンバスの色素を返す
+ // --------------------------------------------------
+ public Color spuitCursorColor()
+ {
+ return new Color(img.getRGB((int) p2.x, (int) p2.y));
+ }
}
--- PtSpuit.java Mon Jun 01 05:12:13 2009
+++ PtSpuit.java Sat Jun 13 02:46:30 2009
@@ -16,11 +16,13 @@
// コンストラクタ
// --------------------------------------------------
PtSpuit() {
+ // 特に何もしない
}
// --------------------------------------------------
// Paint()をオーバーライド
// --------------------------------------------------
public void Paint(Point2D.Double p1, Point2D.Double p2, Graphics2D g2d, BufferedImage img) {
+ // 特に何もしない
}
}
\ No newline at end of file
--- ReviewPaintMain.java Mon Jun 01 05:12:12 2009
+++ ReviewPaintMain.java Sat Jun 13 02:46:30 2009
@@ -53,6 +53,8 @@
// ツールパレットの状態変数・状態番号
+ private int toolPalletState; // 状態変数
+
private static final int PAINT_TOOL_STATE_PENCIL = 0;
private static final int PAINT_TOOL_STATE_ERASER = 1;
@@ -166,6 +168,19 @@
public void mouseDragged(java.awt.event.MouseEvent e) {
jLabelCursorPosition.setText(e.getX() + "," + e.getY()); // 座標の表示
+ if (toolPalletState == PAINT_TOOL_STATE_SPUIT) {
+ colorPanel.setColor(jPanelCanvasPaper.spuitCursorColor()); // カラーパレットにマウス座標のキャンバス色素を取得し設定する
+ }
+ }
+
+ });
+
+ // マウス押下時のイベントリスナ
+ jPanelCanvasPaper.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent e) {
+ if (toolPalletState == PAINT_TOOL_STATE_SPUIT) {
+ colorPanel.setColor(jPanelCanvasPaper.spuitCursorColor()); // カラーパレットにマウス座標のキャンバス色素を取得し設定する
+ }
}
});
}
@@ -261,6 +276,9 @@
// --------------------------------------------------
private PaintTool changeMainButton(int state) {
+ // ツールパレットの状態を更新する
+ toolPalletState = state;
+
// 一度、全てのボタンを非選択状態にする
jButtonPencil.setBorder(nonactiveToolBoder);
jButtonEraser.setBorder(nonactiveToolBoder);
@@ -392,7 +410,6 @@
private JButton getJButtonSpuit() {
if (jButtonSpuit == null) {
jButtonSpuit = new JButton();
- jButtonSpuit.setEnabled(false);
jButtonSpuit.setPreferredSize(new Dimension(50, 50));
jButtonSpuit.setToolTipText("色の選択");
jButtonSpuit.setIcon(new ImageIcon(getClass().getResource("/img/spuit.png")));