差分情報適用後の実行イメージ

差分情報

パッチファイル (Unified diffs)

--- PtAirbrush.java	Mon Jun 01 05:12:12 2009
+++ PtAirbrush.java	Mon Jun 01 05:28:49 2009
@@ -5,22 +5,184 @@
 // ----------------------------------------------------------------------------------------------------
 
 // パッケージのインポート
-import java.awt.geom.Point2D;
+import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Graphics2D;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
+import java.util.Random;
+import javax.swing.BorderFactory;
+import javax.swing.JPanel;
+import javax.swing.JButton;
+import javax.swing.ImageIcon;
+import javax.swing.BoxLayout;
 
 // PaintToolを継承する
 public class PtAirbrush extends PaintTool {
 
+	// 矩形
+	Rectangle2D.Double rect = new Rectangle2D.Double();
+
+	// 乱数用
+	Random rand = new Random();
+
+	// エアブラシの半径
+	private int airbrushRadius;
+
+	// エアブラシのドット量(=airbrushRadius * AMOUNT_OF_LIQUID)
+	private static final int AMOUNT_OF_LIQUID = 5;
+
+	// オプション状態番号
+
+	private static final int OPTION_1 = 0;
+
+	private static final int OPTION_2 = 1;
+
+	private static final int OPTION_3 = 2;
+
+	// 各オプションに対応するエアブラシの半径
+	private static final int AIRBRUSH_RADIUS_1 = 5;
+
+	private static final int AIRBRUSH_RADIUS_2 = 10;
+
+	private static final int AIRBRUSH_RADIUS_3 = 15;
+
+	// 以降、ボタンやパネルなどのコンポーネント関連の宣言
+
+	private JPanel jPanelLayout = null;
+
+	private JButton jButton1 = null;
+
+	private JButton jButton2 = null;
+
+	private JButton jButton3 = null;
+
 	// --------------------------------------------------
 	// コンストラクタ
 	// --------------------------------------------------
 	PtAirbrush() {
+		// ぺン色
+		super.penColor = Color.black;
+		// オプション部品のレイアウト用パネルの配置
+		super.jPanel.add(getJPanelLayout());
+		// オプション部品のデフォルト選択
+		changeOption(OPTION_1);
 	}
 
 	// --------------------------------------------------
 	// Paint()をオーバーライド
 	// --------------------------------------------------
 	public void Paint(Point2D.Double p1, Point2D.Double p2, Graphics2D g2d, BufferedImage img) {
+		// ペン色を設定
+		g2d.setPaint(penColor);
+
+		// エアブラシの半径×AMOUNT_OF_LIQUID個のドットを打つ
+		for (int i = 0; i < airbrushRadius * AMOUNT_OF_LIQUID; i++) {
+			double x, y, r; // インクの飛散座標と距離
+
+			// X方向とY方向に一定距離で散布させるが、エアブラシの半径内に収まっていなければ、再散布する
+			do {
+				x = rand.nextInt(2 * airbrushRadius + 1) - airbrushRadius;
+				y = rand.nextInt(2 * airbrushRadius + 1) - airbrushRadius;
+				r = Math.sqrt(Math.pow(x, 2.0F) + Math.pow(y, 2.0F));
+			} while (r > airbrushRadius);
+
+			// 半径内に収まる座標を得れれば、それをドットで描写する
+			rect.setFrame(p2.x + x, p2.y + y, 1, 1);
+			g2d.fill(rect);
+		}
+	}
+
+	// --------------------------------------------------
+	// オプション状態遷移関数(各種オプションのボタン押下時に呼び出されるメソッド)
+	// --------------------------------------------------
+	private void changeOption(int state) {
+
+		// 一度、全てのボタンを非選択状態にする
+		jButton1.setIcon(new ImageIcon(getClass().getResource("/img/airbrush_1_n.png")));
+		jButton2.setIcon(new ImageIcon(getClass().getResource("/img/airbrush_2_n.png")));
+		jButton3.setIcon(new ImageIcon(getClass().getResource("/img/airbrush_3_n.png")));
+
+		// 押されたボタンを選択状態にし、押されたボタンに応じたエアブラシ半径を設定する
+		switch (state) {
+		case OPTION_1:
+			airbrushRadius = AIRBRUSH_RADIUS_1; // エアブラシ半径
+			jButton1.setIcon(new ImageIcon(getClass().getResource("/img/airbrush_1_a.png"))); // ボタンを選択状態の画像にする
+			break;
+		case OPTION_2:
+			airbrushRadius = AIRBRUSH_RADIUS_2;
+			jButton2.setIcon(new ImageIcon(getClass().getResource("/img/airbrush_2_a.png")));
+			break;
+		case OPTION_3:
+			airbrushRadius = AIRBRUSH_RADIUS_3;
+			jButton3.setIcon(new ImageIcon(getClass().getResource("/img/airbrush_3_a.png")));
+			break;
+		}
+	}
+
+	// ----------------------------------------------------------------------------------------------------
+	// 以降、ボタンやパネルなどのコンポーネント関連の初期化
+	// ----------------------------------------------------------------------------------------------------
+
+	// オプション部品のレイアウト用パネル
+	private JPanel getJPanelLayout() {
+		if (jPanelLayout == null) {
+			jPanelLayout = new JPanel();
+			jPanelLayout.setLayout(new BoxLayout(getJPanelLayout(), BoxLayout.Y_AXIS)); // Y軸方向に整列させる
+			jPanelLayout.add(getJButton1());
+			jPanelLayout.add(getJButton2());
+			jPanelLayout.add(getJButton3());
+		}
+		return jPanelLayout;
+	}
+
+	// エアブラシ:細
+	private JButton getJButton1() {
+		if (jButton1 == null) {
+			jButton1 = new JButton();
+			jButton1.setPreferredSize(new Dimension(40, 40)); // サイズ
+			jButton1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); // 枠無し
+			jButton1.setIcon(new ImageIcon(getClass().getResource("/img/airbrush_1_n.png"))); // ボタン画像
+			// ボタン押下イベント
+			jButton1.addActionListener(new java.awt.event.ActionListener() {
+				public void actionPerformed(java.awt.event.ActionEvent e) {
+					changeOption(OPTION_1); // オプションの切り替え処理へ
+				}
+			});
+		}
+		return jButton1;
+	}
+
+	// エアブラシ:中
+	private JButton getJButton2() {
+		if (jButton2 == null) {
+			jButton2 = new JButton();
+			jButton2.setPreferredSize(new Dimension(40, 40));
+			jButton2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
+			jButton2.setIcon(new ImageIcon(getClass().getResource("/img/airbrush_2_n.png")));
+			jButton2.addActionListener(new java.awt.event.ActionListener() {
+				public void actionPerformed(java.awt.event.ActionEvent e) {
+					changeOption(OPTION_2);
+				}
+			});
+		}
+		return jButton2;
+	}
+
+	// エアブラシ:太
+	private JButton getJButton3() {
+		if (jButton3 == null) {
+			jButton3 = new JButton();
+			jButton3.setPreferredSize(new Dimension(40, 40));
+			jButton3.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
+			jButton3.setIcon(new ImageIcon(getClass().getResource("/img/airbrush_3_n.png")));
+			jButton3.addActionListener(new java.awt.event.ActionListener() {
+				public void actionPerformed(java.awt.event.ActionEvent e) {
+					changeOption(OPTION_3);
+				}
+			});
+		}
+		return jButton3;
 	}
