1 | package de.uka.ipd.sdq.pcm.gmf.composite; |
2 | |
3 | import org.eclipse.draw2d.ChopboxAnchor; |
4 | import org.eclipse.draw2d.ConnectionAnchor; |
5 | import org.eclipse.draw2d.Graphics; |
6 | import org.eclipse.draw2d.IFigure; |
7 | import org.eclipse.draw2d.PositionConstants; |
8 | import org.eclipse.draw2d.geometry.Rectangle; |
9 | |
10 | /** |
11 | * Represents the border figure --[ for provided infrastructure roles. The figure is rotated depending on it's relative location with respect to it's parent. |
12 | * |
13 | * @author groenda |
14 | */ |
15 | public class InfrastructureRequiredRoleManualFigure extends AbstractBorderFigure { |
16 | |
17 | /** |
18 | * @param size width and height of the figure in logical units (LP) |
19 | * @param posType position type of the figure |
20 | */ |
21 | public InfrastructureRequiredRoleManualFigure(int logicalSize, POSITION_TYPE posType) { |
22 | super(logicalSize, posType); |
23 | } |
24 | |
25 | protected void paintFigure(Graphics graphics) { |
26 | super.paintFigure(graphics); |
27 | |
28 | if (getBorderItemLocator() == null) { |
29 | throw new IllegalStateException("border item locator null in InfrastructureProvidedRoleFigure.paintFigure"); |
30 | } |
31 | |
32 | // determine the side the border item is located relative to it's parent |
33 | int side = (getBorderItemLocator() == null ? PositionConstants.EAST : getBorderItemLocator().getCurrentSideOfParent()); |
34 | |
35 | Rectangle rect = new Rectangle(); |
36 | graphics.getClip(rect); |
37 | |
38 | // shrink rect so the last pixel of the circle is not clipped by the bounding box |
39 | rect.shrink(1, 1); |
40 | |
41 | /* Figure: |
42 | * +- |
43 | * --| |
44 | * +- |
45 | */ |
46 | switch(side){ |
47 | case PositionConstants.EAST: |
48 | // stem |
49 | graphics.drawLine(rect.getLeft().x,rect.getCenter().y,rect.getCenter().x,rect.getCenter().y); |
50 | // | |
51 | graphics.drawLine(rect.getCenter().x, rect.getTop().y+rect.height*1/8, rect.getCenter().x, rect.getTop().y+rect.height*7/8); |
52 | // upper |
53 | graphics.drawLine(rect.getCenter().x, rect.getTop().y+rect.height*1/8, rect.getCenter().x+rect.width*3/8, rect.getTop().y+rect.height*1/8); |
54 | // lower |
55 | graphics.drawLine(rect.getCenter().x, rect.getTop().y+rect.height*7/8, rect.getCenter().x+rect.width*3/8, rect.getTop().y+rect.height*7/8); |
56 | break; |
57 | case PositionConstants.WEST: |
58 | graphics.drawLine(rect.getRight().x,rect.getCenter().y,rect.getCenter().x,rect.getCenter().y); |
59 | // | |
60 | graphics.drawLine(rect.getCenter().x, rect.getTop().y+rect.height*1/8, rect.getCenter().x, rect.getTop().y+rect.height*7/8); |
61 | // upper |
62 | graphics.drawLine(rect.getCenter().x, rect.getTop().y+rect.height*1/8, rect.getCenter().x-rect.width*3/8, rect.getTop().y+rect.height*1/8); |
63 | // lower |
64 | graphics.drawLine(rect.getCenter().x, rect.getTop().y+rect.height*7/8, rect.getCenter().x-rect.width*3/8, rect.getTop().y+rect.height*7/8); |
65 | break; |
66 | case PositionConstants.NORTH: |
67 | graphics.drawLine(rect.getCenter().x,rect.getBottom().y,rect.getCenter().x,rect.getCenter().y); |
68 | // | |
69 | graphics.drawLine(rect.getLeft().x+rect.width*1/8, rect.getCenter().y, rect.getRight().x-rect.width*1/8, rect.getCenter().y); |
70 | // upper |
71 | graphics.drawLine(rect.getLeft().x+rect.width*1/8, rect.getCenter().y, rect.getLeft().x+rect.width*1/8, rect.getCenter().y-rect.height*3/8); |
72 | // lower |
73 | graphics.drawLine(rect.getRight().x-rect.width*1/8, rect.getCenter().y, rect.getRight().x-rect.width*1/8, rect.getCenter().y-rect.height*3/8); |
74 | break; |
75 | case PositionConstants.SOUTH: |
76 | graphics.drawLine(rect.getCenter().x,rect.getTop().y,rect.getCenter().x,rect.getCenter().y); |
77 | // | |
78 | graphics.drawLine(rect.getLeft().x+rect.width*1/8, rect.getCenter().y, rect.getRight().x-rect.width*1/8, rect.getCenter().y); |
79 | // upper |
80 | graphics.drawLine(rect.getLeft().x+rect.width*1/8, rect.getCenter().y, rect.getLeft().x+rect.width*1/8, rect.getCenter().y+rect.height*3/8); |
81 | // lower |
82 | graphics.drawLine(rect.getRight().x-rect.width*1/8, rect.getCenter().y, rect.getRight().x-rect.width*1/8, rect.getCenter().y+rect.height*3/8); |
83 | break; |
84 | } |
85 | } |
86 | |
87 | /** |
88 | * @return the rectangle surrounding the [ part of the figure |
89 | * relative to the position of the figure |
90 | */ |
91 | private Rectangle getTargetConnectionFigureBounds() { |
92 | int side = (getBorderItemLocator() == null ? PositionConstants.EAST : getBorderItemLocator().getCurrentSideOfParent()); |
93 | |
94 | Rectangle rect = getBounds(); |
95 | Rectangle result = null; |
96 | |
97 | switch(side){ |
98 | case PositionConstants.EAST: |
99 | result = new Rectangle(rect.getCenter().x, rect.getTop().y+rect.height*1/8, rect.width*3/8, rect.height*6/8); |
100 | break; |
101 | case PositionConstants.WEST: |
102 | result = new Rectangle(rect.getLeft().x+rect.width*1/8, rect.getTop().y+rect.height*1/8, rect.width*3/8, rect.height*6/8); |
103 | break; |
104 | case PositionConstants.NORTH: |
105 | result = new Rectangle(rect.getCenter().x-rect.width*3/8, rect.getTop().y+rect.height*1/8, rect.width*6/8, rect.height*3/8); |
106 | break; |
107 | case PositionConstants.SOUTH: |
108 | result = new Rectangle(rect.getCenter().x-rect.width*3/8, rect.getCenter().y, rect.height*6/8, rect.height*3/8); |
109 | break; |
110 | } |
111 | return result; |
112 | } |
113 | |
114 | /**Anchor providing a connection point to the rectangular connection part of {@link InfrastructureRequiredRoleManualFigure}. |
115 | * @author groenda |
116 | * |
117 | */ |
118 | private class RectangleAnchor extends ChopboxAnchor { |
119 | public RectangleAnchor(IFigure owner) { |
120 | super(owner); |
121 | } |
122 | |
123 | @Override |
124 | protected Rectangle getBox() { |
125 | return getTargetConnectionFigureBounds(); |
126 | } |
127 | } |
128 | |
129 | protected ConnectionAnchor createAnchorInternal() { |
130 | return new RectangleAnchor(this); |
131 | } |
132 | |
133 | protected ConnectionAnchor createAnchorExternal() { |
134 | return new StemAnchor(this); |
135 | } |
136 | } |