Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Redor2016-04-18 14:29:57 +0000
committerLaurent Redor2016-04-22 15:16:34 +0000
commit225f5107a327a9817035ba761203fdb5f93bedd2 (patch)
treee95235bf45ba3ae591451a24da4118295f9fa7ca
parent1aa0866554e951523c77e681c5cd18177bc668a6 (diff)
downloadorg.eclipse.sirius-225f5107a327a9817035ba761203fdb5f93bedd2.tar.gz
org.eclipse.sirius-225f5107a327a9817035ba761203fdb5f93bedd2.tar.xz
org.eclipse.sirius-225f5107a327a9817035ba761203fdb5f93bedd2.zip
[491913] Improve gradient quality for export with PNG and SVG formats
* PNG format: The method DiagramEditPartService.getDiagramGenerator(DiagramEditPart, ImageFileFormat) has been overridden to redirect to specific SiriusDiagramImageGenerator (instead of original DiagramImageGenerator). SiriusDiagramImageGenerator uses SiriusGraphicsToGraphics2DAdaptor to create the AWT image. * SVG format: The method DiagramEditPartService.getDiagramGenerator(DiagramEditPart, ImageFileFormat) has been overridden to redirect to specific SiriusDiagramSVGGenerator (instead of original DiagramSVGGenerator). Several other methods have been duplicated to use SiriusDiagramSVGGenerator instead of DiagramSVGGenerator as parameter (copyToImageByteArray, saveSVGToFile, saveToFile, saveToOutputStream). * PNG and SVG formats: ** Several modifications have been necessary for both formats. For java.awt.Graphics2D, the graphics used to draw the canvas, it is possible to handle the gradient with a java.awt.GradientPaint. For JPG format, the org.eclipse.draw2d.SWTGraphics is used to draw the canvas and already handles the gradient with a org.eclipse.swt.graphics.Pattern. ** All methods of SiriusGraphicsToGraphics2DAdaptor that uses BackgroundColor have been completed to handle, if possible, the gradient with GradientPaint. Even if currently only drawRoundRectangle is used. ** GradientHelper now handles GradientPaint as background pattern (in addition to Pattern that is already natively handles in GMF). ** A cache map has been added in VisualBindingManager for GradientPaint as for Pattern. Bug: 491913 Change-Id: Ie060f5d6f8f87ccc3d278dabebfaf6baf8a12ef3 Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java100
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java171
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/util/GraphicsUtilities.java23
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusDiagramImageGenerator.java98
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusDiagramSVGGenerator.java15
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsSVG.java13
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java66
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.html28
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile8
-rw-r--r--plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java44
12 files changed, 543 insertions, 25 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF
index 172e386877..f111135c33 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF
@@ -181,6 +181,7 @@ Export-Package: org.eclipse.sirius.diagram.description.concern.provider;version=
org.eclipse.sirius.diagram.ui.tools.internal.properties.filter;version="2.1.0";x-internal:=true,
org.eclipse.sirius.diagram.ui.tools.internal.providers;version="2.0.4";x-internal:=true,
org.eclipse.sirius.diagram.ui.tools.internal.providers.decorators;version="3.0.0";x-internal:=true,
+ org.eclipse.sirius.diagram.ui.tools.internal.render;version="4.0.0";x-internal:=true,
org.eclipse.sirius.diagram.ui.tools.internal.resource;version="2.0.4";x-internal:=true,
org.eclipse.sirius.diagram.ui.tools.internal.routers;version="2.0.4";x-internal:=true,
org.eclipse.sirius.diagram.ui.tools.internal.ruler;version="3.1.0";x-internal:=true,
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java
index 68c3485d82..e315af7f7d 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java
@@ -10,11 +10,14 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.api.figure;
+import java.awt.GradientPaint;
+
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.sirius.diagram.BackgroundStyle;
import org.eclipse.sirius.diagram.ui.tools.internal.figure.util.GraphicsUtilities;
+import org.eclipse.sirius.diagram.ui.tools.internal.render.SiriusGraphicsToGraphics2DAdaptor;
import org.eclipse.sirius.ui.tools.api.color.VisualBindingManager;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Pattern;
@@ -43,13 +46,18 @@ public final class GradientHelper {
final Rectangle zoomedBounds = GraphicsUtilities.zoomFillRectangle(graphics, figure.getBounds());
if (zoomedBounds != null) {
- final Pattern pattern = GradientHelper.getGradientPattern(figure.getBackgroundStyle().getValue(), zoomedBounds, figure.getBackgroundColor(), figure.getGradientColor());
SWTGraphics swtGraphics = GraphicsUtilities.getSWTGraphics(graphics);
if (swtGraphics != null) {
+ final Pattern pattern = GradientHelper.getGradientPattern(figure.getBackgroundStyle().getValue(), zoomedBounds, figure.getBackgroundColor(), figure.getGradientColor());
swtGraphics.setBackgroundPattern(pattern);
+ } else {
+ SiriusGraphicsToGraphics2DAdaptor siriusGraphics2DAdaptor = GraphicsUtilities.getSiriusGraphicsToGraphics2DAdaptor(graphics);
+ if (siriusGraphics2DAdaptor != null) {
+ GradientPaint gradientPaint = GradientHelper.getGradientPaint(figure.getBackgroundStyle().getValue(), zoomedBounds, figure.getBackgroundColor(), figure.getGradientColor());
+ siriusGraphics2DAdaptor.setBackgroundPattern(gradientPaint);
+ }
}
}
-
}
/**
@@ -83,6 +91,36 @@ public final class GradientHelper {
}
/**
+ * Returns the pattern corresponding to the wanted gradient.
+ *
+ * @param backgroundStyle
+ * the background style
+ * @param bounds
+ * the bounds
+ * @param backgroundColor
+ * the background color
+ * @param gradientColor
+ * the gradient color
+ * @return the wanted pattern
+ */
+ private static GradientPaint getGradientPaint(int backgroundStyle, Rectangle bounds, Color backgroundColor, Color gradientColor) {
+ GradientPaint gradientPaint;
+ switch (backgroundStyle) {
+ case BackgroundStyle.GRADIENT_TOP_TO_BOTTOM:
+ gradientPaint = GradientHelper.getGradientPaintTopToBottom(bounds, backgroundColor, gradientColor);
+ break;
+ case BackgroundStyle.LIQUID:
+ gradientPaint = GradientHelper.getGradientPaintDiag(bounds, backgroundColor, gradientColor);
+ break;
+ case BackgroundStyle.GRADIENT_LEFT_TO_RIGHT:
+ default:
+ gradientPaint = GradientHelper.getGradientPaintLeftToRight(bounds, backgroundColor, gradientColor);
+ break;
+ }
+ return gradientPaint;
+ }
+
+ /**
* Returns the pattern corresponding to the LeftToRight gradient.
*
* @param bounds
@@ -141,4 +179,62 @@ public final class GradientHelper {
return VisualBindingManager.getDefault().getPatternFromValue(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height, backgroundColor, gradientColor);
}
+ /**
+ * Returns the pattern corresponding to the LeftToRight gradient.
+ *
+ * @param bounds
+ * the bounds
+ * @param backgroundColor
+ * the background color
+ * @param gradientColor
+ * teh gradient color
+ * @return the correesponding pattern.
+ */
+ public static GradientPaint getGradientPaintLeftToRight(final Rectangle bounds, final Color backgroundColor, final Color gradientColor) {
+ return VisualBindingManager.getDefault().getGradientPaintFromValue(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y, backgroundColor, gradientColor);
+ }
+
+ /**
+ * Returns the pattern corresponding to the diagonal gradient.
+ *
+ * @param bounds
+ * the bounds
+ * @param backgroundColor
+ * the background color
+ * @param gradientColor
+ * the gradient color
+ * @return a diagonal pattern
+ */
+ public static GradientPaint getGradientPaintDiag(final Rectangle bounds, final Color backgroundColor, final Color gradientColor) {
+ // size of the square use to compute gradient
+ int x = bounds.x;
+ int y = bounds.y;
+ int i = (bounds.width + bounds.height) / 2;
+
+ int gradientZoneWidth = Math.max(bounds.width, i);
+ if (gradientZoneWidth != bounds.width) {
+ x = bounds.x - (i - bounds.width) / 2;
+ }
+
+ int gradientZoneHeight = Math.max(bounds.height, i);
+ if (gradientZoneHeight != bounds.height) {
+ y = bounds.y - (i - bounds.height) / 2;
+ }
+ return VisualBindingManager.getDefault().getGradientPaintFromValue(x, y, x + gradientZoneWidth, y + gradientZoneHeight, backgroundColor, gradientColor);
+ }
+
+ /**
+ * Returns the pattern corresponding to the TopToBottom gradient.
+ *
+ * @param bounds
+ * the bounds
+ * @param backgroundColor
+ * the background color
+ * @param gradientColor
+ * the gradient color
+ * @return the correesponding pattern.
+ */
+ public static GradientPaint getGradientPaintTopToBottom(final Rectangle bounds, final Color backgroundColor, final Color gradientColor) {
+ return VisualBindingManager.getDefault().getGradientPaintFromValue(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height, backgroundColor, gradientColor);
+ }
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java
index fddcccf3ba..ae79c9f95f 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java
@@ -11,9 +11,12 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.api.part;
+import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.MessageFormat;
@@ -29,17 +32,24 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.gmf.runtime.common.core.command.FileModificationValidator;
+import org.eclipse.gmf.runtime.common.core.util.Log;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.image.ImageFileFormat;
import org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramGenerator;
+import org.eclipse.gmf.runtime.diagram.ui.render.internal.DiagramUIRenderPlugin;
import org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUtil;
+import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.image.ImageExporter;
+import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImage;
+import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImageConverter;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.sirius.diagram.DSemanticDiagram;
import org.eclipse.sirius.diagram.ui.internal.refresh.layout.SiriusCanonicalLayoutHandler;
import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin;
import org.eclipse.sirius.diagram.ui.provider.Messages;
import org.eclipse.sirius.diagram.ui.tools.internal.part.OffscreenEditPartFactory;
+import org.eclipse.sirius.diagram.ui.tools.internal.render.SiriusDiagramImageGenerator;
+import org.eclipse.sirius.diagram.ui.tools.internal.render.SiriusDiagramSVGGenerator;
import org.eclipse.sirius.ui.tools.api.actions.export.SizeTooLargeException;
import org.eclipse.sirius.viewpoint.SiriusPlugin;
import org.eclipse.swt.graphics.Image;
@@ -135,6 +145,36 @@ public class DiagramEditPartService extends org.eclipse.gmf.runtime.diagram.ui.r
}
/**
+ * Only overridden to use {@link SiriusDiagramSVGGenerator} instead of
+ * {@link org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramSVGGenerator}
+ * .
+ */
+ @Override
+ public byte[] copyToImageByteArray(DiagramEditPart diagramEP, List editParts, int maxWidth, int maxHeight, ImageFileFormat format, IProgressMonitor monitor, boolean useMargins)
+ throws CoreException {
+ Assert.isNotNull(diagramEP);
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ DiagramGenerator gen = getDiagramGenerator(diagramEP, format);
+ if (editParts == null || editParts.isEmpty()) {
+ // CHECKSTYLE:OFF
+ editParts = diagramEP.getPrimaryEditParts();
+ // CHECKSTYLE:ON
+ }
+ if (format.equals(ImageFileFormat.SVG) || format.equals(ImageFileFormat.PDF)) {
+ gen.createConstrainedSWTImageDecriptorForParts(editParts, maxWidth, maxHeight, useMargins);
+ monitor.worked(1);
+ saveToOutputStream(stream, (SiriusDiagramSVGGenerator) gen, format, monitor);
+ } else {
+ Image image = gen.createConstrainedSWTImageDecriptorForParts(editParts, maxWidth, maxHeight, useMargins).createImage();
+ monitor.worked(1);
+ saveToOutputStream(stream, image, format, monitor);
+ image.dispose();
+ }
+ monitor.worked(1);
+ return stream.toByteArray();
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUtil#copyToImage(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart,
@@ -170,6 +210,58 @@ public class DiagramEditPartService extends org.eclipse.gmf.runtime.diagram.ui.r
}
/**
+ * Only overridden to use {@link SiriusDiagramSVGGenerator} instead of
+ * {@link org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramSVGGenerator}
+ * and {@link SiriusDiagramImageGenerator} instead of
+ * {@link org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramImageGenerator}
+ * .
+ */
+ @Override
+ protected DiagramGenerator getDiagramGenerator(DiagramEditPart diagramEP, ImageFileFormat format) {
+ if (format.equals(ImageFileFormat.SVG) || format.equals(ImageFileFormat.PDF)) {
+ return new SiriusDiagramSVGGenerator(diagramEP);
+ } else {
+ return new SiriusDiagramImageGenerator(diagramEP);
+ }
+ }
+
+ /**
+ * Only overridden to use {@link SiriusDiagramSVGGenerator} instead of
+ * {@link org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramSVGGenerator}
+ * .
+ */
+ @Override
+ protected void copyToImage(DiagramGenerator gen, List editParts, org.eclipse.swt.graphics.Rectangle imageRect, IPath destination, ImageFileFormat format, IProgressMonitor monitor)
+ throws CoreException {
+ boolean found = false;
+ if (format.equals(ImageFileFormat.SVG) || format.equals(ImageFileFormat.PDF)) {
+ gen.createSWTImageDescriptorForParts(editParts, imageRect);
+ monitor.worked(1);
+ saveToFile(destination, (SiriusDiagramSVGGenerator) gen, format, monitor);
+ found = true;
+ } else if (format.equals(ImageFileFormat.JPEG) || format.equals(ImageFileFormat.PNG)) {
+
+ String exportFormat = ImageExporter.JPEG_FILE;
+ if (format.equals(ImageFileFormat.PNG))
+ exportFormat = ImageExporter.PNG_FILE;
+
+ java.awt.Image image = gen.createAWTImageForParts(editParts, imageRect);
+ monitor.worked(1);
+ if (image instanceof BufferedImage) {
+ ImageExporter.exportToFile(destination, (BufferedImage) image, exportFormat, monitor, format.getQuality());
+ found = true;
+ }
+ }
+
+ if (!found) {
+ Image image = gen.createSWTImageDescriptorForParts(editParts, imageRect).createImage();
+ monitor.worked(1);
+ saveToFile(destination, image, format, monitor);
+ image.dispose();
+ }
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUtil#saveToFile(org.eclipse.core.runtime.IPath,
@@ -232,6 +324,85 @@ public class DiagramEditPartService extends org.eclipse.gmf.runtime.diagram.ui.r
}
/**
+ * Saves an SVG DOM to a file.<BR>
+ * Method duplicated from
+ * {@link #saveSVGToFile(IPath, org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramSVGGenerator, IProgressMonitor)}
+ * to use a {@link SiriusDiagramSVGGenerator} instead of a
+ * DiagramSVGGenerator.
+ *
+ * @param destination
+ * the destination file, including path and file name
+ * @param generator
+ * the svg generator for a diagram, used to write
+ * @param monitor
+ * the progress monitor
+ * @exception CoreException
+ * if this method fails
+ */
+ protected void saveSVGToFile(IPath destination, SiriusDiagramSVGGenerator generator, IProgressMonitor monitor) throws CoreException {
+ saveToFile(destination, generator, ImageFileFormat.SVG, monitor);
+ }
+
+ /**
+ * Saves an SVG or PDF files.<BR>
+ * Method duplicated from
+ * {@link #saveToFile(IPath, org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramSVGGenerator, ImageFileFormat, IProgressMonitor)}
+ * to use a {@link SiriusDiagramSVGGenerator} instead of a
+ * DiagramSVGGenerator.
+ *
+ * @param destination
+ * the destination file, including path and file name
+ * @param generator
+ * the svg generator for a diagram, used to write
+ * @param format
+ * currently supports SVG or PDF
+ * @param monitor
+ * the progress monitor
+ * @exception CoreException
+ * if this method fails
+ */
+ protected void saveToFile(IPath destination, SiriusDiagramSVGGenerator generator, ImageFileFormat format, IProgressMonitor monitor) throws CoreException {
+
+ IStatus fileModificationStatus = createFile(destination);
+ if (!fileModificationStatus.isOK()) {
+ // can't write to the file
+ return;
+ }
+ monitor.worked(1);
+
+ try {
+ FileOutputStream os = new FileOutputStream(destination.toOSString());
+ monitor.worked(1);
+ saveToOutputStream(os, generator, format, monitor);
+ os.close();
+ monitor.worked(1);
+ refreshLocal(destination);
+ } catch (IOException ex) {
+ Log.error(DiagramUIRenderPlugin.getInstance(), IStatus.ERROR, ex.getMessage(), ex);
+ IStatus status = new Status(IStatus.ERROR, "exportToFile", IStatus.OK, //$NON-NLS-1$
+ ex.getMessage(), null);
+ throw new CoreException(status);
+ }
+ }
+
+ /**
+ * Method duplicated from
+ * {@link #saveToOutputStream(OutputStream, org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramSVGGenerator, ImageFileFormat, IProgressMonitor)}
+ * to use a {@link SiriusDiagramSVGGenerator} instead of a
+ * DiagramSVGGenerator.
+ */
+ private void saveToOutputStream(OutputStream stream, SiriusDiagramSVGGenerator generator, ImageFileFormat format, IProgressMonitor monitor) throws CoreException {
+ if (format == ImageFileFormat.PDF) {
+ SVGImageConverter.exportToPDF((SVGImage) generator.getRenderedImage(), stream);
+ } else if (format == ImageFileFormat.SVG) {
+ generator.stream(stream);
+ } else {
+ throw new IllegalArgumentException("Unexpected format: " + format.getName()); //$NON-NLS-1$
+ }
+ monitor.worked(1);
+ }
+
+ /**
* create a file in the workspace if the destination is in a project in the
* workspace.
*
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/util/GraphicsUtilities.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/util/GraphicsUtilities.java
index 4dc4fc44cc..60beee2df9 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/util/GraphicsUtilities.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/util/GraphicsUtilities.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES.
* 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
@@ -17,6 +17,7 @@ import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.ScaledGraphics;
+import org.eclipse.sirius.diagram.ui.tools.internal.render.SiriusGraphicsToGraphics2DAdaptor;
/**
* .
@@ -70,6 +71,25 @@ public final class GraphicsUtilities {
return swtGrpahics;
}
+ /**
+ * Get the SiriusGraphicsToGraphics2DAdaptor graphic instance.
+ *
+ * @param graphics
+ * the wrapped SiriusGraphicsToGraphics2DAdaptor graphics
+ * instance
+ * @return the wrapped graphic instance
+ */
+ public static SiriusGraphicsToGraphics2DAdaptor getSiriusGraphicsToGraphics2DAdaptor(Graphics graphics) {
+ Graphics internalGraphics = null;
+ if (graphics instanceof ScaledGraphics) {
+ internalGraphics = GraphicsUtilities.getInternalGraphics((ScaledGraphics) graphics);
+ }
+ if (internalGraphics instanceof SiriusGraphicsToGraphics2DAdaptor) {
+ return (SiriusGraphicsToGraphics2DAdaptor) internalGraphics;
+ }
+ return null;
+ }
+
private static Graphics getInternalGraphics(final ScaledGraphics graphics) {
try {
method = ScaledGraphics.class.getDeclaredMethod("getGraphics"); //$NON-NLS-1$
@@ -116,5 +136,4 @@ public final class GraphicsUtilities {
}
return null;
}
-
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusDiagramImageGenerator.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusDiagramImageGenerator.java
new file mode 100644
index 0000000000..737cc4a9dc
--- /dev/null
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusDiagramImageGenerator.java
@@ -0,0 +1,98 @@
+/******************************************************************************
+ * Copyright (c) 2002, 2016 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ ****************************************************************************/
+package org.eclipse.sirius.diagram.ui.tools.internal.render;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.util.List;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants;
+import org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramImageGenerator;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
+import org.eclipse.gmf.runtime.draw2d.ui.render.internal.graphics.RenderedMapModeGraphics;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * Class override to use a specific GraphicsToGraphics2DAdaptor that handles the
+ * gradient.
+ *
+ * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a>
+ */
+public class SiriusDiagramImageGenerator extends DiagramImageGenerator {
+
+ /**
+ * Default constructor.
+ *
+ * @param dgrmEP
+ * the diagram editpart
+ */
+ public SiriusDiagramImageGenerator(DiagramEditPart dgrmEP) {
+ super(dgrmEP);
+ }
+
+ /**
+ * Same method as parent but using a
+ * {@link SiriusGraphicsToGraphics2DAdaptor} instead of a
+ * {@link org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor}
+ * .
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramImageGenerator#
+ * createAWTImageForParts(java.util.List,
+ * org.eclipse.swt.graphics.Rectangle)
+ */
+ @Override
+ public java.awt.Image createAWTImageForParts(List selectedObjects, org.eclipse.swt.graphics.Rectangle sourceRect) {
+
+ BufferedImage awtImage = null;
+ IMapMode mm = getMapMode();
+ PrecisionRectangle rect = new PrecisionRectangle();
+ rect.setX(sourceRect.x);
+ rect.setY(sourceRect.y);
+ rect.setWidth(sourceRect.width);
+ rect.setHeight(sourceRect.height);
+
+ mm.LPtoDP(rect);
+
+ awtImage = new BufferedImage((int) Math.round(rect.preciseWidth), (int) Math.rint(rect.preciseHeight), BufferedImage.TYPE_4BYTE_ABGR_PRE);
+
+ Graphics2D g2d = awtImage.createGraphics();
+ g2d.setColor(Color.white);
+ g2d.fillRect(0, 0, awtImage.getWidth(), awtImage.getHeight());
+
+ // Check anti-aliasing preference
+ IPreferenceStore preferenceStore = (IPreferenceStore) getDiagramEditPart().getDiagramPreferencesHint().getPreferenceStore();
+
+ if (preferenceStore.getBoolean(IPreferenceConstants.PREF_ENABLE_ANTIALIAS)) {
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ } else {
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
+ }
+
+ g2d.clip(new java.awt.Rectangle(0, 0, awtImage.getWidth(), awtImage.getHeight()));
+
+ Graphics graphics = new SiriusGraphicsToGraphics2DAdaptor(g2d, new Rectangle(0, 0, awtImage.getWidth(), awtImage.getHeight()));
+
+ RenderedMapModeGraphics mapModeGraphics = new RenderedMapModeGraphics(graphics, mm);
+
+ renderToGraphics(mapModeGraphics, new Point(sourceRect.x, sourceRect.y), selectedObjects);
+
+ graphics.dispose();
+ g2d.dispose();
+ return awtImage;
+ }
+}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusDiagramSVGGenerator.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusDiagramSVGGenerator.java
index a7c2c45eb9..9a5fd4d0b3 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusDiagramSVGGenerator.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusDiagramSVGGenerator.java
@@ -35,7 +35,6 @@ import org.eclipse.gmf.runtime.diagram.ui.render.internal.DiagramUIRenderDebugOp
import org.eclipse.gmf.runtime.diagram.ui.render.internal.DiagramUIRenderPlugin;
import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage;
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.image.ImageConverter;
-import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.export.GraphicsSVG;
import org.eclipse.gmf.runtime.draw2d.ui.render.factory.RenderedImageFactory;
import org.eclipse.gmf.runtime.draw2d.ui.render.internal.RenderedImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
@@ -43,7 +42,13 @@ import org.w3c.dom.Element;
/**
* Supports generation of an SVG DOM for a diagram or a subset of editparts on a
- * diagram.
+ * diagram.<BR>
+ * Class copied from
+ * {@link org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramSVGGenerator}
+ * to use a specific GraphicsToGraphics2DAdaptor ({@link SiriusGraphicsSVG}
+ * instead of
+ * {@link org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.export.GraphicsSVG}
+ * ) that handles the gradient.
*
* @author jschofie / sshaw
*/
@@ -75,7 +80,8 @@ public class SiriusDiagramSVGGenerator extends DiagramGenerator {
@Override
protected Graphics setUpGraphics(int width, int height) {
viewBox = new Rectangle(0, 0, width, height);
- return GraphicsSVG.getInstance(viewBox);
+ // GraphicsSVG replaced by SiriusGraphicsSVG
+ return SiriusGraphicsSVG.getInstance(viewBox);
}
/*
@@ -87,7 +93,8 @@ public class SiriusDiagramSVGGenerator extends DiagramGenerator {
@Override
protected ImageDescriptor getImageDescriptor(Graphics g) {
try {
- GraphicsSVG svgG = (GraphicsSVG) g;
+ // GraphicsSVG replaced by SiriusGraphicsSVG
+ SiriusGraphicsSVG svgG = (SiriusGraphicsSVG) g;
// Get the root element (the svg element)
svgRoot = svgG.getRoot();
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsSVG.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsSVG.java
index 1def9e07f8..7f15399ea0 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsSVG.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsSVG.java
@@ -23,7 +23,6 @@ import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo;
import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage;
-import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor;
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGColorConverter;
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImage;
import org.eclipse.gmf.runtime.draw2d.ui.render.internal.DrawableRenderedImage;
@@ -33,12 +32,18 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
- * Objects of this class can be used with draw2d to create an SVG DOM.
- *
+ * Objects of this class can be used with draw2d to create an SVG DOM.<BR>
+ * Class copied from
+ * {@link org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.export.GraphicsSVG}
+ * to inherit of {@link SiriusGraphicsToGraphics2DAdaptor} instead of
+ * {@link org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor}
+ * and so handles gradient with method
+ * {@link #setBackgroundPattern(java.awt.GradientPaint)}.
+ *
* @author jschofie / sshaw
*/
// CHECKSTYLE:OFF
-public class SiriusGraphicsSVG extends GraphicsToGraphics2DAdaptor implements DrawableRenderedImage {
+public class SiriusGraphicsSVG extends SiriusGraphicsToGraphics2DAdaptor implements DrawableRenderedImage {
private Document doc;
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java
index bdefa47852..3943ebdc76 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java
@@ -60,8 +60,10 @@ import org.eclipse.swt.graphics.TextLayout;
//CHECKSTYLE:OFF
/**
- * Objects of this class can be used with draw2d to render to a Graphics2D
- * object.
+ * Class copied from
+ * {@link org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor}
+ * . But this class handles the gradient background (method
+ * {@link #setBackgroundPattern(GradientPaint)}.
*
* @author jschofie / sshaw
*/
@@ -121,6 +123,11 @@ public class SiriusGraphicsToGraphics2DAdaptor extends Graphics implements Drawa
public Color bgColor;
/**
+ * cached background pattern
+ */
+ GradientPaint bgPattern;
+
+ /**
* cached alpha value
*/
public int alpha;
@@ -423,7 +430,12 @@ public class SiriusGraphicsToGraphics2DAdaptor extends Graphics implements Drawa
Arc2D arc = new Arc2D.Float(x + transX, y + transY, w, h, offset, length, Arc2D.OPEN);
checkState();
- getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ GradientPaint pattern = getBackgroundPattern();
+ if (pattern == null) {
+ getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ } else {
+ getGraphics2D().setPaint(pattern);
+ }
getGraphics2D().fill(arc);
}
@@ -562,7 +574,12 @@ public class SiriusGraphicsToGraphics2DAdaptor extends Graphics implements Drawa
Ellipse2D ellipse = new Ellipse2D.Float(x + transX, y + transY, w - 1, h - 1);
checkState();
- getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ GradientPaint pattern = getBackgroundPattern();
+ if (pattern == null) {
+ getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ } else {
+ getGraphics2D().setPaint(pattern);
+ }
getGraphics2D().fill(ellipse);
}
@@ -601,7 +618,12 @@ public class SiriusGraphicsToGraphics2DAdaptor extends Graphics implements Drawa
public void fillPolygon(PointList pointList) {
checkState();
- getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ GradientPaint pattern = getBackgroundPattern();
+ if (pattern == null) {
+ getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ } else {
+ getGraphics2D().setPaint(pattern);
+ }
getGraphics2D().fill(createPolygon(pointList));
}
@@ -649,7 +671,12 @@ public class SiriusGraphicsToGraphics2DAdaptor extends Graphics implements Drawa
Rectangle2D rect = new Rectangle2D.Float(x + transX, y + transY, width, height);
checkState();
- getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ GradientPaint pattern = getBackgroundPattern();
+ if (pattern == null) {
+ getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ } else {
+ getGraphics2D().setPaint(pattern);
+ }
getGraphics2D().fill(rect);
}
@@ -680,7 +707,13 @@ public class SiriusGraphicsToGraphics2DAdaptor extends Graphics implements Drawa
RoundRectangle2D roundRect = new RoundRectangle2D.Float(rect.x + transX, rect.y + transY, rect.width, rect.height, arcWidth, arcHeight);
checkState();
- getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ GradientPaint pattern = getBackgroundPattern();
+ if (pattern == null) {
+ getGraphics2D().setPaint(getColor(swtGraphics.getBackgroundColor()));
+ } else {
+ getGraphics2D().setPaint(pattern);
+ }
+
getGraphics2D().fill(roundRect);
}
@@ -944,6 +977,25 @@ public class SiriusGraphicsToGraphics2DAdaptor extends Graphics implements Drawa
swtGraphics.setBackgroundColor(rgb);
}
+ /**
+ * Sets the background pattern.
+ *
+ * @param gradientPaint
+ * The pattern to use for gradient background.
+ */
+ public void setBackgroundPattern(GradientPaint gradientPaint) {
+ currentState.bgPattern = gradientPaint;
+ }
+
+ /**
+ * Returns the background pattern used for filling.
+ *
+ * @return the background pattern
+ */
+ private GradientPaint getBackgroundPattern() {
+ return currentState.bgPattern;
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.draw2d.Graphics#setClip(org.eclipse.draw2d.geometry.
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
index 885085b9ff..222fadde00 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
@@ -97,14 +97,17 @@
<li><span class="label label-info">Modified</span> The wizard to ask the new representation name has been changed. These concerns the title of the wizard and the input label. Example with a new Entities diagram for EcoreTools:</li>
</ul>
<p>
- <img border="0" src="images/representationNameWizardChange.png"/>
+ <img border="0" src="images/representationNameWizardChange.png"/>
</p>
+ <ul>
+ <li><span class="label label-info">Modified</span> The export of diagram as image handles the gradient color for container background for BMP, JPG, PNG and SVG formats. Before, it only works for JPG format.</li>
+ </ul>
<h3 id="SpecifierVisibleChanges">Specifier-Visible Changes</h3>
<ul>
<li><span class="label label-success">Added</span> It is possible to create Typed Variable under Variable Filter.</li>
<li><span class="label label-info">Added</span> The specifier can now restrict the border node authorized sides. This new option is available in the advanced tab of the border node style. See the specifier documentation for more details.</li>
<li><span class="label label-info">Modified</span> The
- <code>BorderSizeComputationExpression</code> migration has been corrected to recursively handle the sub container mappings. VSM created or migrated with Sirius 3.1.0, 3.1.1 or 3.1.2 might require a manual modification for the style descriptions of sub container mappings with border size computation equals to 0 as we cannot determine if they were added (or updated) after or before the migration: starting with Sirius 3.1.0, no border will be displayed for a 0 pixel value whereas with older version container always had at least a 1 pixel border.
+ <code>BorderSizeComputationExpression</code> migration has been corrected to recursively handle the sub container mappings. VSM created or migrated with Sirius 3.1.0, 3.1.1 or 3.1.2 might require a manual modification for the style descriptions of sub container mappings with border size computation equals to 0 as we cannot determine if they were added (or updated) after or before the migration: starting with Sirius 3.1.0, no border will be displayed for a 0 pixel value whereas with older version container always had at least a 1 pixel border.
</li>
<li><span class="label label-info">Modified</span> The variable under VariableFilter, previously named &#8220;Variable&#8221;, is renamed to &#8220;Select Model Element Variable&#8221;. It is functionally equivalent.</li>
</ul>
@@ -331,6 +334,27 @@
<code>Image getImage(Rectangle, Graphics)</code>,
<code>static boolean doRemoveFromCache(String)</code>.
</li>
+ <li><span class="label label-success">Added</span> 2 methods are added in
+ <code>org.eclipse.sirius.diagram.ui.tools.api.part.DiagramEditPartService</code> to manage gradient color in export to PNG or SVG formats:
+ <code>DiagramEditPartService.saveSVGToFile(IPath, SiriusDiagramSVGGenerator, IProgressMonitor)</code> and
+ <code>org.eclipse.sirius.diagram.ui.tools.api.part.DiagramEditPartService.saveToFile(IPath, SiriusDiagramSVGGenerator, ImageFileFormat, IProgressMonitor)</code>. These 2 methods are copy of parent methods with
+ <code>SiriusDiagramSVGGenerator</code> as parameter instead of a
+ <code>DiagramSVGGenerator</code>.
+ </li>
+ <li><span class="label label-success">Added</span> The method
+ <code>org.eclipse.sirius.ui.tools.api.color.VisualBindingManager.getGradientPaintFromValue(int, int, int, int, Color, Color)</code> has been added to handle a cache for
+ <code>java.awt.GradientPaint</code> as it is the case for
+ <code>org.eclipse.swt.graphics.Pattern</code> with
+ <code>getPatternFromValue()</code>.
+ </li>
+ <li><span class="label label-success">Added</span> Methods have been added in
+ <code>org.eclipse.sirius.diagram.ui.tools.api.figure.GradientHelper</code> to handle
+ <code>java.awt.GradientPaint</code> as
+ <code>org.eclipse.swt.graphics.Pattern</code>:
+ <code>getGradientPaintDiag(Rectangle, Color, Color)</code>,
+ <code>getGradientPaintLeftToRight(Rectangle, Color, Color)</code> and
+ <code>getGradientPaintTopToBottom(Rectangle, Color, Color)</code>.
+ </li>
<li><span class="label label-info">Modified</span>
<code>org.eclipse.sirius.diagram.ui.tools.api.figure.BundleImageFigure</code> now overrides the method
<code>setBorder(Border border)</code>. It also provides the accessors for the new field
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
index d0a02c5fcf..038336e571 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
@@ -13,13 +13,14 @@ h3. User-Visible Changes
* <span class="label label-info">Modified</span> When trying to reconnect an edge end on another edge, the edge is now highlighted only if a reconnect tool is found (the precondition of the tool is not tested here).
* <span class="label label-info">Modified</span> List items now have the same margin whichever their parent is a simple list or a compartmentalized list. The margin in compartmentalized list was incorrectly set to 0 pixel.
* <span class="label label-info">Modified</span> The wizard to ask the new representation name has been changed. These concerns the title of the wizard and the input label. Example with a new Entities diagram for EcoreTools:
-!images/representationNameWizardChange.png!
+!images/representationNameWizardChange.png!
+* <span class="label label-info">Modified</span> The export of diagram as image handles the gradient color for container background for BMP, JPG, PNG and SVG formats. Before, it only works for JPG format.
h3. Specifier-Visible Changes
* <span class="label label-success">Added</span> It is possible to create Typed Variable under Variable Filter.
* <span class="label label-info">Added</span> The specifier can now restrict the border node authorized sides. This new option is available in the advanced tab of the border node style. See the specifier documentation for more details.
-* <span class="label label-info">Modified</span> The @BorderSizeComputationExpression@ migration has been corrected to recursively handle the sub container mappings. VSM created or migrated with Sirius 3.1.0, 3.1.1 or 3.1.2 might require a manual modification for the style descriptions of sub container mappings with border size computation equals to 0 as we cannot determine if they were added (or updated) after or before the migration: starting with Sirius 3.1.0, no border will be displayed for a 0 pixel value whereas with older version container always had at least a 1 pixel border.
+* <span class="label label-info">Modified</span> The @BorderSizeComputationExpression@ migration has been corrected to recursively handle the sub container mappings. VSM created or migrated with Sirius 3.1.0, 3.1.1 or 3.1.2 might require a manual modification for the style descriptions of sub container mappings with border size computation equals to 0 as we cannot determine if they were added (or updated) after or before the migration: starting with Sirius 3.1.0, no border will be displayed for a 0 pixel value whereas with older version container always had at least a 1 pixel border.
* <span class="label label-info">Modified</span> The variable under VariableFilter, previously named "Variable", is renamed to "Select Model Element Variable". It is functionally equivalent.
h3. Developer-Visible Changes
@@ -90,6 +91,9 @@ h4. Changes in @org.eclipse.sirius.diagram.ui@
* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.tools.api.figure.DBorderedNodeFigure.setForbiddenSides(int...)@ has been added to set the figure forbidden sides on its parent.
* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.tools.api.figure.DBorderedNodeFigure.getAuthorizedSides()@ has been added to retrieve the figure authorized side (by default all sides).
* <span class="label label-success">Added</span> The following protected methods have been added to @org.eclipse.sirius.diagram.ui.tools.api.figure.SVGFigure@ : @String getKey(Graphics)@, @Image getImage(Rectangle, Graphics)@, @static boolean doRemoveFromCache(String)@.
+* <span class="label label-success">Added</span> 2 methods are added in @org.eclipse.sirius.diagram.ui.tools.api.part.DiagramEditPartService@ to manage gradient color in export to PNG or SVG formats: @DiagramEditPartService.saveSVGToFile(IPath, SiriusDiagramSVGGenerator, IProgressMonitor)@ and @org.eclipse.sirius.diagram.ui.tools.api.part.DiagramEditPartService.saveToFile(IPath, SiriusDiagramSVGGenerator, ImageFileFormat, IProgressMonitor)@. These 2 methods are copy of parent methods with @SiriusDiagramSVGGenerator@ as parameter instead of a @DiagramSVGGenerator@.
+* <span class="label label-success">Added</span> The method @org.eclipse.sirius.ui.tools.api.color.VisualBindingManager.getGradientPaintFromValue(int, int, int, int, Color, Color)@ has been added to handle a cache for @java.awt.GradientPaint@ as it is the case for @org.eclipse.swt.graphics.Pattern@ with @getPatternFromValue()@.
+* <span class="label label-success">Added</span> Methods have been added in @org.eclipse.sirius.diagram.ui.tools.api.figure.GradientHelper@ to handle @java.awt.GradientPaint@ as @org.eclipse.swt.graphics.Pattern@: @getGradientPaintDiag(Rectangle, Color, Color)@, @getGradientPaintLeftToRight(Rectangle, Color, Color)@ and @getGradientPaintTopToBottom(Rectangle, Color, Color)@.
* <span class="label label-info">Modified</span> @org.eclipse.sirius.diagram.ui.tools.api.figure.BundleImageFigure@ now overrides the method @setBorder(Border border)@. It also provides the accessors for the new field @mainBorderSize@.
* <span class="label label-info">Modified</span> @org.eclipse.sirius.diagram.ui.tools.api.figure.BundledImageFigure@ now inherits directly from @SVGFigure@ instead of @AbstractCachedSVGFigure@.
* <span class="label label-info">Modified</span> @org.eclipse.sirius.diagram.ui.tools.api.figure.SVGWorkspaceImageFigure@ now inherits directly from @SVGFigure@ instead of @AbstractCachedSVGFigure@.
diff --git a/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF
index a669dc4a3e..24e456c52f 100644
--- a/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF
@@ -117,6 +117,7 @@ Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.sirius.ext.base;version="2.1.0",
+ org.eclipse.sirius.ext.base.cache;version="2.0.4",
org.eclipse.sirius.ext.base.relations;version="2.0.0",
org.eclipse.sirius.ext.emf.ui,
org.eclipse.sirius.ext.emf.ui.properties,
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java
index b1f333b892..6ce9135f42 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES and others.
* 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
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.sirius.ui.tools.api.color;
+import java.awt.GradientPaint;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
@@ -24,6 +25,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.sirius.business.api.helper.SiriusUtil;
+import org.eclipse.sirius.ext.base.cache.LRUCache;
import org.eclipse.sirius.ext.swt.SWTResourceLRUCache;
import org.eclipse.sirius.tools.api.ui.color.EnvironmentSystemColorFactory;
import org.eclipse.sirius.viewpoint.BasicLabelStyle;
@@ -65,6 +67,8 @@ public class VisualBindingManager {
private Map<PatternDescriptor, Pattern> patternCache;
+ private Map<PatternDescriptor, GradientPaint> gradientPaintCache;
+
/**
* Create a new {@link VisualBindingManager}.
*/
@@ -109,6 +113,7 @@ public class VisualBindingManager {
fontCache = new SWTResourceLRUCache<FontStyleDescriptor, Font>(fontCacheSize, fontCacheSize);
intToFontCache = new SWTResourceLRUCache<Integer, Font>(fontCacheSize, fontCacheSize);
patternCache = new SWTResourceLRUCache<PatternDescriptor, Pattern>(colorCacheSize, colorCacheSize);
+ gradientPaintCache = new LRUCache<PatternDescriptor, GradientPaint>(colorCacheSize, colorCacheSize);
}
/**
@@ -124,6 +129,7 @@ public class VisualBindingManager {
intToFontCache.clear();
VisualBindingManager.disposeResources(patternCache.values());
patternCache.clear();
+ gradientPaintCache.clear();
}
private static <T extends Resource> void disposeResources(final Collection<T> resources) {
@@ -548,6 +554,11 @@ public class VisualBindingManager {
public Pattern createPattern() {
return new Pattern(null, this.x, this.y, this.w, this.h, this.backgroundColor, this.foregroundColor);
}
+
+ public GradientPaint createGradientPaint() {
+ return new GradientPaint(this.x, this.y, new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()), this.w, this.h,
+ new java.awt.Color(foregroundColor.getRed(), foregroundColor.getGreen(), foregroundColor.getBlue()));
+ }
}
private Pattern getPatternFromCache(final PatternDescriptor desc) {
@@ -557,6 +568,13 @@ public class VisualBindingManager {
return patternCache.get(desc);
}
+ private GradientPaint getGradientPaintFromCache(final PatternDescriptor desc) {
+ if (!gradientPaintCache.containsKey(desc)) {
+ gradientPaintCache.put(desc, desc.createGradientPaint());
+ }
+ return gradientPaintCache.get(desc);
+ }
+
/**
* Get a pattern from value.
*
@@ -581,6 +599,29 @@ public class VisualBindingManager {
}
/**
+ * Get a pattern from value.
+ *
+ * @param x
+ * the x coordinate
+ * @param y
+ * the x coordinate
+ * @param w
+ * the width
+ * @param h
+ * the height
+ * @param backgroundColor
+ * the background color
+ * @param foregrounColor
+ * the foreground color
+ * @return the created or cached pattern, which does not need to be
+ * disposed.
+ */
+ public GradientPaint getGradientPaintFromValue(int x, int y, int w, int h, Color backgroundColor, Color foregrounColor) {
+ final PatternDescriptor desc = new PatternDescriptor(x, y, w, h, backgroundColor, foregrounColor);
+ return getGradientPaintFromCache(desc);
+ }
+
+ /**
* This method helps avoiding memory leaks by keeping track of the already
* built fonts.
*
@@ -754,5 +795,4 @@ public class VisualBindingManager {
((InternalEObject) color).eSetProxyURI(colorURI);
return (SystemColor) color;
}
-
}

Back to the top