Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e491632ecdee61b7b2c038eef47c6b1e037550d8 (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
172
173
174
175
176
177
178
179
180
181
182
183
/*****************************************************************************
 * Copyright (c) 2010 CEA
 *
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Soyatec - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.RotatableDecoration;
import org.eclipse.draw2d.Shape;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel;
import org.eclipse.papyrus.uml.diagram.common.figure.edge.UMLEdgeFigure;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;

/**
 * @author Jin Liu (jin.liu@soyatec.com)
 */
public abstract class MessageFigure extends UMLEdgeFigure {

	private static final Font LABEL_FIGURE_FONT = new Font(Display.getCurrent(), "SANS", 9, SWT.NORMAL);

	private WrappingLabel messageLabelFigure;

	private boolean selection;

	private Cursor customCursor;

	private IMapMode mapMode;

	/**
	 * Constructor.
	 *
	 */
	public MessageFigure() {
		this(null);
	}

	public MessageFigure(IMapMode mapMode) {
		this.mapMode = mapMode;
		createContents();
		if (createTargetDecoration() != null) {
			setTargetDecoration(createTargetDecoration());
		}
		if (createSourceDecoration() != null) {
			setSourceDecoration(createSourceDecoration());
		}
	}

	@Override
	public void resetStyle() {
		super.resetStyle();
		if (createTargetDecoration() != null) {
			setTargetDecoration(createTargetDecoration());
		}
		if (createSourceDecoration() != null) {
			setSourceDecoration(createSourceDecoration());
		}
	}

	@Override
	public void setLineWidth(int w) {
		super.setLineWidth(w);
		if (getSourceDecoration() instanceof Shape) {
			((Shape) getSourceDecoration()).setLineWidth(w);
		}
		if (getTargetDecoration() instanceof Shape) {
			((Shape) getTargetDecoration()).setLineWidth(w);
		}
	}

	@Override
	public void setForegroundColor(Color c) {
		super.setForegroundColor(c);
		if (getSourceDecoration() instanceof Shape) {
			((Shape) getSourceDecoration()).setForegroundColor(c);
			((Shape) getSourceDecoration()).setBackgroundColor(c);
		}
		if (getTargetDecoration() instanceof Shape) {
			((Shape) getTargetDecoration()).setForegroundColor(c);
			((Shape) getTargetDecoration()).setBackgroundColor(c);
		}
	}

	protected abstract RotatableDecoration createTargetDecoration();

	/**
	 * @since 3.0
	 */
	protected abstract RotatableDecoration createSourceDecoration();

	@Override
	protected void createContents() {
		super.createContents();
		messageLabelFigure = new PapyrusWrappingLabel();
		messageLabelFigure.setText("");
		messageLabelFigure.setForegroundColor(ColorConstants.black);
		messageLabelFigure.setFont(LABEL_FIGURE_FONT);
		this.add(messageLabelFigure);
	}

	/**
	 * @return the messageLabelFigure
	 */
	public WrappingLabel getMessageLabelFigure() {
		return messageLabelFigure;
	}

	public IMapMode getMapMode() {
		if (mapMode != null) {
			return mapMode;
		}
		return MapModeUtil.getMapMode();
	}

	/**
	 * @return the selection
	 */
	public boolean isSelection() {
		return selection;
	}

	/**
	 * @param selection
	 *            the selection to set
	 */
	public void setSelection(boolean selection) {
		this.selection = selection;
		repaint();
	}

	/**
	 * @return the customCursor
	 */
	public Cursor getCustomCursor() {
		return customCursor;
	}

	/**
	 * @see org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx#getCursor()
	 *
	 * @return
	 */
	@Override
	public Cursor getCursor() {
		if (customCursor != null) {
			return customCursor;
		}
		return super.getCursor();
	}

	/**
	 * @param customCursor
	 *            the customCursor to set
	 */
	public void setCustomCursor(Cursor customCursor) {
		this.customCursor = customCursor;
	}

	/**
	 * @param mapMode
	 *            the mapMode to set
	 */
	public void setMapMode(IMapMode mapMode) {
		this.mapMode = mapMode;
	}
}

Back to the top