Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: <mungady@us...> - 2012-07-02 05:13:17
|
Revision: 2472 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2472&view=rev Author: mungady Date: 2012-07-02 05:13:11 +0000 (Mon, 02 Jul 2012) Log Message: ----------- Replace code that doesn't compile with JDK1.4 Modified Paths: -------------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2012-07-01 16:28:03 UTC (rev 2471) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2012-07-02 05:13:11 UTC (rev 2472) @@ -404,13 +404,13 @@ /* * Buffered Images may have properties, but NEVER disclose them! * Nevertheless, just in case someone implements getPropertyNames() one day... - */ - Hashtable<String, Object> props = null; - - if (image.getPropertyNames() != null) { // ALWAYS null - props = new Hashtable<String, Object>(); - for (String s : image.getPropertyNames()) { - props.put(s, image.getProperty(s)); + */ + Hashtable props = null; + String[] propNames = image.getPropertyNames(); + if (propNames != null) { // ALWAYS null + props = new Hashtable(); + for (int i = 0; i < propNames.length; i++) { + props.put(propNames[i], image.getProperty(propNames[i])); } } return new BufferedImage(image.getColorModel(), ras, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mungady@us...> - 2012-07-02 05:13:17
|
Revision: 2472 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2472&view=rev Author: mungady Date: 2012-07-02 05:13:11 +0000 (Mon, 02 Jul 2012) Log Message: ----------- Replace code that doesn't compile with JDK1.4 Modified Paths: -------------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2012-07-01 16:28:03 UTC (rev 2471) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2012-07-02 05:13:11 UTC (rev 2472) @@ -404,13 +404,13 @@ /* * Buffered Images may have properties, but NEVER disclose them! * Nevertheless, just in case someone implements getPropertyNames() one day... - */ - Hashtable<String, Object> props = null; - - if (image.getPropertyNames() != null) { // ALWAYS null - props = new Hashtable<String, Object>(); - for (String s : image.getPropertyNames()) { - props.put(s, image.getProperty(s)); + */ + Hashtable props = null; + String[] propNames = image.getPropertyNames(); + if (propNames != null) { // ALWAYS null + props = new Hashtable(); + for (int i = 0; i < propNames.length; i++) { + props.put(propNames[i], image.getProperty(propNames[i])); } } return new BufferedImage(image.getColorModel(), ras, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mungady@us...> - 2012-10-22 05:32:49
|
Revision: 2522 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2522&view=rev Author: mungady Date: 2012-10-22 05:32:42 +0000 (Mon, 22 Oct 2012) Log Message: ----------- Use reflection in PaintAlpha to allow compilation in JDK 1.4 (from Dave Law) Modified Paths: -------------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2012-09-23 20:11:22 UTC (rev 2521) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2012-10-22 05:32:42 UTC (rev 2522) @@ -35,6 +35,8 @@ * Changes * ------- * 09-Mar-2011 : Written (DaveLaw) + * 03-Jul-2012 : JDK 1.6 References made reflective for JDK 1.3 compatibility ( + * DaveLaw) * */ @@ -42,13 +44,15 @@ import java.awt.Color; import java.awt.GradientPaint; -import java.awt.LinearGradientPaint; import java.awt.Paint; -import java.awt.RadialGradientPaint; import java.awt.TexturePaint; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; import java.awt.image.BufferedImage; import java.awt.image.IndexColorModel; import java.awt.image.WritableRaster; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.Hashtable; /** @@ -76,6 +80,10 @@ * @author DaveLaw */ public class PaintAlpha { + // TODO Revert to SVN revision 2469 in JFreeChart 1.0.16 + // (MultipleGradientPaint's / JDK issues) + // TODO THEN: change visibility of ALL darker(...) Methods EXCEPT + // darker(Paint) to private! /** * Multiplier for the <code>darker</code> Methods.<br> @@ -86,13 +94,13 @@ private static boolean legacyAlpha = false; /** - * Per default <code>PaintAlpha</code> will try to honour alpha-channel + * Per default <code>PaintAlpha</code> will try to honour alpha-channel * information. In the past this was not the case. - * If you wish legacy functionality for your application you can request + * If you wish legacy functionality for your application you can request * this here. - * + * * @param legacyAlpha boolean - * + * * @return the previous setting */ public static boolean setLegacyAlpha(boolean legacyAlpha) { @@ -125,11 +133,13 @@ if (paint instanceof GradientPaint) { return darker((GradientPaint) paint); } - if (paint instanceof LinearGradientPaint) { - return darker((LinearGradientPaint) paint); + if (paint.getClass().getName().equals("java.awt.LinearGradientPaint")) { + // TODO -> instanceof + return darkerLinearGradientPaint(paint); } - if (paint instanceof RadialGradientPaint) { - return darker((RadialGradientPaint) paint); + if (paint.getClass().getName().equals("java.awt.RadialGradientPaint")) { + // TODO -> instanceof + return darkerRadialGradientPaint(paint); } if (paint instanceof TexturePaint) { return darker((TexturePaint) paint, true); @@ -142,12 +152,12 @@ * <p> * The essential difference is that this method * maintains the alpha-channel unchanged<br> - * + * * @param paint a <code>Color</code> - * + * * @return a darker version of the <code>Color</code> */ - public static Color darker(Color paint) { + private static Color darker(Color paint) { return new Color( (int)(paint.getRed () * FACTOR), (int)(paint.getGreen() * FACTOR), @@ -156,12 +166,12 @@ /** * Create a new Gradient with its colours darkened. - * + * * @param paint a <code>GradientPaint</code> - * + * * @return a darker version of the <code>GradientPaint</code> */ - public static GradientPaint darker(GradientPaint paint) { + private static GradientPaint darker(GradientPaint paint) { return new GradientPaint( paint.getPoint1(), darker(paint.getColor1()), paint.getPoint2(), darker(paint.getColor2()), @@ -170,51 +180,124 @@ /** * Create a new Gradient with its colours darkened. - * + * * @param paint a <code>LinearGradientPaint</code> - * + * * @return a darker version of the <code>LinearGradientPaint</code> */ - public static LinearGradientPaint darker(LinearGradientPaint paint) { + private static final Paint darkerLinearGradientPaint(Paint paint) { + // TODO Rename->darker & change Paint->LinearGradientPaint + try { + final Color[] paintColours = (Color[]) invokeZeroArgumentMethod( + paint, "getColors"); - final Color[] paintColours = paint.getColors(); + for (int i = 0; i < paintColours.length; i++) { + paintColours[i] = darker(paintColours[i]); + } - for (int i = 0; i < paintColours.length; i++) { - paintColours[i] = darker(paintColours[i]); + final Constructor[] constructors + = paint.getClass().getConstructors(); + + for (int i = 0; i < constructors.length; i++) { + + final Class[] args = constructors[i].getParameterTypes(); + + if (args.length == 7 + && args[args.length-1].equals(AffineTransform.class)) { + + return (Paint) constructors[i].newInstance(new Object[] { + (Point2D) invokeZeroArgumentMethod(paint, "getStartPoint"), + (Point2D) invokeZeroArgumentMethod(paint, "getEndPoint"), + (float[]) invokeZeroArgumentMethod(paint, "getFractions"), + paintColours, + (Object) invokeZeroArgumentMethod(paint, "getCycleMethod"), + (Object) invokeZeroArgumentMethod(paint, "getColorSpace"), + (AffineTransform) invokeZeroArgumentMethod(paint, + "getTransform") }); + } + } + } catch (IllegalArgumentException e) { + } catch (SecurityException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } catch (NoSuchMethodException e) { + } catch (InstantiationException e) { } - - return new LinearGradientPaint(paint.getStartPoint(), - paint.getEndPoint(), - paint.getFractions(), - paintColours, - paint.getCycleMethod(), - paint.getColorSpace(), - paint.getTransform()); + throw new UnsupportedOperationException( + "Probably new Constructor signatures in newer JDK"); } /** * Create a new Gradient with its colours darkened. - * + * * @param paint a <code>RadialGradientPaint</code> - * + * * @return a darker version of the <code>RadialGradientPaint</code> */ - public static RadialGradientPaint darker(RadialGradientPaint paint) { + private static final Paint darkerRadialGradientPaint(Paint paint) { + // TODO Rename->darker & change Paint->RadialGradientPaint + try { + final Color[] paintColours + = (Color[]) invokeZeroArgumentMethod(paint, "getColors"); - final Color[] paintColours = paint.getColors(); + for (int i = 0; i < paintColours.length; i++) { + paintColours[i] = darker(paintColours[i]); + } - for (int i = 0; i < paintColours.length; i++) { - paintColours[i] = darker(paintColours[i]); + final Constructor[] constructors + = paint.getClass().getConstructors(); + + for (int i = 0; i < constructors.length; i++) { + + final Class[] args = constructors[i].getParameterTypes(); + + if ( args.length == 8 + && args[args.length-1].equals(AffineTransform.class)) { + + return (Paint) constructors[i].newInstance(new Object[] { + (Point2D) invokeZeroArgumentMethod(paint, "getCenterPoint"), + (Float) invokeZeroArgumentMethod(paint, "getRadius"), + (Point2D) invokeZeroArgumentMethod(paint, "getFocusPoint"), + (float[]) invokeZeroArgumentMethod(paint, "getFractions"), + paintColours, + (Object) invokeZeroArgumentMethod(paint, "getCycleMethod"), + (Object) invokeZeroArgumentMethod(paint, "getColorSpace"), + (AffineTransform) invokeZeroArgumentMethod(paint, + "getTransform") }); + } + } + } catch (IllegalArgumentException e) { + } catch (SecurityException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } catch (NoSuchMethodException e) { + } catch (InstantiationException e) { } + throw new UnsupportedOperationException( + "Probably new Constructor signatures in newer JDK"); + } - return new RadialGradientPaint(paint.getCenterPoint(), - paint.getRadius(), - paint.getFocusPoint(), - paint.getFractions(), - paintColours, - paint.getCycleMethod(), - paint.getColorSpace(), - paint.getTransform()); + /** + * Convenience method to invoke the zero argument <code>methodName</code> + * method of <code>object</code> via Reflection. + * + * @param object + * @param methodName + * + * @return the result + * + * @throws IllegalArgumentException + * @throws SecurityException + * @throws IllegalAccessException + * @throws InvocationTargetException + * @throws NoSuchMethodException + */ + private static final Object invokeZeroArgumentMethod(Object object, + String methodName) throws IllegalArgumentException, + SecurityException, IllegalAccessException, + InvocationTargetException, NoSuchMethodException { + return object.getClass().getMethod(methodName, + new Class[] {}).invoke(object, new Object[] {}); } /** @@ -222,24 +305,24 @@ * <p> * This entails cloning the underlying <code>BufferedImage</code>, * then darkening each colour-pixel individually! - * + * * @param paint a <code>TexturePaint</code> - * - * @param ignoreThisDummyArgument which is just to guarantee a unique + * + * @param ignoreThisDummyArgument which is just to guarantee a unique * method signature - * + * * @return a darker version of the <code>TexturePaint</code> */ - private static TexturePaint darker(TexturePaint paint, + private static TexturePaint darker(TexturePaint paint, boolean ignoreThisDummyArgument) { try { return darker(paint); } catch (Exception e) { /* - * Lots can go wrong while fiddling with Images, Colour Models - * & such! If anything at all goes awry, just return the original - * TexturePaint. (TexturePaint's are immutable anyway, so no harm + * Lots can go wrong while fiddling with Images, Colour Models + * & such! If anything at all goes awry, just return the original + * TexturePaint. (TexturePaint's are immutable anyway, so no harm * done) */ return paint; @@ -251,20 +334,22 @@ * <p> * This entails cloning the underlying <code>BufferedImage</code>, * then darkening each colour-pixel individually! - * + * * @param paint a <code>TexturePaint</code> - * + * * @return a darker version of the <code>TexturePaint</code> */ - public static TexturePaint darker(TexturePaint paint) { + private static TexturePaint darker(TexturePaint paint) { /** - * Colour Models with pre-multiplied Alpha tested OK without any + * Colour Models with pre-multiplied Alpha tested OK without any * special logic - * + * * BufferedImage.TYPE_INT_ARGB_PRE: // Type 03: tested OK 2011.02.27 * BufferedImage.TYPE_4BYTE_ABGR_PRE: // Type 07: tested OK 2011.02.27 */ - if (paint.getImage().getColorModel().isAlphaPremultiplied()) {/* Placeholder */} + if (paint.getImage().getColorModel().isAlphaPremultiplied()) { + /* Placeholder */ + } BufferedImage img = cloneImage(paint.getImage()); @@ -280,26 +365,26 @@ /* (pix-buffer is large enough for all pixels of one row) */ /** - * Indexed Colour Models (sort of a Palette) CANNOT be simply + * Indexed Colour Models (sort of a Palette) CANNOT be simply * multiplied (the pixel-value is just an index into the Palette). - * + * * Fortunately, IndexColorModel.getComponents(..) resolves the colours. * The resolved colours can then be multiplied by our FACTOR. * IndexColorModel.getDataElement(..) then tries to map the computed * colour to the "nearest" in the Palette. - * - * It is quite possible that the "nearest" colour is the ORIGINAL + * + * It is quite possible that the "nearest" colour is the ORIGINAL * colour! In the worst case, the returned Image will be identical to * the original. - * + * * Applies to following Image Types: - * + * * BufferedImage.TYPE_BYTE_BINARY: // Type 12: tested OK 2011.02.27 * BufferedImage.TYPE_BYTE_INDEXED: // Type 13: tested OK 2011.02.27 */ if (img.getColorModel() instanceof IndexColorModel) { - int[] nco = new int[4]; // RGB (+ optional Alpha which we leave + int[] nco = new int[4]; // RGB (+ optional Alpha which we leave // unchanged) for (int y = miY; y < maY; y++) { @@ -310,7 +395,7 @@ nco = img.getColorModel().getComponents(pix[p], nco, 0); nco[0] *= FACTOR; // Red nco[1] *= FACTOR; // Green - nco[2] *= FACTOR; // Blue. Now map computed colour to + nco[2] *= FACTOR; // Blue. Now map computed colour to // nearest in Palette... pix[p] = img.getColorModel().getDataElement(nco, 0); } @@ -328,7 +413,7 @@ */ if (img.getSampleModel().getNumBands() == 4) { /** - * The following Image Types have an Alpha-channel which we will + * The following Image Types have an Alpha-channel which we will * leave unchanged: * * BufferedImage.TYPE_INT_ARGB: // Type 02: tested OK 2011.02.27 @@ -363,7 +448,7 @@ /** * Above, we multiplied every pixel by our FACTOR because the * applicable Image Types consist only of colour or grey channels: - * + * * BufferedImage.TYPE_INT_RGB: // Type 01: tested OK 2011.02.27 * BufferedImage.TYPE_INT_BGR: // Type 04: tested OK 2011.02.27 * BufferedImage.TYPE_3BYTE_BGR: // Type 05: tested OK 2011.02.27 @@ -371,7 +456,7 @@ * BufferedImage.TYPE_USHORT_GRAY: // Type 11: tested OK 2011.02.27 * BufferedImage.TYPE_USHORT_565_RGB: // Type 08: tested OK 2011.02.27 * BufferedImage.TYPE_USHORT_555_RGB: // Type 09: tested OK 2011.02.27 - * + * * Note: as ras.getPixels(..) returned colours in the order R, G, B, A (optional) * for both TYPE_4BYTE_ABGR & TYPE_3BYTE_BGR, * it is assumed that TYPE_INT_BGR will behave similarly. @@ -382,17 +467,17 @@ /** * Clone a {@link BufferedImage}. * <p> - * Note: when constructing the clone, the original Colour Model Object is - * reused.<br> That keeps things simple & should not be a problem, as all + * Note: when constructing the clone, the original Colour Model Object is + * reused.<br> That keeps things simple & should not be a problem, as all * known Colour Models<br> * ({@link java.awt.image.IndexColorModel IndexColorModel}, * {@link java.awt.image.DirectColorModel DirectColorModel}, - * {@link java.awt.image.ComponentColorModel ComponentColorModel}) are + * {@link java.awt.image.ComponentColorModel ComponentColorModel}) are * immutable. - * + * * @param image original BufferedImage to clone - * - * @return a new BufferedImage reusing the original's Colour Model & + * + * @return a new BufferedImage reusing the original's Colour Model & * containing a clone of its pixels */ public static BufferedImage cloneImage(BufferedImage image) { @@ -403,8 +488,9 @@ /* * Buffered Images may have properties, but NEVER disclose them! - * Nevertheless, just in case someone implements getPropertyNames() one day... - */ + * Nevertheless, just in case someone implements getPropertyNames() + * one day... + */ Hashtable props = null; String[] propNames = image.getPropertyNames(); if (propNames != null) { // ALWAYS null @@ -412,8 +498,8 @@ for (int i = 0; i < propNames.length; i++) { props.put(propNames[i], image.getProperty(propNames[i])); } - } - return new BufferedImage(image.getColorModel(), ras, + } + return new BufferedImage(image.getColorModel(), ras, image.isAlphaPremultiplied(), props); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mungady@us...> - 2013-11-22 12:20:48
|
Revision: 2991 http://sourceforge.net/p/jfreechart/code/2991 Author: mungady Date: 2013-11-22 12:20:45 +0000 (Fri, 22 Nov 2013) Log Message: ----------- 2013-11-22 David Gilbert <david.gilbert@...> * org/jfree/chart/util/PaintAlpha.java (darker): Remove reflection code no longer required, (darkerLinearGradientPaint): Likewise, (darkerRadialGradientPaint): Likewise, (darkerTexturePaint): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2013-11-22 12:20:33 UTC (rev 2990) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2013-11-22 12:20:45 UTC (rev 2991) @@ -27,16 +27,17 @@ * --------------- * PaintAlpha.java * --------------- - * (C) Copyright 2011 by DaveLaw and Contributors. + * (C) Copyright 2011-2013 by DaveLaw and Contributors. * * Original Author: DaveLaw (dave ATT davelaw D0TT de); - * Contributor(s): could this be you?; + * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 09-Mar-2011 : Written (DaveLaw) - * 03-Jul-2012 : JDK 1.6 References made reflective for JDK 1.3 compatibility ( - * DaveLaw) + * 03-Jul-2012 : JDK 1.6 References made reflective for JDK 1.3 compatibility + * (DaveLaw); + * 16-Sep-2013 : Removed reflection since we are requiring JDK 1.6 now (DG) * */ @@ -44,15 +45,13 @@ import java.awt.Color; import java.awt.GradientPaint; +import java.awt.LinearGradientPaint; import java.awt.Paint; +import java.awt.RadialGradientPaint; import java.awt.TexturePaint; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; import java.awt.image.BufferedImage; import java.awt.image.IndexColorModel; import java.awt.image.WritableRaster; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.util.Hashtable; /** @@ -78,6 +77,8 @@ * method which is needed to darken objects of type {@link TexturePaint}. * * @author DaveLaw + * + * @since 1.0.15 */ public class PaintAlpha { // TODO Revert to SVN revision 2469 in JFreeChart 1.0.16 @@ -133,16 +134,25 @@ if (paint instanceof GradientPaint) { return darker((GradientPaint) paint); } - if (paint.getClass().getName().equals("java.awt.LinearGradientPaint")) { - // TODO -> instanceof - return darkerLinearGradientPaint(paint); + if (paint instanceof LinearGradientPaint) { + return darkerLinearGradientPaint((LinearGradientPaint) paint); } - if (paint.getClass().getName().equals("java.awt.RadialGradientPaint")) { - // TODO -> instanceof - return darkerRadialGradientPaint(paint); + if (paint instanceof RadialGradientPaint) { + return darkerRadialGradientPaint((RadialGradientPaint) paint); } if (paint instanceof TexturePaint) { - return darker((TexturePaint) paint, true); + try { + return darkerTexturePaint((TexturePaint) paint); + } + catch (Exception e) { + /* + * Lots can go wrong while fiddling with Images, Color Models + * & such! If anything at all goes awry, just return the original + * TexturePaint. (TexturePaint's are immutable anyway, so no harm + * done) + */ + return paint; + } } return paint; } @@ -165,9 +175,9 @@ } /** - * Create a new Gradient with its colours darkened. + * Create a new <code>GradientPaint</code> with its colors darkened. * - * @param paint a <code>GradientPaint</code> + * @param paint the gradient paint (<code>null</code> not permitted). * * @return a darker version of the <code>GradientPaint</code> */ @@ -185,46 +195,15 @@ * * @return a darker version of the <code>LinearGradientPaint</code> */ - private static final Paint darkerLinearGradientPaint(Paint paint) { - // TODO Rename->darker & change Paint->LinearGradientPaint - try { - final Color[] paintColours = (Color[]) invokeZeroArgumentMethod( - paint, "getColors"); - - for (int i = 0; i < paintColours.length; i++) { - paintColours[i] = darker(paintColours[i]); - } - - final Constructor[] constructors - = paint.getClass().getConstructors(); - - for (int i = 0; i < constructors.length; i++) { - - final Class[] args = constructors[i].getParameterTypes(); - - if (args.length == 7 - && args[args.length-1].equals(AffineTransform.class)) { - - return (Paint) constructors[i].newInstance(new Object[] { - (Point2D) invokeZeroArgumentMethod(paint, "getStartPoint"), - (Point2D) invokeZeroArgumentMethod(paint, "getEndPoint"), - (float[]) invokeZeroArgumentMethod(paint, "getFractions"), - paintColours, - (Object) invokeZeroArgumentMethod(paint, "getCycleMethod"), - (Object) invokeZeroArgumentMethod(paint, "getColorSpace"), - (AffineTransform) invokeZeroArgumentMethod(paint, - "getTransform") }); - } - } - } catch (IllegalArgumentException e) { - } catch (SecurityException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } catch (NoSuchMethodException e) { - } catch (InstantiationException e) { + private static Paint darkerLinearGradientPaint(LinearGradientPaint paint) { + final Color[] paintColors = paint.getColors(); + for (int i = 0; i < paintColors.length; i++) { + paintColors[i] = darker(paintColors[i]); } - throw new UnsupportedOperationException( - "Probably new Constructor signatures in newer JDK"); + return new LinearGradientPaint(paint.getStartPoint(), + paint.getEndPoint(), paint.getFractions(), paintColors, + paint.getCycleMethod(), paint.getColorSpace(), + paint.getTransform()); } /** @@ -234,114 +213,30 @@ * * @return a darker version of the <code>RadialGradientPaint</code> */ - private static final Paint darkerRadialGradientPaint(Paint paint) { - // TODO Rename->darker & change Paint->RadialGradientPaint - try { - final Color[] paintColours - = (Color[]) invokeZeroArgumentMethod(paint, "getColors"); - - for (int i = 0; i < paintColours.length; i++) { - paintColours[i] = darker(paintColours[i]); - } - - final Constructor[] constructors - = paint.getClass().getConstructors(); - - for (int i = 0; i < constructors.length; i++) { - - final Class[] args = constructors[i].getParameterTypes(); - - if ( args.length == 8 - && args[args.length-1].equals(AffineTransform.class)) { - - return (Paint) constructors[i].newInstance(new Object[] { - (Point2D) invokeZeroArgumentMethod(paint, "getCenterPoint"), - (Float) invokeZeroArgumentMethod(paint, "getRadius"), - (Point2D) invokeZeroArgumentMethod(paint, "getFocusPoint"), - (float[]) invokeZeroArgumentMethod(paint, "getFractions"), - paintColours, - (Object) invokeZeroArgumentMethod(paint, "getCycleMethod"), - (Object) invokeZeroArgumentMethod(paint, "getColorSpace"), - (AffineTransform) invokeZeroArgumentMethod(paint, - "getTransform") }); - } - } - } catch (IllegalArgumentException e) { - } catch (SecurityException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } catch (NoSuchMethodException e) { - } catch (InstantiationException e) { + private static Paint darkerRadialGradientPaint(RadialGradientPaint paint) { + final Color[] paintColors = paint.getColors(); + for (int i = 0; i < paintColors.length; i++) { + paintColors[i] = darker(paintColors[i]); } - throw new UnsupportedOperationException( - "Probably new Constructor signatures in newer JDK"); + return new RadialGradientPaint(paint.getCenterPoint(), + paint.getRadius(), paint.getFocusPoint(), + paint.getFractions(), paintColors, paint.getCycleMethod(), + paint.getColorSpace(), paint.getTransform()); } /** - * Convenience method to invoke the zero argument <code>methodName</code> - * method of <code>object</code> via Reflection. - * - * @param object - * @param methodName - * - * @return the result - * - * @throws IllegalArgumentException - * @throws SecurityException - * @throws IllegalAccessException - * @throws InvocationTargetException - * @throws NoSuchMethodException - */ - private static final Object invokeZeroArgumentMethod(Object object, - String methodName) throws IllegalArgumentException, - SecurityException, IllegalAccessException, - InvocationTargetException, NoSuchMethodException { - return object.getClass().getMethod(methodName, - new Class[] {}).invoke(object, new Object[] {}); - } - - /** - * Create a new <code>TexturePaint</code> with its colours darkened. + * Create a new <code>TexturePaint</code> with its colors darkened. * <p> * This entails cloning the underlying <code>BufferedImage</code>, - * then darkening each colour-pixel individually! + * then darkening each color-pixel individually! * * @param paint a <code>TexturePaint</code> * - * @param ignoreThisDummyArgument which is just to guarantee a unique - * method signature - * * @return a darker version of the <code>TexturePaint</code> */ - private static TexturePaint darker(TexturePaint paint, - boolean ignoreThisDummyArgument) { - try { - return darker(paint); - } - catch (Exception e) { - /* - * Lots can go wrong while fiddling with Images, Colour Models - * & such! If anything at all goes awry, just return the original - * TexturePaint. (TexturePaint's are immutable anyway, so no harm - * done) - */ - return paint; - } - } - - /** - * Create a new <code>TexturePaint</code> with its colours darkened. - * <p> - * This entails cloning the underlying <code>BufferedImage</code>, - * then darkening each colour-pixel individually! - * - * @param paint a <code>TexturePaint</code> - * - * @return a darker version of the <code>TexturePaint</code> - */ - private static TexturePaint darker(TexturePaint paint) { + private static TexturePaint darkerTexturePaint(TexturePaint paint) { /** - * Colour Models with pre-multiplied Alpha tested OK without any + * Color Models with pre-multiplied Alpha tested OK without any * special logic * * BufferedImage.TYPE_INT_ARGB_PRE: // Type 03: tested OK 2011.02.27 @@ -365,16 +260,16 @@ /* (pix-buffer is large enough for all pixels of one row) */ /** - * Indexed Colour Models (sort of a Palette) CANNOT be simply + * Indexed Color Models (sort of a Palette) CANNOT be simply * multiplied (the pixel-value is just an index into the Palette). * - * Fortunately, IndexColorModel.getComponents(..) resolves the colours. - * The resolved colours can then be multiplied by our FACTOR. + * Fortunately, IndexColorModel.getComponents(..) resolves the colors. + * The resolved colors can then be multiplied by our FACTOR. * IndexColorModel.getDataElement(..) then tries to map the computed - * colour to the "nearest" in the Palette. + * color to the "nearest" in the Palette. * - * It is quite possible that the "nearest" colour is the ORIGINAL - * colour! In the worst case, the returned Image will be identical to + * It is quite possible that the "nearest" color is the ORIGINAL + * color! In the worst case, the returned Image will be identical to * the original. * * Applies to following Image Types: @@ -407,7 +302,7 @@ } /** - * For the other 2 Colour Models, java.awt.image.ComponentColorModel and + * For the other 2 Color Models, java.awt.image.ComponentColorModel and * java.awt.image.DirectColorModel, the order of subpixels returned by * ras.getPixels(..) was observed to correspond to the following... */ @@ -447,7 +342,7 @@ return new TexturePaint(img, paint.getAnchorRect()); /** * Above, we multiplied every pixel by our FACTOR because the - * applicable Image Types consist only of colour or grey channels: + * applicable Image Types consist only of color or grey channels: * * BufferedImage.TYPE_INT_RGB: // Type 01: tested OK 2011.02.27 * BufferedImage.TYPE_INT_BGR: // Type 04: tested OK 2011.02.27 @@ -467,9 +362,9 @@ /** * Clone a {@link BufferedImage}. * <p> - * Note: when constructing the clone, the original Colour Model Object is + * Note: when constructing the clone, the original Color Model Object is * reused.<br> That keeps things simple & should not be a problem, as all - * known Colour Models<br> + * known Color Models<br> * ({@link java.awt.image.IndexColorModel IndexColorModel}, * {@link java.awt.image.DirectColorModel DirectColorModel}, * {@link java.awt.image.ComponentColorModel ComponentColorModel}) are @@ -477,7 +372,7 @@ * * @param image original BufferedImage to clone * - * @return a new BufferedImage reusing the original's Colour Model & + * @return a new BufferedImage reusing the original's Color Model & * containing a clone of its pixels */ public static BufferedImage cloneImage(BufferedImage image) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mungady@us...> - 2014-07-01 08:53:41
|
Revision: 3174 http://sourceforge.net/p/jfreechart/code/3174 Author: mungady Date: 2014-07-01 08:53:37 +0000 (Tue, 01 Jul 2014) Log Message: ----------- Fix Javadoc warnings. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2014-07-01 08:52:30 UTC (rev 3173) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/PaintAlpha.java 2014-07-01 08:53:37 UTC (rev 3174) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------------- * PaintAlpha.java * --------------- - * (C) Copyright 2011-2013 by DaveLaw and Contributors. + * (C) Copyright 2011-2014 by DaveLaw and Contributors. * * Original Author: DaveLaw (dave ATT davelaw D0TT de); * Contributor(s): David Gilbert (for Object Refinery Limited); @@ -363,7 +363,7 @@ * Clone a {@link BufferedImage}. * <p> * Note: when constructing the clone, the original Color Model Object is - * reused.<br> That keeps things simple & should not be a problem, as all + * reused.<br> That keeps things simple and should not be a problem, as all * known Color Models<br> * ({@link java.awt.image.IndexColorModel IndexColorModel}, * {@link java.awt.image.DirectColorModel DirectColorModel}, @@ -372,7 +372,7 @@ * * @param image original BufferedImage to clone * - * @return a new BufferedImage reusing the original's Color Model & + * @return a new BufferedImage reusing the original's Color Model and * containing a clone of its pixels */ public static BufferedImage cloneImage(BufferedImage image) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |