Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-02-22 11:31:43 -0500
committercletavernie2012-02-22 11:31:43 -0500
commit9c1e0cbf09d24c7e3a0076972b3c73ed87df5c50 (patch)
tree4c84f56859fe149486efbaab1f1ab5f2d6b8d922 /plugins
parent7370cc2326588c69bed86b8df7b910f492b22767 (diff)
downloadorg.eclipse.papyrus-9c1e0cbf09d24c7e3a0076972b3c73ed87df5c50.tar.gz
org.eclipse.papyrus-9c1e0cbf09d24c7e3a0076972b3c73ed87df5c50.tar.xz
org.eclipse.papyrus-9c1e0cbf09d24c7e3a0076972b3c73ed87df5c50.zip
368591: [All diagrams] It should be possible to use icons with a higher resolution
https://bugs.eclipse.org/bugs/show_bug.cgi?id=368591
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/AffixedNamedElementFigure.java28
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/LabelWithScalableIcons.java91
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/ScaledImageFigure.java72
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/WrappingLabelWithScalableIcons.java98
5 files changed, 289 insertions, 6 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/AffixedNamedElementFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/AffixedNamedElementFigure.java
index 6d6eb6db574..09cca460bb1 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/AffixedNamedElementFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/AffixedNamedElementFigure.java
@@ -16,6 +16,8 @@ package org.eclipse.papyrus.uml.diagram.common.figure.node;
import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.ImageFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Image;
/**
@@ -25,13 +27,15 @@ import org.eclipse.swt.graphics.Image;
public class AffixedNamedElementFigure extends NodeNamedElementFigure {
/** Container for icon (stereotype icon) */
- protected ImageFigure icon;
+ // protected ScalableImageFigure icon;
+ protected ScaledImageFigure icon;
/** Constructor */
public AffixedNamedElementFigure() {
super();
- icon = new ImageFigure();
+ // icon = new ScalableImageFigure(new Image(Display.getCurrent(), 2, 2));
+ icon = new ScaledImageFigure();
this.add(icon);
BorderLayout layout = new BorderLayout();
@@ -57,7 +61,25 @@ public class AffixedNamedElementFigure extends NodeNamedElementFigure {
* the new
*/
protected void setIcon(Image image) {
- getIconContainer().setImage(image);
+ icon.setImage(image);
+ if(image == null) {
+ icon.setScale(1.0);
+ // icon.setImage(new Image(Display.getCurrent(), 2, 2));
+ return;
+ }
+
+ Dimension imageDim = new Rectangle(image.getBounds()).getSize();
+ int imageMax = imageDim.width;
+ if(imageDim.height > imageMax) {
+ imageMax = imageDim.height;
+ }
+ // size of enclosing box
+ Dimension size = getParent().getBounds().getSize();
+
+ if((imageDim.width >= size.width) || (imageDim.height >= size.height)) {
+ // 5 = border width
+ icon.setScale((size.width - 5.0) / imageMax);
+ }
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/LabelWithScalableIcons.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/LabelWithScalableIcons.java
new file mode 100644
index 00000000000..b57eef3bd78
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/LabelWithScalableIcons.java
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Ansgar Radermacher (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.figure.node;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * A label in which the added icon is scaled to the height of the
+ * text font. Only bigger icons are scaled, smaller remain unchanged.
+ *
+ */
+public class LabelWithScalableIcons extends Label {
+
+ @Override
+ public void paintFigure(Graphics graphics) {
+ if(isOpaque()) {
+ // super.paintFigure(graphics);
+ }
+ Rectangle bounds = getBounds();
+ graphics.translate(bounds.x, bounds.y);
+ if(getIcon() != null)
+ paintScaledIcon(graphics);
+ if(!isEnabled()) {
+ graphics.translate(1, 1);
+ graphics.setForegroundColor(ColorConstants.buttonLightest);
+ graphics.drawText(getSubStringText(), getTextLocation());
+ graphics.translate(-1, -1);
+ graphics.setForegroundColor(ColorConstants.buttonDarker);
+ }
+ graphics.drawText(getSubStringText(), getTextLocation());
+ graphics.translate(-bounds.x, -bounds.y);
+ }
+
+ @Override
+ protected Dimension getIconSize() {
+ int width = 0;
+ int height = getTextSize().height;
+ Image icon = getIcon();
+ if(icon != null) {
+ org.eclipse.swt.graphics.Rectangle bounds = icon.getBounds();
+ double scale = (double)(height - 2) / bounds.height;
+ if(scale > 1) {
+ scale = 1;
+ }
+ width = (int)(bounds.width * scale);
+ }
+ return new Dimension(width, height);
+ }
+
+ /**
+ * Paints the icon(s)
+ *
+ * @param graphics
+ * The graphics context
+ */
+ private void paintScaledIcon(Graphics graphics) {
+ Point p = getIconLocation();
+
+ if(p != null) {
+ int height = getTextSize().height;
+
+ Image icon = getIcon();
+ if(icon != null) {
+ org.eclipse.swt.graphics.Rectangle bounds = icon.getBounds();
+ double scale = (double)(height - 2) / bounds.height;
+ if(scale > 1) {
+ scale = 1;
+ }
+ graphics.drawImage(icon, 0, 0, bounds.width, bounds.height,
+ p.x, p.y, (int)(bounds.width * scale), (int)(bounds.height * scale));
+ }
+ }
+ }
+}
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 cc98fd8b9a0..71ee185ec35 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 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -366,7 +366,7 @@ public class NodeNamedElementFigure extends PapyrusNodeFigure implements IPapyru
* used to create a label that contains the icon.
*/
protected void createIconLabel() {
- iconLabel = new Label();
+ iconLabel = new LabelWithScalableIcons();
// Add the label to the figure, at pos 0
getIconLabelContainer().add(iconLabel, getIconLabelConstraint(), getIconLabelPosition());
iconLabel.setLabelAlignment(PositionConstants.LEFT);
@@ -379,7 +379,7 @@ public class NodeNamedElementFigure extends PapyrusNodeFigure implements IPapyru
* the position
*/
protected void createIconLabel(int position) {
- iconLabel = new Label();
+ iconLabel = new LabelWithScalableIcons();
getIconLabelContainer().add(iconLabel, getIconLabelConstraint(), getIconLabelPosition());
iconLabel.setLabelAlignment(position);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/ScaledImageFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/ScaledImageFigure.java
new file mode 100644
index 00000000000..7f66d7ff916
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/ScaledImageFigure.java
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Ansgar Radermacher (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.figure.node;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.ImageFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * An image that can be scaled (respecting the aspect ratio).
+ * See also GMF ScalableImageFigure (which does not work well for an unknown reason)
+ *
+ */
+public class ScaledImageFigure extends ImageFigure {
+
+ @Override
+ protected void paintFigure(Graphics graphics) {
+ Image img = getImage();
+ if(img == null) {
+ return;
+ }
+ Rectangle area = getBounds().getShrinked(getInsets());
+ int x = (area.width - (int)(size.width * scale)) / 2 + area.x;
+ int y = (area.height - (int)(size.height * scale)) / 2 + area.y;
+
+ graphics.drawImage(getImage(), 0, 0, size.width, size.height,
+ x, y, (int)(size.width * scale), (int)(size.height * scale));
+ }
+
+ @Override
+ public Dimension getPreferredSize(int wHint, int hHint) {
+ Dimension d = super.getPreferredSize(wHint, hHint).getCopy();
+ d.scale(scale);
+ return d;
+ }
+
+ @Override
+ public void setImage(Image image) {
+ if(image != null)
+ size = new Rectangle(image.getBounds()).getSize();
+ else
+ size = new Dimension();
+ super.setImage(image);
+ }
+
+ /**
+ * set the scale factor.
+ *
+ * @param scale
+ * the scale factor. 0 < scale <= 1
+ */
+ public void setScale(double scale) {
+ this.scale = scale;
+ }
+
+ private double scale = 1;
+
+ private Dimension size;
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/WrappingLabelWithScalableIcons.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/WrappingLabelWithScalableIcons.java
new file mode 100644
index 00000000000..293a0f0a9c8
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/WrappingLabelWithScalableIcons.java
@@ -0,0 +1,98 @@
+/****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Ansgar Radermacher (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.figure.node;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * A wrapped label in which icons are scaled to the height of the text font. As for the
+ * superclass WrappingLabel, multiple icons are supported and aligned horizontally.
+ * Only bigger icons are scaled, smaller remain unchanged.
+ *
+ */
+public class WrappingLabelWithScalableIcons extends WrappingLabel {
+
+ /**
+ * Width between icons (and between icons & text)
+ */
+ public final static int GAP_WIDTH = 4;
+
+ @Override
+ public void paintFigure(Graphics graphics) {
+ if(hasIcons()) {
+ paintScaledIcons(graphics);
+ }
+ }
+
+ @Override
+ protected Dimension getTotalIconSize() {
+ int num = getNumberofIcons();
+ if(num == 0) {
+ return new Dimension(0, 0);
+ }
+ Rectangle r = getTextBounds();
+ int width = 0;
+ for(int i = 0; i < num; i++) {
+ Image icon = getIcon(i);
+ if(icon != null) {
+ org.eclipse.swt.graphics.Rectangle bounds = icon.getBounds();
+ double scale = (double)(r.height - 2) / bounds.height;
+ if(scale > 1) {
+ scale = 1;
+ }
+ width += GAP_WIDTH + (int)(bounds.width * scale);
+ }
+ }
+ return new Dimension(width, r.height);
+ }
+
+ /**
+ * Paints the icon(s)
+ *
+ * @param graphics
+ * The graphics context
+ */
+ private void paintScaledIcons(Graphics graphics) {
+
+ if(getIconLocation() != null) {
+ Point p = Point.SINGLETON;
+ p.setLocation(getIconLocation());
+
+ Rectangle figBounds = getBounds();
+ p.x += figBounds.x;
+ p.y += figBounds.y;
+
+ Rectangle r = getTextBounds();
+
+ int num = getNumberofIcons();
+ for(int i = 0; i < num; i++) {
+ Image icon = getIcon(i);
+ if(icon != null) {
+ org.eclipse.swt.graphics.Rectangle bounds = icon.getBounds();
+ double scale = (double)(r.height - 2) / bounds.height;
+ if(scale > 1) {
+ scale = 1;
+ }
+ graphics.drawImage(icon, 0, 0, bounds.width, bounds.height,
+ p.x, p.y, (int)(bounds.width * scale), (int)(bounds.height * scale));
+ p.x += GAP_WIDTH + (int)(bounds.width * scale);;
+ }
+ }
+ }
+ }
+}

Back to the top