KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24
25 import org.eclipse.draw2d.IFigure;
26 import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
27 import ca.mcgill.sable.soot.cfg.model.*;
28 import ca.mcgill.sable.soot.cfg.figures.*;
29 import java.util.*;
30 import ca.mcgill.sable.soot.*;
31 import org.eclipse.swt.graphics.*;
32
33
34 public class NodeDataEditPart
35     extends AbstractGraphicalEditPart
36     implements PropertyChangeListener JavaDoc {
37
38     public NodeDataEditPart() {
39         super();
40     }
41
42     /* (non-Javadoc)
43      * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
44      */

45     protected IFigure createFigure() {
46         return new CFGNodeDataFigure();
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 java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
57      */

58     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
59         if (evt.getPropertyName().equals(CFGElement.TEXT)){
60             ((CFGNodeDataFigure)getFigure()).setData((ArrayList)evt.getNewValue());
61             ((CFGNodeDataFigure)getFigure()).updateFigure();
62             ((CFGNodeEditPart)getParent()).updateSize(getFigure().getBounds().width, getFigure().getBounds().height);
63         }
64         else if (evt.getPropertyName().equals(CFGElement.HEAD)){
65             ((CFGNodeDataFigure)getFigure()).getRect().setBackgroundColor(SootPlugin.getDefault().getColorManager().getColor(new RGB(0,45,200)));
66         }
67         else if (evt.getPropertyName().equals(CFGElement.TAIL)){
68             ((CFGNodeDataFigure)getFigure()).getRect().setBackgroundColor(SootPlugin.getDefault().getColorManager().getColor(new RGB(0,200,45)));
69         }
70     }
71
72     /**
73      * @return
74      */

75     public CFGNodeData getNodeData() {
76         return (CFGNodeData)getModel();
77     }
78
79     
80     
81     public void activate(){
82         super.activate();
83         getNodeData().addPropertyChangeListener(this);
84     }
85     
86     public void deactivate(){
87         super.deactivate();
88         getNodeData().removePropertyChangeListener(this);
89     }
90
91     public void markStop(){
92         ArrayList list = getNodeData().getText();
93         ((CFGNodeDataFigure)getFigure()).addStopIcon();
94         // send event marking this unit
95
soot.toolkits.graph.interaction.InteractionHandler.v().addToStopUnitList(((CFGNodeDataFigure)getFigure()).getUnit());
96     }
97     
98     public void unMarkStop(){
99         ((CFGNodeDataFigure)getFigure()).removeStopIcon();
100         soot.toolkits.graph.interaction.InteractionHandler.v().removeFromStopUnitList(((CFGNodeDataFigure)getFigure()).getUnit());
101     }
102     
103     public void resetColors(){
104         removeIndicator();
105     }
106     
107     public void addIndicator(){
108         ((CFGNodeDataFigure)getFigure()).addIndicator();
109     }
110     
111     public void removeIndicator(){
112         ((CFGNodeDataFigure)getFigure()).removeIndicator();
113     }
114 }
115
Popular Tags