blob: d7138f8c37b7cfa69f591927283c1976fa1317b0 (
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
|
/*****************************************************************************
* Copyright (c) 2014, 2018 CEA LIST, EclipseSource and others.
*
*
* 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:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
* EclipseSource - Bug 536638
*
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.helper;
import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
import org.eclipse.gmf.runtime.notation.IdentityAnchor;
/**
*
* Helper used for identity anchor
*
*/
public class IdentityAnchorHelper {
/**
* the char starting an id of {@link IdentityAnchor}
*/
public static final char START_ID = '(';
/**
* the char ending an id of {@link IdentityAnchor}
*/
public static final char END_ID = ')';
/**
* the char separating percentage in ids of {@link IdentityAnchor}
*/
public static final char X_Y_SEPARATOR = ',';
/**
* the char separating percentage as string in ids of {@link IdentityAnchor}
*/
public static final String X_Y_SEPARATOR_AS_STRING = Character.toString(X_Y_SEPARATOR);
/**
*
* Constructor.
*
*/
private IdentityAnchorHelper() {
// to prevent instanciation
}
/**
*
* @param anchor
* an {@link IdentityAnchor} representing a {@link BaseSlidableAnchor}
* @return
* the value of x percentage
* @deprecated
* This method only supports {@link IdentityAnchor IdentityAnchors} representing a {@link BaseSlidableAnchor}. Other
* anchors would cause an exception. Use {@link BaseSlidableAnchor#parseTerminalString(String)} instead; and check if the
* resulting point is != null (If null, then the {@link IdentityAnchor} doesn't represent a {@link BaseSlidableAnchor})
*/
@Deprecated
public static final double getXPercentage(final IdentityAnchor anchor) {
PrecisionPoint point = BaseSlidableAnchor.parseTerminalString(anchor.getId());
if (point == null) {
throw new IllegalArgumentException("Anchor " + anchor.getId() + " is not a valid BaseSlidableAnchor");
}
return point.preciseX();
}
/**
*
* @param anchor
* an anchor
* @return
* the value of y percentage
* @deprecated
* This method only supports {@link IdentityAnchor IdentityAnchors} representing a {@link BaseSlidableAnchor}. Other
* anchors would cause an exception. Use {@link BaseSlidableAnchor#parseTerminalString(String)} instead; and check if the
* resulting point is != null (If null, then the {@link IdentityAnchor} doesn't represent a {@link BaseSlidableAnchor})
*/
@Deprecated
public static final double getYPercentage(final IdentityAnchor anchor) {
PrecisionPoint point = BaseSlidableAnchor.parseTerminalString(anchor.getId());
if (point == null) {
throw new IllegalArgumentException("Anchor " + anchor.getId() + " is not a valid BaseSlidableAnchor");
}
return point.preciseY();
}
/**
*
* @param percentageOnX
* the percentage on x
* @param percentageOnY
* the percentage on y
* @return
* the string representing the new id for an anchor
*/
public static final String createNewAnchorIdValue(final double percentageOnX, final double percentageOnY) {
final StringBuilder builder = new StringBuilder();
builder.append(START_ID);
builder.append(Double.toString(percentageOnX));
builder.append(X_Y_SEPARATOR_AS_STRING);
builder.append(Double.toString(percentageOnY));
builder.append(END_ID);
return builder.toString();
}
}
|