KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > explorer > graph > VertexGraphics


1 /*====================================================================
2
3  Objectweb Explorer Framework
4  Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5  Contact: openccm@objectweb.org
6
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or any later version.
11
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  USA
21
22  Initial developer(s): Laëtitia Lafeuille.
23  Contributor(s): ______________________________________.
24
25  ====================================================================*/

26 package org.objectweb.fractal.explorer.graph;
27
28 import java.awt.Color JavaDoc;
29 import java.awt.Dimension JavaDoc;
30 import java.awt.Font JavaDoc;
31 import java.awt.Graphics JavaDoc;
32
33 import org.objectweb.util.explorer.swing.graph.CompositeVertex;
34 import org.objectweb.util.explorer.swing.graph.PrimitiveVertex;
35 import org.objectweb.util.explorer.swing.graph.VertexGraphicsInterface;
36 import org.objectweb.util.explorer.swing.graph.VertexType;
37
38 /**
39  *
40  * @version 0.2
41  */

42 public class VertexGraphics
43   implements VertexGraphicsInterface
44 {
45
46     /** Draw a dotted rectangle */
47     private void drawDottedRect(Graphics JavaDoc g, int x, int y, int width, int height) {
48         //draw horizontal lines
49
int currentX = x;
50         int currentY = y;
51         while (currentX < x + width - 5) {
52             g.drawLine(currentX, y, currentX + 5, y);
53             g.drawLine(currentX, y + height, currentX + 5, y + height);
54             currentX = currentX + 10;
55         }
56         //draw vertical lines
57
while (currentY < y + height - 5) {
58             g.drawLine(x, currentY, x, currentY + 5);
59             g.drawLine(x + width, currentY, x + width, currentY + 5);
60             currentY = currentY + 10;
61         }
62     }
63
64     public Font JavaDoc getTextFont() {
65         return new Font JavaDoc("SansSerif", Font.BOLD, 10);
66     }
67
68     /** Returns the vertex default size */
69     public Dimension JavaDoc getDefaultSize() {
70         return new Dimension JavaDoc(110, 60);
71     }
72
73     /** Returns the open composite (super composite) size */
74     public Dimension JavaDoc getSuperCompositeSize() {
75         return new Dimension JavaDoc(10, 10);
76     }
77
78     /** Draw the specific vertex into the specific grahics g */
79     public void drawVertex(Graphics JavaDoc g, String JavaDoc vertexType, Dimension JavaDoc d, PrimitiveVertex vertex) {
80         g.setColor(Color.DARK_GRAY);
81         if (!vertex.isStarted())
82             g.setColor(new Color JavaDoc(149, 0, 0));
83
84         //if the vertex is primitive
85
if (vertexType.equals(VertexType.PRIMITIF_VERTEX)) {
86             int size = VertexGraphicsInterface.PRIMITIVE_MEMBRANE_SIZE - 1;
87             if (vertex.isShared()) {
88                 drawDottedRect(g, 0, 0, d.width - 1, d.height - 1);
89                 drawDottedRect(g, size, size, d.width - 3, d.height - 3);
90             } else {
91                 g.drawRect(0, 0, d.width - 1, d.height - 1);
92                 g.drawRect(size, size, d.width - 3, d.height - 3);
93             }
94         }
95
96         //else if the vertex is composite
97
else if (vertexType.equals(VertexType.COMPOSITE_VERTEX)) {
98             if (!((CompositeVertex) vertex).isOpen()) {
99                 //if the vertex isn't open
100
int size = VertexGraphicsInterface.PRIMITIVE_MEMBRANE_SIZE - 1;
101                 if (vertex.isShared()) {
102                     drawDottedRect(g, 0, 0, d.width - 1, d.height - 1);
103                     drawDottedRect(g, size, size, d.width - size - 2, d.height
104                             - size - 2);
105                 } else {
106                     g.drawRect(0, 0, d.width - 1, d.height - 1);
107                     g.drawRect(size, size, d.width - size - 2, d.height - size
108                             - 2);
109                 }
110                 g.setColor(Color.PINK);
111                 g.fillRect(size + 1, size + 1, d.width - (size + 1) - 2,
112                         d.height - (size + 1) - 2);
113             }
114
115             // if the vertex is the open vertex (super composite)
116
else {
117                 int size = VertexGraphicsInterface.COMPOSITE_MEMBRANE_SIZE;
118                 if (vertex.isShared()) {
119                     drawDottedRect(g, 0, 0, d.width - 1, d.height - 1);
120                     drawDottedRect(g, 1, 1, d.width - 3, d.height - 3);
121                     drawDottedRect(g, size, size, d.width - size * 2 - 1,
122                             d.height - size * 2 - 1);
123                     drawDottedRect(g, size + 1, size + 1, d.width - size * 2
124                             - 3, d.height - size * 2 - 3);
125                 } else {
126                     g.drawRect(0, 0, d.width - 1, d.height - 1);
127                     g.drawRect(1, 1, d.width - 3, d.height - 3);
128                     g.drawRect(size, size, d.width - size * 2 - 1, d.height
129                             - size * 2 - 1);
130                     g.drawRect(size + 1, size + 1, d.width - size * 2 - 3,
131                             d.height - size * 2 - 3);
132                 }
133             }
134         }
135     }
136 }
Popular Tags