Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dffde8f53203dfc00ec1ae8b20aea26bb3a70119 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*****************************************************************************
 * Copyright (c) 2013 CEA LIST.
 *
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Patrick Tessier (CEA LIST)- Initial API and implementation
 /*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.component.custom.figure.nodes;

import org.eclipse.draw2d.Border;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;

/**
 * Figure for Required interface. It draws an half circle.
 */
public class LollipopInterfaceFigure extends RoundedCompartmentFigure implements IPapyrusNodeUMLElementFigure {

	/** sets the beginning of the arc */
	protected int arcStarting = 0;

	protected boolean isRequired = false;
	protected boolean isProvided = false;

	/**
	 * Constructor.
	 */
	public LollipopInterfaceFigure() {
		setShadow(false);
		setBorder(null);
	}	
	
	/**
	 * display the Interface as Required
	 *
	 * @param required
	 *            true if required
	 */
	public void setRequired(boolean required) {
		this.isRequired = required;
	}



	@Override
	public void setBorder(Border border) {
		super.setBorder(null);
	}

	/**
	 * display it as provided
	 *
	 * @param provided
	 *            true if the display has to be provided
	 */
	public void setProvided(boolean provided) {
		this.isProvided = provided;
	}

	/**
	 * Sets the orientation of the arc
	 *
	 * @param positionConstants
	 *            position of the interface compared to the port
	 * @see PositionConstants
	 */
	public void setOrientation(int positionConstants) {
		if (positionConstants == PositionConstants.SOUTH) {
			arcStarting = 180;
		}
		if (positionConstants == PositionConstants.SOUTH_EAST) {
			arcStarting = 225;
		}
		if (positionConstants == PositionConstants.EAST) {
			arcStarting = 270;
		}
		if (positionConstants == PositionConstants.NORTH_EAST) {
			arcStarting = 315;
		}
		if (positionConstants == PositionConstants.NORTH) {
			arcStarting = 0;
		}
		if (positionConstants == PositionConstants.NORTH_WEST) {
			arcStarting = 45;
		}
		if (positionConstants == PositionConstants.WEST) {
			arcStarting = 90;
		}
		if (positionConstants == PositionConstants.SOUTH_WEST) {
			arcStarting = 135;
		}
		this.repaint();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.cea.papyrus.diagram.composite.figure.ProvidedInterfaceFigure#paintFigure(org.eclipse.
	 * draw2d.Graphics)
	 */
	@Override
	public void paintFigure(Graphics graphics) {
		if (isRequired && !isProvided) {
			graphics.pushState();
			graphics.setAntialias(SWT.ON);
			Rectangle area = getBounds();
			graphics.setLineWidth(1);
			graphics.drawArc(area.x, area.y, area.width - 1, area.height - 1, arcStarting, 180);
			graphics.popState();
		}
		else if (!isRequired && isProvided) {
			graphics.pushState();
			graphics.setAntialias(SWT.ON);
			graphics.setLineWidth(1);
			Rectangle area = getBounds();

			graphics.drawOval(area.x, area.y, area.width - 1, area.height - 1);
			graphics.popState();

		}
		else if (isRequired && isProvided) {
			graphics.pushState();
			graphics.setAntialias(SWT.ON);
			graphics.setLineWidth(1);
			Rectangle area = getBounds();
			graphics.drawOval(area.x + 2, area.y + 2, area.width - 5, area.height - 5);
			graphics.drawArc(area.x, area.y, area.width - 1, area.height - 1, arcStarting, 180);
			graphics.popState();

		}
		else {
			graphics.pushState();
			graphics.setAntialias(SWT.ON);
			graphics.setLineWidth(1);
			Rectangle area = getBounds();

			graphics.drawOval(area.x, area.y, area.width - 1, area.height - 1);
			graphics.popState();
		}
	}

	@Override
	public void setStereotypeDisplay(String stereotypes, Image image) {
	}

	@Override
	public void setStereotypePropertiesInBrace(String stereotypeProperties) {
	}

	@Override
	public void setStereotypePropertiesInCompartment(String stereotypeProperties) {
	}

	@Override
	public PapyrusWrappingLabel getStereotypesLabel() {
		return null;
	}

}

Back to the top