001    /*
002      Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com>
003    
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public
015      License along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017      USA. */
018    
019    package org.objectweb.jac.ide.diagrams;
020    
021    import CH.ifa.draw.figures.TextFigure;
022    import org.apache.log4j.Logger;
023    import org.objectweb.jac.core.rtti.FieldItem;
024    import org.objectweb.jac.util.Log;
025    
026    public class AttributeValueFigure extends TextFigure {
027    
028        public AttributeValueFigure(FieldItem attribute,Object substance) {
029            this.attribute=attribute;
030            this.substance=substance;
031            DiagramView.init = true;
032            Object value=attribute.getThroughAccessor(substance); 
033            if(value==null)
034                setText("");
035            else
036                setText(value.toString());
037            DiagramView.init = false;
038        }
039    
040        FieldItem attribute;
041       
042        /**
043         * Get the value of attribute.
044         * @return value of attribute.
045         */
046        public FieldItem getAttribute() {
047            return attribute;
048        }
049       
050        /**
051         * Set the value of attribute.
052         * @param v  Value to assign to attribute.
053         */
054        public void setAttribute(FieldItem  v) {
055            this.attribute = v;
056        }
057       
058        Object substance;
059       
060        /**
061         * Get the value of substance.
062         * @return value of substance.
063         */
064        public Object getSubstance() {
065            return substance;
066        }
067       
068        /**
069         * Set the value of substance.
070         * @param v  Value to assign to substance.
071         */
072        public void setSubstance(Object v) {
073            this.substance = v;
074        }
075       
076        public void setText(String s) {
077            super.setText(s);
078            if (substance != null && attribute != null && !DiagramView.init) {
079                try {
080                    attribute.setThroughWriter(substance,s);
081                } catch (Exception e) {
082                    Logger.getLogger("figures").error(
083                        "Failed to set attribute value for "+
084                        substance+"."+attribute+" to "+s);
085                }
086            }
087        }
088    
089    }