1 18 19 package org.objectweb.jac.ide.diagrams; 20 21 import java.util.Iterator ; 22 import java.util.StringTokenizer ; 23 import java.util.Vector ; 24 import org.objectweb.jac.aspects.gui.DisplayContext; 25 import org.objectweb.jac.aspects.gui.EventHandler; 26 import org.objectweb.jac.aspects.gui.ObjectUpdate; 27 import org.objectweb.jac.aspects.gui.Utils; 28 import org.objectweb.jac.core.rtti.ClassRepository; 29 import org.objectweb.jac.core.rtti.CollectionItem; 30 import org.objectweb.jac.ide.Class; 31 import org.objectweb.jac.ide.Method; 32 import org.objectweb.jac.ide.ModelElement; 33 import org.objectweb.jac.util.Log; 34 35 public class MethodFigure extends MemberFigure 36 implements ModelElementFigure, ObjectUpdate, Selectable 37 { 38 Method method; 39 40 public MethodFigure(Method method, ClassFigure parentFigure) { 41 super(parentFigure); 42 this.method = method; 43 setText(); 44 Utils.registerObject(method,this); 45 } 46 47 public void close() { 48 Utils.unregisterObject(method,this); 49 } 50 51 protected void setText() { 52 super.setText(method.getName()+"("+method.getParameterNames()+")"); 53 } 54 55 59 public ModelElement getSubstance() { 60 return method; 61 } 62 63 public String getPrototype() { 64 String text = getText(); 65 int sep = text.indexOf(':'); 66 if (sep == -1) { 67 return "void "+text; 68 } else { 69 return text.substring(sep+1)+" "+text.substring(0,sep); 70 } 71 } 72 73 public String getName() { 74 String name = super.getName(); 75 int sep = name.indexOf('('); 76 if (sep == -1) { 77 return name; 78 } else { 79 return name.substring(0,sep).trim(); 80 } 81 } 82 83 public Vector getArgs() { 84 Vector result = new Vector (); 85 String text = getText(); 86 String args = text.substring(text.indexOf('(')+1); 87 args = args.substring(0,args.indexOf(')')); 88 StringTokenizer st = new StringTokenizer (args,","); 89 while (st.hasMoreTokens()) { 90 String s = st.nextToken(); 91 s=s.trim(); 92 String type = s.substring(0,s.indexOf(' ')); 93 String name = s.substring(s.indexOf(' ')+1); 94 Log.trace("diagram","parameter: "+type+" "+name); 95 result.add(new String []{name,type}); 96 } 97 return result; 98 } 99 100 boolean updating = false; 101 102 public synchronized void setText(String s) { 103 super.setText(s); 104 Log.trace("diagram","settext("+s+")"); 105 Log.trace("diagram","gettext()="+getText()); 106 if (method != null && !DiagramView.init) { 107 updating=true; 108 Log.trace("diagram","gettext()="+getText()); 109 Log.trace("diagram","name: "+getName()); 110 method.setName(getName()); 111 Log.trace("diagram","gettext()="+getText()); 112 Log.trace("diagram","type: "+getType()); 113 method.setType(org.objectweb.jac.ide.Projects.types.resolveType(getType())); 114 Iterator it = new Vector (method.getParameters()).iterator(); 115 while(it.hasNext()) { 116 method.getParameters().remove(it.next()); 117 } 118 it = getArgs().iterator(); 119 while(it.hasNext()) { 120 String [] param = (String [])it.next(); 121 org.objectweb.jac.ide.Parameter parameter = new org.objectweb.jac.ide.Parameter(); 122 parameter.setName(param[0]); 123 parameter.setType(org.objectweb.jac.ide.Projects.types.resolveType(param[1])); 124 method.addParameter(parameter); 125 } 126 updating=false; 127 } 128 } 129 130 public void objectUpdated(Object object, Object extra) { 132 Log.trace("diagram","objectUpdated()"+object); 133 if (!updating) { 134 setText(); 135 } 136 } 137 138 140 public void onSelect(DisplayContext context) { 141 CollectionItem coll = ClassRepository.get().getClass(Class .class) 142 .getCollection("methods"); 143 EventHandler.get().onSelection( 144 context,coll,getSubstance(),null,null); 145 } 146 } 147 | Popular Tags |