use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.
the class NodeLabelEditPart method refreshVisuals.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals()
*/
@Override
protected void refreshVisuals() {
Node node = ((NodeLabel) getModel()).getNode();
// Node node = ((NodeContainer) ((NodeContainerPart) getParent()).getModel()).getNode();
String text = ((NodeLabel) getModel()).getLabelText();
SimpleHtmlFigure htmlFig = (SimpleHtmlFigure) this.getFigure();
htmlFig.setText(text);
Point loc = node.getLocation().getCopy();
Point offset = ((NodeLabel) getModel()).getOffset();
Point textOffset = new Point();
Dimension size = htmlFig.getPreferredSize();
textOffset.y = node.getSize().height;
textOffset.x = (node.getSize().width - size.width) / 2;
((NodeLabel) getModel()).setTextOffset(textOffset);
loc.translate(textOffset.x + offset.x, textOffset.y + offset.y);
Rectangle rectangle = new Rectangle(loc, size);
((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), rectangle);
}
use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.
the class NodeAnchor method getDirectionPosition.
private Point getDirectionPosition(IConnection connection, Point figCenter, boolean isSource) {
if (!DesignerPlugin.getDefault().getPreferenceStore().getBoolean(TalendDesignerPrefConstants.EDITOR_LINESTYLE)) {
return null;
}
Dimension nodeSize = null;
if (isSource) {
nodeSize = this.source.getSize();
} else {
nodeSize = this.target.getSize();
}
EConnectionCategory category = null;
EConnectionType lineStyle = null;
if (connection != null) {
lineStyle = connection.getLineStyle();
category = lineStyle.getCategory();
} else {
lineStyle = ConnectionManager.getNewConnectionType();
category = lineStyle.getCategory();
}
Point result = new Point(figCenter);
if (category == EConnectionCategory.MAIN && lineStyle != EConnectionType.FLOW_REF) {
if (isSource) {
result.x = figCenter.x + nodeSize.width / 2;
} else {
result.x = figCenter.x - nodeSize.width / 2;
}
return result;
} else if (category == EConnectionCategory.OTHER && (lineStyle == EConnectionType.FLOW_REF || lineStyle == EConnectionType.TABLE_REF)) {
Rectangle sourceBounds = new Rectangle(this.source.getLocation(), this.source.getSize());
Rectangle targetBounds = new Rectangle(this.target.getLocation(), this.target.getSize());
if (isSource) {
int sourceY = this.source.getPosY();
int targetY = this.target.getPosY();
if (sourceY <= targetY) {
if ((targetBounds.getTopRight().y == sourceBounds.getBottomLeft().y)) {
result.y = figCenter.y - nodeSize.height / 2;
} else {
result.y = figCenter.y + nodeSize.height / 2;
}
} else {
if (targetBounds.getBottomLeft().y == sourceBounds.getTopRight().y) {
result.y = figCenter.y + nodeSize.height / 2;
} else {
result.y = figCenter.y - nodeSize.height / 2;
}
}
return result;
}
int sourceY = this.source.getPosY();
int targetY = this.target.getPosY();
if (sourceY < targetY) {
result.y = figCenter.y - nodeSize.height / 2;
} else {
result.y = figCenter.y + nodeSize.height / 2;
}
return result;
}
return null;
}
use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.
the class NodeAnchor method getLocationForMultipleConnections.
public Point getLocationForMultipleConnections(int connectionId) {
if ((sourceLocation.y >= targetLocation.y) && ((sourceLocation.y + sourceRect.height) <= (targetLocation.y + targetRect.height))) {
targetRect = new Rectangle(new Point(targetLocation.x, sourceLocation.y), new Dimension(targetRect.width, sourceRect.height));
} else if ((sourceLocation.x >= targetLocation.x) && ((sourceLocation.x + sourceRect.width) <= (targetLocation.x + targetRect.width))) {
targetRect = new Rectangle(new Point(sourceLocation.x, targetLocation.y), new Dimension(sourceRect.width, sourceRect.height));
}
// will calculate the numerator and denominator for the function to place the points.
// example: 1/2; 3/4; 1/4; 5/8; 3/8; 7/8; 1/8; 9/16; 7/16; 11/16; 5/16; 13/16; 3/16...
int num = 1;
int numPair = 1;
int numImpair = 1;
int denom = 2;
for (int i = 1; i < connectionId + 1; i++) {
if ((i % 2) == 0) {
// pair
if ((numPair + 2) > denom) {
denom = denom * 2;
numPair = (denom / 2) + 1;
numImpair = numPair;
} else {
numPair += 2;
}
num = numPair;
} else {
// impair
numImpair -= 2;
if (numImpair > 0) {
num = numImpair;
}
}
}
LineSeg lineSource, lineTarget;
if ((sourceLocation.x < targetRect.getCenter().x) && (targetRect.getCenter().x < (sourceLocation.x + sourceRect.width))) {
lineSource = new LineSeg(sourceRect.getLeft(), sourceRect.getRight());
lineTarget = new LineSeg(targetRect.getLeft(), targetRect.getRight());
} else {
lineSource = new LineSeg(sourceRect.getTop(), sourceRect.getBottom());
lineTarget = new LineSeg(targetRect.getTop(), targetRect.getBottom());
}
Double length = (lineSource.length() * num / denom);
Point pointSource = new Point();
lineSource.pointOn(length.longValue(), KeyPoint.ORIGIN, pointSource);
length = (lineTarget.length() * num / denom);
Point pointTarget = new Point();
lineTarget.pointOn(length.longValue(), KeyPoint.ORIGIN, pointTarget);
if ((sourceLocation.y < pointTarget.y) && (pointTarget.y < (sourceLocation.y + sourceRect.height))) {
// contains
pointSource.y = pointTarget.y;
}
if ((sourceLocation.x < pointTarget.x) && (pointTarget.x < (sourceLocation.x + sourceRect.width))) {
// contains
pointSource.x = pointTarget.x;
}
return calculateLocationFromRef(pointSource, pointTarget);
}
use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.
the class NodeAnchor method getLocation.
/*
* (non-Javadoc)
*
* @see org.eclipse.draw2d.ChopboxAnchor#getLocation(org.eclipse.draw2d.geometry.Point)
*/
@Override
public Point getLocation(Point reference) {
if (target != null && !target.equals(source)) {
sourceLocation = new Point(source.getLocation());
targetLocation = new Point(target.getLocation());
Point diff = new Point(0, 0);
if (!isTargetAnchor) {
if (((reference.y - (target.getSize().height / 2)) != targetLocation.y) || ((reference.x - (target.getSize().width / 2)) != targetLocation.x)) {
FreeformViewport viewport = getViewport();
if (viewport != null) {
int y = viewport.getVerticalRangeModel().getValue();
int x = viewport.getHorizontalRangeModel().getValue();
diff = new Point(-x, -y);
}
}
} else {
if (((reference.y - (source.getSize().height / 2)) != sourceLocation.y) || ((reference.x - (source.getSize().width / 2)) != sourceLocation.x)) {
FreeformViewport viewport = getViewport();
if (viewport != null) {
int y = viewport.getVerticalRangeModel().getValue();
int x = viewport.getHorizontalRangeModel().getValue();
diff = new Point(-x, -y);
}
}
}
ScalableFreeformLayeredPane pane = getScalableFreeform();
sourceRect = new Rectangle(sourceLocation, source.getSize());
targetRect = new Rectangle(targetLocation, target.getSize());
if (pane != null) {
double scale = pane.getScale();
sourceLocation.performScale(scale);
targetLocation.performScale(scale);
sourceRect.performScale(scale);
targetRect.performScale(scale);
}
sourceLocation = sourceLocation.getTranslated(diff);
targetLocation = targetLocation.getTranslated(diff);
sourceRect = sourceRect.getTranslated(diff);
targetRect = targetRect.getTranslated(diff);
int nb = 0;
int connectionId = 0;
for (Connection connection : (List<Connection>) source.getOutgoingConnections()) {
if (connection.getTarget().equals(target)) {
nb++;
if (connection.equals(this.connection)) {
connectionId = nb;
}
}
}
if (nb <= 1) {
return getLocationForSimpleConnection(reference);
} else {
return getLocationForMultipleConnections(connectionId);
}
}
return super.getLocation(reference);
}
use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.
the class NodeContainerLayoutEditPolicy method createChangeConstraintCommand.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChangeConstraintCommand(org.eclipse.gef.EditPart,
* java.lang.Object)
*/
@Override
protected Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
if (child instanceof NodeLabelEditPart) {
boolean nodeSelected;
// if (((NodeLabelEditPart) child).getNodePart().getSelected() != 0) {
// nodeSelected = true;
// } else {
nodeSelected = false;
// }
MoveNodeLabelCommand locationCommand = new MoveNodeLabelCommand((NodeLabel) child.getModel(), ((Rectangle) constraint).getLocation(), nodeSelected);
return locationCommand;
} else if (child instanceof NodePart) {
if (((Node) child.getModel()).isReadOnly() && !((Node) child.getModel()).isForceReadOnly()) {
return null;
}
MoveNodeCommand locationCommand = new MoveNodeCommand((Node) child.getModel(), ((Rectangle) constraint).getLocation());
return locationCommand;
} else {
return null;
}
}
Aggregations