diff options
| author | Pierre-Charles David | 2015-09-17 14:58:06 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2016-02-19 16:12:03 +0000 |
| commit | 36ccc7b9f424913c5197af9148d24b9acbf80c30 (patch) | |
| tree | 3a3009c730fed67ec93ec3caf4e9072b17aff511 | |
| parent | ffd657406aa9f5d2fbfa67e6b422d1e0e1e15052 (diff) | |
| download | org.eclipse.sirius-36ccc7b9f424913c5197af9148d24b9acbf80c30.tar.gz org.eclipse.sirius-36ccc7b9f424913c5197af9148d24b9acbf80c30.tar.xz org.eclipse.sirius-36ccc7b9f424913c5197af9148d24b9acbf80c30.zip | |
[442268] Move implementation of StyledFigure, ITransparentFigure, ImageFigureWithAlpha up into SVGFigure
This has nothing to do with caching. The only reason it was not in
SVGFigure is that SVGFigure was initialy a copy of GMF Tooling code, and
was kept free of Sirius-specific code.
Bug: 442268
Change-Id: I1ba9c459763ab3aba7bb037709398304e9f08509
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
2 files changed, 75 insertions, 80 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 725617d93d..d9159dbe05 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 @@ -14,13 +14,11 @@ import java.awt.image.BufferedImage; import java.util.Collection; import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.XYLayout; 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.sirius.diagram.ui.tools.internal.figure.svg.SVGUtils; -import org.eclipse.sirius.diagram.ui.tools.internal.figure.svg.SimpleImageTranscoder; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; @@ -34,46 +32,12 @@ import com.google.common.collect.Lists; * * @author mporhel */ -public abstract class AbstractCachedSVGFigure extends SVGFigure implements StyledFigure, ITransparentFigure, ImageFigureWithAlpha { +public abstract class AbstractCachedSVGFigure extends SVGFigure { /** * Cache to store bitmaps of rendered SVGs. */ private static final ImageCache CACHE = new ImageCache(); - - private int viewpointAlpha = DEFAULT_ALPHA; - - private boolean transparent; - - /** - * Build a new {@link AbstractCachedSVGFigure} from an Image instance. - * - */ - public AbstractCachedSVGFigure() { - this.setLayoutManager(new XYLayout()); - } - - @Override - public int getSiriusAlpha() { - return viewpointAlpha; - } - - @Override - public boolean isTransparent() { - return transparent; - } - - @Override - public void setSiriusAlpha(int alpha) { - this.viewpointAlpha = alpha; - - } - - @Override - public void setTransparent(boolean transparent) { - this.transparent = transparent; - } - @Override protected void paintFigure(Graphics graphics) { TransparentFigureGraphicsModifier modifier = new TransparentFigureGraphicsModifier(this, graphics); @@ -179,46 +143,4 @@ public abstract class AbstractCachedSVGFigure extends SVGFigure implements Style return false; } - @Override - public int getImageHeight() { - SimpleImageTranscoder transcoder = getTranscoder(); - int height = 0; - if (transcoder != null) { - int canvasHeight = transcoder.getCanvasHeight(); - if (canvasHeight == -1) { - height = transcoder.getBufferedImage().getHeight(); - } else { - height = canvasHeight; - } - } - return height; - } - - @Override - public int getImageWidth() { - SimpleImageTranscoder transcoder = getTranscoder(); - int width = 0; - if (transcoder != null) { - int canvasWidth = transcoder.getCanvasWidth(); - if (canvasWidth == -1) { - width = transcoder.getBufferedImage().getWidth(); - } else { - width = canvasWidth; - } - } - return width; - } - - @Override - public int getImageAlphaValue(int x, int y) { - SimpleImageTranscoder transcoder = getTranscoder(); - if (transcoder != null) { - BufferedImage bufferedImage = transcoder.getBufferedImage(); - if (bufferedImage != null && bufferedImage.getWidth() >= x && bufferedImage.getHeight() >= y) { - int[] result = bufferedImage.getAlphaRaster().getPixel(x, y, new int[1]); - return result[0]; - } - } - return 255; - } } 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 69097155eb..226437fa0b 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 @@ -22,6 +22,7 @@ import org.apache.batik.dom.svg.SAXSVGDocumentFactory; import org.apache.batik.util.XMLResourceDescriptor; import org.eclipse.draw2d.Figure; import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.XYLayout; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.sirius.diagram.DiagramPlugin; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; @@ -34,7 +35,7 @@ import org.eclipse.swt.widgets.Display; import org.w3c.dom.Document; //CHECKSTYLE:OFF -public class SVGFigure extends Figure { +public class SVGFigure extends Figure implements StyledFigure, ITransparentFigure, ImageFigureWithAlpha { /** * The uri of the image to display when the file has not been found. */ @@ -47,11 +48,83 @@ public class SVGFigure extends Figure { private String uri; + private int viewpointAlpha = ITransparentFigure.DEFAULT_ALPHA; + + private boolean transparent; + private boolean failedToLoadDocument; private SimpleImageTranscoder transcoder; protected static WeakHashMap<String, Document> documentsMap = new WeakHashMap<String, Document>(); + + public SVGFigure() { + this.setLayoutManager(new XYLayout()); + } + + @Override + public int getSiriusAlpha() { + return viewpointAlpha; + } + + @Override + public boolean isTransparent() { + return transparent; + } + + @Override + public void setSiriusAlpha(int alpha) { + this.viewpointAlpha = alpha; + + } + + @Override + public void setTransparent(boolean transparent) { + this.transparent = transparent; + } + + @Override + public int getImageHeight() { + SimpleImageTranscoder transcoder = getTranscoder(); + int height = 0; + if (transcoder != null) { + int canvasHeight = transcoder.getCanvasHeight(); + if (canvasHeight == -1) { + height = transcoder.getBufferedImage().getHeight(); + } else { + height = canvasHeight; + } + } + return height; + } + + @Override + public int getImageWidth() { + SimpleImageTranscoder transcoder = getTranscoder(); + int width = 0; + if (transcoder != null) { + int canvasWidth = transcoder.getCanvasWidth(); + if (canvasWidth == -1) { + width = transcoder.getBufferedImage().getWidth(); + } else { + width = canvasWidth; + } + } + return width; + } + + @Override + public int getImageAlphaValue(int x, int y) { + SimpleImageTranscoder transcoder = getTranscoder(); + if (transcoder != null) { + BufferedImage bufferedImage = transcoder.getBufferedImage(); + if (bufferedImage != null && bufferedImage.getWidth() >= x && bufferedImage.getHeight() >= y) { + int[] result = bufferedImage.getAlphaRaster().getPixel(x, y, new int[1]); + return result[0]; + } + } + return 255; + } public final String getURI() { return uri; |
