KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > whiteboard > graph > shapes > ShapeManager


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.whiteboard.graph.shapes;
20
21 import java.awt.Graphics JavaDoc;
22 import java.awt.Point JavaDoc;
23 import java.util.HashMap JavaDoc;
24
25 import org.lucane.applications.whiteboard.WhiteBoard;
26 import org.lucane.applications.whiteboard.graph.MyGraph;
27
28 public class ShapeManager
29 {
30     private HashMap JavaDoc shapes;
31     private String JavaDoc selectedShape;
32     
33     public ShapeManager(WhiteBoard plugin)
34     {
35         this.shapes = new HashMap JavaDoc();
36         this.shapes.put("rectangle", new Rectangle());
37         this.shapes.put("roundRectangle", new RoundRectangle());
38         this.shapes.put("diamond", new Diamond());
39         this.shapes.put("ellipse", new Ellipse());
40         
41         this.shapes.put("line", new Line());
42         this.shapes.put("simpleArrow", new SimpleArrow());
43         this.shapes.put("doubleArrow", new DoubleArrow());
44         
45         this.shapes.put("text", new Text(plugin));
46         this.shapes.put("image", new Image(plugin));
47         
48         this.selectedShape = null;
49     }
50     
51     public void setSelectedShape(String JavaDoc name)
52     {
53         this.selectedShape = name;
54     }
55     
56     public String JavaDoc getSelectedShape()
57     {
58         return selectedShape;
59     }
60     
61     public void paintSelectedShape(Graphics JavaDoc g, Point JavaDoc start, Point JavaDoc end)
62     {
63         if(this.selectedShape != null)
64             getShape(selectedShape).paint(g, start, end);
65     }
66     
67     public void addSelectedShape(MyGraph graph, Point JavaDoc start, Point JavaDoc end)
68     {
69         if(this.selectedShape != null)
70             getShape(selectedShape).addToGraph(graph, start, end);
71     }
72     
73     private Shape getShape(String JavaDoc name)
74     {
75         return (Shape)shapes.get(name);
76     }
77
78 }
Popular Tags