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 */ 018 019 package org.objectweb.jac.ide.diagrams; 020 021 import org.objectweb.jac.aspects.gui.FieldUpdate; 022 import org.objectweb.jac.aspects.gui.Utils; 023 import org.objectweb.jac.core.rtti.ClassRepository; 024 import org.objectweb.jac.core.rtti.FieldItem; 025 import org.objectweb.jac.ide.Class; 026 import java.awt.Color; 027 028 public class ClassNameFigure extends TextFigure implements FieldUpdate { 029 030 Class substance; 031 ClassFigure parentFigure; 032 033 static FieldItem nameField = 034 ClassRepository.get().getClass(Class.class).getField("name"); 035 036 public ClassNameFigure(Class substance, ClassFigure parentFigure) { 037 this.substance = substance; 038 this.parentFigure = parentFigure; 039 super.setText(substance.getName()); 040 Utils.registerField(substance,nameField,this); 041 } 042 043 public Color getTextColor() { 044 return parentFigure.getColor(); 045 } 046 047 /** 048 * Get the value of substance. 049 * @return value of substance. 050 */ 051 public Class getSubstance() { 052 return substance; 053 } 054 055 /** 056 * Set the value of substance. 057 * @param v Value to assign to substance. 058 */ 059 public void setSubstance(Class v) { 060 this.substance = v; 061 } 062 063 public String getName() { 064 return getText(); 065 } 066 067 public void setText(String s) { 068 super.setText(s); 069 if (substance != null && !DiagramView.init) { 070 substance.setName(s); 071 } 072 } 073 074 // FieldUpdate interface 075 public void fieldUpdated(Object substance, FieldItem field, Object 076 value, Object param) { 077 super.setText((String)value); 078 } 079 }