diff options
author | Camille Letavernier | 2018-06-26 13:59:38 +0000 |
---|---|---|
committer | Nicolas FAUVERGUE | 2018-07-03 15:08:56 +0000 |
commit | 8c848ad6f5ea600dd74c448f631a19042349ba97 (patch) | |
tree | d609d701603f6b6aae0cc86b1a8025f00f105c0f | |
parent | 6b3deccc9dc1d98628dfb300fd87f76606ee44ba (diff) | |
download | org.eclipse.papyrus-8c848ad6f5ea600dd74c448f631a19042349ba97.tar.gz org.eclipse.papyrus-8c848ad6f5ea600dd74c448f631a19042349ba97.tar.xz org.eclipse.papyrus-8c848ad6f5ea600dd74c448f631a19042349ba97.zip |
Bug 535519: [Sequence Diagram] Sequence Diagram layout (& semantics) do
not support DPI scaling
https://bugs.eclipse.org/bugs/show_bug.cgi?id=535519
- Initial version: support a labelHeight / labelWidth in CSS
- Remove the layout tolerance from the tests
Change-Id: Ie46bb206c3046e6111ebaea2a7cc1f66ca09ea15
Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
11 files changed, 180 insertions, 24 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF index d5224cbb99d..a9896bff8e1 100755 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF @@ -82,7 +82,7 @@ Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.common.Activator Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-ClassPath: . -Bundle-Version: 3.100.0.qualifier +Bundle-Version: 3.101.0.qualifier Bundle-Localization: plugin Bundle-Name: %pluginName Bundle-ManifestVersion: 2 diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/pom.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/pom.xml index 50f2d50fc3e..f060d90a431 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/pom.xml +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/pom.xml @@ -7,6 +7,6 @@ <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.papyrus.infra.gmfdiag.common</artifactId> - <version>3.100.0-SNAPSHOT</version> + <version>3.101.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project>
\ No newline at end of file diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusCompartmentEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusCompartmentEditPart.java index 605425d43a3..312c5d0b85d 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusCompartmentEditPart.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusCompartmentEditPart.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2012 CEA LIST. + * Copyright (c) 2012 - 2018 CEA LIST, EclipseSource and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,12 +8,16 @@ * * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * EclipseSource - Bug 535519 *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common.editpart; import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; +import org.eclipse.papyrus.infra.gmfdiag.common.utils.NamedStyleProperties; public abstract class PapyrusCompartmentEditPart extends CompartmentEditPart { @@ -43,4 +47,23 @@ public abstract class PapyrusCompartmentEditPart extends CompartmentEditPart { } + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshLabelSize(); + } + + + /** + * @since 3.101 + */ + // Bug 535519 + protected void refreshLabelSize() { + if (getFigure() instanceof PapyrusWrappingLabel) { + int labelWidth = NotationUtils.getIntValue(getNotationView(), NamedStyleProperties.LABEL_WIDTH, PapyrusWrappingLabel.AUTO_SIZE); + int labelHeight = NotationUtils.getIntValue(getNotationView(), NamedStyleProperties.LABEL_HEIGHT, PapyrusWrappingLabel.AUTO_SIZE); + ((PapyrusWrappingLabel)getFigure() ).setLabelSize(labelWidth, labelHeight); + } + } + } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java index a3718d020d0..a617b8253c5 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010 Atos Origin. + * Copyright (c) 2010 Atos Origin, CEA LIST, EclipseSource and others. * * * All rights reserved. This program and the accompanying materials @@ -11,11 +11,13 @@ * Atos Origin - Initial API and implementation * Arthur Daussy - Bug 354622 - [ActivityDiagram] Object Flows selection prevent selecting other close elements. * CĂ©line Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 440230 - Margin Label + * EclipseSource - Bug 535519 * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common.figure.node; import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; import org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel; import org.eclipse.swt.graphics.Image; @@ -25,7 +27,19 @@ import org.eclipse.swt.graphics.Image; * * @author arthur daussy */ -public class PapyrusWrappingLabel extends WrappingLabel implements IPapyrusWrappingLabel{ +public class PapyrusWrappingLabel extends WrappingLabel implements IPapyrusWrappingLabel { + + /** + * A constant used for {@link #setLabelSize(int, int)}, {@link #setLabelHeight(int)}, {@link #setLabelWidth(int)} + * to indicate that the label size should be automatically derived from the current font size. + * + * @since 3.101 + */ + public static final int AUTO_SIZE = -1; + + private int labelWidth = AUTO_SIZE; + + private int labelHeight = AUTO_SIZE; /** * Constructor. @@ -94,7 +108,7 @@ public class PapyrusWrappingLabel extends WrappingLabel implements IPapyrusWrapp public void setMarginLabel(int xMargin, int yMargin) { this.setMarginLabel(xMargin, yMargin , xMargin, yMargin); - + } /** @@ -111,7 +125,62 @@ public class PapyrusWrappingLabel extends WrappingLabel implements IPapyrusWrapp this.setBorder(mb); repaint(); revalidate(); - + } - + + /** + * Set the height of this Label, in pixels. Use {@linksetText #AUTO_SIZE} to + * compute the best size based on the current font size. + * + * @param labelHeight + * @since 3.101 + */ + public void setLabelHeight(int labelHeight) { + this.labelHeight = labelHeight; + } + + /** + * Set the width of this Label, in pixels. Use {@link #AUTO_SIZE} to + * compute the best size based on the current font size. + * + * @param labelWidthgetStringExtents + * @since 3.101 + */ + public void setLabelWidth(int labelWidth) { + this.labelWidth = labelWidth; + } + + /** + * Set the size (Width, Height) of this label, in pixels. Use {@link #AUTO_SIZE} to + * compute the best size based on the current font size. + * + * @param height + * @param width + * @since 3.101 + */ + public void setLabelSize(int width, int height) { + setLabelWidth(width); + setLabelHeight(height); + } + + /** + * @see org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel#getPreferredSize(int, int) + * + * @param wHint + * @param hHint + * @return + */ + @Override + public Dimension getPreferredSize(int wHint, int hHint) { + //TODO Compute the best font size to fit the height, and truncate on width + Dimension prefSize = super.getPreferredSize(wHint, hHint); + if (labelHeight > 0) { + prefSize.height = labelHeight; + } + if (labelWidth > 0) { + prefSize.width = labelWidth; + } + return prefSize; + } + } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/NamedStyleProperties.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/NamedStyleProperties.java index 577b0512c7e..6c61e857cc7 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/NamedStyleProperties.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/NamedStyleProperties.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010, 2014 CEA LIST and others. + * Copyright (c) 2010, 2018 CEA LIST, EclipseSource and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation + * EclipseSource - Bug 535519 * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common.utils; @@ -174,19 +175,32 @@ public interface NamedStyleProperties { /** name of the CSS property that manages the enablement of the {@link StyleBasedShapeProvider} for decoration */ public static final String SHAPE_DECORATION_STYLE_PROPERTY = "shapeDecorationStyle"; //$NON-NLS-1$ - /** NameStyle property to show an icon next to the label of an element. + /** NameStyle property to show an icon next to the label of an element. * @since 3.0*/ public static final String ELEMENT_ICON = "elementIcon"; //$NON-NLS-1$ - /** NameStyle property to define the depth of the qualified name to display. + /** NameStyle property to define the depth of the qualified name to display. * @since 3.0*/ public static final String QUALIFIED_NAME_DEPTH = "qualifiedNameDepth"; //$NON-NLS-1$ - /** NameStyle property to display a shadow under the shape. + /** NameStyle property to display a shadow under the shape. * @since 3.0*/ public static final String SHADOW = "shadow"; //$NON-NLS-1$ - /** NamedStyle property used to show an image on the symbol compartment. + /** NamedStyle property used to show an image on the symbol compartment. * @since 3.0*/ public static final String IMAGE_PATH = "imagePath"; //$NON-NLS-1$ + + /** + * NamedStyle property used to set a fixed height for a Label, in pixels + * @since 3.101 + */ + public static final String LABEL_HEIGHT = "labelHeight"; //$NON-NLS-1$ + + /** + * NamedStyle property used to set a fixed width for a Label, in pixels + * @since 3.101 + */ + public static final String LABEL_WIDTH = "labelWidth"; //$NON-NLS-1$ + } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF index 345721d20e5..5721199b697 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF @@ -92,7 +92,7 @@ Require-Bundle: org.eclipse.papyrus.extensionpoints.editors;bundle-version="[3.0 org.eclipse.papyrus.infra.gmfdiag.style;bundle-version="[2.0.0,3.0.0)", org.eclipse.papyrus.infra.gmfdiag.representation;bundle-version="[2.0.0,3.0.0)" Bundle-Vendor: %providerName -Bundle-Version: 3.2.0.qualifier +Bundle-Version: 3.3.0.qualifier Eclipse-BuddyPolicy: dependent Bundle-Activator: org.eclipse.papyrus.uml.diagram.common.Activator Bundle-ManifestVersion: 2 diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml index 02e705d20ca..d5234fdea10 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml @@ -7,6 +7,6 @@ <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.papyrus.uml.diagram.common</artifactId> - <version>3.2.0-SNAPSHOT</version> + <version>3.3.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project>
\ No newline at end of file diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java index c9a25071015..364aaa50791 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java @@ -1,5 +1,5 @@ /***************************************************************************** -< * Copyright (c) 2008 CEA LIST. +< * Copyright (c) 2008, 2018 CEA LIST, EclipseSource and others. * * * All rights reserved. This program and the accompanying materials @@ -11,6 +11,7 @@ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation * Atos Origin - Enable extending with a composite figure, by adding overrideable methods. * Mickael ADAM (ALL@TEC) mickael.adam@all4tec.net - bug 462448 + * EclipseSource - Bug 535519 * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.figure.node; @@ -1151,4 +1152,40 @@ public class NodeNamedElementFigure extends PapyrusNodeFigure implements IPapyru this.iconLabel.setIcon(image); } + + + /** + * Set the height of this Label, in pixels. Use {@linksetText #AUTO_SIZE} to + * compute the best size based on the current font size. + * + * @param labelHeight + * @since 3.3 + */ + public void setLabelHeight(int labelHeight) { + this.nameLabel.setLabelHeight(labelHeight); + } + + /** + * Set the width of this Label, in pixels. Use {@link #AUTO_SIZE} to + * compute the best size based on the current font size. + * + * @param labelWidthgetStringExtents + * @since 3.3 + */ + public void setLabelWidth(int labelWidth) { + this.nameLabel.setLabelWidth(labelWidth); + } + + /** + * Set the size (Width, Height) of this label, in pixels. Use {@link #AUTO_SIZE} to + * compute the best size based on the current font size. + * + * @param height + * @param width + * @since 3.3 + */ + public void setLabelSize(int width, int height) { + this.nameLabel.setLabelSize(width, height); + } + } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentEditPart.java index 9b6764ef396..5126f2ab52d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CCombinedFragmentEditPart.java @@ -21,6 +21,9 @@ import org.eclipse.gef.EditPolicy; import org.eclipse.gef.Request; import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; +import org.eclipse.papyrus.infra.gmfdiag.common.utils.NamedStyleProperties; import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.CombinedFragmentResizeEditPolicy; import org.eclipse.uml2.uml.CombinedFragment; import org.eclipse.uml2.uml.ConsiderIgnoreFragment; @@ -66,6 +69,7 @@ public class CCombinedFragmentEditPart extends CombinedFragmentEditPart { protected void refreshVisuals() { refreshLabel(); super.refreshVisuals(); + refreshLabelSize(); } /** @@ -79,6 +83,16 @@ public class CCombinedFragmentEditPart extends CombinedFragmentEditPart { } /** + * @since 5.1 + */ + // Bug 535519 + protected void refreshLabelSize() { + int labelWidth = NotationUtils.getIntValue(getNotationView(), NamedStyleProperties.LABEL_WIDTH, PapyrusWrappingLabel.AUTO_SIZE); + int labelHeight = NotationUtils.getIntValue(getNotationView(), NamedStyleProperties.LABEL_HEIGHT, PapyrusWrappingLabel.AUTO_SIZE); + getPrimaryShape().setLabelSize(labelWidth, labelHeight); + } + + /** * @see org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart#createDefaultEditPolicies() * */ diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/style.css b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/style.css index eaddd93f659..04b78359071 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/style.css +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/style.css @@ -1,3 +1,4 @@ * { - fontName: Roboto; /* Used a fixed font to make sure the layout is deterministic */ + fontName: Roboto; + labelHeight: 15; /* Used a fixed label height to make sure the layout is deterministic (width doesn't matter) */ } diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestCombinedFragmentOperandsLayout.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestCombinedFragmentOperandsLayout.java index 493b009369e..8ed11ba75f0 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestCombinedFragmentOperandsLayout.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestCombinedFragmentOperandsLayout.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2018 EclipseSource and others. + * Copyright (c) 2018 CEA LIST, EclipseSource and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -69,12 +69,13 @@ public class TestCombinedFragmentOperandsLayout extends AbstractPapyrusTest { * The value is specified in Pixels. * </p> */ - private static final int LAYOUT_TOLERANCE = 2; // FIXME: When Bug 535061 is fixed, we should be able to set this to 0. + // Bug 535519 now allows specifying label sizes in pixels. If tests specify it (e.g. via CSS), we don't need a Tolerance anymore + private static final int LAYOUT_TOLERANCE = 0; /** - * Size of the CF Label (It is fixed on all platforms, because we use a font explicitly shipped with Papyrus) + * Size of the CF Label (It is fixed on all platforms, since it is set in the test stylesheet) */ - private static final int CF_LABEL_HEIGHT = 19; + private static final int CF_LABEL_HEIGHT = 19; // 15 (Text, from CSS) + two 1px borders above and below /** * Initial value for the CF Width */ @@ -426,9 +427,6 @@ public class TestCombinedFragmentOperandsLayout extends AbstractPapyrusTest { private void assertSize(int width, int height, Dimension actual) { Dimension expected = new Dimension(width, height); String message = String.format("Expected %s (with a %spx tolerance); got %s", expected, LAYOUT_TOLERANCE, actual); - // Note: This test only works at 100% DPI Scaling. This is a general SeqD issue - // that needs to be solved properly. If you're using a 1440p or 4K screen, errors - // are expected. Assert.assertTrue(message, getDelta(expected, actual) <= LAYOUT_TOLERANCE); } |