KickJava   Java API By Example, From Geeks To Geeks.

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


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   USA. */

18
19 package org.objectweb.jac.ide.diagrams;
20
21 import CH.ifa.draw.figures.TextFigure;
22 import org.apache.log4j.Logger;
23 import org.objectweb.jac.core.rtti.FieldItem;
24 import org.objectweb.jac.util.Log;
25
26 public class AttributeValueFigure extends TextFigure {
27
28     public AttributeValueFigure(FieldItem attribute,Object JavaDoc substance) {
29         this.attribute=attribute;
30         this.substance=substance;
31         DiagramView.init = true;
32         Object JavaDoc value=attribute.getThroughAccessor(substance);
33         if(value==null)
34             setText("");
35         else
36             setText(value.toString());
37         DiagramView.init = false;
38     }
39
40     FieldItem attribute;
41    
42     /**
43      * Get the value of attribute.
44      * @return value of attribute.
45      */

46     public FieldItem getAttribute() {
47         return attribute;
48     }
49    
50     /**
51      * Set the value of attribute.
52      * @param v Value to assign to attribute.
53      */

54     public void setAttribute(FieldItem v) {
55         this.attribute = v;
56     }
57    
58     Object JavaDoc substance;
59    
60     /**
61      * Get the value of substance.
62      * @return value of substance.
63      */

64     public Object JavaDoc getSubstance() {
65         return substance;
66     }
67    
68     /**
69      * Set the value of substance.
70      * @param v Value to assign to substance.
71      */

72     public void setSubstance(Object JavaDoc v) {
73         this.substance = v;
74     }
75    
76     public void setText(String JavaDoc s) {
77         super.setText(s);
78         if (substance != null && attribute != null && !DiagramView.init) {
79             try {
80                 attribute.setThroughWriter(substance,s);
81             } catch (Exception JavaDoc e) {
82                 Logger.getLogger("figures").error(
83                     "Failed to set attribute value for "+
84                     substance+"."+attribute+" to "+s);
85             }
86         }
87     }
88
89 }
90
Popular Tags