KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > graph > editparts > ComplexNodeEditPart


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

19
20
21 package ca.mcgill.sable.graph.editparts;
22
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25
26 import org.eclipse.draw2d.*;
27 import org.eclipse.gef.*;
28 import org.eclipse.gef.editparts.*;
29 import org.eclipse.draw2d.graph.*;
30 import java.util.*;
31 import ca.mcgill.sable.graph.model.*;
32 import ca.mcgill.sable.graph.figures.*;
33 import org.eclipse.draw2d.geometry.*;
34 import org.eclipse.swt.graphics.RGB;
35 import org.eclipse.swt.widgets.Display;
36
37 import com.sun.rsasign.t;
38
39 import ca.mcgill.sable.graph.editpolicies.*;
40
41 public class ComplexNodeEditPart
42     extends AbstractGraphicalEditPart
43     implements NodeEditPart, PropertyChangeListener JavaDoc {
44
45     public ComplexNodeEditPart() {
46         super();
47     }
48     
49     /* (non-Javadoc)
50      * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
51      */

52     protected void createEditPolicies() {
53     }
54     
55     /* (non-Javadoc)
56      * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
57      */

58     public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) {
59         return new ChopboxAnchor(getFigure());
60     }
61
62     /* (non-Javadoc)
63      * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
64      */

65     public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) {
66         return new ChopboxAnchor(getFigure());
67     }
68
69     /* (non-Javadoc)
70      * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.Request)
71      */

72     public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
73         return new ChopboxAnchor(getFigure());
74     }
75
76     /* (non-Javadoc)
77      * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.Request)
78      */

79     public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
80         return new ChopboxAnchor(getFigure());
81     }
82
83
84     /* (non-Javadoc)
85      * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
86      */

87     protected IFigure createFigure() {
88         return new ComplexNodeFigure();
89     }
90
91     public void contributeNodesToGraph(DirectedGraph graph, HashMap map){
92         Node node = new Node(this);
93         node.width = getFigure().getBounds().width;//getNode().getWidth();
94
node.height = getFigure().getBounds().height;
95         graph.nodes.add(node);
96         map.put(this, node);
97     }
98     
99     public void contributeEdgesToGraph(DirectedGraph graph, HashMap map) {
100         List outgoing = getSourceConnections();
101         for (int i = 0; i < outgoing.size(); i++){
102             EdgeEditPart edge = (EdgeEditPart)outgoing.get(i);
103             edge.contributeToGraph(graph, map);
104         }
105     }
106     
107     public void applyGraphResults(DirectedGraph graph, HashMap map){
108         SimpleNode node = (SimpleNode)map.get(this);
109         List outgoing = getSourceConnections();
110         for (int i = 0; i < outgoing.size(); i++){
111             EdgeEditPart edge = (EdgeEditPart)outgoing.get(i);
112             edge.applyGraphResults(graph, map);
113         }
114     
115     }
116     
117     public ComplexNode getNode(){
118         return (ComplexNode)getModel();
119     }
120     
121     public List getModelChildren(){
122         return ((ComplexNode)getNode()).getChildren();
123     }
124     
125     
126     public void propertyChange(PropertyChangeEvent JavaDoc event){
127         if (event.getPropertyName().equals(Element.COMPLEX_CHILD)){
128             refreshChildren();
129         }
130     }
131     
132     protected void refreshVisuals(){
133         Iterator it = getChildren().iterator();
134         while (it.hasNext()){
135             Object JavaDoc next = it.next();
136             if (next instanceof SimpleNodeEditPart){
137                 getFigure().add(((SimpleNodeEditPart)next).getFigure());
138                 getFigure().setSize(getFigure().getBounds().width+((SimpleNodeEditPart)next).getFigure().getBounds().width, getFigure().getBounds().height+((SimpleNodeEditPart)next).getFigure().getBounds().height);
139             }
140             else if (next instanceof GraphEditPart){
141                 getFigure().add(((GraphEditPart)next).getFigure());
142                 getFigure().setSize(getFigure().getBounds().width+((GraphEditPart)next).getFigureWidth(), getFigure().getBounds().height+((GraphEditPart)next).getFigureHeight());
143             }
144             
145         }
146     }
147
148 }
149
Popular Tags