-}
\ No newline at end of file
+}
--- ReviewPaintMain.java	Mon Jun 01 05:12:12 2009
+++ ReviewPaintMain.java	Mon Jun 01 05:28:29 2009
@@ -375,7 +375,6 @@
 	private JButton getJButtonAirbrush() {
 		if (jButtonAirbrush == null) {
 			jButtonAirbrush = new JButton();
-			jButtonAirbrush.setEnabled(false);
 			jButtonAirbrush.setPreferredSize(new Dimension(50, 50));
 			jButtonAirbrush.setToolTipText("エアブラシ");
 			jButtonAirbrush.setIcon(new ImageIcon(getClass().getResource("/img/airbrush.png")));

変更後のファイルと変更前後の比較

変更の種類 変更後のファイル 変更前後の比較
修正 /branches/add_airbrush/PtAirbrush.java Side-by-side diffs
修正 /branches/add_airbrush/ReviewPaintMain.java Side-by-side diffs
追加 /branches/add_airbrush/img/airbrush_1_a.png Side-by-side diffs
追加 /branches/add_airbrush/img/airbrush_1_n.png Side-by-side diffs
追加 /branches/add_airbrush/img/airbrush_2_a.png Side-by-side diffs
追加 /branches/add_airbrush/img/airbrush_2_n.png Side-by-side diffs
追加 /branches/add_airbrush/img/airbrush_3_a.png Side-by-side diffs
追加 /branches/add_airbrush/img/airbrush_3_a.png Side-by-side diffs
リンク先は リポジトリ上のURLです