Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrung-Truc NGUYEN2016-01-25 22:48:31 +0000
committerGerrit Code Review @ Eclipse.org2016-02-10 08:34:16 +0000
commiteeccb08c415e2091bce608043aeaff14bd7f6690 (patch)
treed8408ba354ea03f59e659b8c7e8b2582788a161c /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src
parentaa593b9a2870da6662ac032b7b3dd0e779374952 (diff)
downloadorg.eclipse.papyrus-eeccb08c415e2091bce608043aeaff14bd7f6690.tar.gz
org.eclipse.papyrus-eeccb08c415e2091bce608043aeaff14bd7f6690.tar.xz
org.eclipse.papyrus-eeccb08c415e2091bce608043aeaff14bd7f6690.zip
Bug 473722 - [Composite Diagram] Papyrus should support graphical
resizable ports Change-Id: I4743f4166f33e15a45df427406e10fefc9bf5241 Signed-off-by: Trung-Truc NGUYEN<truc.ensma@gmail.com>
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomClassCompositeEditPart.java66
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java8
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomFullPortAffixedEditPart.java86
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java58
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/locators/CustomPortPositionLocator.java225
5 files changed, 442 insertions, 1 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomClassCompositeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomClassCompositeEditPart.java
new file mode 100644
index 00000000000..7130c8170ff
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomClassCompositeEditPart.java
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AllowResizeAffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.composite.custom.locators.CustomPortPositionLocator;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeEditPart;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
+
+
+/**
+ *
+ * This class just takes care of installing a new policy that calls the resize command of a child item (a port in this case).
+ *
+ * @author Trung-Truc Nguyen
+ *
+ */
+public class CustomClassCompositeEditPart extends ClassCompositeEditPart{
+
+ /**
+ * Constructor.
+ *
+ * @param view
+ */
+ public CustomClassCompositeEditPart(View view) {
+ super(view);
+ installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AllowResizeAffixedNodeAlignmentEditPolicy());
+ }
+
+ public void installEditPolicy(Object key, EditPolicy editPolicy) {
+ if (AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE.equals(key)) {
+ if (editPolicy instanceof AllowResizeAffixedNodeAlignmentEditPolicy)
+ super.installEditPolicy(key, editPolicy);
+ }
+ else
+ super.installEditPolicy(key, editPolicy);
+ }
+
+ protected boolean addFixedChild(EditPart childEditPart) {
+ //Papyrus Gencode :Affixed Port locator
+ if(childEditPart instanceof PortEditPart) {
+ IBorderItemLocator locator = new CustomPortPositionLocator(getMainFigure(), (RoundedBorderNamedElementEditPart) childEditPart, PositionConstants.NONE);
+ getBorderedFigure().getBorderItemContainer().add(((PortEditPart)childEditPart).getFigure(), locator);
+ return true;
+ }
+ return super.addFixedChild(childEditPart);
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java
index ef0899bffe3..fdc9719c420 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomEditPartFactory.java
@@ -15,6 +15,7 @@ package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicitySourceEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorMultiplicityTargetEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConstraintEditPartCN;
@@ -23,6 +24,7 @@ import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ParameterAppliedSter
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortAppliedStereotypeEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortNameEditPart;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.TimeObservationStereotypeLabelEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.UMLEditPartFactory;
import org.eclipse.papyrus.uml.diagram.composite.part.UMLVisualIDRegistry;
@@ -48,7 +50,7 @@ public class CustomEditPartFactory extends UMLEditPartFactory {
case ConstraintEditPartCN.VISUAL_ID:
return new CustomConstraintEditPartCN(view);
case PortEditPart.VISUAL_ID:
- return new CustomPortEditPart(view);
+ return new CustomFullPortAffixedEditPart(view);
case PortNameEditPart.VISUAL_ID:
return new CustomPortNameEditPart(view);
case DurationObservationStereotypeLabelEditPart.VISUAL_ID:
@@ -57,8 +59,12 @@ public class CustomEditPartFactory extends UMLEditPartFactory {
return new CustomParameterAppliedStereotypeEditPart(view);
case PortAppliedStereotypeEditPart.VISUAL_ID:
return new CustomPortAppliedStereotypeEditPart(view);
+ case ClassCompositeEditPart.VISUAL_ID:
+ return new CustomClassCompositeEditPart(view);
case TimeObservationStereotypeLabelEditPart.VISUAL_ID:
return new CustomTimeObservationStereotypeLabelEditPart(view);
+ case PropertyPartEditPartCN.VISUAL_ID:
+ return new CustomPropertyPartEditPartCN(view);
}
}
return super.createEditPart(context, model);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomFullPortAffixedEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomFullPortAffixedEditPart.java
new file mode 100644
index 00000000000..d6fcdd8c59f
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomFullPortAffixedEditPart.java
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts;
+
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PreferencesConstantsHelper;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.PortResizableEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.helper.PreferenceInitializerForElementHelper;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
+
+
+/**
+ * This class is used for 2 purposes.
+ * 1. Install new ResizablePolicy for port
+ * 2. Override Affixed_child_alignment_role policy for resize commands
+ * @author Trung-Truc Nguyen
+ *
+ */
+public class CustomFullPortAffixedEditPart extends PortEditPart{
+
+ /**
+ * Constructor.
+ *
+ * @param view
+ */
+ public CustomFullPortAffixedEditPart(View view) {
+ super(view);
+ installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PortResizableEditPolicy());
+ installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new PortResizableEditPolicy());
+ }
+
+ public void installEditPolicy(Object key, EditPolicy editPolicy){
+ if(EditPolicy.PRIMARY_DRAG_ROLE.equals(key)) {
+ //prevent its parents from overriding this policy
+ if(editPolicy instanceof PortResizableEditPolicy)
+ super.installEditPolicy(key, editPolicy);
+ }
+ else
+ super.installEditPolicy(key, editPolicy);
+ }
+
+ /**
+ * this override method serves to resize the DefaultSizeNodeFigure each time the diagram is opened.
+ * without this, the DefaultNodeFigure size is 20x20 by default although the size of port figure is different.
+ */
+ protected NodeFigure createNodePlate() {
+ String prefElementId = getNotationView().getType();
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ String preferenceConstantWitdh = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferencesConstantsHelper.WIDTH);
+ String preferenceConstantHeight = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferencesConstantsHelper.HEIGHT);
+ DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(store.getInt(preferenceConstantWitdh), store.getInt(preferenceConstantHeight));
+
+ int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue();
+ int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue();
+
+// Dimension size = new Dimension(width, height);
+ // FIXME: workaround for #154536
+
+ int w = width > 20 ? width : 20;
+ int h = height > 20 ? height : 20;
+
+ result.getBounds().setSize(w, h);
+ result.setDefaultSize(w, h);
+
+
+ return result;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java
new file mode 100644
index 00000000000..44405447291
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/edit/parts/CustomPropertyPartEditPartCN.java
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.composite.custom.edit.parts;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AllowResizeAffixedNodeAlignmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.composite.custom.locators.CustomPortPositionLocator;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN;
+
+public class CustomPropertyPartEditPartCN extends PropertyPartEditPartCN {
+
+ /**
+ * Constructor.
+ *
+ * @param view
+ */
+ public CustomPropertyPartEditPartCN(View view) {
+ super(view);
+ installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AllowResizeAffixedNodeAlignmentEditPolicy());
+ }
+ public void installEditPolicy(Object key, EditPolicy editPolicy) {
+ if (AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE.equals(key)) {
+ if (editPolicy instanceof AllowResizeAffixedNodeAlignmentEditPolicy)
+ super.installEditPolicy(key, editPolicy);
+ }
+ else
+ super.installEditPolicy(key, editPolicy);
+ }
+
+ protected boolean addFixedChild(EditPart childEditPart) {
+
+ //Papyrus Gencode :Affixed Port locator
+ if(childEditPart instanceof PortEditPart) {
+ IBorderItemLocator locator = new CustomPortPositionLocator(getMainFigure(), (RoundedBorderNamedElementEditPart) childEditPart, PositionConstants.NONE);
+ getBorderedFigure().getBorderItemContainer().add(((PortEditPart)childEditPart).getFigure(), locator);
+ return true;
+ }
+ return super.addFixedChild(childEditPart);
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/locators/CustomPortPositionLocator.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/locators/CustomPortPositionLocator.java
new file mode 100644
index 00000000000..a1ed9e68e64
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/locators/CustomPortPositionLocator.java
@@ -0,0 +1,225 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.composite.custom.locators;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.papyrus.uml.diagram.common.editparts.RoundedBorderNamedElementEditPart;
+import org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator;
+
+/**
+ * This class helps to set the port location on a figure border.
+ * If the port size is 20x20 -> it keeps the same value with the PortPositionLocator class. (10 inside and 10 outside
+ * of the figure)
+ * If the port size is different from 20x20, it will set the inside part of the port on the figure
+ * border is always 10. If using the PortPositionLocator, the inside part of the port may bigger than
+ * the outside and may cause some difficulties for other parts location inside of the figure border.
+ *
+ * @author Trung-Truc Nguyen
+ *
+ */
+public class CustomPortPositionLocator extends PortPositionLocator {
+
+ protected RoundedBorderNamedElementEditPart portEditPart = null;
+
+
+
+ public CustomPortPositionLocator(IFigure parentFigure, RoundedBorderNamedElementEditPart childEditPart,
+ int none) {
+ super(parentFigure, none);
+ portEditPart = childEditPart;
+ }
+
+ /**
+ * This method helps to set the Port location which is satisfied the criterion on the top of the class.
+ * @param proposedLocation
+ * the proposed location
+ * @return a possible location on parent figure border
+ */
+ public final Rectangle getPreferredLocation(Rectangle proposedLocation) {
+
+ // Initialize port location with proposed location
+ // and resolve the bounds of it graphical parent
+ Rectangle realLocation = new Rectangle(proposedLocation);
+
+ Rectangle parentRec = getParentFigure().getBounds().getCopy();
+
+ Rectangle thisRec = portEditPart.getFigure().getBounds().getCopy();
+
+ // Calculate Max position around the graphical parent (1/2 size or the port around
+ // the graphical parent bounds.
+// int xMin = parentRec.x - thisRec.width + borderItemOffset;
+ int xMin = parentRec.x - thisRec.width/2;
+// int xMax = parentRec.x - borderItemOffset + parentRec.width;
+ int xMax = parentRec.x + parentRec.width - thisRec.width/2;
+
+// int yMin = parentRec.y - thisRec.height + borderItemOffset;
+ int yMin = parentRec.y - thisRec.height/2;
+// int yMax = parentRec.y - borderItemOffset + parentRec.height;
+ int yMax = parentRec.y + parentRec.height - thisRec.height/2;
+
+ // Modify Port location if MAX X or Y are exceeded
+ if (realLocation.x < xMin) {
+ realLocation.x = xMin;
+ }
+
+ if (realLocation.x > xMax) {
+ realLocation.x = xMax;
+ }
+
+ if (realLocation.y < yMin) {
+ realLocation.y = yMin;
+ }
+
+ if (realLocation.y > yMax) {
+ realLocation.y = yMax;
+ }
+
+ // commented by V. Lorenzo to allow to create port on the top of a figure
+ // replaced by the next block of code
+
+ // Ensure the port is positioned on its parent borders and not in the middle.
+ // Modify position if needed.
+ // if((realLocation.y != yMin) && (realLocation.y != yMax)) {
+ // if((realLocation.x != xMin) && (realLocation.x != xMax)) {
+ //
+ // if(realLocation.x <= (xMin + (parentRec.width / 2))) {
+ // realLocation.x = xMin;
+ // } else {
+ // realLocation.x = xMax;
+ // }
+ // }
+ // }
+
+ // this code replaces the previous commented lines
+ final Rectangle maxRect = parentRec.getCopy();
+ maxRect.shrink(-borderItemOffset, -borderItemOffset);
+ while (maxRect.contains(realLocation.getLocation())) {
+ maxRect.shrink(1, 1);
+ }
+ int pos = maxRect.getPosition(realLocation.getLocation());
+ switch (pos) {
+ case PositionConstants.NORTH:
+ realLocation.y = yMin;
+ break;
+ case PositionConstants.SOUTH:
+ realLocation.y = yMax;
+ break;
+ case PositionConstants.EAST:
+ realLocation.x = xMax;
+ break;
+ case PositionConstants.WEST:
+ realLocation.x = xMin;
+ break;
+ case PositionConstants.NORTH_EAST:
+ realLocation.x = xMax;
+ realLocation.y = yMin;
+ break;
+ case PositionConstants.NORTH_WEST:
+ realLocation.x = xMin;
+ realLocation.y = yMin;
+ break;
+ case PositionConstants.SOUTH_EAST:
+ realLocation.x = xMax;
+ realLocation.y = yMax;
+ break;
+ case PositionConstants.SOUTH_WEST:
+ realLocation.x = xMin;
+ realLocation.y = yMax;
+ break;
+ }
+
+ // Return constrained location
+ return realLocation;
+ }
+
+ /**
+ * Due to the new algorithm of calculating port position, this method need to be recalculated.
+ * @see org.eclipse.papyrus.uml.diagram.common.locator.PortPositionLocator#getCurrentSideOfParent()
+ *
+ * @return
+ */
+ public int getCurrentSideOfParent() {
+ int position = PositionConstants.NONE;
+ Rectangle thisRec = portEditPart.getFigure().getBounds().getCopy();
+
+ int x = constraint.x;
+ int y = constraint.y;
+// int h = thisRec.height;
+// int w = thisRec.width;
+
+ Rectangle p = parentFigure.getBounds();
+
+ int xMin = p.x - thisRec.width/2;
+// int xMax = parentRec.x - borderItemOffset + parentRec.width;
+ int xMax = p.x + p.width - thisRec.width/2;
+
+// int yMin = parentRec.y - thisRec.height + borderItemOffset;
+ int yMin = p.y - thisRec.height/2;
+// int yMax = parentRec.y - borderItemOffset + parentRec.height;
+ int yMax = p.y + p.height - thisRec.height/2;
+
+ if(x == xMin && y == yMin)
+ position = PositionConstants.NORTH_WEST;
+ else if(x == xMin && y == yMax)
+ position = PositionConstants.SOUTH_WEST;
+ else if (x == xMax && y == yMin)
+ position = PositionConstants.NORTH_EAST;
+ else if(x == xMax && y == yMax)
+ position = PositionConstants.SOUTH_EAST;
+ else if(y == yMin)
+ position = PositionConstants.NORTH;
+ else if(y == yMax)
+ position = PositionConstants.SOUTH;
+ else if(x == xMin)
+ position = PositionConstants.WEST;
+ else
+ position = PositionConstants.EAST;
+
+
+// //NORTH EAST
+// if(y == borderItemOffset -h && x == p.width - borderItemOffset)
+// position = PositionConstants.NORTH_EAST;
+//
+// //NORTH WEST
+// else if(x == -(w - borderItemOffset) && y == -(h - borderItemOffset))
+// position = PositionConstants.NORTH_WEST;
+//
+// //SOUTH WEST
+// else if(x == -(w - borderItemOffset) && y == p.height - borderItemOffset)
+// position = PositionConstants.SOUTH_WEST;
+//
+// //SOUTH EAST
+// else if(x == p.width - borderItemOffset && y == p.height - borderItemOffset)
+// position = PositionConstants.SOUTH_EAST;
+//
+// //EAST
+// else if(x >= p.width - borderItemOffset )
+// position = PositionConstants.EAST;
+//
+// //WEST
+// else if(x <= -(w - borderItemOffset))
+// position = PositionConstants.WEST;
+//
+// //NORTH
+// else if(y <= -(h-borderItemOffset))
+// position = PositionConstants.NORTH;
+// //SOUTH
+// else if(y >= p.height - borderItemOffset)
+// position = PositionConstants.SOUTH;
+ return position;
+ }
+
+}

Back to the top