Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Charles David2015-09-18 08:24:17 +0000
committerPierre-Charles David2016-02-19 16:12:03 +0000
commit47e7573e73d4a130b74f3d1e03ed51a905e7d119 (patch)
tree1126ad3fd90b4aab1bd7bd4d2b124978d72d14f3
parenta4ce04159734e26350ff87408932216500e0ddb0 (diff)
downloadorg.eclipse.sirius-47e7573e73d4a130b74f3d1e03ed51a905e7d119.tar.gz
org.eclipse.sirius-47e7573e73d4a130b74f3d1e03ed51a905e7d119.tar.xz
org.eclipse.sirius-47e7573e73d4a130b74f3d1e03ed51a905e7d119.zip
[442268] Move getKey() and paintFigure() into SVGFigure
- Add getImage() variant with implicit key and use it in paintFigure(). - Move paintFigure() up into SVGFigure and make the default implementation re-render the SVG each time (for now). - Move getKey() up to SVGFigure. It was defined in AbstractCachedSVGFigure, but both concrete subclasses used the exact same implementation. Also perform some additional code simplifications: - Make render() static (to make it easier to move elsewhere later). - Inline SVGFigure.updateRenderingHints (trivial method only called once). - Remove useless calls to getTranscoder() from inside SVGFigure. We have equivalent, direct access to the corresponding field. Bug: 442268 Change-Id: Ia93de5339a22eced8be97d77879e0b023345d3d3 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/AbstractCachedSVGFigure.java41
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/BundledImageFigure.java18
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java105
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGWorkspaceImageFigure.java19
4 files changed, 79 insertions, 104 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/AbstractCachedSVGFigure.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/AbstractCachedSVGFigure.java
index 0d7d4b643c..08924c2824 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/AbstractCachedSVGFigure.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/AbstractCachedSVGFigure.java
@@ -13,7 +13,6 @@ package org.eclipse.sirius.diagram.ui.tools.api.figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.sirius.common.tools.api.util.StringUtil;
-import org.eclipse.sirius.diagram.ui.tools.internal.figure.TransparentFigureGraphicsModifier;
import org.eclipse.sirius.diagram.ui.tools.internal.figure.svg.ImageCache;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
@@ -30,30 +29,6 @@ public abstract class AbstractCachedSVGFigure extends SVGFigure {
*/
private static final ImageCache CACHE = new ImageCache();
- @Override
- protected void paintFigure(Graphics graphics) {
- TransparentFigureGraphicsModifier modifier = new TransparentFigureGraphicsModifier(this, graphics);
- modifier.pushState();
-
- Rectangle r = getClientArea();
- Image image = getImage(getKey() + getContextKey(graphics), r, graphics);
- // Draw the image
- if (image != null) {
- graphics.drawImage(image, r.x, r.y);
- }
- modifier.popState();
- }
-
- /**
- * Compute a key for this figure. This key is used to store in cache the
- * corresponding {@link org.eclipse.swt.graphics.Image}.
- *
- * The key must begin by the document key.
- *
- * @return The key corresponding to this BundleImageFigure.
- */
- protected abstract String getKey();
-
private String getContextKey(Graphics graphics) {
// CHECKSTYLE:OFF
int aaText = SWT.DEFAULT;
@@ -78,6 +53,20 @@ public abstract class AbstractCachedSVGFigure extends SVGFigure {
/**
* Get the image cached or create new one and cache it.
*
+ * @param clientArea
+ * the client area
+ * @param graphics
+ * the graphical context
+ * @return an image store in a cache
+ */
+ @Override
+ protected Image getImage(Rectangle clientArea, Graphics graphics) {
+ return getImage(getKey() + getContextKey(graphics), clientArea, graphics);
+ }
+
+ /**
+ * Get the image cached or create new one and cache it.
+ *
* @param key
* the key
* @param clientArea
@@ -89,7 +78,7 @@ public abstract class AbstractCachedSVGFigure extends SVGFigure {
protected Image getImage(String key, Rectangle clientArea, Graphics graphics) {
Image result = AbstractCachedSVGFigure.CACHE.getIfPresent(key);
if (result == null) {
- result = render(clientArea, graphics);
+ result = render(this, clientArea, graphics);
if (result != null) {
AbstractCachedSVGFigure.CACHE.put(key, result);
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/BundledImageFigure.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/BundledImageFigure.java
index 41a6d412c1..9b1f3651f8 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/BundledImageFigure.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/BundledImageFigure.java
@@ -482,24 +482,6 @@ public class BundledImageFigure extends AbstractCachedSVGFigure {
* @return The key corresponding to this BundleImageFigure.
*/
@Override
- protected String getKey() {
- StringBuffer result = new StringBuffer();
- result.append(getDocumentKey());
- result.append(AbstractCachedSVGFigure.SEPARATOR);
- result.append(getSiriusAlpha());
- result.append(AbstractCachedSVGFigure.SEPARATOR);
- return result.toString();
- }
-
- /**
- * Compute a key for this BundleImageFigure. This key is used to store in
- * cache the corresponding {@link org.eclipse.swt.graphics.Image}.
- *
- * {@inheritDoc}
- *
- * @return The key corresponding to this BundleImageFigure.
- */
- @Override
protected String getDocumentKey() {
StringBuffer result = new StringBuffer();
result.append(super.getDocumentKey());
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java
index be5e1b8e9f..94586f9528 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java
@@ -26,6 +26,7 @@ import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.sirius.diagram.DiagramPlugin;
import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin;
import org.eclipse.sirius.diagram.ui.provider.Messages;
+import org.eclipse.sirius.diagram.ui.tools.internal.figure.TransparentFigureGraphicsModifier;
import org.eclipse.sirius.diagram.ui.tools.internal.figure.svg.SVGUtils;
import org.eclipse.sirius.diagram.ui.tools.internal.figure.svg.SimpleImageTranscoder;
import org.eclipse.swt.graphics.Image;
@@ -83,30 +84,17 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur
@Override
public int getImageHeight() {
- SimpleImageTranscoder transcoder = getTranscoder();
- if (transcoder != null) {
- return transcoder.getImageHeight();
- } else {
- return 0;
- }
+ return (transcoder != null) ? transcoder.getImageHeight() : 0;
}
@Override
public int getImageWidth() {
- SimpleImageTranscoder transcoder = getTranscoder();
- if (transcoder != null) {
- return transcoder.getImageWidth();
- }
- return 0;
+ return (transcoder != null) ? transcoder.getImageWidth() : 0;
}
@Override
public int getImageAlphaValue(int x, int y) {
- SimpleImageTranscoder transcoder = getTranscoder();
- if (transcoder != null) {
- return transcoder.getImageAlphaValue(x, y);
- }
- return 255;
+ return (transcoder != null) ? transcoder.getImageAlphaValue(x, y) : 255;
}
public final String getURI() {
@@ -146,7 +134,6 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur
transcoder = new SimpleImageTranscoder(document);
failedToLoadDocument = false;
}
-
}
private Document createDocument() {
@@ -187,6 +174,22 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur
}
/**
+ * Should be called when SVG document has been changed. It will be
+ * re-rendered and figure will be repainted.
+ */
+ public void contentChanged() {
+ getDocument();
+ if (transcoder != null) {
+ transcoder.contentChanged();
+ }
+ repaint();
+ }
+
+ protected SimpleImageTranscoder getTranscoder() {
+ return transcoder;
+ }
+
+ /**
* The key used to store the document.
*
* @return the key.
@@ -195,39 +198,59 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur
return uri;
}
- protected Image render(Rectangle clientArea, Graphics graphics) {
- Image result = null;
- if (getDocument() != null) {
- getTranscoder().setCanvasSize(clientArea.width, clientArea.height);
- updateRenderingHints(graphics);
- BufferedImage awtImage = getTranscoder().getBufferedImage();
- if (awtImage != null) {
- result = SVGUtils.toSWT(Display.getCurrent(), awtImage);
- }
- }
- return result;
+ /**
+ * Compute a key for this figure. This key is used to store in cache the
+ * corresponding {@link org.eclipse.swt.graphics.Image}.
+ *
+ * The key must begin by the document key.
+ *
+ * @return The key corresponding to this BundleImageFigure.
+ */
+ protected String getKey() {
+ StringBuffer result = new StringBuffer();
+ result.append(getDocumentKey());
+ result.append(AbstractCachedSVGFigure.SEPARATOR);
+ result.append(getSiriusAlpha());
+ result.append(AbstractCachedSVGFigure.SEPARATOR);
+ return result.toString();
}
- protected void updateRenderingHints(Graphics graphics) {
- if (transcoder != null) {
- transcoder.updateRenderingHints(graphics);
+ @Override
+ protected void paintFigure(Graphics graphics) {
+ TransparentFigureGraphicsModifier modifier = new TransparentFigureGraphicsModifier(this, graphics);
+ modifier.pushState();
+ Rectangle r = getClientArea();
+ Image image = getImage(r, graphics);
+ if (image != null) {
+ graphics.drawImage(image, r.x, r.y);
}
+ modifier.popState();
}
/**
- * Should be called when SVG document has been changed. It will be
- * re-rendered and figure will be repainted.
+ * Get the image cached or create new one and cache it.
+ *
+ * @param clientArea
+ * the client area
+ * @param graphics
+ * the graphical context
+ * @return an image store in a cache
*/
- public void contentChanged() {
- getDocument();
- if (transcoder != null) {
- transcoder.contentChanged();
- }
- repaint();
+ protected Image getImage(Rectangle clientArea, Graphics graphics) {
+ return render(this, clientArea, graphics);
}
- protected SimpleImageTranscoder getTranscoder() {
- return transcoder;
+ protected static Image render(SVGFigure fig, Rectangle clientArea, Graphics graphics) {
+ Image result = null;
+ if (fig.getDocument() != null) {
+ fig.getTranscoder().setCanvasSize(clientArea.width, clientArea.height);
+ fig.getTranscoder().updateRenderingHints(graphics);
+ BufferedImage awtImage = fig.getTranscoder().getBufferedImage();
+ if (awtImage != null) {
+ result = SVGUtils.toSWT(Display.getCurrent(), awtImage);
+ }
+ }
+ return result;
}
// CHECKSTYLE:ON
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGWorkspaceImageFigure.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGWorkspaceImageFigure.java
index 8256a640ea..e2ce66c5ae 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGWorkspaceImageFigure.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGWorkspaceImageFigure.java
@@ -194,25 +194,6 @@ public class SVGWorkspaceImageFigure extends AbstractCachedSVGFigure implements
}
/**
- * Compute a key for this {@link SVGWorkspaceImageFigure}. This key is used
- * to store in cache the corresponding
- * {@link org.eclipse.swt.graphics.Image}.
- *
- * {@inheritDoc}
- *
- * @return The key corresponding to this SVGWorkspaceImageFigure.
- */
- @Override
- protected String getKey() {
- StringBuffer result = new StringBuffer();
- result.append(getDocumentKey());
- result.append(AbstractCachedSVGFigure.SEPARATOR);
- result.append(getSiriusAlpha());
- result.append(AbstractCachedSVGFigure.SEPARATOR);
- return result.toString();
- }
-
- /**
* Get an {@link Image} instance. The image will be stored in a cache.
*
* @param path

Back to the top