1 18 19 package org.objectweb.jac.ide; 20 21 22 import org.objectweb.jac.ide.InheritanceLink; 23 import org.objectweb.jac.util.Log; 24 import java.awt.Point ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Set ; 29 import java.util.Vector ; 30 31 public class Diagram extends ModelElement { 32 33 public Diagram() { 34 } 35 36 public Diagram(String name) { 37 this.name = name; 38 } 39 40 Package container; 41 42 46 public Package getContainer() { 47 return container; 48 } 49 50 54 public void setContainer(Package v) { 55 this.container = v; 56 } 57 58 59 HashSet figures = new HashSet (); 60 61 public Set getFigures() { 62 return figures; 63 } 64 65 public void addFigure(Figure figure) { 66 figures.add(figure); 67 } 68 69 public void removeFigure(Figure figure) { 70 figures.remove(figure); 71 } 72 73 77 public void removeElement(ModelElement element) { 78 Iterator it = figures.iterator(); 79 while (it.hasNext()) { 80 Figure figure = (Figure)it.next(); 81 if (figure.getElement()==element) { 82 removeFigure(figure); 83 return; 84 } 85 } 86 } 87 88 93 public void removeInheritanceLink(Class cl, Class superClass) { 94 Iterator it = figures.iterator(); 95 while (it.hasNext()) { 96 Figure figure = (Figure)it.next(); 97 if (figure.getElement() instanceof InheritanceLink) { 98 InheritanceLink link = (InheritanceLink)figure.getElement(); 99 if (link.getStart()==cl && link.getEnd()==superClass) { 100 removeFigure(figure); 101 return; 102 } 103 } 104 } 105 } 106 107 110 public boolean contains(ModelElement element) { 111 Iterator it = figures.iterator(); 112 while (it.hasNext()) { 113 Figure figure = (Figure)it.next(); 114 if (figure.getElement()==element) { 115 return true; 116 } 117 } 118 return false; 119 } 120 121 124 public void importClass(Class cl, Point corner) { 125 figures.add(new ClassFigure(cl,corner)); 126 } 127 128 134 public List getMissingRelations(Class cl) { 135 List relations = new Vector (); 136 137 Iterator it = cl.getRelationLinks().iterator(); 139 while (it.hasNext()) { 140 RelationLink relation = (RelationLink)it.next(); 141 if (!contains(relation) && 142 contains(relation.getEnd()) && contains(relation.getStart())) { 143 relations.add(relation); 144 } 145 } 146 147 Type superClass = cl.getSuperClass(); 149 if (superClass instanceof Class && contains(superClass)) { 150 relations.add(new InheritanceLink(cl,(Class )superClass)); 151 } 152 it = figures.iterator(); 153 while (it.hasNext()) { 154 Figure figure = (Figure)it.next(); 155 if (figure.getElement() instanceof Class ) { 156 Class otherClass = (Class )figure.getElement(); 157 superClass = otherClass.getSuperClass(); 158 if (superClass instanceof Class && superClass==cl) { 159 relations.add(new InheritanceLink(otherClass,cl)); 160 } 161 } 162 } 163 164 return relations; 165 } 166 } 167 | Popular Tags |