Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e5ded3991d5ed86b4fbf240a349c8cdac63ae545 (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
/*****************************************************************************
 * Copyright (c) 2009 CEA
 *
 *
 * 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:
 *   Atos Origin - Initial API and implementation
 *   C�line Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 440230 : Label Margin
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.figures;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.papyrus.uml.diagram.common.figure.node.RectangularShadowBorder;

/**
 * Change super type to support displaying stereotypes, modified by [Jin Liu(jin.liu@soyatec.com)]
 */
public class CombinedFragmentFigure extends StereotypeInteractionFigure {


	/**
	 * Height of the Bracket in case of CoRegion in Pixel
	 */
	private static final int BRACKET_HEIGHT = 30;
	private WrappingLabel titleLabel;
	private RectangleFigure header;
	private boolean coRegion;

	public WrappingLabel getTitleLabel() {
		return titleLabel;
	}

	public IFigure getHeaderContainer() {
		return header;
	}

	@Override
	public void setShadow(boolean shadow) {
		final int BORDER_WIDTH = 3;

		if (!shadow) {
			super.setShadow(shadow);
		} else {
			RectangularShadowBorder b = new RectangularShadowBorder(BORDER_WIDTH, getForegroundColor()) {
				@Override
				public Insets getInsets(IFigure figure) {
					return new Insets(1, 1, 1, 1);
				}
			};
			setBorder(b);
		}

		Rectangle figureRect = new Rectangle(getBounds()).expand(new Insets(0, 0, BORDER_WIDTH, BORDER_WIDTH));
		IFigure parent = getParent();
		while (parent != null) {
			if (parent.getBounds().contains(figureRect)) {
				parent.revalidate();
				parent.repaint();
				break;
			}
			parent = parent.getParent();
		}
	}


	/**
	 * @see org.eclipse.draw2d.Figure#paint(org.eclipse.draw2d.Graphics)
	 *
	 * @param graphics
	 */
	@Override
	public void paint(Graphics graphics) {
		if (isCoregion()) {
			Rectangle CBbounds = this.getBounds();

			graphics.pushState();

			Rectangle clipRectangle = new Rectangle();
			graphics.getClip(clipRectangle);
			graphics.setClip(clipRectangle.expand(2, 2));

			graphics.setLineWidth(getLineWidth());
			graphics.setLineStyle(getLineStyle());
			graphics.setForegroundColor(getForegroundColor());
			graphics.setBackgroundColor(getBackgroundColor());



			// Top Bracket Creation
			PointList list = new PointList();
			Point topLeft = CBbounds.getTopLeft().getCopy().getTranslated(0, BRACKET_HEIGHT);
			Point topRight = CBbounds.getTopRight().getCopy().getTranslated(0, BRACKET_HEIGHT);

			list.addPoint(topRight);
			list.addPoint(CBbounds.getTopRight().getCopy());
			list.addPoint(CBbounds.getTopLeft().getCopy());
			list.addPoint(topLeft);

			graphics.drawPolyline(list);

			// Bottom Bracket Creation
			list = new PointList();

			Point bottomLeft = CBbounds.getBottomLeft().getCopy().getTranslated(0, -BRACKET_HEIGHT);
			Point bottomRight = CBbounds.getBottomRight().getCopy().getTranslated(0, -BRACKET_HEIGHT);

			list.addPoint(bottomRight);
			list.addPoint(CBbounds.getBottomRight().getCopy());
			list.addPoint(CBbounds.getBottomLeft().getCopy());
			list.addPoint(bottomLeft);

			graphics.drawPolyline(list);

			this.setPreferredSize(new Dimension(40, 100));
			graphics.popState();
		} else {
			super.paint(graphics);
		}
	}


	/**
	 * @return
	 */
	public boolean isCoregion() {

		return this.coRegion;

	}

	/**
	 * @return
	 */
	public void setCoregion(boolean coregion) {
		this.coRegion = coregion;

	}

}

Back to the top