001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2005 Jennifer Lhotak
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package ca.mcgill.sable.graph.editparts;
021:
022: import java.beans.PropertyChangeEvent;
023: import java.beans.PropertyChangeListener;
024:
025: import org.eclipse.draw2d.*;
026: import org.eclipse.gef.*;
027: import org.eclipse.gef.editparts.*;
028: import org.eclipse.draw2d.graph.*;
029: import java.util.*;
030: import ca.mcgill.sable.graph.model.*;
031: import ca.mcgill.sable.graph.figures.*;
032: import org.eclipse.draw2d.geometry.*;
033: import org.eclipse.swt.graphics.RGB;
034: import org.eclipse.swt.widgets.Display;
035:
036: import ca.mcgill.sable.graph.editpolicies.*;
037:
038: public class ComplexNodeEditPart extends AbstractGraphicalEditPart
039: implements NodeEditPart, PropertyChangeListener {
040:
041: public ComplexNodeEditPart() {
042: super ();
043: }
044:
045: /* (non-Javadoc)
046: * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
047: */
048: protected void createEditPolicies() {
049: }
050:
051: /* (non-Javadoc)
052: * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
053: */
054: public ConnectionAnchor getSourceConnectionAnchor(
055: ConnectionEditPart arg0) {
056: return new ChopboxAnchor(getFigure());
057: }
058:
059: /* (non-Javadoc)
060: * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
061: */
062: public ConnectionAnchor getTargetConnectionAnchor(
063: ConnectionEditPart arg0) {
064: return new ChopboxAnchor(getFigure());
065: }
066:
067: /* (non-Javadoc)
068: * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.Request)
069: */
070: public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
071: return new ChopboxAnchor(getFigure());
072: }
073:
074: /* (non-Javadoc)
075: * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.Request)
076: */
077: public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
078: return new ChopboxAnchor(getFigure());
079: }
080:
081: /* (non-Javadoc)
082: * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
083: */
084: protected IFigure createFigure() {
085: return new ComplexNodeFigure();
086: }
087:
088: public void contributeNodesToGraph(DirectedGraph graph, HashMap map) {
089: Node node = new Node(this );
090: node.width = getFigure().getBounds().width;//getNode().getWidth();
091: node.height = getFigure().getBounds().height;
092: graph.nodes.add(node);
093: map.put(this , node);
094: }
095:
096: public void contributeEdgesToGraph(DirectedGraph graph, HashMap map) {
097: List outgoing = getSourceConnections();
098: for (int i = 0; i < outgoing.size(); i++) {
099: EdgeEditPart edge = (EdgeEditPart) outgoing.get(i);
100: edge.contributeToGraph(graph, map);
101: }
102: }
103:
104: public void applyGraphResults(DirectedGraph graph, HashMap map) {
105: SimpleNode node = (SimpleNode) map.get(this );
106: List outgoing = getSourceConnections();
107: for (int i = 0; i < outgoing.size(); i++) {
108: EdgeEditPart edge = (EdgeEditPart) outgoing.get(i);
109: edge.applyGraphResults(graph, map);
110: }
111:
112: }
113:
114: public ComplexNode getNode() {
115: return (ComplexNode) getModel();
116: }
117:
118: public List getModelChildren() {
119: return ((ComplexNode) getNode()).getChildren();
120: }
121:
122: public void propertyChange(PropertyChangeEvent event) {
123: if (event.getPropertyName().equals(Element.COMPLEX_CHILD)) {
124: refreshChildren();
125: }
126: }
127:
128: protected void refreshVisuals() {
129: Iterator it = getChildren().iterator();
130: while (it.hasNext()) {
131: Object next = it.next();
132: if (next instanceof SimpleNodeEditPart) {
133: getFigure()
134: .add(((SimpleNodeEditPart) next).getFigure());
135: getFigure()
136: .setSize(
137: getFigure().getBounds().width
138: + ((SimpleNodeEditPart) next)
139: .getFigure()
140: .getBounds().width,
141: getFigure().getBounds().height
142: + ((SimpleNodeEditPart) next)
143: .getFigure()
144: .getBounds().height);
145: } else if (next instanceof GraphEditPart) {
146: getFigure().add(((GraphEditPart) next).getFigure());
147: getFigure().setSize(
148: getFigure().getBounds().width
149: + ((GraphEditPart) next)
150: .getFigureWidth(),
151: getFigure().getBounds().height
152: + ((GraphEditPart) next)
153: .getFigureHeight());
154: }
155:
156: }
157: }
158:
159: }
|