diff options
author | kitfox | 2012-10-10 10:25:22 +0200 |
---|---|---|
committer | kitfox | 2012-10-10 10:25:22 +0200 |
commit | 683eba468b16f0a85ded546d1426125dcf1d47b0 (patch) | |
tree | 9f3085482f832dc6fb558188f6035fab1ffba5b5 /src | |
parent | Fixing color parsing bug in gradients. (diff) | |
download | svg-salamander-core-683eba468b16f0a85ded546d1426125dcf1d47b0.tar.gz svg-salamander-core-683eba468b16f0a85ded546d1426125dcf1d47b0.tar.xz svg-salamander-core-683eba468b16f0a85ded546d1426125dcf1d47b0.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/kitfox/svg/app/beans/SVGIcon.java | 37 | ||||
-rw-r--r-- | src/main/java/com/kitfox/svg/app/beans/SVGPanel.form | 6 | ||||
-rw-r--r-- | src/main/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 @@ <?xml version="1.0" encoding="UTF-8" ?> -<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> +<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> <AuxValues> + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> diff --git a/src/main/java/com/kitfox/svg/app/beans/SVGPanel.java b/src/main/java/com/kitfox/svg/app/beans/SVGPanel.java index 396bd9b..a60be35 100644 --- a/src/main/java/com/kitfox/svg/app/beans/SVGPanel.java +++ b/src/main/java/com/kitfox/svg/app/beans/SVGPanel.java @@ -6,13 +6,11 @@ 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 javax.swing.*;
/**
*
@@ -41,35 +39,54 @@ public class SVGPanel extends JPanel public int getSVGHeight()
{
- if (scaleToFit) return getPreferredSize().height;
+ if (scaleToFit)
+ {
+ return getPreferredSize().height;
+ }
SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
- if (diagram == null) return 0;
+ if (diagram == null)
+ {
+ return 0;
+ }
return (int)diagram.getHeight();
}
public int getSVGWidth()
{
- if (scaleToFit) return getPreferredSize().width;
+ if (scaleToFit)
+ {
+ return getPreferredSize().width;
+ }
SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
- if (diagram == null) return 0;
+ if (diagram == null)
+ {
+ return 0;
+ }
return (int)diagram.getWidth();
}
-// Draw the icon at the specified location.
public void paintComponent(Graphics gg)
{
super.paintComponent(gg);
-
- Graphics2D g = (Graphics2D)gg;
-
+
+ Graphics2D g = (Graphics2D)gg.create();
+ paintComponent(g);
+ g.dispose();
+ }
+
+ private void paintComponent(Graphics2D g)
+ {
Object oldAliasHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
- if (diagram == null) return;
+ if (diagram == null)
+ {
+ return;
+ }
if (!scaleToFit)
{
|