KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.jac.aspects.gui.DisplayContext;
22 import org.objectweb.jac.aspects.gui.EventHandler;
23 import org.objectweb.jac.aspects.gui.GuiAC;
24 import org.objectweb.jac.aspects.gui.ObjectUpdate;
25 import org.objectweb.jac.aspects.gui.Utils;
26 import org.objectweb.jac.core.rtti.ClassRepository;
27 import org.objectweb.jac.core.rtti.CollectionItem;
28 import org.objectweb.jac.ide.Class;
29 import org.objectweb.jac.ide.Field;
30 import org.objectweb.jac.ide.ModelElement;
31
32 public class FieldFigure extends MemberFigure
33     implements ModelElementFigure, ObjectUpdate, Selectable
34 {
35     Field field;
36
37     public FieldFigure(Field field, ClassFigure parentFigure) {
38         super(parentFigure);
39         this.field = field;
40         super.setText(GuiAC.toString(field));
41         Utils.registerObject(field,this);
42     }
43     
44     public void close() {
45         Utils.unregisterObject(field,this);
46     }
47
48     public ModelElement getSubstance() {
49         return field;
50     }
51
52     public void linkToField(Class JavaDoc cl) {
53         field = cl.findField(getName());
54     }
55
56     boolean updating = false;
57
58     public void setText(String JavaDoc s) {
59         super.setText(s);
60         if (field != null && !DiagramView.init) {
61             updating=true;
62             field.setName(getName());
63             field.setType(org.objectweb.jac.ide.Projects.types.resolveType(getType()));
64             updating=false;
65         }
66     }
67
68     // ObjectUpdate interface
69
public void objectUpdated(Object JavaDoc object, Object JavaDoc extra) {
70         if (!updating) {
71             super.setText(GuiAC.toString(field));
72         }
73     }
74
75     // Selectable interface
76
public void onSelect(DisplayContext context) {
77         CollectionItem coll = ClassRepository.get().getClass(Class JavaDoc.class)
78             .getCollection("fields");
79         EventHandler.get().onSelection(
80             context,coll,getSubstance(),null,null);
81     }
82 }
83
Popular Tags