Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 458ae8c020732fac9a4a4a01e3447fc1176039f6 (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
/*******************************************************************************
 * Copyright (c) 2012 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
 *******************************************************************************/
package org.eclipse.papyrus.uml.diagram.timing.custom.figures;

import java.util.List;

import org.eclipse.draw2d.AbstractLayout;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
import org.eclipse.papyrus.uml.diagram.common.figure.node.PapyrusNodeFigure;
import org.eclipse.swt.graphics.Image;

public class LifelineFigure extends PapyrusNodeFigure implements IPapyrusNodeUMLElementFigure {

	protected final int LABEL_WIDTH = 30;
	protected RectangleFigure nameLabelContainerFigure;
	protected LifelineVerticalLabel nameLabel;
	protected RectangleFigure timeRulerContainerFigure;
	protected RectangleFigure lifelineDataContainerFigure;
	protected RectangleFigure timelineContainerFigure;

	private boolean selected;
	private boolean displayTimeRuler;

	public LifelineFigure() {
		setShadow(false);
		createContents();
		setLayoutManager(new AbstractLayout() {
			public void layout(final IFigure container) {
				final Rectangle clientArea = container.getClientArea();
				final List<?> children = container.getChildren();
				for (int i = 0; i < children.size(); i++) {
					final IFigure child = (IFigure) children.get(i);
					if (child == getNameLabelContainerFigure()) {
						child.setBounds(new Rectangle(clientArea.x, clientArea.y, LifelineFigure.this.LABEL_WIDTH, clientArea.height));
					} else if (child == getLifelineDataContainerFigure()) {
						child.setBounds(new Rectangle(clientArea.x + LifelineFigure.this.LABEL_WIDTH, clientArea.y, clientArea.width
								- LifelineFigure.this.LABEL_WIDTH, clientArea.height));
					}
				}
			}

			@Override
			protected Dimension calculatePreferredSize(final IFigure container, final int wHint, final int hHint) {
				return new Dimension(-1, -1);
			}
		});
	}

	protected void createContents() {
		// meant to be overridden
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.draw2d.Figure#setPreferredSize(org.eclipse.draw2d.geometry.Dimension)
	 */
	@Override
	public void setPreferredSize(final Dimension size) {
		final IFigure container = getParent();
		final int childrenSize = container.getChildren().size();
		final Rectangle containerRectangle = container.getBounds();
		final Rectangle resultBounds = new Rectangle(0, 0, containerRectangle.width(), containerRectangle.height() / childrenSize);
		this.prefSize = resultBounds.getSize();
	}

	public void setSelected(final boolean selected) {
		this.selected = selected;
	}

	@Override
	public void paintFigure(final Graphics graphics) {
		super.paintFigure(graphics);
		if (this.selected) {
			graphics.pushState();
			graphics.setForegroundColor(ColorConstants.black);
			graphics.setLineWidth(1);
			graphics.drawRectangle(getBounds().getShrinked(1, 1).resize(-1, -1));
			graphics.popState();
		}
	}

	public boolean isDisplayTimeRuler() {
		return this.displayTimeRuler;
	}

	public void setDisplayTimeRuler(final boolean visible) {
		this.displayTimeRuler = visible;
	}

	public LifelineVerticalLabel getLifelineLabelFigure() {
		return this.nameLabel;
	}

	public RectangleFigure getNameLabelContainerFigure() {
		return this.nameLabelContainerFigure;
	}

	public RectangleFigure getTimelineContainerFigure() {
		return this.timelineContainerFigure;
	}

	public RectangleFigure getTimeRulerContainerFigure() {
		return this.timeRulerContainerFigure;
	}

	public RectangleFigure getLifelineDataContainerFigure() {
		return this.lifelineDataContainerFigure;
	}

	public void setStereotypeDisplay(final String stereotypes, final Image image) {
		// TODO implement LifelineFigure#setStereotypeDisplay
	}

	public void setStereotypePropertiesInBrace(final String stereotypeProperties) {
		// TODO implement LifelineFigure#setStereotypePropertiesInBrace
	}

	public void setStereotypePropertiesInCompartment(final String stereotypeProperties) {
		// TODO implement LifelineFigure#setStereotypePropertiesInCompartment
	}

	public Label getStereotypesLabel() {
		return null;
	}
}

Back to the top