KickJava   Java API By Example, From Geeks To Geeks.

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


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.Graphics JavaDoc;
31
32 import org.objectweb.util.explorer.swing.graph.PortGraphicsInterface;
33 import org.objectweb.util.explorer.swing.graph.PortType;
34
35 /**
36  *
37  * @version 0.2
38  */

39 public class PortGraphics
40   implements PortGraphicsInterface
41 {
42
43     /**
44      * @param portType the type of the port
45      * @return Dimension the size of the port. The center right must be the
46      * server port location. The center left must be the client port
47      * location. The center up must be the controler port location.
48      */

49     public Dimension JavaDoc getPortSize(String JavaDoc portType, boolean isInternal) {
50         if (portType.equals(PortType.SERVER_PORT))
51             return new Dimension JavaDoc(11, 10);
52         else if (portType.equals(PortType.CLIENT_PORT))
53             return new Dimension JavaDoc(11, 10);
54         else if (portType.equals(PortType.COLLECTION_PORT))
55             return new Dimension JavaDoc(11, 10);
56         else if (portType.equals(PortType.CONTROLLER_PORT)) {
57             if (!isInternal)
58                 return new Dimension JavaDoc(8, 10);
59             else
60                 return new Dimension JavaDoc(8 + COMPOSITE_CONTROLLER_PORT_WIDTH, 10);
61         } else
62             return new Dimension JavaDoc(11, 10);
63     }
64
65     /**
66      * @param g the Graphics where the port have to be paint.
67      * @param portType the type of the port.
68      */

69     public void drawPort(Graphics JavaDoc g, String JavaDoc portName, String JavaDoc portType,
70             boolean isInternal) {
71         if (portType.equals(PortType.SERVER_PORT)) {
72             g.setColor(Color.red);
73             g.drawRect(2, 3, 8, 2);
74             g.fillRect(2, 3, 8, 2);
75             g.drawRect(0, 0, 2, 8);
76             g.fillRect(0, 0, 2, 8);
77         } else if (portType.equals(PortType.COLLECTION_PORT)) {
78             g.setColor(new Color JavaDoc(20, 61, 18));
79             g.drawLine(3, 2, 6, 2);
80             g.drawLine(3, 0, 6, 4);
81             g.drawLine(3, 4, 6, 0);
82             g.drawRect(8, 1, 2, 8);
83             g.fillRect(8, 1, 2, 8);
84             g.drawRect(0, 5, 8, 2);
85             g.fillRect(0, 5, 8, 2);
86         } else if (portType.equals(PortType.CLIENT_PORT)) {
87             g.setColor(new Color JavaDoc(2708224));
88             g.drawRect(8, 0, 2, 8);
89             g.fillRect(8, 0, 2, 8);
90             g.drawRect(0, 3, 8, 2);
91             g.fillRect(0, 3, 8, 2);
92         } else if (portType.equals(PortType.CONTROLLER_PORT)) {
93             g.setColor(Color.BLUE);
94             g.drawRect(0, 0, 8, 2);
95             g.fillRect(0, 0, 8, 2);
96             g.drawRect(3, 2, 2, 8);
97             g.fillRect(3, 2, 2, 8);
98             if (isInternal) {
99                 g.setColor(Color.BLACK);
100                 g.drawString(portName, 10, 9);
101             }
102         }
103     }
104 }
Popular Tags