KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > cfg > editParts > FlowDataEditPart


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004 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 package ca.mcgill.sable.soot.cfg.editParts;
21
22 import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
23
24 import java.beans.PropertyChangeEvent JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26
27 import org.eclipse.draw2d.*;
28 import ca.mcgill.sable.soot.cfg.figures.*;
29 import ca.mcgill.sable.soot.cfg.model.*;
30 import java.util.*;
31 import org.eclipse.draw2d.geometry.*;
32
33
34 public class FlowDataEditPart
35     extends AbstractGraphicalEditPart
36     implements PropertyChangeListener JavaDoc {
37
38     
39     /* (non-Javadoc)
40      * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
41      */

42     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
43         if (evt.getPropertyName().equals(CFGElement.FLOW_CHILDREN)){
44             refreshChildren();
45             refreshVisuals();
46         }
47     }
48     
49     
50     protected void refreshVisuals(){
51         Iterator it = getChildren().iterator();
52         while (it.hasNext()){
53             Object JavaDoc next = it.next();
54             if (next instanceof PartialFlowDataEditPart){
55                 ((CFGFlowFigure)getFigure()).add(((PartialFlowDataEditPart)next).getFigure());
56             }
57             
58         }
59     }
60     
61     public void updateSize(FlowInfoEditPart childEdit, IFigure child, Rectangle rect){
62         this.setLayoutConstraint(childEdit, child, rect);
63         ((CFGNodeEditPart)getParent()).setLayoutConstraint(this, getFigure(), new Rectangle(getFigure().getBounds().x, getFigure().getBounds().y, getFigure().getBounds().width, getFigure().getBounds().height));//.updateSize(getFigure(), getFigure().getBounds());
64
}
65     
66     public void updateSize(int width){
67         int w = ((CFGFlowFigure)getFigure()).getBounds().width;
68         
69         if (width > w){
70             w = width;
71         }
72         
73         int height = getChildren().size() * 20;
74         
75         ((CFGNodeEditPart)getParent()).updateSize(w+10, height);
76         ((CFGFlowFigure)getFigure()).setSize(w+10, height);
77             
78     }
79     
80     public void resetChildColors(){
81         Iterator it = getChildren().iterator();
82         while (it.hasNext()){
83             Object JavaDoc next = it.next();
84             if (next instanceof PartialFlowDataEditPart){
85                 ((PartialFlowDataEditPart)next).resetChildColors();
86             }
87         }
88     }
89     
90     /* (non-Javadoc)
91      * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
92      */

93     protected IFigure createFigure() {
94         return new CFGFlowFigure();
95     }
96
97     /* (non-Javadoc)
98      * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
99      */

100     protected void createEditPolicies() {
101     }
102
103     public List getModelChildren(){
104         return getFlowData().getChildren();
105     }
106     
107     public void activate(){
108         super.activate();
109         getFlowData().addPropertyChangeListener(this);
110     }
111     
112     public void deactivate(){
113         super.deactivate();
114         getFlowData().removePropertyChangeListener(this);
115     }
116     /**
117      * @return
118      */

119     public CFGFlowData getFlowData() {
120         return (CFGFlowData)getModel();
121     }
122
123     
124     public void handleClickEvent(Object JavaDoc evt){
125         ((CFGNodeEditPart)getParent()).handleClickEvent(evt);
126     }
127 }
128
Popular Tags