KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > diagrams > ClassFigureCreationTool


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

18
19 package org.objectweb.jac.ide.diagrams;
20
21 import CH.ifa.draw.framework.DrawingEditor;
22 import java.awt.Point JavaDoc;
23 import java.awt.event.MouseEvent JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Vector JavaDoc;
28 import org.objectweb.jac.aspects.gui.DisplayContext;
29 import org.objectweb.jac.aspects.gui.EventHandler;
30 import org.objectweb.jac.aspects.gui.InvokeEvent;
31 import org.objectweb.jac.core.rtti.ClassRepository;
32 import org.objectweb.jac.ide.Class;
33 import org.objectweb.jac.ide.Diagram;
34 import org.objectweb.jac.ide.Project;
35 import org.objectweb.jac.util.Log;
36
37 public class ClassFigureCreationTool extends CreationTool {
38
39     DisplayContext context;
40
41     public ClassFigureCreationTool(DrawingEditor newDrawingEditor,
42                                    DisplayContext context) {
43         super(newDrawingEditor);
44         this.context = context;
45     }
46
47     Point JavaDoc anchorPoint;
48
49     /**
50      * Creates a new figure by cloning the prototype.
51      */

52     public void mouseDown(MouseEvent JavaDoc e, int x, int y) {
53         anchorPoint = new Point JavaDoc(x,y);
54         EventHandler.get().onInvoke(
55             context,
56             new InvokeEvent(
57                 null,
58                 this,
59                 ClassRepository.get().getClass(getClass())
60                 .getMethod("importClass(org.objectweb.jac.ide.Class,boolean)")));
61         // (view().add(getCreatedFigure())).displayBox(anchorPoint, anchorPoint);
62
}
63
64     public void mouseUp(MouseEvent JavaDoc e, int x, int y) {
65     }
66
67     /**
68      * Import class
69      * @param cl the class to import
70      * @param importRelations wether to also import relations with
71      * other classes on the diagram
72      */

73     public void importClass(Class JavaDoc cl, boolean importRelations) {
74         Log.trace("figures","createFigure for "+cl);
75         if (cl!=null) {
76             DiagramView diagram = ((DiagramView)editor());
77             diagram.addClass(cl,anchorPoint);
78
79             if (importRelations) {
80                 diagram.importRelations(cl);
81             }
82         }
83         editor().toolDone();
84     }
85
86     public Collection JavaDoc importClassChoice() {
87         List JavaDoc result = new Vector JavaDoc();
88         Diagram diagram = (Diagram)((DiagramView)editor()).getSubstance();
89         Project project = diagram.getContainer().getProject();
90         Iterator JavaDoc it = project.getClasses().iterator();
91         while (it.hasNext()) {
92             Class JavaDoc cl = (Class JavaDoc)it.next();
93             if (!diagram.contains(cl))
94                 result.add(cl);
95         }
96         return result;
97     }
98 }
99
Popular Tags