KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > swing > graph > MyBindingView


1 /*
2  * @(#)MyPortView 1.0.5 06/01/03
3  *
4  * Copyright (C) 2003 Gaudenz Alder
5  *
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18  * Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  */

21
22 package org.objectweb.util.explorer.swing.graph;
23
24 import java.awt.BasicStroke JavaDoc;
25 import java.awt.Graphics JavaDoc;
26 import java.awt.Graphics2D JavaDoc;
27 import java.awt.Rectangle JavaDoc;
28 import java.awt.Shape JavaDoc;
29 import java.awt.geom.Rectangle2D JavaDoc;
30
31 import org.jgraph.JGraph;
32 import org.jgraph.graph.CellViewRenderer;
33 import org.jgraph.graph.EdgeRenderer;
34 import org.jgraph.graph.EdgeView;
35
36 public class MyBindingView extends EdgeView {
37
38     private static int portCourantPosition = 0;
39
40     protected static MyEdgeRenderer renderer = new MyEdgeRenderer();
41
42     public MyBindingView(JGraph graph, org.jgraph.graph.CellMapper cm, Object JavaDoc cell) {
43         super(cell, graph, cm);
44     }
45
46     /**
47      * Returns the bounds for the port view.
48      */

49     public CellViewRenderer getRenderer() {
50         return renderer;
51     }
52     
53     public static class MyEdgeRenderer extends EdgeRenderer {
54                 
55         public Rectangle2D JavaDoc getPaintBounds(EdgeView view) {
56             Rectangle JavaDoc r = super.getPaintBounds(view).getBounds();
57             return new Rectangle JavaDoc(r.x-40,r.y-40,r.width+80,r.height+80);
58         }
59
60
61         public void paint(Graphics JavaDoc g) {
62             MyPortView sourceView = (MyPortView) view.getSource();
63             MyPortView targetView = (MyPortView) view.getTarget();
64             MyPort source = (MyPort)sourceView.getCell();
65             MyPort target = (MyPort)targetView.getCell();
66             
67             Graphics2D JavaDoc g2 = (Graphics2D JavaDoc) g;
68             int c = BasicStroke.CAP_BUTT;
69             int j = BasicStroke.JOIN_MITER;
70             g2.setStroke(new BasicStroke JavaDoc(lineWidth, c, j));
71             //g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
72
// BasicStroke.JOIN_MITER, 1.0f, new float[]{.5f, .5f}, .0f));
73
translateGraphics(g);
74             g.setColor(getForeground());
75
76             //paint line
77
if (view.lineShape != null) {
78                 Shape JavaDoc s = view.lineShape;
79                 g2.draw(view.lineShape);
80             }
81
82             //paint label
83
Object JavaDoc label = graph.convertValueToString(view);
84                 g2.setStroke(new BasicStroke JavaDoc(1));
85                 g.setFont(getFont());
86                 String JavaDoc targetName = target.getName();
87                 g.drawString(source.getName(),(int)sourceView.getLocation(view).getX(),(int)sourceView.getLocation(view).getY());
88                 g.drawString(targetName,(int)targetView.getLocation(view).getX()-(targetName.length()*6),(int)targetView.getLocation(view).getY());
89                 }
90     }
91
92 }
Popular Tags