Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java2
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java37
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java2
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java337
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java100
5 files changed, 471 insertions, 7 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java
index 685b5f632b0..b2933ddcb06 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java
@@ -193,7 +193,7 @@ public class SynchronizableGmfDiagramEditor extends DiagramDocumentEditor implem
EclipseCommandUtils.updateToggleCommandState(command, wsPreferenceStore.getBoolean(PreferencesConstantsHelper.SNAP_TO_GRID_CONSTANT));
} else {
- throw new RuntimeException(String.format("The Eclipse service {0} has not been found", ICommandService.class)); //$NON-NLS-1$
+ throw new RuntimeException(String.format("The Eclipse service %s has not been found", ICommandService.class)); //$NON-NLS-1$
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java
index 464d745788e..766cbf5c445 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java
@@ -17,15 +17,21 @@ import java.util.List;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
-import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.NodeEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.FixAnchorHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
/**
*
@@ -34,6 +40,8 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
*/
public class XYLayoutWithConstrainedResizedEditPolicy extends XYLayoutEditPolicy {
+ private FixAnchorHelper helper = null;
+
/**
* Returns the <code>Command</code> to resize a group of children.
*
@@ -43,14 +51,15 @@ public class XYLayoutWithConstrainedResizedEditPolicy extends XYLayoutEditPolicy
*/
protected Command getChangeConstraintCommand(ChangeBoundsRequest request) {
final CompoundCommand resize = new CompoundCommand("Resize Command");//$NON-NLS-1$
- GraphicalEditPart child;
+ IGraphicalEditPart child;
final List<?> children = request.getEditParts();
- final Point move = request.getMoveDelta();
final int direction = request.getResizeDirection();
- boolean forceLocation = request.isConstrainedResize() && (direction == PositionConstants.WEST || direction == PositionConstants.NORTH || direction == PositionConstants.NORTH_WEST);
+ boolean isConstrainedResize = request.isConstrainedResize();
+ boolean forceLocation = isConstrainedResize && (direction == PositionConstants.WEST || direction == PositionConstants.NORTH || direction == PositionConstants.NORTH_WEST);
for(int i = 0; i < children.size(); i++) {
- child = (GraphicalEditPart)children.get(i);
+ child = (IGraphicalEditPart)children.get(i);
resize.add(createChangeConstraintCommand(request, child, translateToModelConstraint(getConstraintFor(request, child))));
+ final Point move = request.getMoveDelta();
if(forceLocation) {
for(Object object : child.getChildren()) {
if(object instanceof CompartmentEditPart) {
@@ -72,7 +81,25 @@ public class XYLayoutWithConstrainedResizedEditPolicy extends XYLayoutEditPolicy
}
}
}
+ //we add the command to fix the anchor
+ if(isConstrainedResize && child instanceof INodeEditPart) {
+ if(helper == null) {
+ TransactionalEditingDomain domain = null;
+ try {
+ domain = ServiceUtilsForEditPart.getInstance().getTransactionalEditingDomain(child);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ this.helper = new FixAnchorHelper(domain);
+ }
+ final Command fixAnchorCommand = this.helper.getFixIdentityAnchorCommand((INodeEditPart)child, request.getMoveDelta(), request.getSizeDelta(), request.getResizeDirection());
+ if(fixAnchorCommand != null) {
+ resize.add(fixAnchorCommand);
+ }
+ }
}
return resize.unwrap();
}
+
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java
index 76345568f33..43c43666546 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java
@@ -335,7 +335,7 @@ public abstract class PapyrusEdgeFigure extends PolylineConnectionEx {
if(diameter <= 1) {
this.bendpointDiameter = 0;
}
- if(diameter % 2 == 1) {
+ if(diameter % 2 != 0) {
this.bendpointDiameter = diameter;
} else {
setBendPointDiameter(diameter + 1);
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java
new file mode 100644
index 00000000000..e59ea963ac1
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java
@@ -0,0 +1,337 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.AbstractPointListShape;
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.IdentityAnchor;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ *
+ * This class provides command to fix the anchors during a resize.
+ * The methods are not static to allow to overriding
+ *
+ */
+public class FixAnchorHelper {
+
+ /**
+ * the editing domain used for the command
+ */
+ protected final TransactionalEditingDomain domain;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param domain
+ * the editing domain to use, it must not be <code>null</code>
+ */
+ public FixAnchorHelper(final TransactionalEditingDomain domain) {
+ Assert.isNotNull(domain);
+ this.domain = domain;
+ }
+
+ /**
+ *
+ * @param node
+ * the resized node
+ * @param move
+ * the move direction
+ * @param sizeDelta
+ * the delta of the size
+ * @param moveDirection
+ * the direction for the resize/move
+ * @return
+ * the command to fix the anchor or <code>null</code> if we can't fix it
+ */
+ public Command getFixIdentityAnchorCommand(final INodeEditPart node, final Point move, final Dimension sizeDelta, int moveDirection) {
+ final CompoundCommand cc = new CompoundCommand("Fix All Anchors Command"); //$NON-NLS-1$
+ //1. we calculate the new bounds;
+ final IFigure nodeFigure = node.getFigure();
+ final PrecisionRectangle oldBounds = new PrecisionRectangle(nodeFigure.getBounds());
+
+ //we translate the coordinates to absolute
+ nodeFigure.translateToAbsolute(oldBounds);
+ final PrecisionRectangle newBounds = oldBounds.getPreciseCopy();
+ newBounds.translate(move.preciseX(), move.preciseY());
+ newBounds.resize(sizeDelta.preciseWidth(), sizeDelta.preciseHeight());
+
+
+ //2. we iterate on the target anchor
+ for(final Object targetConnection : node.getTargetConnections()) {
+ if(targetConnection instanceof AbstractConnectionEditPart) {
+ final Command tmp = getFixAnchorCommand(node, oldBounds, newBounds, (AbstractConnectionEditPart)targetConnection, move, sizeDelta, false);
+ if(tmp != null) {
+ cc.add(tmp);
+ }
+ }
+ }
+
+ //. we iterate on the source anchor
+ for(final Object sourceConnection : node.getSourceConnections()) {
+ if(sourceConnection instanceof AbstractConnectionEditPart) {
+ final Command tmp = getFixAnchorCommand(node, oldBounds, newBounds, (AbstractConnectionEditPart)sourceConnection, move, sizeDelta, true);
+ if(tmp != null) {
+ cc.add(tmp);
+ }
+ }
+ }
+
+ if(cc.isEmpty()) {
+ return null;
+ }
+ return cc;
+ }
+
+ /**
+ *
+ * @param edgeEP
+ * the edge edit part
+ * @param sourcePoint
+ * if <code>true</code> we return the source point and if false we return the end point
+ * @return
+ * the real point to fix
+ */
+ protected Point getRealAnchorPoint(final AbstractConnectionEditPart edgeEP, final boolean sourcePoint) {
+ final IFigure figure = edgeEP.getFigure();
+ Point point = null;
+ if(figure instanceof AbstractPointListShape) {
+ if(sourcePoint) {
+ point = ((AbstractPointListShape)figure).getStart().getCopy();
+ } else {
+ point = ((AbstractPointListShape)figure).getEnd().getCopy();
+ }
+ }
+ figure.translateToAbsolute(point);
+ return point;
+ }
+
+ /**
+ *
+ * @param edgeEP
+ * the edge edit part
+ * @param sourcePoint
+ * if <code>true</code> we return the source point and if false we return the end point
+ * @param nodeEP
+ * the node edit part
+ * @param p
+ * the real anchor point in absolute coordinate
+ * @return
+ * the anchor representing the point to fix
+ */
+ protected IdentityAnchor getIdentityAnchor(final AbstractConnectionEditPart edgeEP, final boolean sourcePoint, final INodeEditPart nodeEP, final Point p) {
+ final View view = (View)edgeEP.getAdapter(View.class);
+ IdentityAnchor anchor = null;
+ if(view instanceof Edge) {
+ final Object tmpAnchor;
+ if(sourcePoint) {
+ tmpAnchor = ((Edge)view).getSourceAnchor();
+ } else {
+ tmpAnchor = ((Edge)view).getTargetAnchor();
+ }
+ if(tmpAnchor instanceof IdentityAnchor) {
+ anchor = (IdentityAnchor)tmpAnchor;
+ }
+ if(anchor == null) {
+ ConnectionAnchor connectionAnchor = null;
+ if(nodeEP.getFigure() instanceof NodeFigure) {
+ NodeFigure nodeFigure = (NodeFigure)nodeEP.getFigure();
+ if(sourcePoint) {
+ connectionAnchor = nodeFigure.getSourceConnectionAnchorAt(p);
+ } else {
+ connectionAnchor = nodeFigure.getTargetConnectionAnchorAt(p);
+ }
+ if(connectionAnchor != null) {
+ final String id = nodeEP.mapConnectionAnchorToTerminal(connectionAnchor);
+ anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
+ anchor.setId(id);
+ }
+ }
+ }
+
+ }
+ return anchor;
+
+ }
+
+ /**
+ *
+ * @param nodeEditPart
+ * the resized edit part
+ * @param oldNodeBounds
+ * the old bounds for this edit part
+ * @param newNodeBounds
+ * the new bounds for this edit part
+ * @param targetConnectionEP
+ * the edit part of the connection for which we want fix anchor
+ * @param move
+ * the move
+ * @param sizeDelta
+ * the delta of the resize
+ * @param fixSource
+ * if <code>true</code> we are fixing the source anchor if <code>false</code> we are fixing the target anchor
+ * @return
+ */
+ private Command getFixAnchorCommand(final INodeEditPart nodeEditPart, final PrecisionRectangle oldNodeBounds, final PrecisionRectangle newNodeBounds, final AbstractConnectionEditPart targetConnectionEP, final Point move, final Dimension sizeDelta, final boolean fixSource) {
+ final Point realAnchorPoint = getRealAnchorPoint(targetConnectionEP, fixSource);
+
+ final IFigure fig = nodeEditPart.getFigure();
+ if(fig instanceof NodeFigure) {
+ final NodeFigure nodeFigure = (NodeFigure)fig;
+ final IdentityAnchor editedAnchor = getIdentityAnchor(targetConnectionEP, fixSource, nodeEditPart, realAnchorPoint);
+ if(realAnchorPoint != null && editedAnchor != null) {
+
+ final View view = (View)targetConnectionEP.getAdapter(View.class);
+ if(view instanceof Edge) {
+ //1. get the real side on which start/end the manipulated anchor
+ final int anchorSide = getSideOfConnectionPoint(nodeFigure, targetConnectionEP, fixSource);
+ //2. determine the new values
+ double newX = -1;
+ double newY = -1;
+ switch(anchorSide) {
+ case PositionConstants.NORTH:
+ newY = 0;
+ break;
+ case PositionConstants.WEST:
+ newX = 0;
+ break;
+ case PositionConstants.EAST:
+ newX = 1;
+ break;
+ case PositionConstants.SOUTH:
+ newY = 1;
+ break;
+ default:
+ // other case not yet manager because they are resize dependant!
+ break;
+ }
+
+ PrecisionPoint newRealAnchorPoint = new PrecisionPoint(realAnchorPoint);
+ newRealAnchorPoint.setPreciseLocation(newRealAnchorPoint.x() - oldNodeBounds.preciseX(), newRealAnchorPoint.y() - oldNodeBounds.preciseY());
+
+ PrecisionPoint newLocation = newRealAnchorPoint.getPreciseCopy();
+ newLocation.setPreciseX(newLocation.preciseX() - move.preciseX());
+ newLocation.setPreciseY(newLocation.preciseY() - move.preciseY());
+
+ if(newX == -1) {
+ newX = newLocation.preciseX() / newNodeBounds.preciseWidth();
+ }
+ if(newY == -1) {
+ newY = newLocation.preciseY() / newNodeBounds.preciseHeight();
+ }
+
+ if(newX <= 1 && newX >= 0 && newY <= 1 && newY >= 0) {
+ final String newIdValue = IdentityAnchorHelper.createNewAnchorIdValue(newX, newY);
+ final ICommand cmd = new AbstractTransactionalCommand(this.domain, "Fix Anchor Location", null) { //$NON-NLS-1$
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ editedAnchor.setId(newIdValue);
+
+ if(editedAnchor.eContainer() == null) {
+ if(fixSource) {
+ ((Edge)view).setSourceAnchor(editedAnchor);
+ } else {
+ ((Edge)view).setTargetAnchor(editedAnchor);
+ }
+ }
+ return CommandResult.newOKCommandResult(editedAnchor);
+ }
+ };
+ return new ICommandProxy(cmd);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param nodeFigure
+ * the node figure
+ * @param edgeEP
+ * the connection edit part
+ * @param fixingSource
+ * if <code>true</code> we are fixing the source anchor and if <code>false</code> we are fixing the target anchor
+ * @return
+ * the direction of the manipulated anchor (according to {@link PositionConstants}
+ */
+ protected final int getSideOfConnectionPoint(final IFigure nodeFigure, final AbstractConnectionEditPart edgeEP, final boolean fixingSource) {
+ int side = -1;
+ final IFigure figure = edgeEP.getFigure();
+ if(figure instanceof PolylineConnectionEx) {
+ final PolylineConnectionEx connection = (PolylineConnectionEx)figure;
+ final Rectangle bounds = nodeFigure.getBounds().getCopy();
+ nodeFigure.translateToAbsolute(bounds);
+ final Point pt;
+ if(fixingSource) {
+ pt = connection.getStart();
+ } else {
+ pt = connection.getEnd();
+ }
+ figure.translateToAbsolute(pt);
+ Rectangle includedRect = bounds.getCopy();
+ while(includedRect.contains(pt)) {
+ includedRect.shrink(1, 1);
+ }
+ side = includedRect.getPosition(pt);
+ //if the anchor side is a corner, we determine its side using another point
+ if(side == PositionConstants.NORTH_WEST || side == PositionConstants.NORTH_EAST || side == PositionConstants.SOUTH_EAST || side == PositionConstants.SOUTH_WEST) {
+ final Point previousPoint;
+ final PointList list = connection.getPoints();
+ if(list.size() > 1) {
+
+ if(fixingSource) {
+ previousPoint = list.getPoint(1);
+ } else {
+ previousPoint = list.getPoint(list.size() - 2);
+ }
+ nodeFigure.translateToAbsolute(previousPoint.getCopy());
+ while(includedRect.contains(previousPoint)) {
+ includedRect.shrink(1, 1);
+ }
+ side = includedRect.getPosition(previousPoint);
+ }
+ }
+ }
+ return side;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java
new file mode 100644
index 00000000000..a273f738a3e
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+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 = new String(new char[]{ X_Y_SEPARATOR });
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ private IdentityAnchorHelper() {
+ //to prevent instanciation
+ }
+
+ /**
+ *
+ * @param anchor
+ * an anchor
+ * @return
+ * the value of x percentage
+ */
+ public static final double getXPercentage(final IdentityAnchor anchor) {
+ String id = anchor.getId();
+ id = id.substring(1, id.indexOf(X_Y_SEPARATOR_AS_STRING));
+ return Double.parseDouble(id);
+ }
+
+ /**
+ *
+ * @param anchor
+ * an anchor
+ * @return
+ * the value of y percentage
+ */
+ public static final double getYPercentage(final IdentityAnchor anchor) {
+ String id = anchor.getId();
+ id = id.substring(id.indexOf(X_Y_SEPARATOR_AS_STRING) + 1, id.length() - 1);
+ return Double.parseDouble(id);
+ }
+
+
+ /**
+ *
+ * @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 StringBuffer buffer = new StringBuffer();
+ buffer.append(START_ID);
+ buffer.append(Double.toString(percentageOnX));
+ buffer.append(X_Y_SEPARATOR_AS_STRING);
+ buffer.append(Double.toString(percentageOnY));
+ buffer.append(END_ID);
+ return buffer.toString();
+ }
+}

Back to the top