blob: fa0ec1f728d14458023895b756afacdf93609679 (
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
|
/*******************************************************************************
* Copyright (c) 2009 THALES GLOBAL SERVICES.
* 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:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.business.internal.edit.helpers;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.sirius.viewpoint.LabelAlignment;
/**
* Utility class to retrieve diagram elements' {@link LabelAlignment} and
* convert it into the appropriate Draw2D constants to implement the alignment.
*
* @author pcdavid
*/
public final class LabelAlignmentHelper {
private LabelAlignmentHelper() {
// Prevent instantiation.
}
/**
* Converts a {@link LabelAlignment} style value into the equivalent Draw2D
* {@link PositionConstants} value, which can be used in
* {@link org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.draw2d.ui.figures.SiriusWrapLabel}
* s.
*
* @param alignment
* the {@link LabelAlignment} to convert
* @return the equivalent {@link PositionConstants} value
*/
public static int getAsPositionConstant(final LabelAlignment alignment) {
final int alignmentValue;
switch (alignment) {
case CENTER:
alignmentValue = PositionConstants.CENTER;
break;
case LEFT:
alignmentValue = PositionConstants.LEFT;
break;
case RIGHT:
alignmentValue = PositionConstants.RIGHT;
break;
default:
alignmentValue = PositionConstants.CENTER;
break;
}
return alignmentValue;
}
/**
* Converts a {@link LabelAlignment} style value into the equivalent
* alignment constant to use in a
* {@link org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout}
* .
*
* @param alignment
* the {@link LabelAlignment} to convert
* @return the equivalent
* {@link org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout}
* minor alignment value
*/
public static int getAsCTLMinorAlignment(final LabelAlignment alignment) {
final int alignmentValue;
switch (alignment) {
case CENTER:
alignmentValue = ToolbarLayout.ALIGN_CENTER;
break;
case LEFT:
alignmentValue = ToolbarLayout.ALIGN_TOPLEFT;
break;
case RIGHT:
alignmentValue = ToolbarLayout.ALIGN_BOTTOMRIGHT;
break;
default:
alignmentValue = ToolbarLayout.ALIGN_CENTER;
break;
}
return alignmentValue;
}
}
|