Javaで画像処理プロジェクトを行っています。UIには、長方形の選択や魔法の杖ツールなどのツールが用意されています。
今のところ、クラスがあります: ImageView:
/*Other classes can set image, this class will draw the image*/
public class ImageView extends JPanel{
/*It resizes the image to fit the panel and draws the image on the panel.*/
public void setImage(BufferedImage image){/*code*/}
}
各ツールは個別のクラスとして扱われ、ImageViewを拡張します。例: 長方形選択ツール:
/*It has a function which allows the user to draw rectangle around the image, I am not going to write the code here because it is long and unnecessary*/
public class ResizableRectangleView extends ImageView {
/*It returns the rectangle drawn by the user*/
public Rectangle getRectange(){return rectangle;}
}
別のクラスUIControllerは、ユーザーが選択したツールに基づいて「ツール」を作成します。次に、そのJPanel(ツールまたはビュー)(例:ResizableRectangleViewまたはその他のビュー)がGUIに表示されます。その後、ユーザーは長方形を描くことができます(ResizableRectangleViewの場合)。
ツールごとに、個別のクラスがあります。また、ユーザーがツールを選択するたびに、新しいオブジェクトが作成され、そのツールに画像が提供されてから、ツール(ビュー)がUIに追加されます。
私はこのアプローチが好きではありません。私の質問は、GimpやPhotoshopのようなプログラムで、同じ画像/レイヤーで複数のツールを使用できるようにする方法です。どうすればいいですか?
コンポーネント(データとコマンドのフローを示す)を含むブロック図をいただければ幸いです。