1 25 package classycle.renderer; 26 27 import java.text.MessageFormat ; 28 29 import classycle.ClassAttributes; 30 import classycle.graph.AtomicVertex; 31 import classycle.graph.NameAttributes; 32 import classycle.graph.StrongComponent; 33 34 56 public class TemplateBasedClassRenderer implements AtomicVertexRenderer 57 { 58 private MessageFormat _format; 59 60 61 public TemplateBasedClassRenderer(String template) 62 { 63 _format = new MessageFormat (template); 64 } 65 66 72 public String render(AtomicVertex vertex, StrongComponent cycle, 73 int layerIndex) 74 { 75 String [] values = new String [9]; 76 NameAttributes attributes = (NameAttributes) vertex.getAttributes(); 77 values[0] = attributes.getName(); 78 values[2] = Integer.toString(attributes.getSize()); 79 if (attributes instanceof ClassAttributes) 80 { 81 ClassAttributes ca = (ClassAttributes) attributes; 82 values[1] = ca.getType(); 83 values[3] = ca.isInnerClass() ? "true" : "false"; 84 } else 85 { 86 values[1] = ""; 87 values[3] = ""; 88 } 89 values[4] = Integer.toString(vertex.getNumberOfIncomingArcs()); 90 int usesInternal = 0; 91 int usesExternal = 0; 92 for (int i = 0, n = vertex.getNumberOfOutgoingArcs(); i < n; i++) 93 { 94 if (((AtomicVertex) vertex.getHeadVertex(i)).isGraphVertex()) 95 { 96 usesInternal++; 97 } else 98 { 99 usesExternal++; 100 } 101 } 102 values[5] = Integer.toString(usesInternal); 103 values[6] = Integer.toString(usesExternal); 104 values[7] = Integer.toString(layerIndex); 105 values[8] = cycle == null ? "" 106 : AbstractStrongComponentRenderer.createName(cycle); 107 return _format.format(values); 108 } 109 } | Popular Tags |