1 18 19 package org.objectweb.jac.ide.diagrams; 20 21 import CH.ifa.draw.framework.*; 22 import CH.ifa.draw.standard.*; 23 import org.objectweb.jac.core.Wrappee; 24 import org.objectweb.jac.core.Wrapping; 25 import org.objectweb.jac.ide.Instance; 26 import org.objectweb.jac.ide.ModelElement; 27 import org.objectweb.jac.ide.Package; 28 import org.objectweb.jac.util.Log; 29 import java.awt.Color ; 30 import java.awt.Dimension ; 31 import java.awt.Font ; 32 import java.awt.Graphics ; 33 import java.awt.Point ; 34 import java.awt.Rectangle ; 35 import java.util.Vector ; 36 37 public class InstanceFigure extends CompositeFigure 38 implements ModelElementFigure 39 { 40 private static final int BORDER = 3; 41 private Rectangle fDisplayBox; 42 43 Instance substance; 44 45 57 58 public void close() {} 59 60 64 public ModelElement getSubstance() { 65 return substance; 66 } 67 68 72 public void setSubstance(Instance v) { 73 this.substance = v; 74 } 75 76 public String getType() { 77 return substance.getType().getName(); 78 } 79 80 public InstanceFigure() { 81 initialize(); 82 } 83 84 Package containerPackage; 85 86 90 public Package getContainerPackage() { 91 return containerPackage; 92 } 93 94 98 public void setContainerPackage(Package v) { 99 this.containerPackage = v; 100 } 101 102 void initInstance() { 103 if (substance == null) { 104 Log.warning("UNRESOLVED INSTANCE!"); 105 } else { 106 Log.trace("figures","init class "+substance); 107 initTitle(); 108 Wrapping.invokeRoleMethod((Wrappee)substance,"addView",new Object []{this}); 109 } 110 } 111 112 void initTitle() { 113 InstanceNameFigure nf = (InstanceNameFigure)figures().nextFigure(); 114 nf.setSubstance(substance); 115 nf.setText(substance.toString()); 116 } 117 118 protected void basicMoveBy(int x, int y) { 119 fDisplayBox.translate(x, y); 120 super.basicMoveBy(x, y); 121 } 122 123 public Rectangle displayBox() { 124 return new Rectangle ( 125 fDisplayBox.x, 126 fDisplayBox.y, 127 fDisplayBox.width, 128 fDisplayBox.height); 129 } 130 131 public void basicDisplayBox(Point origin, Point corner) { 132 fDisplayBox = new Rectangle (origin); 133 fDisplayBox.add(corner); 134 layout(); 135 } 136 137 protected void drawBorder(Graphics g) { 138 139 Rectangle r = displayBox(); 140 141 g.setColor(Color.white); 142 g.fillRoundRect(r.x, r.y, r.width, r.height,7,7); 143 144 g.setColor(Color.black); 145 g.drawRoundRect(r.x, r.y, r.width, r.height,7,7); 146 147 } 150 151 public void draw(Graphics g) { 152 drawBorder(g); 153 super.draw(g); 154 } 155 156 public Vector handles() { 157 Vector handles = new Vector (); 158 handles.addElement(new NullHandle(this, RelativeLocator.northWest())); 159 handles.addElement(new NullHandle(this, RelativeLocator.northEast())); 160 handles.addElement(new NullHandle(this, RelativeLocator.southWest())); 161 handles.addElement(new NullHandle(this, RelativeLocator.southEast())); 162 return handles; 163 } 164 165 public String getName() { 166 return ((TextFigure)figures().nextFigure()).getText(); 167 } 168 169 void initName() { 170 InstanceNameFigure name=new InstanceNameFigure(); 171 name.setText("NewInstance"); 172 add(name); 173 } 174 175 private void initialize() { 176 177 fDisplayBox = new Rectangle (0, 0, 0, 0); 178 179 Font f = new Font ("Helvetica", Font.PLAIN, 12); 180 Font fb = new Font ("Helvetica", Font.BOLD, 12); 181 182 initName(); 183 184 } 185 186 public void layout() { 187 Point partOrigin = new Point (fDisplayBox.x, fDisplayBox.y); 188 partOrigin.translate(BORDER, BORDER); 189 Dimension extent = new Dimension (0, 0); 190 191 192 Dimension partExtent = figureAt(0).size(); 193 Point corner = new Point ( 194 partOrigin.x+partExtent.width, 195 partOrigin.y+partExtent.height); 196 figureAt(0).basicDisplayBox(partOrigin, corner); 197 198 extent.width = partExtent.width; 199 extent.height = partExtent.height; 200 fDisplayBox.width = extent.width + 2*BORDER; 201 fDisplayBox.height = extent.height + 2*BORDER; 202 203 } 204 205 private boolean needsLayout() { 206 215 return true; 216 } 217 218 public void update(FigureChangeEvent e) { 219 223 if (needsLayout()) { 224 layout(); 225 changed(); 226 } 227 } 228 229 public void figureChanged(FigureChangeEvent e) { 230 update(e); 231 } 232 233 public void figureRemoved(FigureChangeEvent e) { 234 update(e); 235 } 236 237 } 238 | Popular Tags |