001: package newprocess.diagram.edit.parts;
002:
003: import newprocess.diagram.edit.policies.ActorItemSemanticEditPolicy;
004: import newprocess.diagram.part.New_processVisualIDRegistry;
005:
006: import org.eclipse.draw2d.ColorConstants;
007: import org.eclipse.draw2d.Ellipse;
008: import org.eclipse.draw2d.FreeformLayout;
009: import org.eclipse.draw2d.Graphics;
010: import org.eclipse.draw2d.IFigure;
011: import org.eclipse.draw2d.Polygon;
012: import org.eclipse.draw2d.RectangleFigure;
013: import org.eclipse.draw2d.StackLayout;
014: import org.eclipse.draw2d.XYLayout;
015: import org.eclipse.draw2d.geometry.Dimension;
016: import org.eclipse.draw2d.geometry.Point;
017: import org.eclipse.draw2d.geometry.PointList;
018: import org.eclipse.draw2d.geometry.Rectangle;
019: import org.eclipse.gef.EditPart;
020: import org.eclipse.gef.EditPolicy;
021: import org.eclipse.gef.editpolicies.LayoutEditPolicy;
022: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
023: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
024: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
025: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableShapeEditPolicy;
026: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
027: import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
028: import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
029: import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
030: import org.eclipse.gmf.runtime.notation.View;
031: import org.eclipse.swt.graphics.Color;
032:
033: /**
034: * @generated
035: */
036: public class ActorEditPart extends ShapeNodeEditPart {
037:
038: /**
039: * @generated
040: */
041: public static final int VISUAL_ID = 2007;
042:
043: /**
044: * @generated
045: */
046: protected IFigure contentPane;
047:
048: /**
049: * @generated
050: */
051: protected IFigure primaryShape;
052:
053: /**
054: * @generated
055: */
056: public ActorEditPart(View view) {
057: super (view);
058: }
059:
060: /**
061: * @generated
062: */
063: protected void createDefaultEditPolicies() {
064: super .createDefaultEditPolicies();
065:
066: installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
067: new ActorItemSemanticEditPolicy());
068: installEditPolicy(EditPolicy.LAYOUT_ROLE,
069: createLayoutEditPolicy());
070: }
071:
072: /**
073: * @generated
074: */
075: protected LayoutEditPolicy createLayoutEditPolicy() {
076: XYLayoutEditPolicy lep = new XYLayoutEditPolicy() {
077:
078: protected EditPolicy createChildEditPolicy(EditPart child) {
079: EditPolicy result = super .createChildEditPolicy(child);
080: if (result == null) {
081: return new ResizableShapeEditPolicy();
082: }
083: return result;
084: }
085: };
086: return lep;
087: }
088:
089: /**
090: * @generated
091: */
092: protected IFigure createNodeShape() {
093: ActorFigure figure = new ActorFigure();
094: return primaryShape = figure;
095: }
096:
097: /**
098: * @generated
099: */
100: public ActorFigure getPrimaryShape() {
101: return (ActorFigure) primaryShape;
102: }
103:
104: /**
105: * @generated
106: */
107: protected boolean addFixedChild(EditPart childEditPart) {
108: if (childEditPart instanceof ActorNameEditPart) {
109: ((ActorNameEditPart) childEditPart)
110: .setLabel(getPrimaryShape()
111: .getFigureActorNameFigure());
112: return true;
113: }
114: return false;
115: }
116:
117: /**
118: * @generated
119: */
120: protected boolean removeFixedChild(EditPart childEditPart) {
121:
122: return false;
123: }
124:
125: /**
126: * @generated
127: */
128: protected void addChildVisual(EditPart childEditPart, int index) {
129: if (addFixedChild(childEditPart)) {
130: return;
131: }
132: super .addChildVisual(childEditPart, -1);
133: }
134:
135: /**
136: * @generated
137: */
138: protected void removeChildVisual(EditPart childEditPart) {
139: if (removeFixedChild(childEditPart)) {
140: return;
141: }
142: super .removeChildVisual(childEditPart);
143: }
144:
145: /**
146: * @generated
147: */
148: protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
149:
150: return super .getContentPaneFor(editPart);
151: }
152:
153: /**
154: * @generated
155: */
156: protected NodeFigure createNodePlate() {
157: DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(
158: getMapMode().DPtoLP(40), getMapMode().DPtoLP(60));
159:
160: return result;
161: }
162:
163: /**
164: * Creates figure for this edit part.
165: *
166: * Body of this method does not depend on settings in generation model
167: * so you may safely remove <i>generated</i> tag and modify it.
168: *
169: * @generated
170: */
171: protected NodeFigure createNodeFigure() {
172: NodeFigure figure = createNodePlate();
173: figure.setLayoutManager(new StackLayout());
174: IFigure shape = createNodeShape();
175: figure.add(shape);
176: contentPane = setupContentPane(shape);
177: return figure;
178: }
179:
180: /**
181: * Default implementation treats passed figure as content pane.
182: * Respects layout one may have set for generated figure.
183: * @param nodeShape instance of generated figure class
184: * @generated
185: */
186: protected IFigure setupContentPane(IFigure nodeShape) {
187: if (nodeShape.getLayoutManager() == null) {
188: nodeShape.setLayoutManager(new FreeformLayout() {
189:
190: public Object getConstraint(IFigure figure) {
191: Object result = constraints.get(figure);
192: if (result == null) {
193: result = new Rectangle(0, 0, -1, -1);
194: }
195: return result;
196: }
197: });
198: }
199: return nodeShape; // use nodeShape itself as contentPane
200: }
201:
202: /**
203: * @generated
204: */
205: public IFigure getContentPane() {
206: if (contentPane != null) {
207: return contentPane;
208: }
209: return super .getContentPane();
210: }
211:
212: /**
213: * @generated
214: */
215: public EditPart getPrimaryChildEditPart() {
216: return getChildBySemanticHint(New_processVisualIDRegistry
217: .getType(ActorNameEditPart.VISUAL_ID));
218: }
219:
220: /**
221: * the figure ist extended to allow dynamic stretching of child components.
222: * @author sh
223: * @generated NOT
224: */
225: public class ActorFigure extends RectangleFigure {
226: // the objects to resize
227: private Ellipse head = null;
228: private Polygon body = null;
229:
230: // default sizes
231: private Dimension defaultActorSize;
232: private Dimension defaultHeadSize;
233: private PointList defaultBodySize;
234:
235: // initial stretch factors
236: private double stretchWidthFactor = 1.0;
237: private double stretchHeightFactor = 1.0;
238:
239: /**
240: * store the default size for stretch calculations
241: * @author sh
242: * @generated NOT
243: */
244:
245: public ActorFigure() {
246: this .setLayoutManager(new XYLayout());
247: this .setFill(true);
248: this .setFillXOR(false);
249: this .setOutline(false);
250: this .setOutlineXOR(false);
251: this .setLineWidth(1);
252: this .setLineStyle(Graphics.LINE_SOLID);
253: this .setPreferredSize(new Dimension(
254: getMapMode().DPtoLP(40), getMapMode().DPtoLP(60)));
255: defaultActorSize = this .getPreferredSize();
256: createContents();
257: }
258:
259: /**
260: * calculate stretch factors derived from new actors size
261: * @author ts
262: * @param newActorSize
263: */
264: private void setStretchFactor(Rectangle bounds) {
265: stretchWidthFactor = (double) bounds.width
266: / defaultActorSize.width;
267: stretchHeightFactor = (double) bounds.height
268: / defaultActorSize.height;
269: }
270:
271: /**
272: * stretch a point
273: * @author ts
274: * @param p
275: */
276: private Point stretch(Point p) {
277: return new Point((int) (p.x * stretchWidthFactor),
278: (int) (p.y * stretchHeightFactor));
279: }
280:
281: /**
282: * stretch a dimension (for the head)
283: * @author ts
284: * @param d
285: */
286: private Dimension stretch(Dimension d) {
287: return new Dimension((int) (d.width * stretchWidthFactor),
288: (int) (d.height * stretchHeightFactor));
289: }
290:
291: /**
292: * do the job
293: * @author ts
294: */
295: private void stretch() {
296: setStretchFactor(getBounds());
297:
298: head.setSize(stretch(defaultHeadSize));
299:
300: PointList pl = new PointList();
301: for (int i = 0; i < defaultBodySize.size(); i++) {
302: Point p = defaultBodySize.getPoint(i);
303: pl.addPoint(stretch(p));
304: }
305: body.setPoints(pl);
306: }
307:
308: /**
309: * tests if all object references and default sizes are initialized
310: * @author ts
311: * @return
312: */
313: private boolean isStretchable() {
314: return (defaultActorSize != null && defaultBodySize != null
315: && defaultHeadSize != null && head != null && body != null);
316: }
317:
318: /**
319: * extend repaint by a stretch calculation, if completly initialised
320: * @author ts
321: */
322: public void repaint() {
323: super .repaint();
324: if (isStretchable())
325: stretch();
326: }
327:
328: /**
329: * call new methods to build head and body
330: * @author ts
331: * @generated NOT
332: */
333:
334: private void createContents() {
335: createHead();
336: createBody();
337:
338: WrapLabel actorNameFigure0 = new WrapLabel();
339: actorNameFigure0.setText("<...>");
340: // TODO: position the text label
341: this .add(actorNameFigure0);
342: setFigureActorNameFigure(actorNameFigure0);
343: }
344:
345: /**
346: * create the head, store it in the figure and initialize default size
347: * @author ts
348: * create the head of an actor
349: */
350: private void createHead() {
351: head = new Ellipse();
352: head.setFill(true);
353: head.setFillXOR(false);
354: head.setOutline(true);
355: head.setOutlineXOR(false);
356: head.setLineWidth(1);
357: head.setLineStyle(Graphics.LINE_SOLID);
358: head.setForegroundColor(FOREGROUND);
359: head.setBackgroundColor(BACKGROUND);
360: head.setSize(getMapMode().DPtoLP(40), getMapMode().DPtoLP(
361: 20));
362: defaultHeadSize = head.getSize();
363:
364: this .add(head);
365: }
366:
367: /**
368: * create the body, store it in the figure and initialize default size
369: * @author ts
370: * create the body of an actor
371: */
372: private void createBody() {
373: body = new Polygon();
374: body.addPoint(new Point(getMapMode().DPtoLP(23),
375: getMapMode().DPtoLP(19)));
376: body.addPoint(new Point(getMapMode().DPtoLP(23),
377: getMapMode().DPtoLP(24)));
378: body.addPoint(new Point(getMapMode().DPtoLP(39),
379: getMapMode().DPtoLP(24)));
380: body.addPoint(new Point(getMapMode().DPtoLP(39),
381: getMapMode().DPtoLP(29)));
382: body.addPoint(new Point(getMapMode().DPtoLP(23),
383: getMapMode().DPtoLP(29)));
384: body.addPoint(new Point(getMapMode().DPtoLP(23),
385: getMapMode().DPtoLP(36)));
386: body.addPoint(new Point(getMapMode().DPtoLP(39),
387: getMapMode().DPtoLP(48)));
388: body.addPoint(new Point(getMapMode().DPtoLP(39),
389: getMapMode().DPtoLP(53)));
390: body.addPoint(new Point(getMapMode().DPtoLP(20),
391: getMapMode().DPtoLP(42)));
392: body.addPoint(new Point(getMapMode().DPtoLP(1),
393: getMapMode().DPtoLP(53)));
394: body.addPoint(new Point(getMapMode().DPtoLP(1),
395: getMapMode().DPtoLP(48)));
396: body.addPoint(new Point(getMapMode().DPtoLP(17),
397: getMapMode().DPtoLP(36)));
398: body.addPoint(new Point(getMapMode().DPtoLP(17),
399: getMapMode().DPtoLP(29)));
400: body.addPoint(new Point(getMapMode().DPtoLP(1),
401: getMapMode().DPtoLP(29)));
402: body.addPoint(new Point(getMapMode().DPtoLP(1),
403: getMapMode().DPtoLP(24)));
404: body.addPoint(new Point(getMapMode().DPtoLP(17),
405: getMapMode().DPtoLP(24)));
406: body.addPoint(new Point(getMapMode().DPtoLP(17),
407: getMapMode().DPtoLP(19)));
408: body.setFill(true);
409: body.setFillXOR(false);
410: body.setOutline(true);
411: body.setOutlineXOR(false);
412: body.setLineWidth(1);
413: body.setLineStyle(Graphics.LINE_SOLID);
414: body.setForegroundColor(FOREGROUND);
415: body.setBackgroundColor(BACKGROUND);
416: defaultBodySize = body.getPoints().getCopy();
417: this .add(body);
418: }
419:
420: /**
421: * @generated
422: */
423: private WrapLabel fActorNameFigure;
424:
425: /**
426: * @generated
427: */
428: public WrapLabel getFigureActorNameFigure() {
429: return fActorNameFigure;
430: }
431:
432: /**
433: * @generated
434: */
435: private void setFigureActorNameFigure(WrapLabel fig) {
436: fActorNameFigure = fig;
437: }
438:
439: /**
440: * @generated
441: */
442: private boolean myUseLocalCoordinates = true;
443:
444: /**
445: * @generated
446: */
447: protected boolean useLocalCoordinates() {
448: return myUseLocalCoordinates;
449: }
450:
451: /**
452: * @generated
453: */
454: protected void setUseLocalCoordinates(
455: boolean useLocalCoordinates) {
456: myUseLocalCoordinates = useLocalCoordinates;
457: }
458:
459: }
460:
461: /**
462: * @generated
463: */
464: static final Color BODY_FORE = new Color(null, 220, 220, 250);
465:
466: /**
467: * @generated
468: */
469: static final Color BODY_BACK = new Color(null, 230, 230, 255);
470:
471: /**
472: * @generated
473: */
474: static final Color HEAD_FORE = new Color(null, 220, 220, 250);
475:
476: /**
477: * @generated
478: */
479: static final Color HEAD_BACK = new Color(null, 230, 230, 255);
480:
481: /**
482: * @author ts
483: * @generated NOT
484: */
485: static final Color FOREGROUND = ColorConstants.gray;
486: static final Color BACKGROUND = new Color(null, 214, 231, 255);
487:
488: }
|