Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Porhel2015-08-07 15:57:20 +0000
committerMaxime Porhel2015-08-10 07:45:38 +0000
commita55479375c6d47e65d905b88ec3f868aa016db65 (patch)
tree0a10032ef9cf4ef43e78d0448d5c8883beba3ebc
parentd5f85c079265745f40f599aee3689c611768ec68 (diff)
downloadorg.eclipse.sirius-a55479375c6d47e65d905b88ec3f868aa016db65.tar.gz
org.eclipse.sirius-a55479375c6d47e65d905b88ec3f868aa016db65.tar.xz
org.eclipse.sirius-a55479375c6d47e65d905b88ec3f868aa016db65.zip
[470770] Introduce RegionRoundedGradientRectangle
Since Bug 465211 and commit dbecde152cd2c577da12be3ec6f4211c4e3c9649, Sirius allows to define borders with a 0 pix size, it configures the outline of the Shape figures regarding their border width. For regions, we used to set the outline to false once and we add a specifc one line border to draw the region separator. Now the RegionRoundedGradientRectangle always disable the ouline of the shape. RegionRoundedGradientRectangle is also able to draw two different corner size to avoid Region to overlap the RegionContainer rounded corners. Bug: 470770 Change-Id: Ib52248f4711c5ad1d83090f17b611824ff9e035a 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/api/part/AbstractDiagramElementContainerEditPart.java13
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/DiagramContainerEditPartOperation.java34
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/RegionRoundedGradientRectangle.java122
3 files changed, 152 insertions, 17 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramElementContainerEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramElementContainerEditPart.java
index 1305a83e40..edfcbd1da6 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramElementContainerEditPart.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramElementContainerEditPart.java
@@ -19,7 +19,6 @@ import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
@@ -90,6 +89,7 @@ import org.eclipse.sirius.diagram.ui.tools.api.figure.ViewNodeContainerRectangle
import org.eclipse.sirius.diagram.ui.tools.api.graphical.edit.styles.IContainerLabelOffsets;
import org.eclipse.sirius.diagram.ui.tools.api.layout.LayoutUtils;
import org.eclipse.sirius.diagram.ui.tools.internal.figure.ContainerWithTitleBlockFigure;
+import org.eclipse.sirius.diagram.ui.tools.internal.figure.RegionRoundedGradientRectangle;
import org.eclipse.sirius.diagram.ui.tools.internal.figure.RoundedCornerMarginBorder;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
@@ -327,11 +327,6 @@ public abstract class AbstractDiagramElementContainerEditPart extends AbstractBo
*/
protected void configureBorder(IFigure shapeFigure) {
if (isRegion() && shapeFigure != null) {
- // If the figure is a shape, do not draw the shape border.
- if (shapeFigure instanceof Shape) {
- ((Shape) shapeFigure).setOutline(false);
- }
-
if (isFirstRegionPart()) {
shapeFigure.setBorder(new MarginBorder(IContainerLabelOffsets.LABEL_OFFSET, 0, 0, 0));
} else {
@@ -494,7 +489,11 @@ public abstract class AbstractDiagramElementContainerEditPart extends AbstractBo
deactivate();
}
if (shapeFigure == null) {
- shapeFigure = new GradientRoundedRectangle(DiagramContainerEditPartOperation.getCornerDimension(this), DiagramContainerEditPartOperation.getBackgroundStyle(this));
+ if (isRegion()) {
+ shapeFigure = new RegionRoundedGradientRectangle(DiagramContainerEditPartOperation.getCornerDimension(this), DiagramContainerEditPartOperation.getBackgroundStyle(this));
+ } else {
+ shapeFigure = new GradientRoundedRectangle(DiagramContainerEditPartOperation.getCornerDimension(this), DiagramContainerEditPartOperation.getBackgroundStyle(this));
+ }
}
// Compute label visibility
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 06210a28d1..9d5c1eb49f 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
@@ -48,6 +48,7 @@ import org.eclipse.sirius.diagram.ui.tools.api.figure.ViewNodeContainerParallelo
import org.eclipse.sirius.diagram.ui.tools.api.figure.ViewNodeContainerRectangleFigureDesc;
import org.eclipse.sirius.diagram.ui.tools.api.figure.WorkspaceImageFigure;
import org.eclipse.sirius.diagram.ui.tools.api.graphical.edit.styles.IContainerLabelOffsets;
+import org.eclipse.sirius.diagram.ui.tools.internal.figure.RegionRoundedGradientRectangle;
import org.eclipse.sirius.diagram.ui.tools.internal.figure.RoundedCornerMarginBorder;
import org.eclipse.sirius.ui.tools.api.color.VisualBindingManager;
import org.eclipse.sirius.viewpoint.DStylizable;
@@ -179,25 +180,35 @@ 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;
if (self.isRegion()) {
- // If the current stack is a Region, reuse the parent corner
- // dimension as max, to avoid to overlap its border.
+ // If the current stack is a Region, check and avoid overlap of the
+ // region container border.
+
DNodeContainer regionContainer = (DNodeContainer) diagElement.eContainer();
Dimension regionContainerCornerDimension = getCornerDimension(regionContainer);
- if (regionContainerCornerDimension.contains(cornerDimension)) {
+ if (!regionContainerCornerDimension.getShrinked(cornerDimension).isEmpty()) {
int parentStackDirection = self.getParentStackDirection();
if (parentStackDirection == PositionConstants.NORTH_SOUTH && isLastRegionPart(self)) {
+ specificDimension = cornerDimension;
cornerDimension = Dimension.max(cornerDimension, regionContainerCornerDimension);
- // TODO: Vertical stack and last region, we should have
- // bottom rounded corners only;
+ if (specificDimension != cornerDimension) {
+ specificCornerPosition = PositionConstants.NORTH_WEST | PositionConstants.NORTH_EAST;
+ }
updatePrecedingSiblingCorner(self);
} else if (parentStackDirection == PositionConstants.EAST_WEST) {
boolean firstRegionPart = isFirstRegionPart(self);
boolean lastRegionPart = isLastRegionPart(self);
- cornerDimension = (firstRegionPart || lastRegionPart) ? Dimension.max(cornerDimension, regionContainerCornerDimension) : cornerDimension;
- // TODO: Horizontal stack and first/last region, we should
- // have bottom
- // left/right rounded corner only
+
+ 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;
+ }
+
if (lastRegionPart) {
updatePrecedingSiblingCorner(self);
}
@@ -207,6 +218,9 @@ public final class DiagramContainerEditPartOperation {
// Update the corner dimension.
gradientRoundedShape.setCornerDimensions(cornerDimension);
+ if (gradientRoundedShape instanceof RegionRoundedGradientRectangle) {
+ ((RegionRoundedGradientRectangle) gradientRoundedShape).setAdditionalCornerDimensions(specificCornerPosition, specificDimension);
+ }
}
private static void updatePrecedingSiblingCorner(final AbstractDiagramElementContainerEditPart self) {
@@ -258,7 +272,7 @@ public final class DiagramContainerEditPartOperation {
int borderMagin = borderSize;
switch (self.getParentStackDirection()) {
case PositionConstants.NORTH_SOUTH:
- borderMagin = isFirstRegionPart(self) ? 0 : borderSize - 1;
+ borderMagin = isFirstRegionPart(self) ? 0 : Math.max(0, borderSize - 1);
margin = new MarginBorder(borderMagin + labelOffset, 0, 0, 0);
break;
case PositionConstants.EAST_WEST:
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
new file mode 100644
index 0000000000..dea396d338
--- /dev/null
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/RegionRoundedGradientRectangle.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.diagram.ui.tools.internal.figure;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.sirius.diagram.BackgroundStyle;
+import org.eclipse.sirius.diagram.ui.tools.api.figure.GradientRoundedRectangle;
+
+/**
+ * Specific {@link GradientRoundedRectangle} able to use a different dimension
+ * for chosen corners.
+ *
+ * This is currently used to render region, and will always be configured to
+ * have outline == false.
+ *
+ * fillShape(Graphics) draws the chosen corners with the additional dimension
+ * and the other ones with the main corner dimension.
+ *
+ * outlineShape(Graphics) currently calls super.outlineShape() and will draw the
+ * outline corresponding to a standard RoundedCorner with the same corner
+ * dimension.
+ *
+ * outlineShape(Graphics) will never be call as setOutline will do nothing and
+ * the outline is set to false
+ *
+ * @author mporhel
+ */
+public class RegionRoundedGradientRectangle extends GradientRoundedRectangle {
+
+ private final Dimension secondaryCorner = new Dimension(0, 0);
+
+ private int position = PositionConstants.NONE;
+
+ /**
+ * Create a new {@link RegionRoundedGradientRectangle}.
+ *
+ * @param dimension
+ * dimension of the corner (with radius, height radius)
+ * @param backgroundStyle
+ * style of the wanted gradient
+ *
+ */
+ public RegionRoundedGradientRectangle(final Dimension dimension, final BackgroundStyle backgroundStyle) {
+ super(dimension, backgroundStyle);
+ setOutline(false);
+ }
+
+ /**
+ * The outline of the shape is disabled for regions which have a specific
+ * border figure.
+ */
+ @Override
+ public void setOutline(boolean b) {
+ super.setOutline(false);
+ }
+
+ /**
+ * 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.
+ */
+ public void setAdditionalCornerDimensions(int chosenCorners, Dimension d) {
+ position = chosenCorners;
+
+ if (d == null) {
+ secondaryCorner.width = 0;
+ secondaryCorner.height = 0;
+ }
+ secondaryCorner.width = d.width;
+ secondaryCorner.height = d.height;
+ }
+
+ @Override
+ protected void fillShape(Graphics graphics) {
+ super.fillShape(graphics);
+
+ if (PositionConstants.NONE == position) {
+ return;
+ }
+
+ if (correspondsTo(PositionConstants.NORTH_WEST)) {
+ Rectangle corner = new Rectangle(bounds.getCenter(), bounds.getTopLeft());
+ graphics.fillRoundRectangle(corner, secondaryCorner.width, secondaryCorner.height);
+ }
+
+ if (correspondsTo(PositionConstants.NORTH_EAST)) {
+ Rectangle corner = new Rectangle(bounds.getCenter(), bounds.getTopRight());
+ graphics.fillRoundRectangle(corner, secondaryCorner.width, secondaryCorner.height);
+ }
+
+ if (correspondsTo(PositionConstants.SOUTH_EAST)) {
+ Rectangle corner = new Rectangle(bounds.getCenter(), bounds.getBottomRight());
+ graphics.fillRoundRectangle(corner, secondaryCorner.width, secondaryCorner.height);
+ }
+
+ if (correspondsTo(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