KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2002-2003 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 CH.ifa.draw.framework.Figure;
23 import java.util.List JavaDoc;
24 import java.util.Vector JavaDoc;
25 import org.objectweb.jac.aspects.gui.DisplayContext;
26 import org.objectweb.jac.aspects.gui.EventHandler;
27 import org.objectweb.jac.aspects.gui.InvokeEvent;
28 import org.objectweb.jac.core.rtti.ClassRepository;
29 import org.objectweb.jac.ide.Class;
30 import org.objectweb.jac.ide.InheritanceLink;
31 import org.objectweb.jac.ide.Link;
32 import org.objectweb.jac.ide.RelationLink;
33 import org.objectweb.jac.util.Log;
34
35 /**
36  * Show an existing relation or inheritance link
37  */

38 public class RelationLinkShowTool extends AbstractActionTool {
39
40    public RelationLinkShowTool(DrawingEditor newDrawingEditor,
41                                DisplayContext context) throws ClassNotFoundException JavaDoc {
42       super(newDrawingEditor,context,java.lang.Class.forName("org.objectweb.jac.ide.diagrams.ClassFigure"));
43    }
44
45    // gui related infos and methods
46

47    Class JavaDoc curClass = null;
48    ClassFigure startFig = null;
49
50    /**
51     * Returns the list of relations of the current class not yet on
52     * the diagram
53     * @return a list of RelationLink
54     */

55    public List JavaDoc relations() {
56       Log.trace("figures","getting relations for class "+curClass);
57       List JavaDoc relations = new Vector JavaDoc();
58       if (curClass!=null) {
59          return ((DiagramView)editor()).getDiagram().getMissingRelations(curClass);
60       } else {
61          return null;
62       }
63    }
64
65    public void showRelation(Link link) throws Exception JavaDoc {
66       //System.out.println("chooseRelation("+relation+","+relation.getEnd()+")");
67
if (link==null || link.getStart()==null || link.getEnd()==null)
68          return;
69       if (link instanceof RelationLink)
70          ((DiagramView)editor()).importRelation((RelationLink)link);
71       else if (link instanceof InheritanceLink)
72          ((DiagramView)editor()).importInheritance((InheritanceLink)link);
73       view().repairDamage();
74       editor().toolDone();
75    }
76
77    public void action(Figure figure) {
78       startFig = (ClassFigure)figure;
79       curClass = startFig.getClassElement();
80       EventHandler.get().onInvoke(
81          context,
82          new InvokeEvent(
83              null,
84              this,
85              ClassRepository.get().getClass(getClass())
86              .getMethod("showRelation")));
87
88    }
89
90 }
91
92
Popular Tags