KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > graph > view > BasicBindingRenderer


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

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 JavaDoc;
32 import java.awt.Point JavaDoc;
33 import java.awt.Rectangle JavaDoc;
34
35 /**
36  * Basic implementation of the {@link BindingRenderer} interface.
37  */

38
39 public class BasicBindingRenderer implements BindingRenderer {
40
41   /**
42    * Minimal space between a component and a binding.
43    */

44
45   private final static int BORDER = 5;
46
47   /**
48    * Constructs a new {@link BasicBindingRenderer} component.
49    */

50
51   public BasicBindingRenderer () {
52   }
53
54   public void drawBinding (
55     final Graphics JavaDoc g,
56     final Rectangle JavaDoc c,
57     final Rectangle JavaDoc s,
58     final Point JavaDoc cp,
59     final Point JavaDoc 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