Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7efa0acae7bff6d781451cddccf0ee58ae115896 (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
/*******************************************************************************
 * Copyright (c) 2010, 2013 THALES GLOBAL SERVICES.
 * 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:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.sirius.diagram.sequence.ui.tool.internal.figure;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;

import org.eclipse.sirius.BackgroundStyle;
import org.eclipse.sirius.diagram.sequence.business.internal.elements.Operand;
import org.eclipse.sirius.diagram.sequence.business.internal.layout.LayoutConstants;
import org.eclipse.sirius.diagram.tools.api.graphical.edit.styles.IContainerLabelOffsets;
import org.eclipse.sirius.diagram.ui.tools.api.figure.GradientRoundedRectangle;
import org.eclipse.sirius.diagram.ui.tools.api.figure.OneLineMarginBorder;

/**
 * Custom figure to paint only a bottom dash line instead of a full border.
 * 
 * @author smonnier
 */
public class OperandFigure extends GradientRoundedRectangle {

    private Operand operand;

    /**
     * Create a new {@link LifelineNodeFigure}.
     * 
     * @param dimension
     *            dimension of the corner (with radius, height radius)
     * @param backgroundStyle
     *            style of the wanted gradient
     * @param operand
     *            the current operand
     */
    public OperandFigure(final Dimension dimension, final BackgroundStyle backgroundStyle, Operand operand) {
        super(dimension, backgroundStyle);

        this.operand = operand;

        this.setFill(false);
        this.setOutline(false);
    }

    /**
     * {@inheritDoc}
     */
    protected void createBorder() {
        OneLineMarginBorder oneLineBorder = new OneLineMarginBorder(PositionConstants.BOTTOM);
        oneLineBorder.setStyle(Graphics.LINE_CUSTOM);
        oneLineBorder.setLineDash(LayoutConstants.OPERAND_DASH_STYLE);
        oneLineBorder.setMargin(IContainerLabelOffsets.LABEL_OFFSET - 1, 0, 0, 0);

        setBorder(oneLineBorder);
    }

    /**
     * {@inheritDoc}
     * 
     * Overridden to paint only a bottom dash line instead of a full border.
     */
    @Override
    protected void paintBorder(Graphics graphics) {
        if (!isLastOperand()) {
            super.paintBorder(graphics);
        }
    }

    /**
     * Check if it is the last operand. In that case we do not need to paint the
     * operand separator.
     */
    private boolean isLastOperand() {
        boolean isLast = false;
        if (operand != null) {
            isLast = operand.isLastOperand();
        }
        return isLast;
    }
}

Back to the top