| 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 InfrastructureProvidedRoleManualFigure 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 InfrastructureProvidedRoleManualFigure(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.WEST : 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 | switch(side){ |
| 45 | case PositionConstants.EAST: |
| 46 | graphics.drawLine(rect.getLeft().x,rect.getCenter().y,rect.getCenter().x,rect.getCenter().y); |
| 47 | graphics.drawRectangle(rect.getCenter().x, rect.getTop().y+rect.height/4, rect.height/2, rect.height/2); |
| 48 | break; |
| 49 | case PositionConstants.WEST: |
| 50 | graphics.drawLine(rect.getRight().x,rect.getCenter().y,rect.getCenter().x,rect.getCenter().y); |
| 51 | graphics.drawRectangle(rect.getLeft().x, rect.getTop().y+rect.height/4, rect.height/2, rect.height/2); |
| 52 | break; |
| 53 | case PositionConstants.NORTH: |
| 54 | graphics.drawLine(rect.getCenter().x,rect.getBottom().y,rect.getCenter().x,rect.getCenter().y); |
| 55 | graphics.drawRectangle(rect.getCenter().x-rect.width/4, rect.getTop().y, rect.height/2, rect.height/2); |
| 56 | break; |
| 57 | case PositionConstants.SOUTH: |
| 58 | graphics.drawLine(rect.getCenter().x,rect.getTop().y,rect.getCenter().x,rect.getCenter().y); |
| 59 | graphics.drawRectangle(rect.getCenter().x-rect.width/4, rect.getCenter().y, rect.height/2, rect.height/2); |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @return the rectangle surrounding the [] part of the figure |
| 66 | * relative to the position of the figure |
| 67 | */ |
| 68 | private Rectangle getTargetConnectionFigureBounds() { |
| 69 | int side = (getBorderItemLocator() == null ? PositionConstants.WEST : getBorderItemLocator().getCurrentSideOfParent()); |
| 70 | |
| 71 | Rectangle rect = getBounds(); |
| 72 | Rectangle result = null; |
| 73 | |
| 74 | switch(side){ |
| 75 | case PositionConstants.EAST: |
| 76 | result = new Rectangle(rect.getCenter().x, rect.getTop().y+rect.height/4, rect.height/2, rect.height/2); |
| 77 | break; |
| 78 | case PositionConstants.WEST: |
| 79 | result = new Rectangle(rect.getLeft().x, rect.getTop().y+rect.height/4, rect.height/2, rect.height/2); |
| 80 | break; |
| 81 | case PositionConstants.NORTH: |
| 82 | result = new Rectangle(rect.getCenter().x-rect.width/4, rect.getTop().y, rect.height/2, rect.height/2); |
| 83 | break; |
| 84 | case PositionConstants.SOUTH: |
| 85 | result = new Rectangle(rect.getCenter().x-rect.width/4, rect.getCenter().y, rect.height/2, rect.height/2); |
| 86 | break; |
| 87 | } |
| 88 | return result; |
| 89 | } |
| 90 | |
| 91 | /**Anchor providing a connection point to the rectangular connection part of {@link InfrastructureProvidedRoleManualFigure}. |
| 92 | * @author groenda |
| 93 | * |
| 94 | */ |
| 95 | private class RectangleAnchor extends ChopboxAnchor { |
| 96 | public RectangleAnchor(IFigure owner) { |
| 97 | super(owner); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | protected Rectangle getBox() { |
| 102 | return getTargetConnectionFigureBounds(); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | protected ConnectionAnchor createAnchorInternal() { |
| 107 | return new RectangleAnchor(this); |
| 108 | } |
| 109 | |
| 110 | protected ConnectionAnchor createAnchorExternal() { |
| 111 | return new StemAnchor(this); |
| 112 | } |
| 113 | } |