Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Porhel2015-08-10 10:07:30 +0000
committerMaxime Porhel2015-08-13 08:04:44 +0000
commit688f7007c9e5e822122e16a05073c511a771f773 (patch)
treefe3629ca61c26a19a06493f3dc7649eb4be4e774
parent8085750cb2c0dcb3b6099043741e8cd275d02407 (diff)
downloadorg.eclipse.sirius-688f7007c9e5e822122e16a05073c511a771f773.tar.gz
org.eclipse.sirius-688f7007c9e5e822122e16a05073c511a771f773.tar.xz
org.eclipse.sirius-688f7007c9e5e822122e16a05073c511a771f773.zip
[470770] Correct RegionRoundedGradientRectangle
The bit-wise OR was not a good idea, some issues were hidden by the updatePrecedingSiblingCorner() method. Bug 470770 Change-Id: I005ac7e2c77aaff9970fadb4e4345e5a8fadbfc0 Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramContainerEditPartOperation.java53
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/RegionRoundedGradientRectangle.java59
2 files changed, 76 insertions, 36 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramContainerEditPartOperation.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramContainerEditPartOperation.java
index 9d5c1eb49f..38a1677c99 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramContainerEditPartOperation.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramContainerEditPartOperation.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.edit.internal.part;
+import java.util.BitSet;
import java.util.Collection;
import org.eclipse.draw2d.IFigure;
@@ -181,7 +182,7 @@ public final class DiagramContainerEditPartOperation {
private static void refreshCorners(final AbstractDiagramElementContainerEditPart self, DDiagramElement diagElement, RoundedRectangle gradientRoundedShape) {
Dimension cornerDimension = getCornerDimension(self);
Dimension specificDimension = cornerDimension;
- int specificCornerPosition = PositionConstants.NONE;
+ BitSet specificCornerPosition = new BitSet(PositionConstants.NSEW);
if (self.isRegion()) {
// If the current stack is a Region, check and avoid overlap of the
// region container border.
@@ -190,27 +191,30 @@ public final class DiagramContainerEditPartOperation {
Dimension regionContainerCornerDimension = getCornerDimension(regionContainer);
if (!regionContainerCornerDimension.getShrinked(cornerDimension).isEmpty()) {
int parentStackDirection = self.getParentStackDirection();
- if (parentStackDirection == PositionConstants.NORTH_SOUTH && isLastRegionPart(self)) {
+ boolean firstRegionPart = isFirstRegionPart(self);
+ boolean lastRegionPart = isLastRegionPart(self);
+ if (parentStackDirection == PositionConstants.NORTH_SOUTH && lastRegionPart) {
specificDimension = cornerDimension;
cornerDimension = Dimension.max(cornerDimension, regionContainerCornerDimension);
if (specificDimension != cornerDimension) {
- specificCornerPosition = PositionConstants.NORTH_WEST | PositionConstants.NORTH_EAST;
+ specificCornerPosition.set(PositionConstants.NORTH_WEST);
+ specificCornerPosition.set(PositionConstants.NORTH_EAST);
}
- updatePrecedingSiblingCorner(self);
- } else if (parentStackDirection == PositionConstants.EAST_WEST) {
- boolean firstRegionPart = isFirstRegionPart(self);
- boolean lastRegionPart = isLastRegionPart(self);
-
- if (firstRegionPart || lastRegionPart) {
- specificDimension = cornerDimension;
- cornerDimension = Dimension.max(cornerDimension, regionContainerCornerDimension);
- specificCornerPosition = PositionConstants.NORTH_WEST | PositionConstants.NORTH_EAST;
- specificCornerPosition = firstRegionPart ? specificCornerPosition : specificCornerPosition | PositionConstants.SOUTH_WEST;
- specificCornerPosition = lastRegionPart ? specificCornerPosition : specificCornerPosition | PositionConstants.SOUTH_EAST;
+ updatePrecedingSiblingCorner(self, PositionConstants.SOUTH_WEST, PositionConstants.SOUTH_EAST);
+ } else if (parentStackDirection == PositionConstants.EAST_WEST && (firstRegionPart || lastRegionPart)) {
+ specificDimension = cornerDimension;
+ cornerDimension = Dimension.max(cornerDimension, regionContainerCornerDimension);
+
+ specificCornerPosition.set(PositionConstants.NORTH_WEST);
+ specificCornerPosition.set(PositionConstants.NORTH_EAST);
+ if (firstRegionPart && !lastRegionPart) {
+ specificCornerPosition.set(PositionConstants.SOUTH_EAST);
+ } else if (!firstRegionPart && lastRegionPart) {
+ specificCornerPosition.set(PositionConstants.SOUTH_WEST);
}
- if (lastRegionPart) {
- updatePrecedingSiblingCorner(self);
+ if (lastRegionPart && !firstRegionPart) {
+ updatePrecedingSiblingCorner(self, PositionConstants.SOUTH_EAST);
}
}
}
@@ -219,19 +223,28 @@ public final class DiagramContainerEditPartOperation {
// Update the corner dimension.
gradientRoundedShape.setCornerDimensions(cornerDimension);
if (gradientRoundedShape instanceof RegionRoundedGradientRectangle) {
- ((RegionRoundedGradientRectangle) gradientRoundedShape).setAdditionalCornerDimensions(specificCornerPosition, specificDimension);
+ ((RegionRoundedGradientRectangle) gradientRoundedShape).setAdditionalCornerDimensions(specificDimension, specificCornerPosition);
}
}
- private static void updatePrecedingSiblingCorner(final AbstractDiagramElementContainerEditPart self) {
+ private static void updatePrecedingSiblingCorner(final AbstractDiagramElementContainerEditPart self, int... cornerToCorrect) {
// Update previous siblings: needed for the diagram
// opening and the region container creation cases in
// which each child will be the last element once.
Collection<AbstractDiagramElementContainerEditPart> siblings = Lists.newArrayList(Iterables.filter(self.getParent().getChildren(), AbstractDiagramElementContainerEditPart.class));
siblings.remove(self);
AbstractDiagramElementContainerEditPart previous = siblings.isEmpty() ? null : Iterables.getLast(siblings);
- if (previous != null && previous.getPrimaryShape() instanceof GradientRoundedRectangle) {
- ((GradientRoundedRectangle) previous.getPrimaryShape()).setCornerDimensions(getCornerDimension(previous));
+ if (previous != null && previous.getPrimaryShape() instanceof RegionRoundedGradientRectangle) {
+ RegionRoundedGradientRectangle gradientRoundedRectangle = (RegionRoundedGradientRectangle) previous.getPrimaryShape();
+ for (int i : cornerToCorrect) {
+ gradientRoundedRectangle.getAdditionalDimensionCorners().set(i);
+ }
+
+ if (gradientRoundedRectangle.getAdditionalDimensionCorners().cardinality() == 4) {
+ // we do not need specific corner anymore
+ gradientRoundedRectangle.getAdditionalDimensionCorners().clear();
+ gradientRoundedRectangle.setCornerDimensions(gradientRoundedRectangle.getAdditionalCornerDimensions());
+ }
}
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/RegionRoundedGradientRectangle.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/RegionRoundedGradientRectangle.java
index dea396d338..e645d4cee7 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/RegionRoundedGradientRectangle.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/RegionRoundedGradientRectangle.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.internal.figure;
+import java.util.BitSet;
+
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
@@ -40,7 +42,7 @@ public class RegionRoundedGradientRectangle extends GradientRoundedRectangle {
private final Dimension secondaryCorner = new Dimension(0, 0);
- private int position = PositionConstants.NONE;
+ private BitSet positions = new BitSet(PositionConstants.NSEW);
/**
* Create a new {@link RegionRoundedGradientRectangle}.
@@ -69,16 +71,22 @@ public class RegionRoundedGradientRectangle extends GradientRoundedRectangle {
* Sets the dimensions of each corner. This will form the radii of the arcs
* which form the additional corners.
*
- * @param chosenCorners
- * a bit-wise OR of the chosen corners. see
- * {@link PositionConstants}
* @param d
* the dimensions of the corner, it should be smaller than the
* main corner dimension to be visible.
+ *
+ * @param chosenCorners
+ * the chosen corners, see values of the BitSet for the following
+ * indexes: {@link PositionConstants.NORTH_WEST},
+ * {@link PositionConstants.NORTH_EAST},
+ * {@link PositionConstants.SOUTH_EAST},
+ * {@link PositionConstants.SOUTH_WEST}.
*/
- public void setAdditionalCornerDimensions(int chosenCorners, Dimension d) {
- position = chosenCorners;
-
+ public void setAdditionalCornerDimensions(Dimension d, BitSet chosenCorners) {
+ positions.clear();
+ if (chosenCorners != null) {
+ positions.or(chosenCorners);
+ }
if (d == null) {
secondaryCorner.width = 0;
secondaryCorner.height = 0;
@@ -87,36 +95,55 @@ public class RegionRoundedGradientRectangle extends GradientRoundedRectangle {
secondaryCorner.height = d.height;
}
+ /**
+ * Get the additional corner dimension.
+ *
+ * @return the additional corner dimension
+ */
+ public Dimension getAdditionalCornerDimensions() {
+ return secondaryCorner.getCopy();
+ }
+
+ /**
+ * Return a {@link BitSet} knowing the chosen corner, see values of the
+ * BitSet for the following indexes: {@link PositionConstants.NORTH_WEST},
+ * {@link PositionConstants.NORTH_EAST},
+ * {@link PositionConstants.SOUTH_EAST},
+ * {@link PositionConstants.SOUTH_WEST}.
+ *
+ * @return the positions of the corner to draw with the additional corner
+ * dimension.
+ */
+ public BitSet getAdditionalDimensionCorners() {
+ return positions;
+ }
+
@Override
protected void fillShape(Graphics graphics) {
super.fillShape(graphics);
- if (PositionConstants.NONE == position) {
+ if (positions.isEmpty()) {
return;
}
- if (correspondsTo(PositionConstants.NORTH_WEST)) {
+ if (positions.get(PositionConstants.NORTH_WEST)) {
Rectangle corner = new Rectangle(bounds.getCenter(), bounds.getTopLeft());
graphics.fillRoundRectangle(corner, secondaryCorner.width, secondaryCorner.height);
}
- if (correspondsTo(PositionConstants.NORTH_EAST)) {
+ if (positions.get(PositionConstants.NORTH_EAST)) {
Rectangle corner = new Rectangle(bounds.getCenter(), bounds.getTopRight());
graphics.fillRoundRectangle(corner, secondaryCorner.width, secondaryCorner.height);
}
- if (correspondsTo(PositionConstants.SOUTH_EAST)) {
+ if (positions.get(PositionConstants.SOUTH_EAST)) {
Rectangle corner = new Rectangle(bounds.getCenter(), bounds.getBottomRight());
graphics.fillRoundRectangle(corner, secondaryCorner.width, secondaryCorner.height);
}
- if (correspondsTo(PositionConstants.SOUTH_WEST)) {
+ if (positions.get(PositionConstants.SOUTH_WEST)) {
Rectangle corner = new Rectangle(bounds.getCenter(), bounds.getBottomLeft());
graphics.fillRoundRectangle(corner, secondaryCorner.width, secondaryCorner.height);
}
}
-
- private boolean correspondsTo(int corner) {
- return (corner & position) == corner;
- }
}

Back to the top