From 683eba468b16f0a85ded546d1426125dcf1d47b0 Mon Sep 17 00:00:00 2001 From: kitfox Date: Wed, 10 Oct 2012 08:25:22 +0000 Subject: Creating wrapper Graphics when painting SVGIcon, SVGPanel. git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@131 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b --- .../java/com/kitfox/svg/app/beans/SVGIcon.java | 37 ++++++++++++++----- .../java/com/kitfox/svg/app/beans/SVGPanel.form | 6 ++- .../java/com/kitfox/svg/app/beans/SVGPanel.java | 43 +++++++++++++++------- 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/kitfox/svg/app/beans/SVGIcon.java b/src/main/java/com/kitfox/svg/app/beans/SVGIcon.java index acb5bb5..097df5d 100644 --- a/src/main/java/com/kitfox/svg/app/beans/SVGIcon.java +++ b/src/main/java/com/kitfox/svg/app/beans/SVGIcon.java @@ -6,13 +6,12 @@ package com.kitfox.svg.app.beans; -import javax.swing.*; +import com.kitfox.svg.*; import java.awt.*; import java.awt.geom.*; -import java.net.*; import java.beans.*; - -import com.kitfox.svg.*; +import java.net.*; +import javax.swing.*; /** * @@ -68,7 +67,10 @@ public class SVGIcon implements Icon } SVGDiagram diagram = svgUniverse.getDiagram(svgURI); - if (diagram == null) return 0; + if (diagram == null) + { + return 0; + } return (int)diagram.getHeight(); } @@ -83,7 +85,10 @@ public class SVGIcon implements Icon } SVGDiagram diagram = svgUniverse.getDiagram(svgURI); - if (diagram == null) return 0; + if (diagram == null) + { + return 0; + } return (int)diagram.getWidth(); } @@ -96,8 +101,14 @@ public class SVGIcon implements Icon */ public void paintIcon(Component comp, Graphics gg, int x, int y) { - Graphics2D g = (Graphics2D)gg; - + //Copy graphics object so that + Graphics2D g = (Graphics2D)gg.create(); + paintIcon(comp, g, x, y); + g.dispose(); + } + + private void paintIcon(Component comp, Graphics2D g, int x, int y) + { Object oldAliasHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); @@ -117,7 +128,10 @@ public class SVGIcon implements Icon SVGDiagram diagram = svgUniverse.getDiagram(svgURI); - if (diagram == null) return; + if (diagram == null) + { + return; + } g.translate(x, y); diagram.setIgnoringClipHeuristic(!clipToViewbox); @@ -188,7 +202,10 @@ public class SVGIcon implements Icon g.translate(-x, -y); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint); - if (oldInterpolationHint != null) g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolationHint); + if (oldInterpolationHint != null) + { + g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolationHint); + } } /** diff --git a/src/main/java/com/kitfox/svg/app/beans/SVGPanel.form b/src/main/java/com/kitfox/svg/app/beans/SVGPanel.form index b404a39..61a84d5 100644 --- a/src/main/java/com/kitfox/svg/app/beans/SVGPanel.form +++ b/src/main/java/com/kitfox/svg/app/beans/SVGPanel.form @@ -1,8 +1,12 @@ -