1 23 24 package org.objectweb.fractal.gui.graph.view; 25 26 import org.objectweb.fractal.gui.model.ClientInterface; 27 import org.objectweb.fractal.gui.model.ServerInterface; 28 import org.objectweb.fractal.gui.Constants; 29 import org.objectweb.fractal.gui.model.Binding; 30 31 import java.awt.Graphics ; 32 import java.awt.Point ; 33 import java.awt.Rectangle ; 34 35 38 39 public class BasicBindingRenderer implements BindingRenderer { 40 41 44 45 private final static int BORDER = 5; 46 47 50 51 public BasicBindingRenderer () { 52 } 53 54 public void drawBinding ( 55 final Graphics g, 56 final Rectangle c, 57 final Rectangle s, 58 final Point cp, 59 final Point sp, 60 final Binding bd, 61 final int range) 62 { 63 g.setColor(Constants.BINDING_COLOR); 64 if (bd != null) { 65 if (bd.getStatus() != Binding.OK) g.setColor(Constants.ERROR_COLOR); 66 else { 67 ClientInterface citf = bd.getClientInterface(); 68 ServerInterface sitf = bd.getServerInterface(); 69 if ((citf.getName().length() < 1) || 70 (sitf.getName().length() < 1) || 71 (citf.getSignature().length() < 1) || 72 (sitf.getSignature().length() < 1)) g.setColor(Constants.WARNING_COLOR); 73 } 74 } 75 76 if (sp.x >= cp.x || s == null) { 77 g.drawLine(cp.x, cp.y, sp.x, sp.y); 78 } else { 79 int v; 80 if (s.y + s.height < c.y) { 81 v = (c.y + s.y + s.height) / 2; 82 } else if (s.y > c.y + c.height) { 83 v = (s.y + c.y + c.height) / 2; 84 } else { 85 int vMin = Math.min(s.y, c.y); 86 int vMax = Math.max(s.y + s.height, c.y + c.height); 87 if (cp.y - vMin < vMax - cp.y) { 88 v = vMin - BORDER; 89 } else { 90 v = vMax + BORDER; 91 } 92 } 93 int decal = 3*range; 94 g.drawLine(cp.x, cp.y, cp.x + BORDER+decal, cp.y); 95 g.drawLine(cp.x + BORDER+decal, cp.y, cp.x + BORDER+decal, v+decal); 96 g.drawLine(cp.x + BORDER+decal, v+decal, sp.x - BORDER-decal, v+decal); 97 g.drawLine(sp.x - BORDER-decal, v+decal, sp.x - BORDER-decal, sp.y); 98 g.drawLine(sp.x - BORDER-decal, sp.y, sp.x, sp.y); 99 } 100 } 101 } 102 | Popular Tags |