Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraradermache2013-04-13 21:09:00 +0000
committeraradermache2013-04-13 21:09:00 +0000
commit6b0ab295e56b9846e0bb8f9f2ef297537301e466 (patch)
treedcafb26041146bf3fda56c7957bba26938d8cf9b /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication
parentf43719156ca894b50920c6f2f094e5c24bc290e5 (diff)
downloadorg.eclipse.papyrus-6b0ab295e56b9846e0bb8f9f2ef297537301e466.tar.gz
org.eclipse.papyrus-6b0ab295e56b9846e0bb8f9f2ef297537301e466.tar.xz
org.eclipse.papyrus-6b0ab295e56b9846e0bb8f9f2ef297537301e466.zip
391729: [Communication Diagram] message arrow icon is corrupted
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/figures/CustomWrappingLabel.java4
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/helper/RotationHelper.java135
2 files changed, 65 insertions, 74 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/figures/CustomWrappingLabel.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/figures/CustomWrappingLabel.java
index 162d63724aa..27872323646 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/figures/CustomWrappingLabel.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/figures/CustomWrappingLabel.java
@@ -20,7 +20,6 @@ import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.papyrus.uml.diagram.communication.custom.helper.RotationHelper;
import org.eclipse.papyrus.uml.diagram.communication.part.UMLDiagramEditorPlugin;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.PlatformUI;
/**
* This class extends the WrappingLabel class to permit the rotation of the
@@ -117,7 +116,8 @@ public class CustomWrappingLabel extends WrappingLabel
Image icon = org.eclipse.papyrus.uml.diagram.common.Activator.getPluginIconImage(UMLDiagramEditorPlugin.ID, PATH);
if(icon != null) {
icon.setBackground(getBackgroundColor());
- Image image1 = new Image(PlatformUI.getWorkbench().getDisplay(), RotationHelper.rotateImage(icon, getRotation()));
+ // Image image1 = new Image(PlatformUI.getWorkbench().getDisplay(), RotationHelper.rotateImage(icon, getRotation()));
+ Image image1 = RotationHelper.rotateImage(icon, getRotation());
graphics.setClip(graphics.getClip(new Rectangle()).expand(100, 100));
graphics.drawImage(image1, p);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/helper/RotationHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/helper/RotationHelper.java
index da5e253a63c..d76d446bd42 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/helper/RotationHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.communication/custom-src/org/eclipse/papyrus/uml/diagram/communication/custom/helper/RotationHelper.java
@@ -14,9 +14,6 @@
package org.eclipse.papyrus.uml.diagram.communication.custom.helper;
import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.Transparency;
import java.awt.geom.AffineTransform;
@@ -27,31 +24,21 @@ import java.awt.image.IndexColorModel;
import java.awt.image.WritableRaster;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Transform;
+import org.eclipse.ui.PlatformUI;
-// TODO: Auto-generated Javadoc
/**
- * This is a helper for rotating swt figures, it provides a method for computing
- * an rotation angle provided two points, and methods for rotating an swt image.
+ * This is a helper for rotating SWT figures, it provides a method for computing
+ * an rotation angle provided two points, and methods for rotating an SWT image.
*/
public class RotationHelper {
/**
- * Gets the default configuration.
- *
- * @return the GraphicsConfiguration
- */
-
- public static GraphicsConfiguration getDefaultConfiguration() {
- GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
- GraphicsDevice gd = ge.getDefaultScreenDevice();
- return gd.getDefaultConfiguration();
- }
-
- /**
*
* This method calculates the rotation clockwise angle w.r.t the source and
* target connection anchor positions
@@ -63,7 +50,6 @@ public class RotationHelper {
* @return The rotation clockwise angle w.r.t the source and target
* connection
*/
-
public static double calculateRotAngle(Point S, Point T) {
double dx = T.x - S.x;
double dy = T.y - S.y;
@@ -93,50 +79,53 @@ public class RotationHelper {
}
return Math.toDegrees(angle);
-
}
-
+
/**
- * rotates an awt image.
+ * rotates an SWTimage using swt.graphics.Transform.
*
* @param image
- * awt image
- * @param angle
- * angle of rotation in radians
- * @return swt rotated image
+ * SWT image
+ * @param degree
+ * angle of rotation in degrees
+ * @return SWT rotated image
*/
- public static ImageData tilt(BufferedImage image, double angle) {
-
- double sin = Math.abs(Math.sin(angle)), cos = Math.abs(angle);
- int w = image.getWidth(), h = image.getHeight();
- int neww = w;
- int newh = h;
- if(((int)sin != 0) || ((int)cos != 0))
-
- {
- neww = (int)Math.floor(w * cos + h * sin);
- newh = (int)Math.floor(h * cos + w * sin);
+ public static Image rotateImage(Image image, double degree) {
+ ImageData imageData = image.getImageData();
+ int w = imageData.width;
+ int h = imageData.height;
+ float angle = (float) Math.toRadians(degree);
+ float sinA = (float) Math.abs(Math.sin(angle));
+ float cosA = (float) Math.abs(Math.cos(angle));
+ int neww = (int)Math.floor(w * cosA + h * sinA);
+ int newh = (int)Math.floor(h * cosA + w * sinA);
+
+ Transform transform = new Transform(PlatformUI.getWorkbench().getDisplay());
+ transform.translate(neww/2, newh/2); // new center
+ transform.rotate((float) degree);
+ transform.translate(-w/2, -h/2); // old center
+
+ ImageData newImageData = new ImageData(neww, newh, imageData.depth, imageData.palette);
+ // make all pixel transparent (is there a better way to do that?)
+ for (int y = 0; y <newh ; y++) {
+ for (int x = 0; x < neww ; x++) {
+ newImageData.setAlpha(x, y, 0);
+ }
}
-
-
- GraphicsConfiguration gc = getDefaultConfiguration();
- BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
-
- Graphics2D g = result.createGraphics();
-
- g.translate((neww - w) / 2, (newh - h) / 2);
-
- g.rotate(angle, w / 2, h / 2);
-
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g.drawRenderedImage(image, null);
- g.dispose();
-
- return convertToSWT(result);
+ final Image newImage = new Image(PlatformUI.getWorkbench().getDisplay(), newImageData);
+ GC gc = new GC(newImage);
+ gc.setTransform(transform);
+ gc.drawImage(image, 0, 0);
+
+ gc.dispose();
+
+ return newImage;
}
+
+
/**
- * rotates an awt image using Affine Transform.
+ * rotates an AWT image using awt.geom.AffineTransform.
*
* @param image
* awt image
@@ -144,6 +133,7 @@ public class RotationHelper {
* angle of rotation in degrees
* @return swt rotated image
*/
+ @Deprecated
public static ImageData tiltBis(java.awt.Image image, double degree) {
int w = image.getWidth(null);
int h = image.getHeight(null);
@@ -168,39 +158,39 @@ public class RotationHelper {
g.drawImage(image, at, null);
g.dispose();
return convertToSWT(b);
-
}
-
-
-
+
/**
- * Rotates the swt image.
+ * Rotates an SWT image by converting it to AWT first.
*
* @param img
- * the img
+ * the SWT img
* @param degree
* the degree
* @return the rotated image
*/
- public static ImageData rotateImage(Image img, double degree) {
- ImageData data = img.getImageData();
- BufferedImage bufImg = convertToAWT(data);
+ @Deprecated
+ public static Image rotateImageBis(Image img, double degree) {
+
+ ImageData imageData = img.getImageData();
+ BufferedImage bufImg = convertToAWT(imageData);
//double angle = Math.toRadians(degree);
//return tilt(bufImg, angle);
- return tiltBis(bufImg, degree);
-
-
+ ImageData imageDataNew = tiltBis(bufImg, degree);
+ Image imageNew = new Image(PlatformUI.getWorkbench().getDisplay(), imageDataNew);
+ return imageNew;
}
/**
- * convert awt BufferedImage to swt ImageData.
+ * convert an AWT BufferedImage to SWT ImageData.
*
* @param bufferedImage
* the buffered image
* @return converted ImageData
*/
+ @Deprecated
public static ImageData convertToSWT(BufferedImage bufferedImage) {
if(bufferedImage.getColorModel() instanceof DirectColorModel) {
DirectColorModel colorModel = (DirectColorModel)bufferedImage.getColorModel();
@@ -247,13 +237,14 @@ public class RotationHelper {
}
/**
- * converts swt image to awt.
- *
+ * Converts an SWT image to AWT
+ * TODO: This function does not work on MacOS and Linux machines
+ *
* @param data
- * swt ImageData
- * @return awt BufferdImage
+ * SWT ImageData
+ * @return AWT BufferdImage
*/
-
+ @Deprecated
public static BufferedImage convertToAWT(ImageData data) {
ColorModel colorModel = null;
PaletteData palette = data.palette;

Back to the top