final Element parent = element.getParentSection();
if (parent == null)
{
throw new IllegalStateException("Parent has been removed, but the drag operation was not finished: " + element);
}
final CachedLayoutData data = ModelUtility.getCachedLayoutData(parent);
final long layoutedParentX = data.getX() + data.getPaddingX();
final long layoutedParentY = data.getY() + data.getPaddingY();
// this is where I want the element on a global scale...
final long targetPositionX = elementXCoords[i] + dx;
final long targetPositionY = elementYCoords[i] + dy;
if (elementX >= 0)
{
// absolute position; resolving is easy here
final long snapPosition = horizontalSnapModel.getNearestSnapPosition
(targetPositionX, element.getObjectID());
if (Math.abs(snapPosition - targetPositionX) > snapThreshold)
{
final long targetPositionX2 = targetPositionX + elementWidth[i];
final long snapPosition2 = horizontalSnapModel.getNearestSnapPosition
(targetPositionX2, element.getObjectID());
if (Math.abs(snapPosition2 - targetPositionX2) < snapThreshold)
{
// snapping to the right border..
final long snapX = snapPosition2 - elementWidth[i];
final long localXPosition = Math.max(0, snapX - layoutedParentX);
final float position = (float) StrictGeomUtility.toExternalValue(localXPosition);
styleSheet.setStyleProperty(ElementStyleKeys.POS_X, new Float(position));
}
else
{
// not snapping ...
final long localXPosition = Math.max(0, targetPositionX - layoutedParentX);
final float position = (float) StrictGeomUtility.toExternalValue(localXPosition);
styleSheet.setStyleProperty(ElementStyleKeys.POS_X, new Float(position));
}
}
else
{
// snapping to the left border..
final long localXPosition = Math.max(0, snapPosition - layoutedParentX);
final float position = (float) StrictGeomUtility.toExternalValue(localXPosition);
styleSheet.setStyleProperty(ElementStyleKeys.POS_X, new Float(position));
}
}
else
{
final long parentBase = data.getWidth();
if (parentBase > 0)
{
// relative position; resolve the percentage against the width of the parent.
final long snapPosition = horizontalSnapModel.getNearestSnapPosition(targetPositionX,
element.getObjectID());
if (Math.abs(snapPosition - targetPositionX) > snapThreshold)
{
final long targetPositionX2 = targetPositionX + elementWidth[i];
final long snapPosition2 = horizontalSnapModel.getNearestSnapPosition(targetPositionX2,
element.getObjectID());
if (Math.abs(snapPosition2 - targetPositionX2) < snapThreshold)
{
// snapping to the right
final long snapX = snapPosition2 - elementWidth[i];
final long localXPosition = Math.max(0, snapX - layoutedParentX);
final long percentage = StrictGeomUtility.toInternalValue(localXPosition * 100 / parentBase);
styleSheet.setStyleProperty(ElementStyleKeys.POS_X,
new Float(StrictGeomUtility.toExternalValue(-percentage)));
}
else
{
// not snapping
final long localXPosition = Math.max(0, targetPositionX - layoutedParentX);
// strict geometry: all values are multiplied by 1000
// percentages in the engine are represented by floats betwen 0 and 100.
final long percentage = StrictGeomUtility.toInternalValue(localXPosition * 100 / parentBase);
styleSheet.setStyleProperty(ElementStyleKeys.POS_X,
new Float(StrictGeomUtility.toExternalValue(-percentage)));
}
}
else
{
// snapping to the left
final long localXPosition = Math.max(0, snapPosition - layoutedParentX);
// strict geometry: all values are multiplied by 1000
// percentages in the engine are represented by floats betwen 0 and 100.
final long percentage = StrictGeomUtility.toInternalValue(localXPosition * 100 / parentBase);
styleSheet.setStyleProperty(ElementStyleKeys.POS_X,
new Float(StrictGeomUtility.toExternalValue(-percentage)));
}
}
}
if (elementY >= 0)
{
// absolute position; resolving is easy here
final long snapPosition = verticalSnapModel.getNearestSnapPosition(targetPositionY, element.getObjectID());
if (Math.abs(snapPosition - targetPositionY) > snapThreshold)
{
final long targetPositionY2 = targetPositionY + elementHeight[i];
final long snapPosition2 = horizontalSnapModel.getNearestSnapPosition(targetPositionY2,
element.getObjectID());
if (Math.abs(snapPosition2 - targetPositionY2) < snapThreshold)
{
// snap to the bottom
final long snapY = snapPosition2 - elementHeight[i];
final long localYPosition = Math.max(0, snapY - layoutedParentY);
final float position = (float) StrictGeomUtility.toExternalValue(localYPosition);
styleSheet.setStyleProperty(ElementStyleKeys.POS_Y, new Float(position));
}
else
{
// not snapping
final long localYPosition = Math.max(0, targetPositionY - layoutedParentY);
final float position = (float) StrictGeomUtility.toExternalValue(localYPosition);
styleSheet.setStyleProperty(ElementStyleKeys.POS_Y, new Float(position));
}
}
else
{
// snap to the top
final long localYPosition = Math.max(0, snapPosition - layoutedParentY);
final float position = (float) StrictGeomUtility.toExternalValue(localYPosition);
styleSheet.setStyleProperty(ElementStyleKeys.POS_Y, new Float(position));
}
}
else
{
final long parentBase;
if (isCanvasElement(parent))
{
parentBase = data.getHeight();
}
else
{
parentBase = data.getWidth();
}
if (parentBase > 0)
{
// relative position; resolve the percentage against the height of the parent.
final long snapPosition = verticalSnapModel.getNearestSnapPosition(targetPositionY, element.getObjectID());