Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2016-09-27 10:52:59 +0000
committerGerrit Code Review @ Eclipse.org2016-09-28 08:29:13 +0000
commit22498066f77c8ba6079458b82d1ae1ef9f3d092a (patch)
tree9d50825c1e45a06e4e62382d01e334e859196f65 /plugins
parent747c99c3724345b4eb5ee74d4e5aec3719628fb0 (diff)
downloadorg.eclipse.papyrus-22498066f77c8ba6079458b82d1ae1ef9f3d092a.tar.gz
org.eclipse.papyrus-22498066f77c8ba6079458b82d1ae1ef9f3d092a.tar.xz
org.eclipse.papyrus-22498066f77c8ba6079458b82d1ae1ef9f3d092a.zip
Bug 500999 - [Layout][Enhancement] Image should be completely displayed in the compartment
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java88
1 files changed, 41 insertions, 47 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java
index ed60a7cad62..ec5220c360e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java
@@ -19,15 +19,11 @@ import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ScrollPane;
import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.PrecisionDimension;
+import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage;
import org.eclipse.gmf.runtime.draw2d.ui.render.figures.ScalableImageFigure;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.FigureUtils;
-import org.w3c.dom.Document;
-import org.w3c.dom.svg.SVGAnimatedLength;
-import org.w3c.dom.svg.SVGLength;
-import org.w3c.dom.svg.SVGSVGElement;
/**
* Scalable Image figure that will be aligned in the middle/center and keep its own ratio.
@@ -43,6 +39,12 @@ public class BorderedScalableImageFigure extends ScalableImageFigure {
// set a layout manager to override maintain ratio behavior
setLayoutManager(new BorderedLayoutManager());
lastRenderedImage = renderedImage;
+ // assure that ShapeFlowLayout gets the actual image size as preferred size. Otherwise, it would
+ // scale the image to identical width and height which would make it impossible to calculate the
+ // original aspect ratio (SVG specific workaround was in place before, see bug 500999).
+ setPreferredImageSize(
+ renderedImage.getSWTImage().getBounds().width,
+ renderedImage.getSWTImage().getBounds().height);
}
@Override
@@ -103,9 +105,42 @@ public class BorderedScalableImageFigure extends ScalableImageFigure {
if (isMaintainAspectRatio() && container.getParent().getChildren().size() == 1) {
// If the ratio is maintained
ScalableCompartmentFigure scalableCompartmentFigure = FigureUtils.findParentFigureInstance(container, ScalableCompartmentFigure.class);
+
+ // Get the image to calculate ratio
+ ScalableImageFigure scalableImage = FigureUtils.findChildFigureInstance(getParent(), ScalableImageFigure.class);
+ RenderedImage renderedImage = scalableImage.getRenderedImage();
Rectangle scalableCompartmentBounds = scalableCompartmentFigure != null ? scalableCompartmentBounds = scalableCompartmentFigure.getBounds() : container.getBounds();
- container.setBounds(scalableCompartmentBounds);
+ double ratio = (double) renderedImage.getRenderInfo().getWidth() /
+ (double) renderedImage.getRenderInfo().getHeight();
+
+ Point center = new Point(
+ scalableCompartmentBounds.x + scalableCompartmentBounds.width / 2,
+ scalableCompartmentBounds.y + scalableCompartmentBounds.height / 2);
+
+ int width;
+ int height;
+ // Case width>height
+ if (scalableCompartmentBounds.width > scalableCompartmentBounds.height) {
+ if (scalableCompartmentBounds.width > scalableCompartmentBounds.height * ratio) {
+ width = (int) (scalableCompartmentBounds.height * ratio);
+ height = scalableCompartmentBounds.height;
+ } else {
+ width = scalableCompartmentBounds.width;
+ height = (int) (scalableCompartmentBounds.width / ratio);
+ }
+ } else {// Case height>width
+ if (scalableCompartmentBounds.height < scalableCompartmentBounds.width / ratio) {
+ width = (int) (scalableCompartmentBounds.height * ratio);
+ height = scalableCompartmentBounds.height;
+ } else {
+ width = scalableCompartmentBounds.width;
+ height = (int) (scalableCompartmentBounds.width / ratio);
+ }
+ }
+ int y = center.y - height / 2;
+ int x = center.x - width / 2;
+ container.setBounds(new Rectangle(x, y, width, height));
} else {
// Set bounds
if (scrollPaneFigure instanceof ScrollPane) {
@@ -115,44 +150,6 @@ public class BorderedScalableImageFigure extends ScalableImageFigure {
}
/**
- * Transforms the given SVG animated length to a base value, assuming the units in the SVG are pixels
- *
- * @param length
- * The SVG length
- * @return The base value as a double
- */
- private double getValueOf(SVGAnimatedLength length) {
- if (length == null) {
- return 0;
- }
- SVGLength base = length.getBaseVal();
- if (base == null) {
- return 0;
- }
- return base.getValue();
- }
-
- /**
- * Gets the dimension of the SVG document, assuming the units in the SVG are pixels
- *
- * @param document
- * The SVG document
- * @return The equivalent Draw2D dimension
- */
- private PrecisionDimension getSvgDimension(Document document) {
- double svgWidth = 0;
- double svgHeight = 0;
- if (document.getDocumentElement() instanceof SVGSVGElement) {
- SVGSVGElement svgElement = (SVGSVGElement) document.getDocumentElement();
- if (svgElement != null) {
- svgWidth = getValueOf(svgElement.getWidth());
- svgHeight = getValueOf(svgElement.getHeight());
- }
- }
- return new PrecisionDimension(svgWidth, svgHeight);
- }
-
- /**
* @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, int, int)
*
* @param container
@@ -162,10 +159,7 @@ public class BorderedScalableImageFigure extends ScalableImageFigure {
*/
@Override
protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
- // TODO Auto-generated method stub
return null;
}
-
}
-
}

Back to the top